~ubuntu-branches/ubuntu/gutsy/gnome-games/gutsy-proposed

« back to all changes in this revision

Viewing changes to glchess/src/lib/ggz/protocol.py

  • Committer: Package Import Robot
  • Author(s): Aron Sisak
  • Date: 2007-10-16 14:05:41 UTC
  • mfrom: (1.1.40)
  • Revision ID: package-import@ubuntu.com-20071016140541-02baoew129646d4e
Tags: 1:2.20.1-0ubuntu1
* New upstream release:
  - A few bugs fixed: #481245, #482188 (LP: #147485)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import xml.sax.handler
2
 
 
3
 
"<UPDATE TYPE='player' ACTION='delete' ROOM='40' TOROOM='-1'>"
4
 
"<PLAYER ID='kostaya'/>"
5
 
"</UPDATE>"
6
 
 
7
 
"<UPDATE TYPE='table' ACTION='leave' ROOM='40'>"
8
 
"<TABLE ID='1' SEATS='2'>"
9
 
"<SEAT NUM='0' TYPE='player'>kostaya</SEAT>"
10
 
"</TABLE>"
11
 
"</UPDATE>"
12
 
 
13
 
"<UPDATE TYPE='table' ACTION='status' ROOM='40'>"
14
 
"<TABLE ID='1' STATUS='3' SEATS='2'/>"
15
 
"</UPDATE>"
16
 
 
17
 
"<UPDATE TYPE='table' ACTION='delete' ROOM='40'>"
18
 
"<TABLE ID='1' STATUS='-1' SEATS='2'/>"
19
 
"</UPDATE>"
20
 
 
21
 
"<GAME ID=\'24\' NAME=\'TicTacToe\' VERSION=\'0.0.9\'>"
22
 
"<PROTOCOL ENGINE=\'TicTacToe\' VERSION=\'4\'/>"
23
 
"<ALLOW PLAYERS=\'2\' BOTS=\'1\' SPECTATORS=\'true\' PEERS=\'false\'/>"
24
 
"<BOT NAME=\'Alfred\' CLASS=\'easy\'/>"
25
 
"<BOT NAME=\'Tarantula\' CLASS=\'hard\'/>"
26
 
"<ABOUT AUTHOR=\'Brent Hendricks\' URL=\'http://www.ggzgamingzone.org/games/tictactoe/\'/>"
27
 
"<DESC>Simple GGZ game module for playing Tic-Tac-Toe</DESC>"
28
 
"</GAME>"
29
 
 
30
 
class GGZParser:
31
 
    
32
 
    parent = None
33
 
 
34
 
    parser = None
35
 
    
36
 
    def getAttribute(self, attributes, name, default = None):
37
 
        try:
38
 
            return attributes[name]
39
 
        except KeyError:
40
 
            return default
41
 
    
42
 
    def startElement(self, name, attributes):
43
 
        if self.parser is not None:
44
 
            self.parser.startElement(name, attributes)
45
 
            return
46
 
        try:
47
 
            method = getattr(self, 'start_%s' % name.lower())
48
 
        except AttributeError:
49
 
            print 'Unknown start element: %s' % name
50
 
        else:
51
 
            method(attributes)
52
 
    
53
 
    def characters(self, data):
54
 
        if self.parser is not None:
55
 
            self.parser.characters(data)
56
 
            return
57
 
        self.handle_data(data)
58
 
    
59
 
    def endElement(self, name):
60
 
        if self.parser is not None:
61
 
            self.parser.endElement(name)
62
 
            return
63
 
        try:
64
 
            method = getattr(self, 'end_%s' % name.lower())
65
 
        except AttributeError:
66
 
            print 'Unknown end element: %s' % name
67
 
        else:
68
 
            method()
69
 
            
70
 
    def push(self, parser, attributes):
71
 
        assert(self.parser is None)
72
 
        parser.attributes = attributes
