All pastes #20013 Raw Edit

Stuff

public text v1 · immutable
#20013 ·published 2005-08-14 18:06 UTC
rendered paste body

#set dir
import os
import sys
#check if we are running linux
if os.name == "posix":
	f = open(os.environ["HOME"] + "/.bnet.conf","r")
	thedir = f.read()
	while 1:
		try:
			sys.path.remove(thedir)
		except:
			break
	
	sys.path.append(thedir)
	
if os.name == "nt":
	sys.path.append(os.getcwd())
###########################################
###########################################
###########################################
###########################################



import client
from socket import *
from bsock import *
import libpac
import GameLogic

class client_sock(tcp_bsock):
	def __init__(self,port = 8501, debug = 1, blocking = 1, transfer = 0, libpac = libpac, len = len,int = int,GameLogic = GameLogic, float = float):
		tcp_bsock.__init__(self,port,debug,blocking,transfer)
		self.libpac = libpac
		self.len = len
		self.int = int
		self.servername = ""
		self.ID = 0
		self.GL = GameLogic
		self.cont = self.GL.getCurrentController()
		self.float = float
		self.owner = self.cont.getOwner()

		
	def run(self):
		self.write()#stupid function, user write_raw from now on
		self.filter(self.read2())
		
		
	def filter(self,packet):
		libpac = self.libpac
		if packet[0] == 0 and packet[1] == 0 and packet[2] == 0:
			pass
		else:
			header = packet[0]
			ID = packet[1]
			data = packet[2]
			data = data[1:self.len(data)]
			
			if header == libpac.PAC_AUTH_LOGINGOOD:
				print "Login Good!"

				info = data.split(":")
	
				print "You are on " + info[1] + " with the ID of " + info[0]
				self.ID = self.int(info[0])
				self.servername = info[1]
			
			elif header == libpac.PAC_AUTH_LOGINBAD:
				print "Bad username or password"
				print data
				self.owner.init = -1
			elif header == libpac.PAC_AUTH_SERVERFULL:
				self.owner.init = -1
				print "Server is full"
			elif header == libpac.PAC_AUTH_ALREADYLOGGEDIN:
				print "You are already logged in"
				self.owner.init = -1
				
			elif header == libpac.PAC_AUTH_CLIENTLOGGEDIN:
				print data + " has logged in."
				self.append_sndbuff(libpac.PAC_GAME_REQGAMESETUP,self.ID)
				
			
			elif header == libpac.PAC_AUTH_CLIENTLOGGEDOUT:
				print data + " has logged out."
			
			elif header == libpac.PAC_GAME_MSG:
				info = data.split(":")
				username = info[0]
				msg = info[1]
				print username + " says: " + msg
			
			elif header == libpac.PAC_GAME_SPAWN:
				info = data.split(":")
				obj = info[1]
				
				posx = self.float(info[1])
				posy = self.float(info[2])
				posz = self.float(info[3])
				
				velx = self.float(info[4])
				vely = self.float(info[5])
				velz = self.float(info[6])
				
				self.owner.setPosition([posx,posy,posz])

				
				spawn = self.cont.getActuator("spawn")
				spawn.setObject(obj)
				spawn.setLinearVelocity(velx,vely,velz)
				print spawn.getLinearVelocity()
			
				self.GL.addActiveActuator(spawn,1)
				self.GL.addActiveActuator(spawn,0)
				
					
			else:
				print header,data
			
		
		#insert your code here
		

owner = GameLogic.getCurrentController().getOwner()
owner.Init = 1
GameLogic.client_sock = client_sock()