def refresh(self): global startTime, players pingIndex = int((time.time() - startTime) * 1000) if not sp.isServerUp(self.address, self.port): for player in self.players.values(): player.logoff() player.save() self.players = {} self.online = False self.pings[pingIndex] = 0 addLogMessage("{} is offline.".format(self.name)) return self.online = True info = sp.getInfo(self.address, self.port) self.pings[pingIndex] = sp.ping(self.address, self.port) newMap = info["map"] if info else None if newMap: if newMap != self.map: self.maps[newMap] = self.maps[ newMap] + 1 if newMap in self.maps else 1 self.map = newMap online = sp.getPlayers(self.address, self.port) self.playerNames = [] if online: self.playerNames = sp.getPlayerNames(online) self.lastOnline = time.time() if self.oldPlayers == self.playerNames: return self.joined = getNewPlayers(self.oldPlayers, self.playerNames) self.disconnected = getMissingPlayers(self.oldPlayers, self.playerNames) for player in self.joined: p = Player().createNew(player) p.logon(self) self.players[player] = p if p not in players: players.append(p) for player in self.disconnected: if player not in self.players: continue p: Player = self.players[player] p.logoff() del self.players[player] self.oldPlayers = self.playerNames for player in self.players.values(): player.save()
def __init__(self, name, address, port=27015): addLogMessage("Creating a new server: {}, {}, {}".format( name, address, port)) self.name = name self.address = address self.port = port if isinstance(port, int) else int(port) self.lastOnline = time.time() self.online = sp.isServerUp(self.address, self.port) self.playerNames = [] self.players = {} self.oldPlayers = [] info = sp.getInfo(self.address, self.port) self.maxPlayers = info["max_players"] if info else 32 self.disconnected = [] self.joined = [] self.map = None self.maps = {} self.pings = {}
def pinger(self): while 1: time.sleep(random.randint(30, 300)) ServerPinger.Pinger().check()
del self.puser del self.ppass class ThreadingHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): def handle_error(self, request, client_address): pass class HTTPProxyService(): def __init__(self): self.httpd = ThreadingHTTPServer((sets.LHOST, sets.LPORT), ProxyHandler) self.httpd.allow_reuse_address = True def serve_forever(self): self.httpd.serve_forever() def server_close(self): self.httpd.server_close() if __name__ == "__main__": proxy_service = HTTPProxyService() IsExec(), UrlBlock() try: proxy_service.serve_forever() ServerPinger.Pinger().check() except KeyboardInterrupt: proxy_service.server_close() print "\r", time.asctime(), "Server shutdown successfully"