Exemple #1
0
 def unfoundCity(self, peer, ident):
     '''Checks permissions and, if all good, unfounds city.'''
     # Can't unfound the region or a city that doesn't exist
     logging.debug("Requesting to unfound city %s by %s" %(ident, peer))
     container = proto.Container()
     if not ident or ident not in self.cities:
         container.response = "Can not unfound imaginary city."
         messenger.send("sendData", [peer, container])
         return
     
     user = users.getNameFromPeer(peer)
     access = users.getType(user)
     
     if access > 1 or self.cities[ident].mayor == user:
         for tile in self.tiles:
             if tile.cityid is ident:
                 tile.cityid = 0
                 self.updateTile(container, tile)
         del self.cities[ident]
         container.unfoundCity = ident
         messenger.send("broadcastData", [container])
     else:
         container.response = "Lack permissions for unfounding this city."
         messenger.send("sendData", [peer, container])
     logging.info("City %s unfounded. New city db: %s" %(ident, self.cities))
Exemple #2
0
 def logout(self, peer):
     self.lock.acquire()
     userName = users.getNameFromPeer(peer)
     # Temporary fix.
     if userName:
         users.logout(userName)
         logger.info("User %s %s exiting." % (userName, peer))
     self.lock.release()
Exemple #3
0
 def logout(self, peer):
     self.lock.acquire()
     userName = users.getNameFromPeer(peer)
     # Temporary fix.
     if userName:
         users.logout(userName)
         logger.info("User %s %s exiting." %(userName, peer))
     self.lock.release()
Exemple #4
0
 def newCity(self, peer, info):
     '''Checks to make sure city location is valid. 
     If so we establish city!
     '''
     for x in range(0, 64):
         for y in range(0,64):
             tile = self.getTile(info.positionx+x, info.positiony+y)
             if tile.cityid:
                 container = proto.Container()
                 container.newCityResponse.type = 0
                 container.newCityResponse.message = "A city already claims tile " + str((info.positionx+x, info.positiony+y))
                 messenger.send("sendData", [peer, container])
                 return
     
     # Grab next free id. If we are at region city limit then no build!
     cityids = self.cities.keys()
     cityid = 1
     for n in range(1, self.city_limit):
         if n not in cityids:
             cityid = n
             break
     else:
         container = proto.Container()
         container.newCityResponse.type = 0
         container.newCityResponse.message = "This region has reached its max limit of  " + str(self.city_limit) + " cities."
         messenger.send("sendData", [peer, container])
         return
     
     # Passed the test! Time to found!
     user = users.getNameFromPeer(peer)
     newcity = city.City(info.name, cityid, mayor = user)
     self.cities[cityid] = newcity
     updated_tiles = []
     for y in range(0, 64):
         for x in range(0, 64):
             tile = self.getTile(info.positionx+x, info.positiony+y)
             tile.cityid = cityid
             updated_tiles.append(tile)
     
     container = proto.Container()
     container.newCityResponse.type = 1
     #messenger.send("sendData", [peer, container])
     print info.name, "founded with", newcity.funds
     
     #container = proto.Container()
     container.newCity.id = cityid
     container.newCity.name = info.name
     container.newCity.mayor = user
     container.newCity.population = newcity.population
     container.newCity.funds = newcity.funds
     #messenger.send("broadcastData", [container])
     
     #container = proto.Container()
     for tile in updated_tiles:
         self.updateTile(container, tile)
     messenger.send("broadcastData", [container])
Exemple #5
0
 def checkEnterCity(self, peer, ident):
     '''Checks if user can enter city and if so, what permissions.'''
     # TODO: Check if city is active, if not send tiles to be simulated
     # TODO: Flag city as active
     userName = users.getNameFromPeer(peer)
     city = self.cities[ident]
     container = proto.Container()
     if users.isAdmin(userName) or userName == city.mayor:
         container.enterCity = ident
     elif users.canUser(userName, ident, 'viewCity'):
         container.enterCity = ident
     else:
         container.response = "You lack permission to enter city."
     messenger.send("sendData", [peer, container])
Exemple #6
0
 def processData(self, peer, data):
     """
     processes serialized network event object into internal message system
     """
     container = proto.Container()
     container.ParseFromString(data)
     logger.debug("Data from: %s\nData: %s" % (peer, container))
     # Parsing chain!
     # Great care will need to be taken on when to use if, else, and elif
     # If the profile for this process takes too long
     if container.HasField("login"):
         self.login(peer, container.login)
     # If the player is not logged in we will not process any other message
     if peer not in users.peers:
         print "Unauthorized message from", peer, ". Skipping."
         return
     if container.HasField("chat"):
         messenger.send("onChat", [peer, container.chat])
     if container.HasField("requestServerState"):
         messenger.send("requestServerState", [peer])
     elif container.HasField("requestMaps"):
         messenger.send("requestMaps", [peer])
     elif container.HasField("mapRequest"):
         # Make sure user is admin!
         name = users.getNameFromPeer(peer)
         if users.isAdmin(name):
             messenger.send("mapRequest", [container.mapRequest])
     elif container.HasField("newCityRequest"):
         messenger.send("newCityRequest", [peer, container.newCityRequest])
     elif container.HasField("requestGameState"):
         if not container.requestGameState:
             messenger.send("sendGameState", [peer])
     elif container.HasField("requestUnfoundCity"):
         messenger.send("requestUnfoundCity",
                        [peer, container.requestUnfoundCity])
     elif container.HasField("requestEnterCity"):
         messenger.send("requestEnterCity",
                        [peer, container.requestEnterCity])
     elif container.HasField('requestExitCity'):
         messenger.send('requestExitCity', [
             peer,
         ])
Exemple #7
0
 def processData(self, peer, data):
     """
     processes serialized network event object into internal message system
     """
     container = proto.Container()
     container.ParseFromString(data)
     logger.debug("Data from: %s\nData: %s" %(peer, container))
     # Parsing chain!
     # Great care will need to be taken on when to use if, else, and elif
     # If the profile for this process takes too long
     if container.HasField("login"):
         self.login(peer, container.login)
     # If the player is not logged in we will not process any other message
     if peer not in users.peers:
         print "Unauthorized message from", peer, ". Skipping."
         return
     if container.HasField("chat"):
         messenger.send("onChat", [peer, container.chat])
     if container.HasField("requestServerState"):
         messenger.send("requestServerState", [peer])
     elif container.HasField("requestMaps"):
         messenger.send("requestMaps", [peer])
     elif container.HasField("mapRequest"):
         # Make sure user is admin!
         name = users.getNameFromPeer(peer)
         if users.isAdmin(name):
             messenger.send("mapRequest", [container.mapRequest])
     elif container.HasField("newCityRequest"):
         messenger.send("newCityRequest", [peer, container.newCityRequest])
     elif container.HasField("requestGameState"):
         if not container.requestGameState:
             messenger.send("sendGameState", [peer])
     elif container.HasField("requestUnfoundCity"):
         messenger.send("requestUnfoundCity", [peer, container.requestUnfoundCity])
     elif container.HasField("requestEnterCity"):
         messenger.send("requestEnterCity", [peer, container.requestEnterCity])
     elif container.HasField('requestExitCity'):
         messenger.send('requestExitCity', [peer,])