Mercurial > traipse_dev
comparison orpg/networking/mplay_groups.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 | 449a8900f9ac |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 from orpg.mapper.map_msg import * | |
2 | |
3 class game_group: | |
4 def __init__( self, id, name, pwd, desc="", boot_pwd="", minVersion="", mapFile=None, messageFile=None, persist =0 ): | |
5 self.id = id | |
6 self.name = name | |
7 self.desc = desc | |
8 self.minVersion = minVersion | |
9 self.messageFile = messageFile | |
10 self.players = [] | |
11 self.pwd = pwd | |
12 self.boot_pwd = boot_pwd | |
13 self.game_map = map_msg() | |
14 self.lock = Lock() | |
15 self.moderated = 0 | |
16 self.voice = {} | |
17 self.persistant = persist | |
18 | |
19 if mapFile != None: | |
20 f = open( mapFile ) | |
21 tree = f.read() | |
22 f.close() | |
23 | |
24 else: | |
25 f = open(orpg.dirpath.dir_struct["template"] + "default_map.xml") | |
26 tree = f.read() | |
27 f.close() | |
28 | |
29 self.game_map.init_from_xml(tree) | |
30 | |
31 | |
32 def add_player(self,id): | |
33 self.players.append(id) | |
34 | |
35 def remove_player(self,id): | |
36 if self.voice.has_key(id): | |
37 del self.voice[id] | |
38 self.players.remove(id) | |
39 | |
40 def get_num_players(self): | |
41 num = len(self.players) | |
42 return num | |
43 | |
44 def get_player_ids(self): | |
45 tmp = self.players | |
46 return tmp | |
47 | |
48 | |
49 def check_pwd(self,pwd): | |
50 return (pwd==self.pwd) | |
51 | |
52 def check_boot_pwd(self,pwd): | |
53 return (pwd==self.boot_pwd) | |
54 | |
55 def check_version(self,ver): | |
56 if (self.minVersion == ""): | |
57 return 1 | |
58 minVersion=self.minVersion.split('.') | |
59 version=ver.split('.') | |
60 for i in range(min(len(minVersion),len(version))): | |
61 w=max(len(minVersion[i]),len(version[i])) | |
62 v1=minVersion[i].rjust(w); | |
63 v2=version[i].rjust(w); | |
64 if v1<v2: | |
65 return 1 | |
66 if v1>v2: | |
67 return 0 | |
68 | |
69 if len(minVersion)>len(version): | |
70 return 0 | |
71 return 1 | |
72 | |
73 #depreciated - see send_group_list() | |
74 def toxml(self,act="new"): | |
75 # Please don't add the boot_pwd to the xml, as this will give it away to players watching their console | |
76 xml_data = "<group id=\"" + self.id | |
77 xml_data += "\" name=\"" + self.name | |
78 xml_data += "\" pwd=\"" + str(self.pwd!="") | |
79 xml_data += "\" players=\"" + str(self.get_num_players()) | |
80 xml_data += "\" action=\"" + act + "\" />" | |
81 return xml_data |