mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
return support for python Proxy negotiation in connect-http.
This commit is contained in:
parent
27ad52b306
commit
7214038a5b
@ -37,8 +37,8 @@ class ClientRepository(DirectObject.DirectObject):
|
|||||||
# (e.g. QueuedConnectionManager, etc.) to establish the
|
# (e.g. QueuedConnectionManager, etc.) to establish the
|
||||||
# connection, which ultimately uses the NSPR socket library.
|
# connection, which ultimately uses the NSPR socket library.
|
||||||
# This is a much better socket library, but it may be more
|
# This is a much better socket library, but it may be more
|
||||||
# than you need for most applications; and the Panda net
|
# than you need for most applications; and the proxy support
|
||||||
# interface doesn't support proxies at all.
|
# is weak.
|
||||||
self.connectHttp = base.config.GetBool('connect-http', 1)
|
self.connectHttp = base.config.GetBool('connect-http', 1)
|
||||||
|
|
||||||
self.tcpConn = None
|
self.tcpConn = None
|
||||||
@ -85,11 +85,15 @@ class ClientRepository(DirectObject.DirectObject):
|
|||||||
failureCallback, failureArgs])
|
failureCallback, failureArgs])
|
||||||
else:
|
else:
|
||||||
self.qcm = QueuedConnectionManager()
|
self.qcm = QueuedConnectionManager()
|
||||||
|
# A big old 20 second timeout.
|
||||||
gameServerTimeoutMs = base.config.GetInt("game-server-timeout-ms",
|
gameServerTimeoutMs = base.config.GetInt("game-server-timeout-ms",
|
||||||
20000)
|
20000)
|
||||||
# A big old 20 second timeout.
|
if self.hasProxy:
|
||||||
|
url = self.proxy
|
||||||
|
else:
|
||||||
|
url = serverURL
|
||||||
self.tcpConn = self.qcm.openTCPClientConnection(
|
self.tcpConn = self.qcm.openTCPClientConnection(
|
||||||
serverURL.getServer(), serverURL.getPort(),
|
url.getServer(), url.getPort(),
|
||||||
gameServerTimeoutMs)
|
gameServerTimeoutMs)
|
||||||
|
|
||||||
if self.tcpConn:
|
if self.tcpConn:
|
||||||
@ -97,6 +101,34 @@ class ClientRepository(DirectObject.DirectObject):
|
|||||||
self.qcr=QueuedConnectionReader(self.qcm, 0)
|
self.qcr=QueuedConnectionReader(self.qcm, 0)
|
||||||
self.qcr.addConnection(self.tcpConn)
|
self.qcr.addConnection(self.tcpConn)
|
||||||
self.cw=ConnectionWriter(self.qcm, 0)
|
self.cw=ConnectionWriter(self.qcm, 0)
|
||||||
|
if self.hasProxy:
|
||||||
|
# Now we send an http CONNECT message on that
|
||||||
|
# connection to initiate a connection to the real
|
||||||
|
# game server
|
||||||
|
realGameServer = (serverURL.getServer() + ":" + str(serverURL.getPort()))
|
||||||
|
connectString = "CONNECT " + realGameServer + " HTTP/1.0\012\012"
|
||||||
|
datagram = Datagram()
|
||||||
|
# Use appendData and sendRaw so we do not send the length of the string
|
||||||
|
datagram.appendData(connectString)
|
||||||
|
self.notify.info("Sending CONNECT string: " + connectString)
|
||||||
|
self.cw.setRawMode(1)
|
||||||
|
self.qcr.setRawMode(1)
|
||||||
|
self.notify.info("done set raw mode")
|
||||||
|
self.send(datagram)
|
||||||
|
self.notify.info("done send datagram")
|
||||||
|
# Find the end of the http response, then call callback
|
||||||
|
self.findRawString(["\015\012", "\015\015"],
|
||||||
|
self.proxyConnectCallback, [successCallback, successArgs])
|
||||||
|
self.notify.info("done find raw string")
|
||||||
|
# Now start the raw reader poll task and look for
|
||||||
|
# the HTTP response When this is finished, it will
|
||||||
|
# call the connect callback just like the non
|
||||||
|
# proxy case
|
||||||
|
self.startRawReaderPollTask()
|
||||||
|
self.notify.info("done start raw reader poll task")
|
||||||
|
|
||||||
|
else:
|
||||||
|
# no proxy. We're done connecting.
|
||||||
self.startReaderPollTask()
|
self.startReaderPollTask()
|
||||||
if successCallback:
|
if successCallback:
|
||||||
successCallback(*successArgs)
|
successCallback(*successArgs)
|
||||||
@ -119,6 +151,64 @@ class ClientRepository(DirectObject.DirectObject):
|
|||||||
if failureCallback:
|
if failureCallback:
|
||||||
failureCallback(ch.getStatusCode(), *failureArgs)
|
failureCallback(ch.getStatusCode(), *failureArgs)
|
||||||
|
|
||||||
|
def proxyConnectCallback(self, successCallback, successArgs):
|
||||||
|
# Make sure we are not in raw mode anymore
|
||||||
|
self.cw.setRawMode(0)
|
||||||
|
self.qcr.setRawMode(0)
|
||||||
|
self.stopRawReaderPollTask()
|
||||||
|
if successCallback:
|
||||||
|
successCallback(*successArgs)
|
||||||
|
|
||||||
|
def startRawReaderPollTask(self):
|
||||||
|
# Stop any tasks we are running now
|
||||||
|
self.stopRawReaderPollTask()
|
||||||
|
self.stopReaderPollTask()
|
||||||
|
task = Task.Task(self.rawReaderPollUntilEmpty)
|
||||||
|
# Start with empty string
|
||||||
|
task.currentRawString = ""
|
||||||
|
taskMgr.add(task, "rawReaderPollTask", priority=self.TASK_PRIORITY)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def stopRawReaderPollTask(self):
|
||||||
|
taskMgr.remove("rawReaderPollTask")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def rawReaderPollUntilEmpty(self, task):
|
||||||
|
while self.rawReaderPollOnce():
|
||||||
|
pass
|
||||||
|
return Task.cont
|
||||||
|
|
||||||
|
def rawReaderPollOnce(self):
|
||||||
|
self.notify.debug("rawReaderPollOnce")
|
||||||
|
self.ensureValidConnection()
|
||||||
|
availGetVal = self.qcr.dataAvailable()
|
||||||
|
if availGetVal:
|
||||||
|
datagram = NetDatagram()
|
||||||
|
readRetVal = self.qcr.getData(datagram)
|
||||||
|
if readRetVal:
|
||||||
|
str = datagram.getMessage()
|
||||||
|
self.notify.debug("rawReaderPollOnce: found str: " + str)
|
||||||
|
self.handleRawString(str)
|
||||||
|
else:
|
||||||
|
ClientRepository.notify.warning("getData returned false")
|
||||||
|
return availGetVal
|
||||||
|
|
||||||
|
def handleRawString(self, str):
|
||||||
|
self.notify.info("handleRawString: str = <%s>" % (str))
|
||||||
|
self.currentRawString += str
|
||||||
|
self.notify.info("currentRawString = <%s>" % (self.currentRawString))
|
||||||
|
# Look in all the match strings to see if we got it yet
|
||||||
|
for matchString in self.rawStringMatchList:
|
||||||
|
if (self.currentRawString.find(matchString) >= 0):
|
||||||
|
self.rawStringCallback(*self.rawStringExtraArgs)
|
||||||
|
return
|
||||||
|
|
||||||
|
def findRawString(self, matchList, callback, extraArgs = []):
|
||||||
|
self.currentRawString = ""
|
||||||
|
self.rawStringMatchList = matchList
|
||||||
|
self.rawStringCallback = callback
|
||||||
|
self.rawStringExtraArgs = extraArgs
|
||||||
|
|
||||||
def startReaderPollTask(self):
|
def startReaderPollTask(self):
|
||||||
# Stop any tasks we are running now
|
# Stop any tasks we are running now
|
||||||
self.stopReaderPollTask()
|
self.stopReaderPollTask()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user