當前位置: 首頁>>代碼示例>>Python>>正文


Python NetDatagram.addUint16方法代碼示例

本文整理匯總了Python中pandac.PandaModules.NetDatagram.addUint16方法的典型用法代碼示例。如果您正苦於以下問題:Python NetDatagram.addUint16方法的具體用法?Python NetDatagram.addUint16怎麽用?Python NetDatagram.addUint16使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandac.PandaModules.NetDatagram的用法示例。


在下文中一共展示了NetDatagram.addUint16方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __handleGameList

# 需要導入模塊: from pandac.PandaModules import NetDatagram [as 別名]
# 或者: from pandac.PandaModules.NetDatagram import addUint16 [as 別名]
	def __handleGameList(self, data, msgID, client):
		''' Assemble a list of active games and send it to the requesting client.
			data (PyDatagramIterator): the list of data sent with this datagram
			msgID (Int): the message ID
			client (Connection): the connection that this datagram came from'''
		
		# Send response
		pkg = NetDatagram()
		pkg.addUint16(MSG_GAMELIST_RES)
		if (len(self.games) == 0):
			pkg.addString('EOT') # Nothing to transmit
		else:
			pkg.addString('SOT') # Start Of Transmission
			for i,g in enumerate(self.games):
				pkg.addInt32(g.id)
				pkg.addString(g.name)
				pkg.addUint32(g.numPlayers)
				pkg.addString(g.map.name)
				pkg.addString(g.mapFile)
				pkg.addUint32(g.startTime)
				pkg.addUint32(g.turnNumber)
				if i < len(self.games)-1:
					pkg.addString('T') # Still tranmitting
			pkg.addString('EOT') # End Of Transmission
		self._cWriter.send(pkg, client)
		
		self._console.printNotice('%s: Request for game list.' %(client.getAddress().getIpString()))
開發者ID:crempp,項目名稱:psg,代碼行數:29,代碼來源:GameServer.py

示例2: __handleNewGame

# 需要導入模塊: from pandac.PandaModules import NetDatagram [as 別名]
# 或者: from pandac.PandaModules.NetDatagram import addUint16 [as 別名]
	def __handleNewGame(self, data, msgID, client):
		''' Create a new game and respond with success or failure.
			data (PyDatagramIterator): the list of data sent with this datagram
			msgID (Int): the message ID
			client (Connection): the connection that tendNehis datagram came from'''
		
		# Unpack message data
		gameName    = data.getString()
		mapID       = data.getString()
		numPlayers  = data.getUint32()
		
		# If we do not have the map for the requested game tell client
		print("id=%s"%mapID)
		if(not self._mapStore.isAvailable(id=mapID)):
			response = 0
		else:
			# Create the game
			newGame = GameStateServer(gameName, numPlayers, mapID)
			if newGame is not None:
				self.games.append(newGame)
				response = newGame.id
			else:
				response = -1
		
		# Send response
		pkg = NetDatagram()
		pkg.addUint16(MSG_NEWGAME_RES)
		pkg.addInt32(response)
		self._cWriter.send(pkg, client)
		
		self._console.printNotice('%s: Request for new game: %s, %s, %d.' %(client.getAddress().getIpString(),gameName,mapID,numPlayers))
開發者ID:crempp,項目名稱:psg,代碼行數:33,代碼來源:GameServer.py

示例3: __handleMapList