73
 
        parser.decoder = self.decoder
74
 
        parser.parent = self
75
 
        self.parser = parser
76
 
        
77
 
    def pop(self):
78
 
        assert(self.parent is not None)
79
 
        parser = self.parent.parser
80
 
        self.parent.parser = None
81
 
        self.parent.childFinished(parser)
82
 
 
83
 
    def handle_data(self, data):
84
 
        pass
85
 
    
86
 
    def childFinished(self, parser):
87
 
        pass
88
 
    
89
 
class DescriptionParser(GGZParser):
90
 
    
91
 
    def handle_data(self, data):
92
 
        self.parent.description = data
93
 
        
94
 
    def end_desc(self):
95
 
        self.pop()
96
 
 
97
 
class GameProtocolParser(GGZParser):
98
 
    
99
 
    def end_protocol(self):
100
 
        self.parent.protocol = self
101
 
        self.engine = self.attributes['ENGINE']
102
 
        self.version = self.attributes['VERSION']
103
 
        self.pop()
104
 
 
105
 
class GameAllowParser(GGZParser):
106
 
    
107
 
    def end_allow(self):
108
 
        self.parent.allow = self
109
 
        self.numPlayers = self.attributes['PLAYERS']
110
 
        self.pop()
111
 
 
112
 
class GameBotParser(GGZParser):
113
 
    
114
 
    def end_bot(self):
115
 
        self.parent.bots.append(self)
116
 
        self.name = self.attributes['NAME']
117
 
        self.difficulty = self.attributes['CLASS']
118
 
        self.pop()
119
 
 
120
 
class GameAboutParser(GGZParser):
121
 
    
122
 
    def end_about(self):
123
 
        self.parent.about = self
124
 
        self.author = self.attributes['AUTHOR']
125
 
        self.url = self.attributes['URL']
126
 
        self.pop()
127
 
 
128
 
class GameParser(GGZParser):
129
 
    
130
 
    def __init__(self):
131
 
        self.bots = []
132
 
    
133
 
    def start_desc(self, attributes):
134
 
        self.push(DescriptionParser(), attributes)
135
 
        
136
 
    def start_protocol(self, attributes):
137
 
        self.push(GameProtocolParser(), attributes)
138
 
 
139
 
    def start_allow(self, attributes):
140
 
        self.push(GameAllowParser(), attributes)
141
 
        
142
 
    def start_bot(self, attributes):
143
 
        self.push(GameBotParser(), attributes)
144
 
    
145
 
    def start_about(self, attributes):
146
 
        self.push(GameAboutParser(), attributes)
147
 
 
148
 
    def end_game(self):
149
 
        self.gameId = self.attributes['ID']
150
 
        self.name = self.attributes['NAME']
151
 
        self.version = self.attributes['VERSION']
152
 
        self.pop()
153
 
 
154
 
    def __str__(self):
155
 
        return 'GGZ Game id=%s protocol=%s (%s) description=%s' % (self.gameId, repr(self.protocol.engine), self.protocol.version, repr(self.description))
156
 
 
157
 
class RoomParser(GGZParser):
158
 
    
159
 
    def start_desc(self, attributes):
160
 
        self.push(DescriptionParser(), attributes)
161
 
 
162
 
    def end_room(self):
163
 
        self.pop()
164
 
    
165
 
    def __str__(self):
166
 
        return 'GGZ Room id=%s game=%s description=%s' % (self.roomId, self.game, repr(self.description))
167
 
 
168
 
class PlayerParser(GGZParser):
169
 
 
170
 
    def end_player(self):
171
 
        self.pop()
172
 
        
173
 
    def __str__(self):
174
 
        return 'GGZ Player id=%s type=%s table=%s perms=%s lag=%s' % (self.id, self.type, self.table, self.perms, self.lag)
175
 
    
176
 
class TableSeatParser(GGZParser):
177
 
    
178
 
    def __init__(self):
