g'day gents... looking for a handful or so of python coders who are interested in helping code an addon for server/league admins.
in the long run, i would like the system to function somewhat similar to the x-system, where the game dumps data into a mysql db for website (php?) interaction as well as in-game interaction.
unfortunately, i only know enough python to ask where the bathroom is, but here is a code sample a friend and i worked on... using some samples from the python API thread:
as you can tell, it sortof stinks... :ices_rofl a lot of features haven't been implemented, and the ones that are there, seem to be broken or are still incomplete. haven't hammered-out a full feature list either, but i would like to have as many features as possible.
if anyone feels daring enough to give this a go, let me know.
cheers
in the long run, i would like the system to function somewhat similar to the x-system, where the game dumps data into a mysql db for website (php?) interaction as well as in-game interaction.
unfortunately, i only know enough python to ask where the bathroom is, but here is a code sample a friend and i worked on... using some samples from the python API thread:
### header, call pyinsim api and initialize stuff
import getopt, sys
from Pyinsim import *
insim = InSim()
connections = {}
playernames = {}
admins = {}
players = {}
### Global Vars
VERSION="0.1"
SERVER_NAME="127.0.0.1"
SERVER_PORT=29999
ADMIN="buntest"
INAME="lfsapp"
### help options
def PrintTodo():
print "LFSapp TODO: exit cleanly if server dies/exits, reconnect mechanism?"
print "LFSapp TODO: configurable settings in a config file"
print "LFSapp TODO: split up server admin stuff and league admin stuff"
print "LFSapp TODO: better detection of insim login issues, app terminates without error if wrong password"
print "LFSapp TODO: more features, implementing http://hamiltonshells.ca/~chris/images/games/lfs/lfsapp-proposal.png"
print "LFSapp TODO: crash on unhandled exception errors"
def PrintHelp():
PrintVersion()
print "Usage: LFSapp [options]"
print "\t\t-t,--todo\t\tPrints Todo List"
print "\t\t-v,--version\t\tPrints Version Info"
print "\t\t-h,--help\t\tPrints This Help Message"
def PrintVersion():
print "LFSapp v. ", VERSION
### message commands
def CommandBeached(UCID, PName):
print "UCID", UCID, "has beached"
insim.SendP(Packet(ISP_MTC, UCID=UCID, Msg="Moving to spectators")) # sends message packet back to user
#insim.SendP(Packet(ISP_MST, Msg=("/spec " + PName))) # this throws an error, something about concatenating a string and a variable?
print "LFSapp TODO: don't let this command work on users not in race"
print "LFSapp TODO: find out how to obtain player names so we can enable the ISP_MST"
def CommandHelp(UCID):
print "UCID", UCID, "used !help command"
insim.SendP(Packet(ISP_MTC, UCID=UCID, Msg="Help test")) # sends message packet back to user
print "LFSapp TODO: make a help GUI, or at least a command list"
def CommandQuit(UCID, Admin, PName): # only people with physical access to the server console itself can use this!!
if UCID == 0:
print "UCID", UCID, "has terminated LFSapp"
insim.Close()
elif UCID != 0:
print "UCID", UCID, "tried to terminate LFSapp"
elif Admin == 1:
print "PName", PName, "has terminated LFSapp"
insim.Close()
elif Admin != 1:
print "PName", PName, "tried to terminate LFSapp"
#print "LFSapp TODO: acquire admin flag from IS_NCN and allow those too"
def CommandReport(UCID):
print "UCID", UCID, "used !report command"
insim.SendP(Packet(ISP_MTC, UCID=UCID, Msg="Report test")) # sends message packet back to user
print "LFSapp TODO: make this actually work"
### game internals
def ConnectionJoined(ncn):
connections[ncn["UCID"]] = ncn
admins[ncn["Admin"]] = ncn
def ConnectionLeft(cnl):
del connections[cnl["UCID"]]
del admins[cnl["PName"]]
def PlayerJoined(npl):
players[npl["PLID"]] = npl
playernames[ncn["PName"]] = npl
def PlayerLeft(pll):
del players[pll["PLID"]]
del playernames[cnl["PName"]]
def JoinedMultiplayer(ism):
# Request all connections and players to be sent.
insim.SendP(Packet(ISP_TINY, ReqI=1, SubT=TINY_NCN))
insim.SendP(Packet(ISP_TINY, ReqI=1, SubT=TINY_NPL))
### message parser
def MessageReceived(mso):
commands = mso["Msg"][mso["TextStart"]:].split(" ")
if commands[0] == "!beached":
CommandBeached(mso["UCID"])
elif commands[0] == "!help":
CommandHelp(mso["UCID"])
elif commands[0] == "!quit":
CommandQuit(mso["UCID"])
elif commands[0] == "!report":
CommandReport(mso["UCID"])
### startup block
def SetupAndRun():
### Entering main block when no arguments are passed
# list of packets this app uses
insim.RegisterPackets({ISP_MSO: MessageReceived,
ISP_NCN: ConnectionJoined,
ISP_CNL: ConnectionLeft,
ISP_NPL: PlayerJoined,
ISP_PLL: PlayerLeft,
ISP_ISM: JoinedMultiplayer}) # packet-type:def-name
# footer, contains server connection information
try:
insim.Connect(SERVER_NAME, SERVER_PORT) # server ip and insim port
except Exception, (msg):
print "Error while establishing connection to server: ", msg
else:
insim.SendP(Packet(ISP_ISI, Admin=ADMIN, IName=INAME, Flags=ISF_MCI | ISF_LOCAL, Interval=500)) # admin="yourpassword"
print "Connected to server, check for InSim connect on host"
insim.Run()
finally:
insim.Close()
### Main block
if __name__ == "__main__":
### Commandline arguments
# t, v, h are the short form options
shortArgs = "tvh"
longArgs = ["todo","version","help"]
try:
### Grab the options and arguments from the commandline
opts,args = getopt.getopt(sys.argv[1:], shortArgs, longArgs);
### Check each option and assocaited arguments and act accordingly
for opt, arg in opts:
if opt in ("-t", "--todo"):
PrintTodo()
sys.exit()
elif opt in ("-v", "--version"):
PrintVersion()
sys.exit()
elif opt in ("-h", "--help"):
PrintHelp()
sys.exit()
except getopt.GetoptError:
PrintHelp()
sys.exit(2)
SetupAndRun()
as you can tell, it sortof stinks... :ices_rofl a lot of features haven't been implemented, and the ones that are there, seem to be broken or are still incomplete. haven't hammered-out a full feature list either, but i would like to have as many features as possible.
if anyone feels daring enough to give this a go, let me know.
cheers