# 需要導入模塊: from pandac.PandaModules import NetDatagram [as 別名]
# 或者: from pandac.PandaModules.NetDatagram import addUint16 [as 別名]
	def __handleMapList(self, data, msgID, client):
		''' Assemble a list of available maps and send it to the requesting client.
			data (PyDatagramIterator): the list of data sent with this datagram
			msgID (Int): the message ID
			client (Connection): the connection that this datagram came from'''
		
		# Assemble a list with entries in the form (filename,mapname,md5sum)
		mapFileList = Map.getMapFiles()
		responseList = []
		for f in mapFileList:
			fh = open(Map.MAP_PATH + f,' rb')
			mapObj = cPickle.load(fh)
			responseList.append((mapObj.name, f, Map.getMapMD5(f)))
		
		# Send response
		pkg = NetDatagram()
		pkg.addUint16(MSG_MAPLIST_RES)
		pkg.addString('SOT') # Start Of Transmission
		for i, (n,f,c) in enumerate(responseList):
			pkg.addString(n)
			pkg.addString(f)
			pkg.addString(c)
			if i < len(responseList)-1:
				pkg.addString('T') # Still tranmitting
		pkg.addString('EOT') # End Of Transmission
		self._cWriter.send(pkg, client)
		
		self._console.printNotice('%s: Request for map list.' %(client.getAddress().getIpString()))
開發者ID:crempp,項目名稱:psg,代碼行數:30,代碼來源:GameServer.py

示例4: __handleAuth

# 需要導入模塊: from pandac.PandaModules import NetDatagram [as 別名]
# 或者: from pandac.PandaModules.NetDatagram import addUint16 [as 別名]
	def __handleAuth(self, data, msgID, client):
		''' Try to authorize the connecting user, send the result.
			data (PyDatagramIterator): the list of data sent with this datagram
			msgID (Int): the message ID
			client (Connection): the connection that this datagram came from'''
		
		# Unpack message data
		username = data.getString()
		password = data.getString()
		auth = 0
		
		# Look for the username in the list of registered users
		for u in self.registeredUsers:
			if u.username == username:
				if u.connected:
					auth = 1
					self._console.printNotice('%s: User %s already connected'%(client.getAddress().getIpString(),username))
					break
				elif u.password != password:
					auth = 2
					self._console.printNotice('%s: User %s gave invalid password'%(client.getAddress().getIpString(),username))
					break
				else:
					auth = 3
					u.connect(client)
					self.connectedUsers.append(u)
					self._console.printNotice('%s: User %s connected with pass %s' %(client.getAddress().getIpString(),username,password))
		
		# Send response
		pkg = NetDatagram()
		pkg.addUint16(MSG_AUTH_RES)
		pkg.addUint32(auth)
		self._cWriter.send(pkg, client)
開發者ID:crempp,項目名稱:psg,代碼行數:35,代碼來源:GameServer.py

示例5: __handleDisconnect

# 需要導入模塊: from pandac.PandaModules import NetDatagram [as 別名]
# 或者: from pandac.PandaModules.NetDatagram import addUint16 [as 別名]
	def __handleDisconnect(self, data, msgID, client):
		''' Disconnect and send confirmation to the client.
			data (PyDatagramIterator): the list of data sent with this datagram
			msgID (Int): the message ID
			client (Connection): the connection that tendNehis datagram came from'''
		
		# Create a response
		pkg = NetDatagram()
		pkg.addUint16(MSG_DISCONNECT_RES)
		self._cWriter.send(pkg, client)
		
		# If user has joined a game, remove the player from that game
		for g in self.games:
			if g.isPlayerInGame(client):
				g.removePlayer(client)
		
		# If user is logged in disconnect
		username = ''
		for u in self.connectedUsers:
			if (u.connectedClient == client):
				username = u.username
				u.disconnect()
				self.connectedUsers.remove(u)
		
		# Delete client from list
		if client in self.connections:
			self.connections.remove(client)
			
		# Don't worry about pings any more
		if client in self.pingNonResponders:
			del(self.pingNonResponders[client])
		
		self._console.printNotice('%s: Disconnected user %s'%(client.getAddress().getIpString(),username))
開發者ID:crempp,項目名稱:psg,代碼行數:35,代碼來源:GameServer.py

示例6: __handleDownloadMap