179
 
        self.label = ''
180
 
 
181
 
    def handle_data(self, data):
182
 
        self.label += data
183
 
 
184
 
    def end_seat(self):
185
 
        self.pop()
186
 
 
187
 
class TableParser(GGZParser):
188
 
    
189
 
    def __init__(self):
190
 
        self.seats = []
191
 
        self.description = ''
192
 
 
193
 
    def start_desc(self, attributes):
194
 
        self.push(DescriptionParser(), attributes)
195
 
 
196
 
    def start_seat(self, attributes):
197
 
        self.push(TableSeatParser(), attributes)
198
 
 
199
 
    def childFinished(self, parser):
200
 
        if isinstance(parser, TableSeatParser):
201
 
            self.seats.append(parser)
202
 
 
203
 
    def end_table(self):
204
 
        self.pop()
205
 
 
206
 
class GameListParser(GGZParser):
207
 
    
208
 
    def __init__(self):
209
 
        self.games = []
210
 
    
211
 
    def start_game(self, attributes):
212
 
        self.push(GameParser(), attributes)
213
 
 
214
 
    def childFinished(self, parser):
215
 
        self.games.append(parser)
216
 
 
217
 
    def end_list(self):
218
 
        for g in self.games:
219
 
            self.decoder.feedback.gameAdded(g.gameId, g.name, g.version, g.about.author, g.about.url, g.allow.numPlayers,
220
 
                                              g.protocol.engine, g.protocol.version)
221
 
        self.pop()
222
 
      
223
 
class TableListParser(GGZParser):
224
 
    
225
 
    def __init__(self):
226
 
        self.tables = []
227
 
    
228
 
    def start_table(self, attributes):
229
 
        self.push(TableParser(), attributes)
230
 
 
231
 
    def childFinished(self, parser):
232
 
        self.tables.append(parser)
233
 
 
234
 
    def end_list(self):
235
 
        for t in self.tables:
236
 
            room = self.attributes['ROOM']
237
 
            tableId = t.attributes['ID']
238
 
            gameId = t.attributes['GAME']
239
 
            status = t.attributes['STATUS']
240
 
            nSeats = int(t.attributes['SEATS'])
241
 
            self.decoder.feedback.tableAdded(room, tableId, gameId, status, nSeats, t.description)
242
 
            for seat in t.seats:
243
 
                self.decoder.feedback.seatChanged(room, tableId, seat.attributes['NUM'], seat.attributes['TYPE'], seat.label)
244
 
        self.pop()
245
 
 
246
 
class PlayerListParser(GGZParser):
247
 
    
248
 
    def __init__(self):
249
 
        self.players = []
250
 
    
251
 
    def start_player(self, attributes):
252
 
        self.push(PlayerParser(), attributes)
253
 
 
254
 
    def childFinished(self, playerParser):
255
 
        playerParser.name = playerParser.attributes['ID']
256
 
        playerParser.type = playerParser.attributes['TYPE']
257
 
        playerParser.table = playerParser.attributes['TABLE']
258
 
        try:
259
 
            playerParser.perms = playerParser.attributes['PERMS']
260
 
        except KeyError:
261
 
            playerParser.perms = ''
262
 
        playerParser.lag = playerParser.attributes['LAG']
263
 
        self.players.append(playerParser)
264
 
 
265
 
    def end_list(self):
266
 
        for p in self.players:
267
 
            self.decoder.feedback.playerAdded(p.name, p.type, p.table, p.perms, p.lag, self.attributes['ROOM'], '-1')
268
 
        self.pop()
269
 
 
270
 
class RoomListParser(GGZParser):
271
 
    
272
 
    def __init__(self):
273
 
        self.rooms = []
274
 
        
275
 
    def start_room(self, attributes):
276
 
        self.push(RoomParser(), attributes)
277
 
 
278
 
    def childFinished(self, parser):
279
 
        parser.roomId = parser.attributes['ID']
