comparison orpg/tools/server_probe.py @ 0:4385a7d0efd1 grumpy-goblin

Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author sirebral
date Tue, 14 Jul 2009 16:41:58 -0500
parents
children dcae32e219f1
comparison
equal deleted inserted replaced
-1:000000000000 0:4385a7d0efd1
1 #!/usr/bin/env python
2
3 # Copyright (C) 2000-2001 The OpenRPG Project
4 #
5 # openrpg-dev@lists.sourceforge.net
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 # --
21 #
22 # File: server_probe.py
23 # Author: Chris Davis
24 # Maintainer:
25 # Version:
26 # $Id: server_probe.py,v 1.10 2006/11/04 21:24:22 digitalxero Exp $
27 #
28 # Description: This is a periodic maintenance script for removing
29 # Unresponsive servers from the meta list.
30 #
31
32 from threading import Event
33 from orpg.networking import mplay_client
34 from orpg.networking import meta_server_lib
35 import time
36
37
38
39 class server_probe:
40 def __init__(self):
41 self.evts = { }
42 self.evts['on_receive'] = self.on_receive
43 self.evts['on_mplay_event'] = self.on_mplay_event
44 self.evts['on_group_event'] = self.on_group_event
45 self.evts['on_player_event'] = self.on_player_event
46 self.evts['on_status_event'] = self.on_status_event
47 self.session = mplay_client.mplay_client("Server Probe",self.evts)
48 self.removed=0
49 self.ok =0
50 self.lock = Event()
51
52
53 def probe_servers(self):
54 names = []
55 addresses = []
56 node_list = None
57 try:
58 xml_dom = meta_server_lib.get_server_list();
59 node_list = xml_dom.getElementsByTagName('server')
60 for n in node_list:
61 address = n.getAttribute('address')
62 name = n.getAttribute( 'name' )
63 id = n.getAttribute('id')
64 if address not in addresses and name not in names:
65 names.append( name )
66 addresses.append( address )
67 self.probe_server(address,id)
68 else:
69 # If we are here, we found a duplicate
70 print "Duplicate entry, \"" + name + "\", is being removed."
71 self.removed = self.removed + 1
72 meta_server_lib.remove_server(id)
73
74 except:
75 print "An exception has occured. Attempting to ignore it..."
76
77 print "\n\nServers probe done "
78 if node_list != None:
79 print "Total Servers:" + str(len(node_list))
80 print "servers removed: " + str(self.removed)
81 print "servers ok: " + str(self.ok)
82
83
84 def probe_server(self,address,id):
85 print "trying server: " + address
86
87 if address == "asdfasdf": # replace with address of server to force from list
88 print "Forced removal of server!!!!!!!!!!"
89 meta_server_lib.remove_server(id)
90 else:
91 if self.session.connect(address):
92 self.lock.wait( timeout=20 )
93 self.session.start_disconnect()
94 while self.session.is_connected():
95 time.sleep( 1 )
96 self.session.check_my_status()
97 print "server: " + address + " ok\n"
98 self.ok = self.ok + 1
99 print "disconnected from valid server."
100 else:
101 print "**********>failed connnection!"
102 print "**********>removng server " + address + "\n"
103 self.removed = self.removed + 1
104 meta_server_lib.remove_server(id)
105 ## meta_server_lib.post_failed_connection( id )
106
107 while self.session.is_connected():
108 time.sleep(1)
109
110
111 def on_receive( self, evt, data ):
112 """Not used
113 """
114 self.lock.set()
115
116
117
118 def on_mplay_event( self, evt ):
119 """Not used
120 """
121 self.lock.set()
122
123
124
125 def on_group_event( self, evt ):
126 """Not used
127 """
128 self.lock.set()
129
130
131
132 def on_player_event( self, evt ):
133 """Disconnects from the server if a 'new player' event is generated.
134 """
135 self.lock.set()
136
137 def on_status_event( self, evt ):
138 """Not used
139 """
140 self.lock.set()
141
142
143
144
145 if __name__ == "__main__":
146 probe = server_probe()
147 probe.probe_servers()