User:Pfc
From WorkCDN
Current Projects
Contents |
-PYMMORPG: A pure-python MMORPG engine for christian development using Python/Pygame/PyOpenGL
Networking
Here lies an overview of the networking to be used in PYMMORPG
Connection overview:
- server listens on port
- client requests connection
- server accepts connection
- client may make any requests that doesn't require a log-in
- once client has logged in, all other requests are available
- server will respond to request along with optional flags for such things as world-reset or major update
- all data will be sent after being pickled with the pickle library in p3k or cpickle in p2.x
Connection request:
The connection request will be automated by the tcp/ip protocol
before log-in:
client may request current server's client version (to update if needed)
['ver'] → ['x.x.x...']
str str
Upgrade request can then be sent if needed (to upgrade to current version
['upgrade'] → [directory_image_of_client]
str list of tuples (name,data) for file or (name,[directory])
log-in can be requested
['login',name,password] → [True/False]
str*3 Boolean
new player can be requested (also acts as login if successful)
['new',name,password] → [True/False]
str*3 Boolean
after log-in:
update the current state
['update'] → [list_of_viewable]
str List of dynamic data dicts (should contain pos/name/visual)
move the character
['move',offset_pos] → [True/False]
str,tuple(x,y,z) Boolean
get some attribute from a character that isn't included in the normal update
['get',name,attr] → [attr]
str*3 the requested attribute
set an attribute
['set',name,attr,value] → [True/False]
str*3, value Boolean
or
single object in tuple
to represent relative change
['edit',[command,data]] → [True/False]
str [str,list of data] Boolean
packets:
data is transferred in the form of: size + space character + pickled data
where size is a string(or bytes as of py3k) representation of the number of characters(or bytes) in the pickled data portion of the message, space character is the ascii character ' ', and the data is the raw pickled data
Note: all data is sent inside a pickled list (due to my lazyness in some of the checking in my multy-threading)This also makes it easier for the server to append extra 'flags' while normal communication continues. The use of pickle may be removed in future versions
Each message may be transferred over may packets. The space character is simply to tell the receiving end that the length of the message has completely arrived and to check if the data portion has been completely received, otherwise keep on receiving until the data portion is equal to the number received in the size portion. if more data has been received than what is needed, save the rest in buffer and only use what was needed
once packet has been received, unpickle the packet. If this fails, just ignore, empty the buffer, and continue normal operation. if too many consecutive transmissions fail, give up.
flags: flags are appended at the end of the list
flags may include
'map' (the map has been changed, reload)
'client' (client version has changed, upgrade)
Server
Outline
- load client image(for upgrade requests)
- create world locally
- load maps
- start AI
- set up socket
- loop
- listen for incomming connections
- create a new uthread for each new connection
- go through each uthread (system, AI, Player...)
multytasking
outline
- new uthreads are created as generator object
- each uthread has full acess to the sceduler(to add/del new uthreads)
- each uthread can yield its priority(high value = lower priority, 0 or None = real time)