280
 
        parser.name = parser.attributes['NAME']
281
 
        parser.game = parser.attributes['GAME']
282
 
        parser.nPlayers = int(parser.attributes['PLAYERS'])
283
 
        self.rooms.append(parser)
284
 
 
285
 
    def end_list(self):
286
 
        for r in self.rooms:
287
 
            self.decoder.feedback.roomAdded(r.roomId, r.game, r.name, r.description, r.nPlayers)
288
 
        self.pop()
289
 
        
290
 
class ServerOptionsParser(GGZParser):
291
 
 
292
 
    def end_options(self):
293
 
        self.pop()
294
 
        
295
 
class ServerParser(GGZParser):
296
 
    
297
 
    def start_options(self, attributes):
298
 
        self.push(ServerOptionsParser(), attributes)
299
 
    
300
 
    def end_server(self):
301
 
        self.pop()
302
 
 
303
 
class MOTDParser(GGZParser):
304
 
    
305
 
    def __init__(self):
306
 
        self.motd = ''
307
 
    
308
 
    def handle_data(self, data):
309
 
        self.motd += data
310
 
    
311
 
    def end_motd(self):
312
 
        print 'MOTD: %s' % repr(self.motd)
313
 
        self.pop()
314
 
 
315
 
class RoomUpdateParser(GGZParser):
316
 
    
317
 
    def __init__(self):
318
 
        pass
319
 
    
320
 
    def start_room(self, attributes):
321
 
        self.push(RoomParser(), attributes)
322
 
        
323
 
    def childFinished(self, parser):
324
 
        action = self.attributes['ACTION'].lower()
325
 
        if action == 'players':
326
 
            roomId = parser.attributes['ID']
327
 
            nPlayers = int(parser.attributes['PLAYERS'])
328
 
            self.decoder.feedback.roomPlayersUpdate(roomId, nPlayers)
329
 
        else:
330
 
            print 'Unknown player update action %s' % action
331
 
    
332
 
    def end_update(self):
333
 
        self.pop()
334
 
 
335
 
class PlayerUpdateParser(GGZParser):
336
 
    
337
 
    def start_player(self, attributes):
338
 
        self.push(PlayerParser(), attributes)
339
 
 
340
 
    def childFinished(self, parser):
341
 
        action = self.attributes['ACTION'].lower()
342
 
        if action == 'add':
343
 
            name = parser.attributes['ID']
344
 
            playerType = parser.attributes['TYPE']
345
 
            table = parser.attributes['TABLE']
346
 
            try:
347
 
                perms = parser.attributes['PERMS']
348
 
            except KeyError:
349
 
                perms = ''
350
 
            lag = parser.attributes['LAG']
351
 
            room = self.attributes['ROOM']
352
 
            fromRoom = self.attributes['FROMROOM']
353
 
            self.decoder.feedback.playerAdded(name, playerType, table, perms, lag, room, fromRoom)
354
 
        elif action == 'lag':
355
 
            playerId = parser.attributes['ID']
356
 
            lag = parser.attributes['LAG']
357
 
            print 'Player %s lag changed to %s' % (playerId, lag)
358
 
        elif action == 'delete':
359
 
            playerId = parser.attributes['ID']
360
 
            room = self.attributes['ROOM']
361
 
            toRoom = self.attributes['TOROOM']
362
 
            self.decoder.feedback.playerRemoved(playerId, room, toRoom)
363
 
        else:
364
 
            print 'Unknown player update action %s' % action
365
 
    
366
 
    def end_update(self):
367
 
        self.pop()
368
 
        
369
 
class TableUpdateParser(GGZParser):   
370
 
 
371
 
    def __init__(self):
372
 
        self.table = None
373
 
    
374
 
    def start_table(self, attributes):
375
 
        self.push(TableParser(), attributes)
376
 
        
377
 
    def childFinished(self, parser):
378
 
        self.table = parser