# 需要導入模塊: from pandac.PandaModules import NetDatagram [as 別名]
# 或者: from pandac.PandaModules.NetDatagram import addUint16 [as 別名]
	def __handleDownloadMap(data, msgID, client):
		''' Prepare and send requested map to client
			data (PyDatagramIterator): the list of data sent with this datagram
			msgID (Int): the message ID
			client (Connection): the connection that tendNehis datagram came from'''
		
		# Unpack message data
		id = data.getUint32()
		resp = 0
		
		filename = self._mapStore.getMap(id=id)['filename']
		mapString = self._mapStore.loadMapAsString(filename)
		
		if (mapString == None):
			LOG.debug('No such map')
			resp = 0
			mapString = ''
		else:
			LOG.debug('Sending map')
			resp = 1
			
		# Send response
		pkg = NetDatagram()
		pkg.addUint16(MSG_JOINGAME_RES)	
		pkg.addUint32(resp)
		pkg.addString(mapString)
		self._cWriter.send(pkg, client)
開發者ID:crempp,項目名稱:psg,代碼行數:29,代碼來源:GameServer.py

示例7: __sendGameListReq

# 需要導入模塊: from pandac.PandaModules import NetDatagram [as 別名]
# 或者: from pandac.PandaModules.NetDatagram import addUint16 [as 別名]
	def __sendGameListReq(self):
		''' Request a list of games on the connected server.'''
		
		# Send request
		if (self._connected and self._authorized):
			pkg = NetDatagram()
			pkg.addUint16(MSG_GAMELIST_REQ)
			self._cWriter.send(pkg, self._tcpSocket)
開發者ID:crempp,項目名稱:psg,代碼行數:10,代碼來源:ClientConnection.py

示例8: shutdown

# 需要導入模塊: from pandac.PandaModules import NetDatagram [as 別名]
# 或者: from pandac.PandaModules.NetDatagram import addUint16 [as 別名]
	def shutdown(self):
		print('Shutting down server ...')
		
		# Send disconnect to all clients
		pkg = NetDatagram()
		pkg.addUint16(MSG_DISCONNECT_REQ)
		for c in self.connections:
			self._cWriter.send(pkg, c)
		self._cManager.closeConnection(self._tcpSocket)
		print('Server done')
		sys.exit()
開發者ID:crempp,項目名稱:psg,代碼行數:13,代碼來源:GameServer.py

示例9: __handlePingReq

# 需要導入模塊: from pandac.PandaModules import NetDatagram [as 別名]
# 或者: from pandac.PandaModules.NetDatagram import addUint16 [as 別名]
	def __handlePingReq(self, data, msgID, client):
		''' Respond to a ping request.
			data (PyDatagramIterator): the list of data sent with this datagram
			msgID (Int): the message ID
			client (Connection): the connection that this datagram came from'''
		
		# Send response
		pkg = NetDatagram()
		pkg.addUint16(MSG_PING_RES)
		self._cWriter.send(pkg, client)
		
		self._console.printNotice('%s: Ping request'%(client.getAddress().getIpString()))
開發者ID:crempp,項目名稱:psg,代碼行數:14,代碼來源:GameServer.py

示例10: __sendJoinGameReq

# 需要導入模塊: from pandac.PandaModules import NetDatagram [as 別名]
# 或者: from pandac.PandaModules.NetDatagram import addUint16 [as 別名]
	def __sendJoinGameReq(self, id):
		''' Join a game on the server.
			id (int): the id of the game to join'''
			
		LOG.debug('Sending join game request')
		
		# Send Request
		if (self._connected and self._authorized):
			pkg = NetDatagram()
			pkg.addUint16(MSG_JOINGAME_REQ)
			pkg.addUint32(id)
			self._cWriter.send(pkg, self._tcpSocket)
開發者ID:crempp,項目名稱:psg,代碼行數:14,代碼來源:ClientConnection.py

示例11: __recievePingReq

# 需要導入模塊: from pandac.PandaModules import NetDatagram [as 別名]
# 或者: from pandac.PandaModules.NetDatagram import addUint16 [as 別名]
	def __recievePingReq(self, data, msgID, client):
		''' Handle pings from the server.
			data (PyDatagramIterator): the list of data sent with this datagram
			msgID (Int): the message ID
			client (Connection): the connection that this datagram came from'''
		
		LOG.debug("Recieved a ping request")
		
		# Send response
		pkg = NetDatagram()
		pkg.addUint16(MSG_PING_RES)
		self._cWriter.send(pkg, self._tcpSocket)
