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


Python PandaModules.NetDatagram類代碼示例

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


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

示例1: __handleAuth

	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,代碼行數:33,代碼來源:GameServer.py

示例2: __handleNewGame

	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,代碼行數:31,代碼來源:GameServer.py

示例3: __handleDisconnect

	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,代碼行數:33,代碼來源:GameServer.py

示例4: reader_polling

    def reader_polling(self, taskdata):

        if self.cReader.dataAvailable():
            datagram = NetDatagram()  # catch the incoming data in this instance
            # Check the return value; if we were threaded, someone else could have
            # snagged this data before we did
            if self.cReader.getData(datagram):
                self.read_buffer = self.read_buffer + datagram.getMessage()
        while (True):
            if self.read_state == 0:
                if len(self.read_buffer) >= self.packet.header_length:
                    bytes_consumed = self.packet.header_length
                    self.packet.header = self.read_buffer[:bytes_consumed]
                    self.read_body_length = self.packet.decode_header()
                    self.read_buffer = self.read_buffer[bytes_consumed:]
                    self.read_state = 1
                else:
                    break
            if self.read_state == 1:
                if len(self.read_buffer) >= self.read_body_length:
                    bytes_consumed = self.read_body_length
                    self.packet.data = self.read_buffer[:bytes_consumed]
                    self.packet.offset = 0        
                    self.read_body_length = 0
                    self.read_buffer = self.read_buffer[bytes_consumed:]
                    self.read_state = 0
                    self.new_data_callback(self.packet)

                else:
                    break
        return Task.cont
開發者ID:shubhamgoyal,項目名稱:virtual-vision-simulator,代碼行數:31,代碼來源:socket_server.py

示例5: __sendGameListReq

	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,代碼行數:8,代碼來源:ClientConnection.py

示例6: eVV_VP_ACK_FAILED

def eVV_VP_ACK_FAILED(ip, port):
    packet = SocketPacket()
    packet.add_int(VV_VP_ACK_FAILED)
    packet.add_string(ip)
    packet.add_int(port)
    packet.encode_header()
    
    datagram = NetDatagram()
    datagram.appendData('' + packet.get_header() + packet.get_body())
    return datagram
開發者ID:shubhamgoyal,項目名稱:virtual-vision-simulator,代碼行數:10,代碼來源:message_handler.py

示例7: eVV_REQ_SIGNATURE

def eVV_REQ_SIGNATURE(ip, port, object_id):
    packet = SocketPacket()
    packet.add_int(VV_REQ_SIGNATURE)
    packet.add_string(ip)
    packet.add_int(port)
    packet.add_int(object_id)
    packet.encode_header()
    
    datagram = NetDatagram()
    datagram.appendData('' + packet.get_header() + packet.get_body())
    return datagram
開發者ID:shubhamgoyal,項目名稱:virtual-vision-simulator,代碼行數:11,代碼來源:message_handler.py

示例8: shutdown

	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,代碼行數:11,代碼來源:GameServer.py

示例9: eVV_ACK_OK

def eVV_ACK_OK(ip, port, client_id):
    packet = SocketPacket()
    packet.add_int(VV_ACK_OK)
    packet.add_string(ip)
    packet.add_int(port)
    packet.add_int(client_id)
    packet.encode_header()
    
    datagram = NetDatagram()
    datagram.appendData('' + packet.get_header() + packet.get_body())
    return datagram
開發者ID:shubhamgoyal,項目名稱:virtual-vision-simulator,代碼行數:11,代碼來源:message_handler.py

示例10: eVV_VP_ACK_OK

def eVV_VP_ACK_OK(ip, port, cam_id):
    packet = SocketPacket()
    packet.add_int(VV_VP_ACK_OK)
    packet.add_string(ip)
    packet.add_int(port)
    packet.add_int(cam_id)  ## Added this
    packet.encode_header()

    datagram = NetDatagram()
    datagram.appendData("" + packet.get_header() + packet.get_body())
    return datagram
開發者ID:vclab,項目名稱:virtual-vision-simulator,代碼行數:11,代碼來源:message_handler.py

示例11: SendPacket

def SendPacket(rpc, addr):
    global pq
    chance = random.random()
    p = rpc.CreateNewPacket(addr)
    rpc.SendPacket(p, addr)
    nd = NetDatagram()
    nd.appendData(p.GetDatagram().getMessage())#, p.GetDatagram().getLength())
    nd.setAddress(NetAddress())
    if(chance < 0.8):
        pq.append(nd)
        return nd
開發者ID:czorn,項目名稱:Modifire,代碼行數:11,代碼來源:TestReliablePacketController.py

示例12: eVV_READY

def eVV_READY(ip, port, vv_id):
    packet = SocketPacket()
    packet.add_int(VV_READY)
    packet.add_string(ip)
    packet.add_int(port)
    packet.add_int(vv_id)
    packet.encode_header()
    
    datagram = NetDatagram()
    datagram.appendData('' + packet.get_header() + packet.get_body())
    return datagram
開發者ID:shubhamgoyal,項目名稱:virtual-vision-simulator,代碼行數:11,代碼來源:message_handler.py

示例13: __handlePingReq

	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,代碼行數:12,代碼來源:GameServer.py

示例14: getData

	def getData(self):
		data = []
		while self.cReader.dataAvailable():
			datagram = NetDatagram()  # catch the incoming data in this instance
			# Check the return value; if we were threaded, someone else could have
			# snagged this data before we did
			if self.cReader.getData(datagram):
				appendage={}
				appendage[0]=self.processData(datagram)
				appendage[1]=datagram.getConnection()
				data.append(appendage)
		return data
開發者ID:H3LLB0Y,項目名稱:Warlocks,代碼行數:12,代碼來源:server.py

示例15: __sendJoinGameReq

	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,代碼行數:12,代碼來源:ClientConnection.py


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