379
 
 
380
 
    def end_update(self):
381
 
        room = self.attributes['ROOM']        
382
 
        action = self.attributes['ACTION']
383
 
        if action == 'add':
384
 
             "<UPDATE TYPE='table' ACTION='add' ROOM='3'>"
385
 
             " <TABLE ID='1' GAME='30' STATUS='1' SEATS='2'>"
386
 
             "  <DESC></DESC>"
387
 
             "  <SEAT NUM='0' TYPE='reserved'>bob</SEAT>"
388
 
             "  <SEAT NUM='1' TYPE='bot'/>"
389
 
             " </TABLE>"
390
 
             "</UPDATE>"
391
 
             room = self.attributes['ROOM']
392
 
             tableId = self.table.attributes['ID']
393
 
             gameId = self.table.attributes['GAME']
394
 
             status = self.table.attributes['STATUS']
395
 
             nSeats = int(self.table.attributes['SEATS'])
396
 
             description = self.table.description
397
 
             # FIXME: Include the seats with the add event somehow (and other adds)
398
 
             self.decoder.feedback.tableAdded(room, tableId, gameId, status, nSeats, description)
399
 
             for seat in self.table.seats:
400
 
                 self.decoder.feedback.seatChanged(room, tableId, seat.attributes['NUM'], seat.attributes['TYPE'], seat.label)
401
 
 
402
 
        elif action == 'join':
403
 
            "<UPDATE TYPE='table' ACTION='join' ROOM='3'>"
404
 
            " <TABLE ID='1' SEATS='2'>"
405
 
            "  <SEAT NUM='0' TYPE='player'>bob</SEAT>"
406
 
            " </TABLE>"
407
 
            "</UPDATE>"
408
 
            room = self.attributes['ROOM']
409
 
            tableId = self.table.attributes['ID']
410
 
            for seat in self.table.seats:
411
 
                self.decoder.feedback.seatChanged(room, tableId, seat.attributes['NUM'], seat.attributes['TYPE'], seat.label)
412
 
 
413
 
        elif action == 'leave':
414
 
            "<UPDATE TYPE='table' ACTION='leave' ROOM='3'>"
415
 
            " <TABLE ID='1' SEATS='2'>"
416
 
            "  <SEAT NUM='0' TYPE='player'>bob</SEAT>"
417
 
            " </TABLE>"
418
 
            "</UPDATE>"
419
 
            room = self.attributes['ROOM']
420
 
            tableId = self.table.attributes['ID']
421
 
            for seat in self.table.seats:
422
 
                self.decoder.feedback.seatChanged(room, tableId, seat.attributes['NUM'], seat.attributes['TYPE'], '') # seat.label)???
423
 
 
424
 
        elif action == 'status':
425
 
            "<UPDATE TYPE='table' ACTION='status' ROOM='3'>"
426
 
            " <TABLE ID='1' STATUS='3' SEATS='2'/>"
427
 
            "</UPDATE>"
428
 
            self.decoder.feedback.tableStatusChanged(self.table.attributes['ID'], self.table.attributes['STATUS'])
429
 
 
430
 
        elif action == 'delete':
431
 
            "<UPDATE TYPE='table' ACTION='delete' ROOM='3'>"
432
 
            " <TABLE ID='1' STATUS='-1' SEATS='2'/>"
433
 
            "</UPDATE>"
434
 
            self.decoder.feedback.tableRemoved(self.table.attributes['ID'])
435
 
 
436
 
        else:
437
 
            print 'Unknown table update action: %s' % action
438
 
 
439
 
        self.pop()
440
 
    
441
 
    "<UPDATE TYPE='table' ACTION='add' ROOM='13'>"
442
 
    " <TABLE ID='1' GAME='24' STATUS='1' SEATS='4'>"
443
 
    "  <DESC>I play alone...</DESC>"
444
 
    "  <SEAT NUM='0' TYPE='reserved'>helg</SEAT>"