開發者ID:crempp,項目名稱:psg,代碼行數:14,代碼來源:ClientConnection.py

示例12: _sendDownloadReq

# 需要導入模塊: from pandac.PandaModules import NetDatagram [as 別名]
# 或者: from pandac.PandaModules.NetDatagram import addUint16 [as 別名]
	def _sendDownloadReq(type, id):
		''' Download a file from the server.'''
		
		LOG.debug("Downloading type=%s, id=%s"%(type, id))
		
		if (self._connected and self._authorized):
			pkg = NetDatagram()
			if (type == "MAP"):
				pkg.addUint16(MSG_DOWNLOADMAP_REQ)
				pkg.addUint32(id)
			elif (type == "UPDATE"):
				pkg.addUint16(MSG_DOWNLOADUPD_REQ)
				pkg.addUint32(id)
			self._cWriter.send(pkg, self._tcpSocket)
開發者ID:crempp,項目名稱:psg,代碼行數:16,代碼來源:ClientConnection.py

示例13: __sendNewGameReq

# 需要導入模塊: from pandac.PandaModules import NetDatagram [as 別名]
# 或者: from pandac.PandaModules.NetDatagram import addUint16 [as 別名]
	def __sendNewGameReq(self, gamename, mapID, numplayers):
		''' Create a new game on the server.
			name (String): the name of the game
			mapID (String): the MD5 ID of the map
			maxplayers (Int): the max players allowed'''
			
		LOG.debug('Sending new game request %s'%map)
		
		# Send Request
		if (self._connected and self._authorized):
			pkg = NetDatagram()
			pkg.addUint16(MSG_NEWGAME_REQ)
			pkg.addString(gamename)
			pkg.addString(mapID)
			pkg.addUint32(numplayers)
			self._cWriter.send(pkg, self._tcpSocket)
開發者ID:crempp,項目名稱:psg,代碼行數:18,代碼來源:ClientConnection.py

示例14: __sendAuthReq

# 需要導入模塊: from pandac.PandaModules import NetDatagram [as 別名]
# 或者: from pandac.PandaModules.NetDatagram import addUint16 [as 別名]
	def __sendAuthReq(self, username, password):
		''' Send user name and password. The password is encypted first using
			SHA256.
			username (String): the username
			password (String): the password'''
			
		if self._connected:
			LOG.notice("Sending authorization")
			h = hashlib.sha256()
			h.update(password)
			pkg = NetDatagram()
			pkg.addUint16(MSG_AUTH_REQ)
			pkg.addString(username)
			pkg.addString(h.hexdigest())
			self._cWriter.send(pkg, self._tcpSocket)
		else:
			LOG.error("Cant authorize, we are not connected")
開發者ID:crempp,項目名稱:psg,代碼行數:19,代碼來源:ClientConnection.py

示例15: __pingTask

# 需要導入模塊: from pandac.PandaModules import NetDatagram [as 別名]
# 或者: from pandac.PandaModules.NetDatagram import addUint16 [as 別名]
	def __pingTask(self, Task):
		''' Ping all clients every PING_DELAY seconds to check for those who
			have dropped their connection.'''
		
		notice = 'Pinging: '
		
		for c in self.connections:
			# Don't ping connections we're still waiting on
			if c not in self.pingNonResponders.keys():
				notice = '%s%s '%(notice, c.getAddress().getIpString())
				self.pingNonResponders[c] = int(time.time())
				pkg = NetDatagram()
				pkg.addUint16(MSG_PING_REQ)
				self._cWriter.send(pkg, c)
		
		LOG.notice(notice)
		# Add task back into the taskmanager
		taskMgr.doMethodLater(PING_DELAY, self.__pingTask, 'serverPingTask', sort=-41)
開發者ID:crempp,項目名稱:psg,代碼行數:20,代碼來源:GameServer.py


注:本文中的pandac.PandaModules.NetDatagram.addUint16方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。