import networkSockets '''Assumptions: * We can use the networking interface to send dataz when we want to * If we want to receive data we call a "isDataz" method on the networker if there is data it returns it, otherwise returns false. * User sets this up in a text UI. * We have a world object to mess with.''' class ServerLogic(): def __init__(self): '''This is a list of parameters for the server.''' self.watchers = {} # client watchers in game at any given time self.participants = {} # client participants in game at any given time self.watcherWhiteList = [] # allowed clients self.watcherBlackList = [] # blocked clients self.participantWhiteList = [] # allowed clients self.participantBlackList = [] # blocked clients self.endConditions = [] # conditions to check for which make the game end self.port = 32323 # for use with the server constructor (32323 default) self.numParticipants = None # The number of players this game is allowed to have. self.numWatchers = None # The number of watchers this game is allowed to have self.networker = TiredSick(32323) self.world = LocalWorld(10, 10) self.allowedAreas = None # This is a 3d list. It says who can place where. self.waitTime = 60 # How long the getPlayers process waits for people to join. self.cycleDelay = .25 # How long the delay is each cycle. # Startup # This gets the settings def startup(): # watcher/participant white/black lists # endConditions temp = input("Would you like to enter a non-standard port? (y/n): ") if temp equals "y": self.port = input("what port would you like to listen on?: ") temp = input("Would you like to set a maximum number of participants? (y/n): ") if temp equals "y": self.numParticipants = ''' Goal: method that takes a parameter and then gives dialog to set it''' ''' The other way was tedious and not cool.''' def setParam(self, parameter): temp = input("Would you like to change the default setting for" + parameter # Startup # This gets players # There are a few type of players: # watcher (just receives updates) # participant (also participates in setup) # The paramter refers to either type, they specify in request def getPlayers(time, type=any): while(True): return # Complicated Part def interactiveSetup(): while(True): return # Initial Board / Species sync def initialize(): pass # Program Loop!! def going(delay): while(going): self.world.getChanges() self.networker.sendChanges(self.world.changeList) self.world.applyChanges() for end in self.endConditions: if end.winner() not equal false: return end.holds() self.getPlayers(delay, watch) '''The actual go method.''' def serverStart(): startup() getPlayers() initeractiveSetup() initialize() going() # ToDo # We need to figure out how endConditions are represented # Class with holds method # We need to figure out how black/white lists are represented # Match to regular expressions '''This is a lot of work. Needs new predicate system for board conditions. implementing it later (maybe).''' class EndCondition(): '''Class that stores a game end condition.''' def __init__(self, winner=None, boardPredicate): self.winner = winner self.boardPredicate = boardPredicate def winner(): if boardPredicate.holds(): return winner else: return False