445
 
    "  <SEAT NUM='1' TYPE='bot'/>"
446
 
    "  <SEAT NUM='2' TYPE='bot'/>"
447
 
    "  <SEAT NUM='3' TYPE='bot'/>"
448
 
    " </TABLE>"
449
 
    "</UPDATE>"
450
 
    "<UPDATE TYPE='table' ACTION='join' ROOM='13'>"
451
 
    " <TABLE ID='1' SEATS='4'>"
452
 
    "  <SEAT NUM='0' TYPE='player'>helg</SEAT>"
453
 
    " </TABLE>"
454
 
    "</UPDATE>"
455
 
 
456
 
class ChatParser(GGZParser):
457
 
    
458
 
    def __init__(self):
459
 
        self.text = ''
460
 
    
461
 
    def handle_data(self, data):
462
 
        self.text += data
463
 
 
464
 
    def end_chat(self):
465
 
        chatType = self.attributes['TYPE']
466
 
        sender = self.attributes['FROM']
467
 
        self.decoder.feedback.onChat(chatType, sender, self.text)
468
 
        self.pop()
469
 
 
470
 
class ResultParser(GGZParser):
471
 
    
472
 
    def start_list(self, attributes):
473
 
        t = attributes['TYPE'].lower()
474
 
        if t == 'player':
475
 
            self.push(PlayerListParser(), attributes)
476
 
        elif t == 'room':
477
 
            self.push(RoomListParser(), attributes)
478
 
        elif t == 'game':
479
 
            self.push(GameListParser(), attributes)
480
 
        elif t == 'table':
481
 
            self.push(TableListParser(), attributes)
482
 
 
483
 
    def end_result(self):
484
 
        self.pop()
485
 
        
486
 
class JoinParser(GGZParser):
487
 
    
488
 
    def end_join(self):
489
 
        tableId = self.attributes['TABLE']
490
 
        isSpectator = self.attributes['SPECTATOR'] == 'true'
491
 
        self.decoder.feedback.onJoin(tableId, isSpectator)
492
 
        self.pop()
493
 
 
494
 
class LeaveParser(GGZParser):
495
 
    "<LEAVE REASON='gameover'/>"
496
 
    
497
 
    def end_leave(self):
498
 
        reason = self.attributes['REASON']
499
 
        self.decoder.feedback.onLeave(reason)
500
 
        self.pop()
501
 
 
502
 
class SessionParser(GGZParser):
503
 
    
504
 
    def start_server(self, attributes):
505
 
        self.push(ServerParser(), attributes)
506
 
    
507
 
    def start_motd(self, attributes):
508
 
        self.push(MOTDParser(), attributes)
509
 
 
510
 
    def start_update(self, attributes):
511
 
        t = attributes['TYPE'].lower()
512
 
        if t == 'room':
513
 
            self.push(RoomUpdateParser(), attributes)
514
 
        elif t == 'player':
515
 
            self.push(PlayerUpdateParser(), attributes)
516
 
        elif t == 'table':
517
 
            self.push(TableUpdateParser(), attributes)
518
 
        else:
519
 
            print 'Unknown update type: %s' % t
520
 
            
521
 
    def start_join(self, attributes):
522
 
        self.push(JoinParser(), attributes)
523
 
        
524
 
    def start_leave(self, attributes):
525
 
        self.push(LeaveParser(), attributes)
526
 
 
527
 
    def start_result(self, attributes):
528
 
        self.push(ResultParser(), attributes)
529
 
        self.decoder.feedback.sendNextCommand()
530
 
        
531
 
    def start_chat(self, attributes):
532
 
        self.push(ChatParser(), attributes)
533
 
    
534
 
    def start_ping(self, attributes):
535
 
        self.decoder.feedback.send("<PONG/>")
536
 
        
537
 
    def end_ping(self):
538
 
        pass
539
 
 
540
 
    def end_session(self):
