mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 02:42:49 -04:00
OTP code migration
This commit is contained in:
parent
e43e69bae3
commit
ab19f18a95
@ -11,7 +11,9 @@ import PythonUtil
|
|||||||
import ParentMgr
|
import ParentMgr
|
||||||
import RelatedObjectMgr
|
import RelatedObjectMgr
|
||||||
import time
|
import time
|
||||||
|
from ClockDelta import *
|
||||||
from PyDatagram import PyDatagram
|
from PyDatagram import PyDatagram
|
||||||
|
from PyDatagramIterator import PyDatagramIterator
|
||||||
|
|
||||||
class ClientRepository(ConnectionRepository.ConnectionRepository):
|
class ClientRepository(ConnectionRepository.ConnectionRepository):
|
||||||
notify = DirectNotifyGlobal.directNotify.newCategory("ClientRepository")
|
notify = DirectNotifyGlobal.directNotify.newCategory("ClientRepository")
|
||||||
@ -40,6 +42,12 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
|
|||||||
# other.
|
# other.
|
||||||
self.relatedObjectMgr = RelatedObjectMgr.RelatedObjectMgr(self)
|
self.relatedObjectMgr = RelatedObjectMgr.RelatedObjectMgr(self)
|
||||||
|
|
||||||
|
# Keep track of how recently we last sent a heartbeat message.
|
||||||
|
# We want to keep these coming at heartbeatInterval seconds.
|
||||||
|
self.heartbeatInterval = base.config.GetDouble('heartbeat-interval', 10)
|
||||||
|
self.heartbeatStarted = 0
|
||||||
|
self.lastHeartbeat = 0
|
||||||
|
|
||||||
def abruptCleanup(self):
|
def abruptCleanup(self):
|
||||||
"""
|
"""
|
||||||
Call this method to clean up any pending hooks or tasks on
|
Call this method to clean up any pending hooks or tasks on
|
||||||
@ -48,6 +56,18 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
|
|||||||
"""
|
"""
|
||||||
self.relatedObjectMgr.abortAllRequests()
|
self.relatedObjectMgr.abortAllRequests()
|
||||||
|
|
||||||
|
def sendDisconnect(self):
|
||||||
|
if self.tcpConn:
|
||||||
|
# Tell the game server that we're going:
|
||||||
|
datagram = PyDatagram()
|
||||||
|
# Add message type
|
||||||
|
datagram.addUint16(CLIENT_DISCONNECT)
|
||||||
|
# Send the message
|
||||||
|
self.send(datagram)
|
||||||
|
self.notify.info("Sent disconnect message to server")
|
||||||
|
self.disconnect()
|
||||||
|
self.stopHeartbeat()
|
||||||
|
|
||||||
def setServerDelta(self, delta):
|
def setServerDelta(self, delta):
|
||||||
"""
|
"""
|
||||||
Indicates the approximate difference in seconds between the
|
Indicates the approximate difference in seconds between the
|
||||||
@ -316,13 +336,11 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
|
|||||||
ClientRepository.notify.warning(
|
ClientRepository.notify.warning(
|
||||||
"Server is booting us out with no explanation.")
|
"Server is booting us out with no explanation.")
|
||||||
|
|
||||||
|
|
||||||
def handleServerHeartbeat(self, di):
|
def handleServerHeartbeat(self, di):
|
||||||
# Got a heartbeat message from the server.
|
# Got a heartbeat message from the server.
|
||||||
if base.config.GetBool('server-heartbeat-info', 1):
|
if base.config.GetBool('server-heartbeat-info', 1):
|
||||||
ClientRepository.notify.info("Server heartbeat.")
|
ClientRepository.notify.info("Server heartbeat.")
|
||||||
|
|
||||||
|
|
||||||
def handleUnexpectedMsgType(self, msgType, di):
|
def handleUnexpectedMsgType(self, msgType, di):
|
||||||
if msgType == CLIENT_GO_GET_LOST:
|
if msgType == CLIENT_GO_GET_LOST:
|
||||||
self.handleGoGetLost(di)
|
self.handleGoGetLost(di)
|
||||||
@ -374,6 +392,69 @@ class ClientRepository(ConnectionRepository.ConnectionRepository):
|
|||||||
# send the message
|
# send the message
|
||||||
self.send(datagram)
|
self.send(datagram)
|
||||||
|
|
||||||
|
def handleDatagram(self, datagram):
|
||||||
|
if self.notify.getDebug():
|
||||||
|
print "ClientRepository received datagram:"
|
||||||
|
datagram.dumpHex(ostream)
|
||||||
|
di = PyDatagramIterator(datagram)
|
||||||
|
msgType = di.getUint16()
|
||||||
|
if self.notify.getDebug():
|
||||||
|
self.notify.debug("handleDatagram: msgType: " + `msgType`)
|
||||||
|
# watch for setZoneDones
|
||||||
|
if msgType == CLIENT_DONE_SET_ZONE_RESP:
|
||||||
|
self.handleSetZoneDone()
|
||||||
|
if self.handler == None:
|
||||||
|
self.handleUnexpectedMsgType(msgType, di)
|
||||||
|
else:
|
||||||
|
self.handler(msgType, di)
|
||||||
|
# If we're processing a lot of datagrams within one frame, we
|
||||||
|
# may forget to send heartbeats. Keep them coming!
|
||||||
|
self.considerHeartbeat()
|
||||||
|
|
||||||
|
def sendHeartbeat(self):
|
||||||
|
datagram = PyDatagram()
|
||||||
|
# Add message type
|
||||||
|
datagram.addUint16(CLIENT_HEARTBEAT)
|
||||||
|
# Send it!
|
||||||
|
self.send(datagram)
|
||||||
|
self.lastHeartbeat = globalClock.getRealTime()
|
||||||
|
# This is important enough to consider flushing immediately
|
||||||
|
# (particularly if we haven't run readerPollTask recently).
|
||||||
|
if self.tcpConn:
|
||||||
|
self.tcpConn.considerFlush()
|
||||||
|
|
||||||
|
def considerHeartbeat(self):
|
||||||
|
"""Send a heartbeat message if we haven't sent one recently."""
|
||||||
|
if not self.heartbeatStarted:
|
||||||
|
self.notify.debug("Heartbeats not started; not sending.")
|
||||||
|
return
|
||||||
|
|
||||||
|
elapsed = globalClock.getRealTime() - self.lastHeartbeat
|
||||||
|
if elapsed < 0 or elapsed > self.heartbeatInterval:
|
||||||
|
# It's time to send the heartbeat again (or maybe someone
|
||||||
|
# reset the clock back).
|
||||||
|
self.notify.info("Sending heartbeat mid-frame.")
|
||||||
|
self.startHeartbeat()
|
||||||
|
|
||||||
|
def stopHeartbeat(self):
|
||||||
|
taskMgr.remove("heartBeat")
|
||||||
|
self.heartbeatStarted = 0
|
||||||
|
|
||||||
|
def startHeartbeat(self):
|
||||||
|
self.stopHeartbeat()
|
||||||
|
self.heartbeatStarted = 1
|
||||||
|
self.sendHeartbeat()
|
||||||
|
self.waitForNextHeartBeat()
|
||||||
|
|
||||||
|
def sendHeartbeatTask(self, task):
|
||||||
|
self.sendHeartbeat()
|
||||||
|
self.waitForNextHeartBeat()
|
||||||
|
return Task.done
|
||||||
|
|
||||||
|
def waitForNextHeartBeat(self):
|
||||||
|
taskMgr.doMethodLater(self.heartbeatInterval, self.sendHeartbeatTask,
|
||||||
|
"heartBeat")
|
||||||
|
|
||||||
def sendUpdate(self, do, fieldName, args, sendToId = None):
|
def sendUpdate(self, do, fieldName, args, sendToId = None):
|
||||||
# Get the DO id
|
# Get the DO id
|
||||||
doId = do.doId
|
doId = do.doId
|
||||||
|
@ -1,7 +1,25 @@
|
|||||||
"""MsgTypes module: contains distributed object message types"""
|
"""MsgTypes module: contains distributed object message types"""
|
||||||
|
|
||||||
|
# 2 new params: passwd, char bool 0/1 1 = new account
|
||||||
|
# 2 new return values: 129 = not found, 12 = bad passwd,
|
||||||
|
CLIENT_LOGIN = 1
|
||||||
|
CLIENT_LOGIN_RESP = 2
|
||||||
|
CLIENT_GET_AVATARS = 3
|
||||||
# Sent by the server when it is dropping the connection deliberately.
|
# Sent by the server when it is dropping the connection deliberately.
|
||||||
CLIENT_GO_GET_LOST = 4
|
CLIENT_GO_GET_LOST = 4
|
||||||
|
CLIENT_GET_AVATARS_RESP = 5
|
||||||
|
CLIENT_CREATE_AVATAR = 6
|
||||||
|
CLIENT_CREATE_AVATAR_RESP = 7
|
||||||
|
CLIENT_GET_SHARD_LIST = 8
|
||||||
|
CLIENT_GET_SHARD_LIST_RESP = 9
|
||||||
|
CLIENT_GET_FRIEND_LIST = 10
|
||||||
|
CLIENT_GET_FRIEND_LIST_RESP = 11
|
||||||
|
CLIENT_GET_FRIEND_DETAILS = 12
|
||||||
|
CLIENT_GET_FRIEND_DETAILS_RESP = 13
|
||||||
|
CLIENT_GET_AVATAR_DETAILS = 14
|
||||||
|
CLIENT_GET_AVATAR_DETAILS_RESP = 15
|
||||||
|
CLIENT_LOGIN_2 = 16
|
||||||
|
CLIENT_LOGIN_2_RESP = 17
|
||||||
|
|
||||||
CLIENT_OBJECT_UPDATE_FIELD = 24
|
CLIENT_OBJECT_UPDATE_FIELD = 24
|
||||||
CLIENT_OBJECT_UPDATE_FIELD_RESP = 24
|
CLIENT_OBJECT_UPDATE_FIELD_RESP = 24
|
||||||
@ -9,10 +27,36 @@ CLIENT_OBJECT_DISABLE_RESP = 25
|
|||||||
CLIENT_OBJECT_DELETE_RESP = 27
|
CLIENT_OBJECT_DELETE_RESP = 27
|
||||||
CLIENT_SET_ZONE = 29
|
CLIENT_SET_ZONE = 29
|
||||||
CLIENT_SET_SHARD = 31
|
CLIENT_SET_SHARD = 31
|
||||||
|
CLIENT_SET_AVATAR = 32
|
||||||
CLIENT_CREATE_OBJECT_REQUIRED = 34
|
CLIENT_CREATE_OBJECT_REQUIRED = 34
|
||||||
CLIENT_CREATE_OBJECT_REQUIRED_OTHER = 35
|
CLIENT_CREATE_OBJECT_REQUIRED_OTHER = 35
|
||||||
|
|
||||||
|
CLIENT_DISCONNECT = 37
|
||||||
|
|
||||||
|
CLIENT_CHANGE_IP_ADDRESS_RESP = 45
|
||||||
|
CLIENT_GET_STATE = 46
|
||||||
|
CLIENT_GET_STATE_RESP = 47
|
||||||
|
CLIENT_DONE_SET_ZONE_RESP = 48
|
||||||
|
CLIENT_DELETE_AVATAR = 49
|
||||||
|
CLIENT_DELETE_AVATAR_RESP = 50
|
||||||
|
|
||||||
CLIENT_HEARTBEAT = 52
|
CLIENT_HEARTBEAT = 52
|
||||||
|
CLIENT_FRIEND_ONLINE = 53
|
||||||
|
CLIENT_FRIEND_OFFLINE = 54
|
||||||
|
CLIENT_REMOVE_FRIEND = 56
|
||||||
|
|
||||||
|
CLIENT_SERVER_UP = 57
|
||||||
|
CLIENT_SERVER_DOWN = 58
|
||||||
|
|
||||||
|
CLIENT_CHANGE_PASSWORD = 65
|
||||||
|
|
||||||
|
CLIENT_SET_NAME_PATTERN = 67
|
||||||
|
CLIENT_SET_NAME_PATTERN_ANSWER = 68
|
||||||
|
|
||||||
|
CLIENT_SET_WISHNAME = 70
|
||||||
|
CLIENT_SET_WISHNAME_RESP = 71
|
||||||
|
CLIENT_SET_WISHNAME_CLEAR = 72
|
||||||
|
CLIENT_SET_SECURITY = 73
|
||||||
|
|
||||||
# These messages are ignored when the client is headed to the quiet zone
|
# These messages are ignored when the client is headed to the quiet zone
|
||||||
QUIET_ZONE_IGNORED_LIST = [
|
QUIET_ZONE_IGNORED_LIST = [
|
||||||
@ -27,3 +71,9 @@ QUIET_ZONE_IGNORED_LIST = [
|
|||||||
#CLIENT_CREATE_OBJECT_REQUIRED_OTHER,
|
#CLIENT_CREATE_OBJECT_REQUIRED_OTHER,
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# The following is a different set of numbers from above.
|
||||||
|
# These are the sub-message types for CLIENT_LOGIN_2.
|
||||||
|
CLIENT_LOGIN_2_GREEN = 1 # Disney's GoReg subscription token, not used.
|
||||||
|
CLIENT_LOGIN_2_PLAY_TOKEN = 2 # VR Studio PlayToken.
|
||||||
|
CLIENT_LOGIN_2_BLUE = 3 # The international GoReg token.
|
||||||
|
@ -6,6 +6,7 @@ from PythonUtil import Functor, sameElements, list2dict, uniqueElements
|
|||||||
from IntervalGlobal import *
|
from IntervalGlobal import *
|
||||||
from ToontownMsgTypes import *
|
from ToontownMsgTypes import *
|
||||||
import ToontownGlobals
|
import ToontownGlobals
|
||||||
|
import OTPGlobals
|
||||||
import DistributedObject
|
import DistributedObject
|
||||||
import Level
|
import Level
|
||||||
import LevelConstants
|
import LevelConstants
|
||||||
@ -633,7 +634,7 @@ class DistributedLevel(DistributedObject.DistributedObject,
|
|||||||
# always include Toontown and factory uberZones
|
# always include Toontown and factory uberZones
|
||||||
uberZone = self.getZoneId(LevelConstants.UberZoneEntId)
|
uberZone = self.getZoneId(LevelConstants.UberZoneEntId)
|
||||||
# the level itself is in the 'level zone'
|
# the level itself is in the 'level zone'
|
||||||
visibleZoneIds = [ToontownGlobals.UberZone, self.levelZone, uberZone]
|
visibleZoneIds = [OTPGlobals.UberZone, self.levelZone, uberZone]
|
||||||
for vz in vizList:
|
for vz in vizList:
|
||||||
visibleZoneIds.append(self.getZoneId(vz))
|
visibleZoneIds.append(self.getZoneId(vz))
|
||||||
assert(uniqueElements(visibleZoneIds))
|
assert(uniqueElements(visibleZoneIds))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user