-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgame.py
73 lines (58 loc) · 1.84 KB
/
game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python2
# -*- coding: utf-8 -*-
from proto.rpcservice import RpcService
from google.protobuf import text_format
import md5, sys, traceback
import gevent
from command import *
from cfg import Config
def _get_secret(uid, token, salt):
m = md5.new()
m.update(str(uid))
m.update(token)
m.update(salt)
return m.hexdigest()
class Game(object):
def __init__(self, addr):
self.srv = RpcService(addr, self)
self.is_login = False
self.uid = None
self.token = None
self.srv._start()
def _dft_handle(self, *args):
print args
def call(self, protoname, msg = {}):
return self.srv.call(protoname, msg)
def send(self, protoname, msg = {}):
return self.srv.invoke(protoname, msg)
################################ Test #########################################
@addcmd()
def help(self, cmdname = ""):
ok,similars = find_cmd(cmdname)
cmds = [cmdname] if ok else similars
for cmdname in cmds:
cmdname,args = inspect_cmd(cmdname)
print cmdname,args
@addcmd()
def login(self, user):
'''for sproto test login '''
resp = self.call("login", {"account": user})
Config["client_prompt"] = "[%s] > " % user
print(resp["prompt"])
@addcmd()
def echo(self, msg):
'''for sproto echo test '''
resp = self.call("echo", {"msg" : msg})
return resp
@addcmd()
def addone(self, i):
self.send("addone", {"i": i})
@addcmd()
def addlist(self, l):
resp = self.call("addlist", {"l": l})
print "answer:", resp["answer"]
@addcmd()
@addhandle("notify_addone")
def notify_addone(self, i):
print "addone result:", i
################################ Test End #########################################