541
 
        pass
542
 
 
543
 
class BaseParser(GGZParser):
544
 
    
545
 
    def __init__(self, decoder):
546
 
        self.decoder = decoder
547
 
 
548
 
    def start_session(self, attributes):
549
 
        self.push(SessionParser(), attributes)
550
 
 
551
 
class Decoder(xml.sax.handler.ContentHandler):
552
 
 
553
 
    def __init__(self, feedback):
554
 
        xml.sax.handler.ContentHandler.__init__(self)
555
 
        self.feedback = feedback
556
 
        self.parser = None
557
 
        self.xparser = xml.sax.make_parser()
558
 
        self.handler = BaseParser(self)
559
 
        self.xparser.setContentHandler(self)
560
 
 
561
 
    def startElement(self, name, attributes):
562
 
        self.handler.startElement(name, attributes)
563
 
 
564
 
    def characters(self, data):
565
 
        self.handler.characters(data)
566
 
 
567
 
    def endElement(self, name):
568
 
        self.handler.endElement(name)
569
 
 
570
 
    def feed(self, data):
571
 
        self.xparser.feed(data)
572
 
 
573
 
class Channel(xml.sax.handler.ContentHandler):
574
 
 
575
 
    def __init__(self, decoder):
576
 
        xml.sax.handler.ContentHandler.__init__(self)
577
 
        
578
 
        self.inSession = True
579
 
        self.decoder = decoder
580
 
        self.xparser = xml.sax.make_parser()
581
 
        self.xparser.setContentHandler(self)
582
 
 
583
 
    def endElement(self, name):
584
 
        if name == 'SESSION':
585
 
            self.inSession = False
586
 
 
587
 
    def feed(self, data):
588
 
        # Decode each line so can stop XML when session ends
589
 
        while self.inSession and len(data) > 0:
590
 
            index = data.find('\n')
591
 
            if index < 0:
592
 
                self.xparser.feed(data)
593
 
                return
594
 
            else:
595
 
                self.xparser.feed(data[:index+1])
596
 
                data = data[index+1:]
597
 
 
598
 
        for c in data:
599
 
            self.decoder.decode(c)
600
 
 
601
 
if __name__ == '__main__':
602
 
    class F:
603
 
        
604
 
        def onSeat(self, seatNum, version):
605
 
            print ('onSeat', seatNum, version)
606
 
            
607
 
        def onPlayers(self, whiteType, whiteName, blackType, blackName):
608
 
            print ('onPlayers', whiteType, whiteName, blackType, blackName)
609
 
                
610
 
        def onTimeRequest(self):
611
 
            print ('onTimeRequest',)
612
 
    
613
 
        def onSetTime(self, time):
614
 
            print ('onSetTime', time)
615
 
 
616
 
        def onStart(self):
617
 
            print ('onStart',)
618
 
    
619
 
        def onMove(self, move):
620
 
            print ('onMove', move)    
621
 
 
622
 
    f = F()
623
 
    d = GGZChess(f);
624
 
 
625
 
    for c in '\x01\x01\x06': # Seat seat=1 version=6
626
 
        d.decode(c)
627
 
 
628
 
    for c in '\x02\x03\x00\x00\x00\x0eglchess-test2\x00\x03\x00\x00\x00\x0dglchess-test\x00': # players type1=03 name1=glchess-test2 type2=03 name2=glchess-test
629
 
        d.decode(c)
630
 
 
631
 
    for c in '\x04\x00\x00\x00\x00':  # rsp time time=0
632
 
        d.decode(c)
633
 
 
634
 
    d.decode('\x05') # start
635
 
 
636
 
    for c in '\x07\x00\x00\x00\x05F2F4\x00': # move move=F2F4
637
 
        d.decode(c)
638
 
 
639
 
    for c in '\x0a\x00\x00\x00\x00\x00\x00\x00\x00': # update
640
 
        d.decode(c)