Mercurial > traipse_dev
comparison orpg/networking/mplay_client.py @ 128:fba298d65cf8 alpha
Traipse Alpha 'OpenRPG' {091003-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 (Cleaning up for Beta)
Added Bookmarks
Fix to Remote Admin Commands
Minor fix to text based Server
Fix to Pretty Print, from Core
Fix to Splitter Nodes not being created
Fix to massive amounts of images loading, from Core
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
default_manifest.xml renamed to default_upmana.xml
Cleaner clode for saved repositories
New TrueDebug Class in orpg_log (See documentation for usage)
Mercurial's hgweb folder is ported to upmana
Happy Halloween!
author | sirebral |
---|---|
date | Tue, 03 Nov 2009 00:52:47 -0600 |
parents | 8827271fbe1b |
children | b4e02e8cd314 |
comparison
equal
deleted
inserted
replaced
127:0f720618a8bd | 128:fba298d65cf8 |
---|---|
192 self.log_msg( "recvThread has terminated..." ) | 192 self.log_msg( "recvThread has terminated..." ) |
193 | 193 |
194 def sendMsg( self, sock, msg ): | 194 def sendMsg( self, sock, msg ): |
195 """Very simple function that will properly encode and send a message to te | 195 """Very simple function that will properly encode and send a message to te |
196 remote on the specified socket.""" | 196 remote on the specified socket.""" |
197 #debug(log=False) | |
198 if self.useCompression and self.compressionType != None: | 197 if self.useCompression and self.compressionType != None: |
199 mpacket = self.compressionType.compress(msg) | 198 mpacket = self.compressionType.compress(msg) |
200 lpacket = pack('!i', len(mpacket)) | 199 lpacket = pack('!i', len(mpacket)) |
201 sock.send(lpacket) | 200 sock.send(lpacket) |
202 offset = 0 | 201 offset = 0 |
216 except socket.error, e: self.log_msg( e ) | 215 except socket.error, e: self.log_msg( e ) |
217 except Exception, e: self.log_msg( e ) | 216 except Exception, e: self.log_msg( e ) |
218 return sentm | 217 return sentm |
219 | 218 |
220 def recvData( self, sock, readSize ): | 219 def recvData( self, sock, readSize ): |
221 #debug(log=False) | |
222 """Simple socket receive method. This method will only return when the exact | 220 """Simple socket receive method. This method will only return when the exact |
223 byte count has been read from the connection, if remote terminates our | 221 byte count has been read from the connection, if remote terminates our |
224 connection or we get some other socket exception.""" | 222 connection or we get some other socket exception.""" |
225 data = "" | 223 data = "" |
226 offset = 0 | 224 offset = 0 |
240 self.log_msg( e ) | 238 self.log_msg( e ) |
241 data = "" | 239 data = "" |
242 return data | 240 return data |
243 | 241 |
244 def recvMsg(self, sock): | 242 def recvMsg(self, sock): |
245 #debug() | |
246 """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. | 243 """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. |
247 | 244 |
248 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.""" | 245 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.""" |
249 msgData = "" | 246 msgData = "" |
250 try: | 247 try: |
258 except IOError, e: self.log_msg( e ) | 255 except IOError, e: self.log_msg( e ) |
259 except Exception, e: self.log_msg( e ) | 256 except Exception, e: self.log_msg( e ) |
260 return msgData | 257 return msgData |
261 | 258 |
262 def initialize_threads(self): | 259 def initialize_threads(self): |
263 #debug() | |
264 "Starts up our threads (2) and waits for them to make sure they are running!" | 260 "Starts up our threads (2) and waits for them to make sure they are running!" |
265 self.status = MPLAY_CONNECTED | 261 self.status = MPLAY_CONNECTED |
266 self.sock.setblocking(1) | 262 self.sock.setblocking(1) |
267 # Confirm that our threads have started | 263 # Confirm that our threads have started |
268 thread.start_new_thread( self.sendThread,(0,)) | 264 thread.start_new_thread( self.sendThread,(0,)) |
269 thread.start_new_thread( self.recvThread,(0,)) | 265 thread.start_new_thread( self.recvThread,(0,)) |
270 self.startedEvent.set() | 266 self.startedEvent.set() |
271 | 267 |
272 def disconnect(self): | 268 def disconnect(self): |
273 #debug() | 269 debug() |
274 self.set_status(MPLAY_DISCONNECTING) | 270 self.set_status(MPLAY_DISCONNECTING) |
275 self.log_msg("client stub " + self.ip +" disconnecting...") | 271 self.log_msg("client stub " + self.ip +" disconnecting...") |
276 self.log_msg("closing sockets...") | 272 self.log_msg("closing sockets...") |
277 try: self.sock.shutdown(2) | 273 try: self.sock.shutdown(2) |
278 except Exception, e: | 274 except Exception, e: |
280 print | 276 print |
281 print "Continuing" | 277 print "Continuing" |
282 self.set_status(MPLAY_DISCONNECTED) | 278 self.set_status(MPLAY_DISCONNECTED) |
283 | 279 |
284 def reset(self,sock): | 280 def reset(self,sock): |
285 #debug() | |
286 self.disconnect() | 281 self.disconnect() |
287 self.sock = sock | 282 self.sock = sock |
288 self.initialize_threads() | 283 self.initialize_threads() |
289 | 284 |
290 def update_role(self,role): | 285 def update_role(self,role): |
291 #debug() | |
292 self.useroles = 1 | 286 self.useroles = 1 |
293 self.role = role | 287 self.role = role |
294 | 288 |
295 def use_roles(self): | 289 def use_roles(self): |
296 #debug() | |
297 if self.useroles: return 1 | 290 if self.useroles: return 1 |
298 else: return 0 | 291 else: return 0 |
299 def update_self_from_player(self, player): | 292 def update_self_from_player(self, player): |
300 try: (self.name, self.ip, self.id, | 293 try: (self.name, self.ip, self.id, |
301 self.text_status, self.version, | 294 self.text_status, self.version, |
305 """ | 298 """ |
306 The IP field should really be deprecated as too many systems are NAT'd and/or behind firewalls for a | 299 The IP field should really be deprecated as too many systems are NAT'd and/or behind firewalls for a |
307 client provided IP address to have much value. As such, we now label it as deprecated. | 300 client provided IP address to have much value. As such, we now label it as deprecated. |
308 """ | 301 """ |
309 def toxml(self, action): | 302 def toxml(self, action): |
310 #debug((myescape(self.name), self.name, self.role)) | |
311 el = Element('player') | 303 el = Element('player') |
312 el.set('name', self.name) | 304 el.set('name', self.name) |
313 el.set('action', action) | 305 el.set('action', action) |
314 el.set('role', self.role) | 306 el.set('role', self.role) |
315 el.set('id', self.id) | 307 el.set('id', self.id) |
327 cmpType = 'zlib' | 319 cmpType = 'zlib' |
328 el.set('cmpType', cmpType) | 320 el.set('cmpType', cmpType) |
329 return tostring(el) | 321 return tostring(el) |
330 | 322 |
331 def log_msg(self,msg): | 323 def log_msg(self,msg): |
332 #debug(msg, log=False) | 324 debug(msg, log=False) |
333 if self.log_console: self.log_console(msg) | 325 if self.log_console: self.log_console(msg) |
334 | 326 |
335 def get_status(self): | 327 def get_status(self): |
336 #debug(log=False) | |
337 self.statLock.acquire() | 328 self.statLock.acquire() |
338 status = self.status | 329 status = self.status |
339 self.statLock.release() | 330 self.statLock.release() |
340 return status | 331 return status |
341 | 332 |
342 def my_role(self): | 333 def my_role(self): |
343 #debug(self.role, log=False) | |
344 return self.role | 334 return self.role |
345 | 335 |
346 def set_status(self,status): | 336 def set_status(self,status): |
347 #debug(status, log=False) | |
348 self.statLock.acquire() | 337 self.statLock.acquire() |
349 self.status = status | 338 self.status = status |
350 self.statLock.release() | 339 self.statLock.release() |
351 | 340 |
352 def isServer( self ): | 341 def isServer( self ): |
396 # MPLAY CLIENT | 385 # MPLAY CLIENT |
397 # | 386 # |
398 # | 387 # |
399 #======================================================================== | 388 #======================================================================== |
400 class mplay_client(client_base): | 389 class mplay_client(client_base): |
401 #debug() | |
402 "mplay client" | 390 "mplay client" |
403 def __init__(self,name,callbacks): | 391 def __init__(self,name,callbacks): |
404 #debug(name) | |
405 client_base.__init__(self) | 392 client_base.__init__(self) |
406 component.add('mp_client', self) | 393 component.add('mp_client', self) |
407 self.xml = component.get('xml') | 394 self.xml = component.get('xml') |
408 self.set_name(name) | 395 self.set_name(name) |
409 self.on_receive = callbacks['on_receive'] | 396 self.on_receive = callbacks['on_receive'] |
429 # implement from our base class | 416 # implement from our base class |
430 def isServer(self): | 417 def isServer(self): |
431 return 0 | 418 return 0 |
432 | 419 |
433 def get_chat(self): | 420 def get_chat(self): |
434 #debug() | |
435 return self.orpgFrame_callback.chat | 421 return self.orpgFrame_callback.chat |
436 | 422 |
437 def set_name(self,name): | 423 def set_name(self,name): |
438 #debug(name) | |
439 self.name = name | 424 self.name = name |
440 self.update() | 425 self.update() |
441 | 426 |
442 def set_text_status(self, status): | 427 def set_text_status(self, status): |
443 #debug() | |
444 if self.text_status != status: | 428 if self.text_status != status: |
445 self.text_status = status | 429 self.text_status = status |
446 self.update() | 430 self.update() |
447 | 431 |
448 def set_status_url(self, url="None"): | 432 def set_status_url(self, url="None"): |
582 e = name[loc+1:] | 566 e = name[loc+1:] |
583 name = b + "'" + e | 567 name = b + "'" + e |
584 oldloc = loc+1 | 568 oldloc = loc+1 |
585 el = Element('alter') | 569 el = Element('alter') |
586 el.set('key', 'pwd') | 570 el.set('key', 'pwd') |
587 el.set('val', npwd) | 571 #el.set('val', npwd) |
588 el.set('bpw', pwd) | 572 el.set('bpw', str(pwd)) |
589 el.set('plr', self.id) | 573 el.set('plr', self.id) |
590 el.set('gid', self.group_id) | 574 el.set('gid', self.group_id) |
591 self.outbox.put(tostring(el)) | 575 self.outbox.put(tostring(el)) |
592 self.update() | 576 self.update() |
593 | 577 |
601 el.set('player', self.id) | 585 el.set('player', self.id) |
602 el.set('group_id', self.group_id) | 586 el.set('group_id', self.group_id) |
603 self.outbox.put(tostring(el)) | 587 self.outbox.put(tostring(el)) |
604 | 588 |
605 def get_role(self): | 589 def get_role(self): |
606 #debug((self.group_id, self.id, self.role)) | |
607 el = Element('role') | 590 el = Element('role') |
608 el.set('action', 'get') | 591 el.set('action', 'get') |
609 el.set('player', self.id) | 592 el.set('player', self.id) |
610 el.set('group_id', self.group_id) | 593 el.set('group_id', self.group_id) |
611 self.outbox.put(tostring(el)) | 594 self.outbox.put(tostring(el)) |
612 | 595 |
613 def set_role(self, player, role, pwd=""): | 596 def set_role(self, player, role, pwd=""): |
614 #debug(role) | |
615 el = Element('role') | 597 el = Element('role') |
616 el.set('action', 'set') | 598 el.set('action', 'set') |
617 el.set('player', player) | 599 el.set('player', player) |
618 el.set('role', role) | 600 el.set('role', role) |
619 el.set('boot_pwd', pwd) | 601 el.set('boot_pwd', pwd) |
696 try: el = fromstring(data) | 678 try: el = fromstring(data) |
697 except ExpatError: | 679 except ExpatError: |
698 end = data.find(">") | 680 end = data.find(">") |
699 head = data[:end+1] | 681 head = data[:end+1] |
700 msg = data[end+1:] | 682 msg = data[end+1:] |
701 el = fromstring(head) | 683 ### Alpha ### |
684 if head[end:] != '/': | |
685 if head[end:] != '>': head = head[:end] + '/>' | |
686 ### This if statement should help close invalid messages. Since it needs fixing, use the try except message for now. | |
687 try: el = fromstring(head) | |
688 except: el = fromstring(head[:end] +'/>') | |
689 | |
702 try: | 690 try: |
703 el1 = fromstring(msg) | 691 el1 = fromstring(msg) |
704 el.append(el1) | 692 el.append(el1) |
705 except ExpatError: | 693 except ExpatError: |
706 el.text = msg | 694 el.text = msg |