def connect(self,f=''): ''' Connect to server using self.flags (or default) ''' #TODO configurations if(self.flags==''): self.flags= pyinsim.ISF_CON|pyinsim.ISF_MCI #contact print 'Connecting to '+str(self.ip), "flags ",self.flags self.insim = pyinsim.insim(self.ip, self.port, Admin=self.passw,Flags=self.flags,Interval=self.interval) #TODO flag to enable, disable outgauge if(self.outg_enabled): print "Initializing outgauge port: ",self.outgauge_port, " int: ",self.outgauge_interval self.outgauge = pyinsim.outgauge('127.0.0.1', self.outgauge_port, self.outgauge_packet, self.outgauge_interval) if(self.outs_enabled): print "Initializing Outsim port: ",self.outsim_port, " int: ",self.outsim_interval self.outsim= pyinsim.outsim('127.0.0.1', self.outsim_port, self.outsim_packet, self.outsim_interval) self.__bindEvents() #self.run() #we need to request connections and players self.request_connection_list() self.request_player_list() self.sendMsg(self.tag +' V.'+ str(self.version)+ " started.")
def connect(self, f=''): ''' Connect to server using self.flags (or default) ''' #TODO configurations if (self.flags == ''): self.flags = pyinsim.ISF_CON | pyinsim.ISF_MCI #contact print 'Connecting to ' + str(self.ip), "flags ", self.flags self.insim = pyinsim.insim(self.ip, self.port, Admin=self.passw, Flags=self.flags, Interval=self.interval) #TODO flag to enable, disable outgauge if (self.outg_enabled): print "Initializing outgauge port: ", self.outgauge_port, " int: ", self.outgauge_interval self.outgauge = pyinsim.outgauge('127.0.0.1', self.outgauge_port, self.outgauge_packet, self.outgauge_interval) if (self.outs_enabled): print "Initializing Outsim port: ", self.outsim_port, " int: ", self.outsim_interval self.outsim = pyinsim.outsim('127.0.0.1', self.outsim_port, self.outsim_packet, self.outsim_interval) self.__bindEvents() #self.run() #we need to request connections and players self.request_connection_list() self.request_player_list() self.sendMsg(self.tag + ' V.' + str(self.version) + " started.")
def outgauge_init(): global insim while (running): insim = pyinsim.insim('192.168.1.10', 29999, Admin='') insim.bind(pyinsim.EVT_ALL, all) outsim = pyinsim.outsim('0.0.0.0', 10000, outsim_packet, 2.0) outgauge = pyinsim.outgauge('0.0.0.0', 10001, outgauge_packet, 2.0) pyinsim.run() print "Connection Closed, Retrying"
def new_player(insim, npl): # Add the new player to the players dict. players[npl.PLID] = npl print 'New player: %s' % pyinsim.stripcols(npl.PName) def player_left(insim, pll): # Get player from the players dict. npl = players[pll.PLID] # Delete them from the dict. del players[pll.PLID] print 'Player left: %s' % pyinsim.stripcols(npl.PName) # Init new InSim object. insim = pyinsim.insim('127.0.0.1', 29999, Admin='') # Bind events for the connection and player packets. insim.bind(pyinsim.ISP_NCN, new_connection) insim.bind(pyinsim.ISP_CNL, connection_left) insim.bind(pyinsim.ISP_NPL, new_player) insim.bind(pyinsim.ISP_PLL, player_left) # Request for LFS to send all connections and players. insim.send(pyinsim.ISP_TINY, ReqI=255, SubT=pyinsim.TINY_NCN) insim.send(pyinsim.ISP_TINY, ReqI=255, SubT=pyinsim.TINY_NPL) # Start pyinsim. pyinsim.run()
# Try get the player for this car (sometimes get MCI # packet before all players have been received). npl = players.get(info.PLID) if npl: # Print the player's name. # print npl.PName if npl.PName == "Kaarel": print info.X, info.Y, info.Speed / 100, info.Heading / 180, info.PLID, npl.PName # savetxt("xy.dat", info.X, info.Y, info.Speed/100, info.Heading/180, info.PLID, npl.PName) # savetxt('myfile.txt', info.X, info.Y, info.Speed/100, info.Heading/180, info.PLID, npl.PName, fmt="%12.6G") # Initialize InSim. insim = pyinsim.insim('127.0.0.1', 29999, Flags=pyinsim.ISF_MCI, Interval=600, Admin='') # Bind packet events. insim.bind(pyinsim.ISP_ISM, insim_multi) insim.bind(pyinsim.ISP_NCN, new_connection) insim.bind(pyinsim.ISP_CNL, connection_leave) insim.bind(pyinsim.ISP_NPL, new_player) insim.bind(pyinsim.ISP_PLL, player_leave) insim.bind(pyinsim.ISP_MCI, multi_car_info) # When first connected request current host info. insim.send(pyinsim.ISP_TINY, ReqI=1, SubT=pyinsim.TINY_ISM) # Run packet receive loop.
"""Example 1: Initialize InSim and send the message 'Hello, InSim!' to the chat.""" import pyinsim # Initialize the InSim system insim = pyinsim.insim('127.0.0.1', 29999, Admin='') # Send message 'Hello, InSim!' to the game insim.sendm('Hello, InSim!') # Start pyinsim. pyinsim.run()
import pyinsim def message_out(insim, packet): pass insim = pyinsim.insim('127.0.0.1', 29999) insim.bind(pyinsim.ISP_MSO, message_out) if __name__ == '__main__': pyinsim.run()
'feedback': [], # List of force feedback types to support 'maxeffects': 4, # Maximum number of concurrent feedback effects 'buttons': [] # List of buttons to use } # The "think" routine runs every few milliseconds. Do NOT perform # blocking operations within this function. Doing so will prevent other # important stuff from happening. theta = 0.0 def doVJoyThink(): global theta theta += 0.05 events = [] x = int(math.cos(theta) * 32500) y = int(math.sin(theta) * 32500) insim.send(pyinsim.ISP_MST, Msg='tore') events.append([vjoy.EV_ABS, vjoy.ABS_X, x]) events.append([vjoy.EV_ABS, vjoy.ABS_Y, y]) print theta insim.send(pyinsim.ISP_MST, Msg='Hello, InSim!') pyinsim.run() print "2" return events insim = pyinsim.insim('127.0.0.1', 29999, Admin='password') #pyinsim.run()
import pyinsim def multi_car_info(insim, mci): for info in mci.Info: print 'X: %d Y: %d Z: %d' % (info.X, info.Y, info.Z) insim = pyinsim.insim('127.0.0.1', 29999, Flags=pyinsim.ISF_MCI, Admin='password') insim.bind(pyinsim.ISP_MCI, multi_car_info) pyinsim.run()