当前位置: 首页>>代码示例>>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;未经允许,请勿转载。