annotate orpg/networking/mplay_client.py @ 163:565ab3d84430 alpha

Traipse Alpha 'OpenRPG' {091202-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Keeping up with Beta) New Features: Added Bookmarks Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager New TrueDebug Class in orpg_log (See documentation for usage) Portable Mercurial Tip of the Day added, from Core and community New Reference Syntax added for custom PC sheets New Child Reference for gametree New Gametree Recursion method, mapping, context sensitivity, and effeciency.. New Features node with bonus nodes and Node Referencing help added Added 7th Sea die roller method; ie [7k3] = [7d10.takeHighest(3).open(10)] New 'Mythos' System die roller added Added new vs. die roller method for WoD; ie [3v3] = [3d10.vs(3)]. Includes support for Mythos roller. Fixes: Fix to Text based Server Fix to Remote Admin Commands Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Fix to Map from gametree not showing to all clients Fix to gametree about menus Fix to Password Manager check on startup Fix to PC Sheets from tool nodes. They now use the tabber_panel Fixed Whiteboard ID to prevent random line or text deleting. Modified ID's to prevent non updated clients from ruining the fix. default_manifest.xml renamed to default_upmana.xml Fix to Update Manager; cleaner clode for saved repositories Fixes made to Settings Panel and no reactive settings when Ok is pressed.
author sirebral
date Wed, 02 Dec 2009 21:20:44 -0600
parents 06f10429eedc
children b633f4c64aae 81d0bfd5e800
rev   line source
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
1 # Copyright (C) 2000-2001 The OpenRPG Project
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
2 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
3 # openrpg-dev@lists.sourceforge.net
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
4 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
5 # This program is free software; you can redistribute it and/or modify
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
6 # it under the terms of the GNU General Public License as published by
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
7 # the Free Software Foundation; either version 2 of the License, or
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
8 # (at your option) any later version.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
9 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
10 # This program is distributed in the hope that it will be useful,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
13 # GNU General Public License for more details.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
14 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
15 # You should have received a copy of the GNU General Public License
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
16 # along with this program; if not, write to the Free Software
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
18 # --
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
19 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
20 # File: mplay_client.py
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
21 # Author: Chris Davis
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
22 # Maintainer:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
23 # Version:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
24 # $Id: mplay_client.py,v 1.71 2007/05/12 20:41:54 digitalxero Exp $
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
25 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
26 # Description: This file contains the code for the client stubs of the multiplayer
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
27 # features in the orpg project.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
28 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
29
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
30 __version__ = "$Id: mplay_client.py,v 1.71 2007/05/12 20:41:54 digitalxero Exp $"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
31
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
32 ### Alpha ###
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
33 ##import orpg.minidom ## Deprecated. xml.parseXml calls minidom.parseString so it was superfluous and wasteful.
124
8827271fbe1b Traipse Alpha 'OpenRPG' {091001-01}
sirebral
parents: 122
diff changeset
34 import socket, Queue, thread, traceback, errno, os, time
8827271fbe1b Traipse Alpha 'OpenRPG' {091001-01}
sirebral
parents: 122
diff changeset
35
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
36 from threading import Event, Lock
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
37 from xml.sax.saxutils import escape
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
38 from struct import pack, unpack, calcsize
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
39 from string import *
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
40 from orpg.orpg_version import CLIENT_STRING, PROTOCOL_VERSION, VERSION
124
8827271fbe1b Traipse Alpha 'OpenRPG' {091001-01}
sirebral
parents: 122
diff changeset
41
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
42 from orpg.orpgCore import component
71
449a8900f9ac Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
sirebral
parents: 66
diff changeset
43 from orpg.orpg_xml import xml
124
8827271fbe1b Traipse Alpha 'OpenRPG' {091001-01}
sirebral
parents: 122
diff changeset
44 from orpg.tools.orpg_log import debug
145
067922263f07 Traipse Alpha 'OpenRPG' {091123-03}
sirebral
parents: 136
diff changeset
45 from orpg.tools.settings import settings
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
46
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
47 from xml.etree.ElementTree import ElementTree, Element, iselement
118
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 96
diff changeset
48 from xml.etree.ElementTree import fromstring, tostring
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
49 from xml.parsers.expat import ExpatError
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
50
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
51 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
52 import bz2
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
53 cmpBZ2 = True
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
54 except: cmpBZ2 = False
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
55
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
56 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
57 import zlib
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
58 cmpZLIB = True
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
59 except: cmpZLIB = False
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
60
124
8827271fbe1b Traipse Alpha 'OpenRPG' {091001-01}
sirebral
parents: 122
diff changeset
61 # Default, is configurable
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
62 OPENRPG_PORT = 9557
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
63
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
64 # We should be sending a length for each packet
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
65 MPLAY_LENSIZE = calcsize( 'i' )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
66 MPLAY_DISCONNECTED = 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
67 MPLAY_CONNECTED = 1
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
68 MPLAY_DISCONNECTING = 3
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
69 MPLAY_GROUP_CHANGE = 4
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
70 MPLAY_GROUP_CHANGE_F = 5
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
71 PLAYER_NEW = 1
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
72 PLAYER_DEL = 2
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
73 PLAYER_GROUP = 3
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
74
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
75 # The next two messages are used to inform others that a player is typing
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
76 PLAYER_TYPING = 4
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
77 PLAYER_NOT_TYPING = 5
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
78 PLAYER_UPDATE = 6
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
79 GROUP_JOIN = 1
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
80 GROUP_NEW = 2
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
81 GROUP_DEL = 3
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
82 GROUP_UPDATE = 4
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
83 STATUS_SET_URL = 1
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
84
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
85 def parseXml(data):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
86 "parse and return doc"
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
87 doc = xml.parseXml(data)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
88 doc.normalize()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
89 return doc
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
90
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
91 def myescape(data):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
92 return escape(data,{"\"":""})
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
93
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
94 class mplay_event:
124
8827271fbe1b Traipse Alpha 'OpenRPG' {091001-01}
sirebral
parents: 122
diff changeset
95 def __init__(self, id, data=None):
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
96 self.id = id
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
97 self.data = data
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
98
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
99 def get_id(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
100 return self.id
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
101
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
102 def get_data(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
103 return self.data
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
104
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
105 BOOT_MSG = "YoU ArE ThE WeAkEsT LiNk. GoOdByE."
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
106
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
107 class client_base:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
108 # Player role definitions
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
109 def __init__(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
110 self.outbox = Queue.Queue(0)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
111 self.inbox = Queue.Queue(0)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
112 self.startedEvent = Event()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
113 self.exitEvent = Event()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
114 self.sendThreadExitEvent = Event()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
115 self.recvThreadExitEvent = Event()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
116 self.id = "0"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
117 self.group_id = "0"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
118 self.name = ""
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
119 self.role = "GM"
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
120 ## Soon to be removed
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
121 self.ROLE_GM = "GM"
2
d5e81dac98ff Made some changes to the way the player list colors. Also fixed an annoyence with images
sirebral
parents: 0
diff changeset
122 self.ROLE_PLAYER = "Player"
d5e81dac98ff Made some changes to the way the player list colors. Also fixed an annoyence with images
sirebral
parents: 0
diff changeset
123 self.ROLE_LURKER = "Lurker"
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
124 ## --TaS
136
b4e02e8cd314 Traipse Alpha 'OpenRPG' {091016-00}
sirebral
parents: 128
diff changeset
125 try: self.ip = socket.gethostbyname(socket.gethostname())
b4e02e8cd314 Traipse Alpha 'OpenRPG' {091016-00}
sirebral
parents: 128
diff changeset
126 except: self.ip = socket.gethostbyname('localhost')
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
127 self.remote_ip = None
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
128 self.version = VERSION
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
129 self.protocol_version = PROTOCOL_VERSION
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
130 self.client_string = CLIENT_STRING
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
131 self.status = MPLAY_DISCONNECTED
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
132 self.useCompression = False
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
133 self.compressionType = 'Undefined'
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
134 self.log_console = None
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
135 self.sock = None
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
136 self.text_status = "Idle"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
137 self.statLock = Lock()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
138 self.useroles = 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
139 self.lastmessagetime = time.time()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
140 self.connecttime = time.time()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
141
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
142 def sendThread( self, arg ):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
143 "Sending thread. This thread reads from the data queue and writes to the socket."
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
144
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
145 # Wait to be told it's okay to start running
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
146 self.startedEvent.wait()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
147
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
148 # Loop as long as we have a connection
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
149 while( self.get_status() == MPLAY_CONNECTED ):
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
150 try: readMsg = self.outbox.get(block=1)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
151 except Exception, text:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
152 self.log_msg( ("outbox.get() got an exception: ", text) )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
153
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
154 # If we are here, it's because we have data to send, no doubt!
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
155 if self.status == MPLAY_CONNECTED:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
156 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
157 # Send the entire message, properly formated/encoded
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
158 sent = self.sendMsg( self.sock, readMsg )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
159 except Exception, e:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
160 self.log_msg( e )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
161 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
162 # If we are not connected, purge the data queue
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
163 self.log_msg( "Data queued without a connection, purging data from queue..." )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
164 self.sendThreadExitEvent.set()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
165 self.log_msg( "sendThread has terminated..." )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
166
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
167 def recvThread( self, arg ):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
168 "Receiving thread. This thread reads from the socket and writes to the data queue."
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
169 # Wait to be told it's okay to start running
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
170 self.startedEvent.wait()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
171
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
172 while( self.get_status() == MPLAY_CONNECTED ):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
173 readMsg = self.recvMsg( self.sock )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
174 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
175 if self.useCompression and self.compressionType != None:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
176 readMsg = self.compressionType.decompress(readMsg)
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
177 except: pass
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
178
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
179 # Check the length of the message
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
180 bytes = len( readMsg )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
181
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
182 # Make sure we are still connected
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
183 if bytes == 0: break
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
184 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
185 # Pass along the message so it can be processed
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
186 self.inbox.put( readMsg )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
187 self.update_idle_time() #update the last message time
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
188 if bytes == 0:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
189 self.log_msg( "Remote has disconnected!" )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
190 self.set_status( MPLAY_DISCONNECTING )
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
191 self.outbox.put("") # Make sure the other thread is woken up!
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
192 self.sendThreadExitEvent.set()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
193 self.log_msg( "recvThread has terminated..." )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
194
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
195 def sendMsg( self, sock, msg ):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
196 """Very simple function that will properly encode and send a message to te
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
197 remote on the specified socket."""
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
198 if self.useCompression and self.compressionType != None:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
199 mpacket = self.compressionType.compress(msg)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
200 lpacket = pack('!i', len(mpacket))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
201 sock.send(lpacket)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
202 offset = 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
203 while offset < len(mpacket):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
204 slice = buffer(mpacket, offset, len(mpacket)-offset)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
205 sent = sock.send(slice)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
206 offset += sent
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
207 sentm = offset
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
208 else:
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
209 length = len(msg) # Calculate our message length
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
210 lp = pack('!i', length) # Encode the message length into network byte order
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
211 try:
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
212 sentl = sock.send( lp ) # Send the encoded length
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
213 # Now, send the message the the length was describing
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
214 sentm = sock.send( msg )
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
215 if self.isServer(): self.log_msg(("data_sent", sentl+sentm))
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
216 except socket.error, e: self.log_msg( e )
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
217 except Exception, e: self.log_msg( e )
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
218 return sentm
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
219
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
220 def recvData( self, sock, readSize ):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
221 """Simple socket receive method. This method will only return when the exact
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
222 byte count has been read from the connection, if remote terminates our
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
223 connection or we get some other socket exception."""
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
224 data = ""
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
225 offset = 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
226 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
227 while offset != readSize:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
228 frag = sock.recv( readSize - offset )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
229 # See if we've been disconnected
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
230 rs = len( frag )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
231 if rs <= 0:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
232 # Loudly raise an exception because we've been disconnected!
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
233 raise IOError, "Remote closed the connection!"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
234 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
235 # Continue to build complete message
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
236 offset += rs
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
237 data += frag
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
238 except socket.error, e:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
239 self.log_msg( e )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
240 data = ""
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
241 return data
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
242
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
243 def recvMsg(self, sock):
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
244 """This method now expects to receive a message having a 4-byte prefix length. It will ONLY read completed messages. In the event that the remote's connection is terminated, it will throw an exception which should allow for the caller to more gracefully handle this exception event.
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
245
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
246 Because we use strictly reading ONLY based on the length that is told to use, we no longer have to worry about partially adjusting for fragmented buffers starting somewhere within a buffer that we've read. Rather, it will get ONLY a whole message and nothing more. Everything else will remain buffered with the OS until we attempt to read the next complete message."""
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
247 msgData = ""
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
248 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
249 lenData = self.recvData( sock, MPLAY_LENSIZE )
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
250 (length,) = unpack('!i', lenData) # Now, convert to a usable form
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
251 msgData = self.recvData( sock, length ) # Read exactly the remaining amount of data
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
252 if self.isServer():
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
253 self.log_msg(("data_recv", length+4))
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
254 if self.remote_ip is None: # Make the peer IP address available for reference later
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
255 self.remote_ip = self.sock.getpeername()
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
256 except IOError, e: self.log_msg( e )
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
257 except Exception, e: self.log_msg( e )
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
258 return msgData
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
259
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
260 def initialize_threads(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
261 "Starts up our threads (2) and waits for them to make sure they are running!"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
262 self.status = MPLAY_CONNECTED
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
263 self.sock.setblocking(1)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
264 # Confirm that our threads have started
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
265 thread.start_new_thread( self.sendThread,(0,))
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
266 thread.start_new_thread( self.recvThread,(0,))
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
267 self.startedEvent.set()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
268
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
269 def disconnect(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
270 self.set_status(MPLAY_DISCONNECTING)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
271 self.log_msg("client stub " + self.ip +" disconnecting...")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
272 self.log_msg("closing sockets...")
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
273 try: self.sock.shutdown(2)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
274 except Exception, e:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
275 print "Caught exception: " + str(e)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
276 print
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
277 print "Continuing"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
278 self.set_status(MPLAY_DISCONNECTED)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
279
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
280 def reset(self,sock):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
281 self.disconnect()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
282 self.sock = sock
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
283 self.initialize_threads()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
284
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
285 def update_role(self,role):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
286 self.useroles = 1
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
287 self.role = role
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
288
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
289 def use_roles(self):
124
8827271fbe1b Traipse Alpha 'OpenRPG' {091001-01}
sirebral
parents: 122
diff changeset
290 if self.useroles: return 1
8827271fbe1b Traipse Alpha 'OpenRPG' {091001-01}
sirebral
parents: 122
diff changeset
291 else: return 0
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 145
diff changeset
292
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
293 def update_self_from_player(self, player):
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
294 try: (self.name, self.ip, self.id,
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
295 self.text_status, self.version,
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
296 self.protocol_version, self.client_string, role) = player
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
297 except Exception, e:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
298 print e
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
299 """
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
300 The IP field should really be deprecated as too many systems are NAT'd and/or behind firewalls for a
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
301 client provided IP address to have much value. As such, we now label it as deprecated.
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
302 """
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
303 def toxml(self, action):
118
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 96
diff changeset
304 el = Element('player')
124
8827271fbe1b Traipse Alpha 'OpenRPG' {091001-01}
sirebral
parents: 122
diff changeset
305 el.set('name', self.name)
118
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 96
diff changeset
306 el.set('action', action)
124
8827271fbe1b Traipse Alpha 'OpenRPG' {091001-01}
sirebral
parents: 122
diff changeset
307 el.set('role', self.role)
118
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 96
diff changeset
308 el.set('id', self.id)
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 96
diff changeset
309 el.set('group_id', self.group_id)
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 96
diff changeset
310 el.set('ip', self.ip)
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 96
diff changeset
311 el.set('status', self.text_status)
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 96
diff changeset
312 el.set('version', self.version)
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 96
diff changeset
313 el.set('protocol_version', self.protocol_version)
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 96
diff changeset
314 el.set('client_string', self.client_string)
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 96
diff changeset
315 el.set('useCompression', str(self.useCompression))
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 96
diff changeset
316 cmpType = 'None'
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 145
diff changeset
317 if cmpBZ2 and (self.compressionType == 'Undefined' or self.compressionType == bz2): cmpType = 'bz2'
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 145
diff changeset
318 elif cmpZLIB and (self.compressionType == 'Undefined' or self.compressionType == zlib): cmpType = 'zlib'
118
217fb049bd00 Traipse Alpha 'OpenRPG' {091028-00}
sirebral
parents: 96
diff changeset
319 el.set('cmpType', cmpType)
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
320 return tostring(el)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
321
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
322 def log_msg(self,msg):
124
8827271fbe1b Traipse Alpha 'OpenRPG' {091001-01}
sirebral
parents: 122
diff changeset
323 if self.log_console: self.log_console(msg)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
324
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
325 def get_status(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
326 self.statLock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
327 status = self.status
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
328 self.statLock.release()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
329 return status
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
330
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
331 def my_role(self):
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
332 return self.role
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
333
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
334 def set_status(self,status):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
335 self.statLock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
336 self.status = status
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
337 self.statLock.release()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
338
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
339 def isServer( self ):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
340 # Return 1 if we are running as a server, else, return 0.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
341 # This method must be overloaded by whomever derives from us
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
342 pass
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
343
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
344 def __str__(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
345 return "%s(%s)\nIP:%s\ngroup_id:%s\n" % (self.name, self.id, self.ip, self.group_id)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
346
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
347 # idle time functions added by snowdog 3/31/04
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
348 def update_idle_time(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
349 self.lastmessagetime = time.time()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
350
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
351 def idle_time(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
352 curtime = time.time()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
353 idletime = curtime - self.lastmessagetime
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
354 return idletime
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
355
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
356 def idle_status(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
357 idletime = self.idle_time()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
358 idlemins = idletime / 60
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
359 status = "Unknown"
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
360 if idlemins < 3: status = "Active"
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
361 elif idlemins < 10: status = "Idle ("+str(int(idlemins))+" mins)"
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
362 else: status = "Inactive ("+str(int(idlemins))+" mins)"
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
363 return status
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
364
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
365 def connected_time(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
366 curtime = time.time()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
367 timeoffset = curtime - self.connecttime
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
368 return timeoffset
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
369
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
370 def connected_time_string(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
371 "returns the time client has been connected as a formated time string"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
372 ct = self.connected_time()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
373 d = int(ct/86400)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
374 h = int( (ct-(86400*d))/3600 )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
375 m = int( (ct-(86400*d)-(3600*h))/60)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
376 s = int( (ct-(86400*d)-(3600*h)-(60*m)) )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
377 cts = zfill(d,2)+":"+zfill(h,2)+":"+zfill(m,2)+":"+zfill(s,2)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
378 return cts
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
379
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
380 #========================================================================
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
381 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
382 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
383 # MPLAY CLIENT
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
384 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
385 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
386 #========================================================================
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
387 class mplay_client(client_base):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
388 "mplay client"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
389 def __init__(self,name,callbacks):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
390 client_base.__init__(self)
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
391 component.add('mp_client', self)
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
392 self.xml = component.get('xml')
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
393 self.set_name(name)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
394 self.on_receive = callbacks['on_receive']
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
395 self.on_mplay_event = callbacks['on_mplay_event']
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
396 self.on_group_event = callbacks['on_group_event']
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
397 self.on_player_event = callbacks['on_player_event']
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
398 self.on_status_event = callbacks['on_status_event']
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
399 self.on_password_signal = callbacks['on_password_signal']
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
400 # I know this is a bad thing to do but it has to be
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
401 # be done to use the unified password manager.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
402 # Should really find a better solution. -- SD 8/03
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
403 self.orpgFrame_callback = callbacks['orpgFrame']
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
404 self.ignore_id = []
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
405 self.ignore_name = []
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
406 self.players = {}
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
407 self.groups = {}
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
408 self.unique_cookie = 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
409 self.msg_handlers = {}
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
410 self.core_msg_handlers = []
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
411 self.load_core_msg_handlers()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
412
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
413 # implement from our base class
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
414 def isServer(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
415 return 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
416
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
417 def get_chat(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
418 return self.orpgFrame_callback.chat
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
419
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
420 def set_name(self,name):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
421 self.name = name
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
422 self.update()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
423
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
424 def set_text_status(self, status):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
425 if self.text_status != status:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
426 self.text_status = status
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
427 self.update()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
428
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
429 def set_status_url(self, url="None"):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
430 self.on_status_event(mplay_event(STATUS_SET_URL,url))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
431
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
432 def update(self, evt=None):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
433 if self.status == MPLAY_CONNECTED:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
434 self.outbox.put(self.toxml('update'))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
435 self.inbox.put(self.toxml('update'))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
436
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
437 def get_group_info(self, id=0):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
438 self.statLock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
439 id = self.groups[id]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
440 self.statLock.release()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
441 return id
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
442
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
443 def get_my_group(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
444 self.statLock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
445 id = self.groups[self.group_id]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
446 self.statLock.release()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
447 return id
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
448
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
449 def get_groups(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
450 self.statLock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
451 groups = self.groups.values()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
452 self.statLock.release()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
453 return groups
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
454
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
455 def get_players(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
456 self.statLock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
457 players = self.players.values()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
458 self.statLock.release()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
459 return players
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
460
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
461 def get_player_info(self,id):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
462 self.statLock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
463 player = self.players[id]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
464 self.statLock.release()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
465 return player
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
466
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
467 def get_player_by_player_id(self,player):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
468 players = self.get_players()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
469 if self.players.has_key(player):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
470 for m in players:
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
471 if player == m[2]: return m
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
472 return -1
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
473
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
474 def get_id(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
475 return self.id
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
476
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
477 def get_my_info(self):
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
478 return (self.name, self.ip, self.id,
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
479 self.text_status, self.version,
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
480 self.protocol_version, self.client_string,
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
481 self.role)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
482
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
483 def is_valid_id(self,id):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
484 self.statLock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
485 value = self.players.has_key( id )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
486 self.statLock.release()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
487 return value
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
488
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
489 def clear_players(self,save_self=0):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
490 self.statLock.acquire()
90
d1aff41c031b Traipse Alpha 'OpenRPG' {090919-00}
sirebral
parents: 88
diff changeset
491 keys = self.players.keys()
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
492 for k in keys: del self.players[k]
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
493 self.statLock.release()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
494
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
495 def clear_groups(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
496 self.statLock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
497 keys = self.groups.keys()
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
498 for k in keys: del self.groups[k]
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
499 self.statLock.release()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
500
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
501 def find_role(self,id):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
502 return self.players[id].role
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
503
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
504 def get_ignore_list(self):
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
505 try: return (self.ignore_id, self.ignore_name)
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
506 except: return (None, None)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
507
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
508 def toggle_ignore(self, id):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
509 for m in self.ignore_id:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
510 if `self.ignore_id[self.ignore_id.index(m)]` == `id`:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
511 name = self.ignore_name[self.ignore_id.index(m)]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
512 self.ignore_id.remove(m)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
513 self.ignore_name.remove(name)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
514 return (0,id,name)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
515 self.ignore_name.append(self.players[id][0])
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
516 self.ignore_id.append(self.players[id][2])
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
517 return (1, self.players[id][2], self.players[id][0])
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
518
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
519 def boot_player(self,id,boot_pwd = ""):
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
520 el = Element('boot')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
521 el.set('boot_pwd', boot_pwd)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
522 self.send(tostring(el), id)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
523
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
524 def set_room_pass(self, npwd, pwd=""):
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
525 el = Element('alter')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
526 el.set('key', 'pwd')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
527 el.set('val', npwd)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
528 el.set('bpw', pwd)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
529 el.set('plr', self.id)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
530 el.set('gid', self.group_id)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
531 self.outbox.put(tostring(el))
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
532 self.update()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
533
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
534 def set_room_name(self, name, pwd=""):
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
535 loc = name.find("&")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
536 oldloc=0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
537 while loc > -1:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
538 loc = name.find("&",oldloc)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
539 if loc > -1:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
540 b = name[:loc]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
541 e = name[loc+1:]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
542 name = b + "&amp;" + e
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
543 oldloc = loc+1
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
544 loc = name.find('"')
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
545 oldloc=0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
546 while loc > -1:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
547 loc = name.find('"',oldloc)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
548 if loc > -1:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
549 b = name[:loc]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
550 e = name[loc+1:]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
551 name = b + "&quot;" + e
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
552 oldloc = loc+1
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
553 loc = name.find("'")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
554 oldloc=0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
555 while loc > -1:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
556 loc = name.find("'",oldloc)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
557 if loc > -1:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
558 b = name[:loc]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
559 e = name[loc+1:]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
560 name = b + "&#39;" + e
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
561 oldloc = loc+1
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
562 el = Element('alter')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
563 el.set('key', 'pwd')
128
fba298d65cf8 Traipse Alpha 'OpenRPG' {091003-00}
sirebral
parents: 124
diff changeset
564 #el.set('val', npwd)
fba298d65cf8 Traipse Alpha 'OpenRPG' {091003-00}
sirebral
parents: 124
diff changeset
565 el.set('bpw', str(pwd))
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
566 el.set('plr', self.id)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
567 el.set('gid', self.group_id)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
568 self.outbox.put(tostring(el))
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
569 self.update()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
570
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
571 def display_roles(self):
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
572 el = Element('role')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
573 el.set('action', 'display')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
574 el.set('player', self.id)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
575 el.set('group_id', self.group_id)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
576 self.outbox.put(tostring(el))
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
577
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
578 def get_role(self):
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
579 el = Element('role')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
580 el.set('action', 'get')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
581 el.set('player', self.id)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
582 el.set('group_id', self.group_id)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
583 self.outbox.put(tostring(el))
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
584
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
585 def set_role(self, player, role, pwd=""):
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
586 el = Element('role')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
587 el.set('action', 'set')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
588 el.set('player', player)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
589 el.set('role', role)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
590 el.set('boot_pwd', pwd)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
591 el.set('group_id', self.group_id)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
592 self.outbox.put(tostring(el))
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
593 self.update()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
594
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
595 def send(self, msg, player="all"):
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
596 if self.status == MPLAY_CONNECTED and player != self.id:
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
597 ### Pre Alpha ###
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
598 #el = Element('msg')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
599 #el.set('to', player)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
600 #el.set('from', self.id)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
601 #el.set('group_id', self.group_id)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
602 #el.append(fromstring(msg))
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
603 #self.outbox.put(tostring(el))
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
604 ### Current chat is not ready for Element Tree ###
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
605 self.outbox.put("<msg to='"+player+"' from='"+self.id+"' group_id='"+self.group_id+"' />"+msg)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
606 self.check_my_status()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
607
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
608 def send_sound(self, snd_xml):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
609 if self.status == MPLAY_CONNECTED:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
610 self.outbox.put(snd_xml)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
611 self.check_my_status()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
612
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
613 def send_create_group(self, name, pwd, boot_pwd, min_version):
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
614 el = Element('create_group')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
615 el.set('from', self.id)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
616 el.set('pwd', pwd)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
617 el.set('name', name)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
618 el.set('boot_pwd', boot_pwd)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
619 el.set('min_version', min_version)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
620 self.outbox.put(tostring(el))
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
621
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
622 def send_join_group(self, group_id, pwd):
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
623 if (group_id != 0): self.update_role("Lurker")
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
624 el = Element('join_group')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
625 el.set('from', self.id)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
626 el.set('pwd', pwd)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
627 el.set('group_id', str(group_id))
124
8827271fbe1b Traipse Alpha 'OpenRPG' {091001-01}
sirebral
parents: 122
diff changeset
628
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
629 self.outbox.put(tostring(el))
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
630
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
631 def poll(self, evt=None):
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
632 try: msg = self.inbox.get_nowait()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
633 except:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
634 if self.get_status() != MPLAY_CONNECTED:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
635 self.check_my_status()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
636 else:
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
637 try: self.pretranslate(msg)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
638 except Exception, e:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
639 print "The following message: " + str(msg)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
640 print "created the following exception: "
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
641 traceback.print_exc()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
642
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
643 def add_msg_handler(self, tag, function, core=False):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
644 if not self.msg_handlers.has_key(tag):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
645 self.msg_handlers[tag] = function
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
646 if core: self.core_msg_handlers.append(tag)
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
647 else: print 'XML Messages ' + tag + ' already has a handler'
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
648
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
649 def remove_msg_handler(self, tag):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
650 if self.msg_handlers.has_key(tag) and not tag in self.core_msg_handlers:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
651 del self.msg_handlers[tag]
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
652 else: print 'XML Messages ' + tag + ' already deleted'
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
653
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
654 def load_core_msg_handlers(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
655 self.add_msg_handler('msg', self.on_msg, True)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
656 self.add_msg_handler('ping', self.on_ping, True)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
657 self.add_msg_handler('group', self.on_group, True)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
658 self.add_msg_handler('role', self.on_role, True)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
659 self.add_msg_handler('player', self.on_player, True)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
660 self.add_msg_handler('password', self.on_password, True)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
661 self.add_msg_handler('sound', self.on_sound, True)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
662
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
663 def pretranslate(self, data):
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
664 # Pre-qualify our data. If we don't have atleast 5-bytes, then there is
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
665 # no way we even have a valid message!
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
666 if len(data) < 5: return
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
667 try: el = fromstring(data)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
668 except ExpatError:
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
669 end = data.find(">")
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
670 head = data[:end+1]
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
671 msg = data[end+1:]
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 145
diff changeset
672 ### This if statement should help close invalid messages. ###
128
fba298d65cf8 Traipse Alpha 'OpenRPG' {091003-00}
sirebral
parents: 124
diff changeset
673 if head[end:] != '/':
fba298d65cf8 Traipse Alpha 'OpenRPG' {091003-00}
sirebral
parents: 124
diff changeset
674 if head[end:] != '>': head = head[:end] + '/>'
fba298d65cf8 Traipse Alpha 'OpenRPG' {091003-00}
sirebral
parents: 124
diff changeset
675 try: el = fromstring(head)
fba298d65cf8 Traipse Alpha 'OpenRPG' {091003-00}
sirebral
parents: 124
diff changeset
676 except: el = fromstring(head[:end] +'/>')
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 145
diff changeset
677 ###########
128
fba298d65cf8 Traipse Alpha 'OpenRPG' {091003-00}
sirebral
parents: 124
diff changeset
678
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
679 try:
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
680 el1 = fromstring(msg)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
681 el.append(el1)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
682 except ExpatError:
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
683 el.text = msg
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
684 id = el.get('from') or el.get('id')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
685 if el.tag in self.msg_handlers: self.msg_handlers[el.tag](id, data, el)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
686
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
687 def on_sound(self, id, data, etreeEl):
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
688 (ignore_id,ignore_name) = self.get_ignore_list()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
689 for m in ignore_id:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
690 if m == id:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
691 # yes we are
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
692 print "ignoring sound from player:"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
693 return
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
694 chat = self.get_chat()
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
695 chat.sound_player.play(etreeEl.get('url'), 'remote', etreeEl.get('loop'))
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
696
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
697 def on_msg(self, id, data, etreeEl):
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
698 end = data.find(">")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
699 head = data[:end+1]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
700 msg = data[end+1:]
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
701 if msg[-6:] == '</msg>': msg = msg[:-6]
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
702 if id == "0": self.on_receive(msg, None)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
703 # None get's interpreted in on_receive as the sys admin.
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
704 # Doing it this way makes it harder to impersonate the admin
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
705 elif self.is_valid_id(id): self.on_receive(msg, self.players[id])
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
706
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
707 def on_ping(self, id, msg, etreeEl):
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 145
diff changeset
708 # A REAL ping time implementation by Snowdog 8/03
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
709 # recieves special server <ping time="###" /> command
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
710 # where ### is a returning time from the clients ping command
151
06f10429eedc Traipse Alpha 'OpenRPG' {091125-00}
sirebral
parents: 145
diff changeset
711 # get current time, pull old time from object and compare them
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
712 # the difference is the latency between server and client * 2
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
713 ct = time.clock()
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
714 ot = etreeEl.get("time")
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
715 latency = float(float(ct) - float(ot))
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
716 latency = int(latency * 10000.0)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
717 latency = float(latency) / 10.0
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
718 ping_msg = "Ping Results: " + str(latency) + " ms (parsed message, round trip)"
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
719 self.on_receive(ping_msg, None)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
720
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
721 def on_group(self, id, msg, etreeEl):
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
722 act = etreeEl.get("action")
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
723 group_data = (id, etreeEl.get("name"), etreeEl.get("pwd"), etreeEl.get("players"))
136
b4e02e8cd314 Traipse Alpha 'OpenRPG' {091016-00}
sirebral
parents: 128
diff changeset
724 if act == 'new' or act == 'update':
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
725 self.groups[id] = group_data
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
726 if act == 'update': self.on_group_event(mplay_event(GROUP_UPDATE, group_data))
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
727 elif act == 'new': self.on_group_event(mplay_event(GROUP_NEW, group_data))
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
728 elif act == 'del':
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
729 del self.groups[id]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
730 self.on_group_event(mplay_event(GROUP_DEL, group_data))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
731
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
732 def on_role(self, id, msg, etreeEl):
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
733 act = etreeEl.get("action")
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
734 if (act == "set") or (act == "update"):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
735 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
736 (a,b,c,d,e,f,g,h) = self.players[id]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
737 if id == self.id:
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
738 self.players[id] = (a,b,c,d,e,f,g,etreeEl.get("role"))
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
739 self.update_role(etreeEl.get("role"))
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
740 else: self.players[id] = (a,b,c,d,e,f,g,etreeEl.get("role"))
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
741 self.on_player_event(mplay_event(PLAYER_UPDATE, self.players[id]))
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
742 except: pass
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
743
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
744 def on_player(self, id, msg, etreeEl):
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
745 act = etreeEl.get("action")
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
746 try: player = (etreeEl.get("name"), etreeEl.get("ip"), id, etreeEl.get("status"),
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
747 etreeEl.get("version"), etreeEl.get("protocol_version"),
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
748 etreeEl.get("client_string"), self.players[id][7])
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
749 except Exception, e:
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
750 player = (etreeEl.get("name"), etreeEl.get("ip"), id, etreeEl.get("status"),
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
751 etreeEl.get("version"), etreeEl.get("protocol_version"),
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
752 etreeEl.get("client_string"), "Player")
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
753 print e
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
754 if act == "new":
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
755 self.players[id] = player
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
756 self.on_player_event(mplay_event(PLAYER_NEW, self.players[id]))
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
757 elif act == "group":
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
758 self.group_id = etreeEl.get('group_id')
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
759 self.clear_players()
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
760 self.on_mplay_event(mplay_event(MPLAY_GROUP_CHANGE, self.groups[self.group_id]))
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
761 self.players[self.id] = self.get_my_info()
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
762 self.on_player_event(mplay_event(PLAYER_NEW, self.players[self.id]))
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
763 elif act == "failed":
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
764 self.on_mplay_event(mplay_event(MPLAY_GROUP_CHANGE_F))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
765 elif act == "del":
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
766 self.on_player_event(mplay_event(PLAYER_DEL, self.players[id]))
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
767 if self.players.has_key(id): del self.players[id]
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
768 if id == self.id: self.do_disconnect()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
769 # the next two cases handle the events that are used to let you know when others are typing
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
770 elif act == "update":
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
771 if id == self.id:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
772 self.players[id] = player
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
773 self.update_self_from_player(player)
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
774 else: self.players[id] = player
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
775 dont_send = 0
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
776 for m in self.ignore_id:
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
777 if m == id: dont_send=1
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
778 if dont_send != 1: self.on_player_event(mplay_event(PLAYER_UPDATE, self.players[id]))
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
779
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
780 def on_password(self, id, msg, etreeEl):
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
781 self.on_password_signal(etreeEl.get("signal"), etreeEl.get("type"),
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
782 etreeEl.get("id"), etreeEl.get("data"))
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
783
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
784 def check_my_status(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
785 status = self.get_status()
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
786 if status == MPLAY_DISCONNECTING: self.do_disconnect()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
787
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
788 def connect(self, addressport):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
789 """Establish a connection to a server while still using sendThread & recvThread for its
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
790 communication."""
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
791 if self.is_connected():
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
792 self.log_msg( "Client is already connected to a server?!? Need to disconnect first." )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
793 return 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
794 self.inbox = Queue.Queue(0)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
795 self.outbox = Queue.Queue(0)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
796 addressport_ar = addressport.split(":")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
797 if len(addressport_ar) == 1:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
798 address = addressport_ar[0]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
799 port = OPENRPG_PORT
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
800 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
801 address = addressport_ar[0]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
802 port = int(addressport_ar[1])
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
803 self.host_server = addressport
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
804 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
805 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
806 self.sock.connect((address,port))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
807 # send client into with id=0
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
808 outgoing = self.toxml('new')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
809 if iselement(outgoing): outgoing = tostring(outgoing)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
810 self.sendMsg(self.sock, outgoing)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
811 data = self.recvMsg(self.sock)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
812 # get new id and group_id
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
813 el = fromstring(data)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
814 self.id = el.get('id')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
815 self.group_id = el.get('group_id')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
816 if el.get('useCompression') == 'True':
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
817 self.useCompression = True
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
818 if cmpBZ2 and el.get('cmpType') == 'bz2':
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
819 self.compressionType = bz2
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
820 elif cmpZLIB and el.get('cmpType') == 'zlib':
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
821 self.compressionType = zlib
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
822 else: self.compressionType = None
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
823 #send confirmation
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
824 outgoing = self.toxml('new')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
825 if iselement(outgoing): outgoing = tostring(outgoing)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
826 self.sendMsg(self.sock, outgoing)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
827 except Exception, e:
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
828 print e
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
829 self.log_msg(e)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
830 return 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
831 # Start things rollings along
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
832 self.initialize_threads()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
833 self.on_mplay_event(mplay_event(MPLAY_CONNECTED))
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
834 self.players[self.id] = (self.name, self.ip, self.id,
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
835 self.text_status, self.version,
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
836 self.protocol_version, self.client_string, self.role)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
837 self.on_player_event(mplay_event(PLAYER_NEW,self.players[self.id]))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
838 return 1
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
839
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
840 def start_disconnect(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
841 self.on_mplay_event(mplay_event(MPLAY_DISCONNECTING))
119
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
842 outgoing = self.toxml('del')
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
843 if iselement(outgoing): outgoing = tostring(outgoing)
9314d63c0941 Traipse Alpha 'OpenRPG' {091029-00}
sirebral
parents: 118
diff changeset
844 self.outbox.put(outgoing)
96
65c1604e7949 Traipse Alpha 'OpenRPG' {090924-00}
sirebral
parents: 90
diff changeset
845 ## Client Side Disconect Forced -- Snowdog 10-09-2003
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
846 #pause to allow GUI events time to sync.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
847 time.sleep(1)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
848 self.do_disconnect()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
849
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
850 def do_disconnect(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
851 client_base.disconnect(self)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
852 self.clear_players()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
853 self.clear_groups()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
854 self.useroles = 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
855 self.on_mplay_event(mplay_event(MPLAY_DISCONNECTED))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
856 self.useCompression = False
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
857
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
858 def is_connected(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
859 return (self.status == MPLAY_CONNECTED)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
860
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
861 def get_next_id(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
862 self.unique_cookie += 1
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
863 return_str = self.id + "-" + str(self.unique_cookie)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
864 return return_str