client._pike
Go to the documentation of this file.
1 /* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
2  * Copyright (C) 2003-2010 Martin Baehr
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: debug.pike.in,v 1.1 2009/09/28 14:19:52 nicke Exp $
19  */
20 #include "/usr/local/lib/steam/server/include/classes.h"
21 class client {
22 public:
23 
24 
25 
26 
27 void ping()
28 {
29  call_out(ping, 60);
30  conn->send_command(14, 0);
31 }
32 
33 object conn;
34 
35 mapping options = ([ ]);
36 
37 mapping init(array argv)
38 {
39  mapping options = ([ ]);
40 
41  array opt=Getopt.find_all_options(argv,aggregate(
42  ({"host",Getopt.HAS_ARG,({"-h","--host"})}),
43  ({"user",Getopt.HAS_ARG,({"-u","--user"})}),
44  ({"port",Getopt.HAS_ARG,({"-p","--port"})}),
45  ));
46 
47  foreach(opt, array option)
48  {
49  options[option[0]]=option[1];
50  }
51  if(!options->host)
52  options->host="127.0.0.1";
53  if(!options->user)
54  options->user="root";
55  if(!options->port)
56  options->port=1900;
57  else
58  options->port=(int)options->port;
59 
60  string server_path = "/usr/local/lib/steam";
61 
62  master()->add_include_path(server_path+"/server/include");
63  master()->add_program_path(server_path+"/server/");
64  master()->add_program_path(server_path+"/conf/");
65  master()->add_program_path(server_path+"/spm/");
66  master()->add_program_path(server_path+"/server/net/coal/");
67 
68  conn = ((program)"client_base.pike")();
69 
70  int start_time = time();
71 
72  werror("Connecting to sTeam server...\n");
73  while ( !conn->connect_server(options->host, options->port) )
74  {
75  if ( time() - start_time > 120 )
76  {
77  throw (({" Couldn't connect to server. Please check steam.log for details! \n", backtrace()}));
78  }
79  werror("Failed to connect... still trying ... (server running ?)\n");
80  sleep(10);
81  }
82 
83  ping();
84  if(lower_case(options->user) == "guest")
85  return options;
86 
87  mixed err;
88  string pw;
89  int tries=3;
90  //readln->set_echo( 0 );
91  do
92  {
93  pw = Input.read_password( sprintf("Password for %s@%s", options->user,
94  options->host), "steam" );
95  //pw=readln->read(sprintf("passwd for %s@%s: ", options->user, options->host));
96  }
97  while((err = catch(conn->login(options->user, pw, 1))) && --tries);
98  //readln->set_echo( 1 );
99 
100  if ( err != 0 )
101  {
102  werror("Failed to log in!\nWrong Password!\n");
103  exit(1);
104  }
105  return options;
106 }
107 
108 
109 int main(int argc, array argv)
110 {
111  options=init(argv);
112  object _Server=conn->SteamObj(0);
113  return 1;
114 }
115 
116 
117 };