Exemple #1
0
        public GameServer addServer(ServerHost host)
        {
            List<GameServer> temp = findServersByHost(host);
            if (temp.Count > 0)
                return temp[0];

            GameServer server = new GameServer();
            server.host = host;
            servers.Add(server);
            return server;
        }
Exemple #2
0
 public List<GameServer> findServersByHost(ServerHost host)
 {
     List<GameServer> temp = new List<GameServer>();
     foreach(GameServer g in servers)
     {
         if (g.host.hostname == host.hostname && g.host.port == host.port)
             temp.Add(g);
     }
     return temp;
 }
Exemple #3
0
        private bool handleDataPush(HTTPConnection connection)
        {
            // it's a server that is updating data
            string command = connection.getArg("action");

            // commands
            if (command == "add")
            {
                //string host = connection.getArg("host");
                string port = connection.getArg("port");
                if (port == string.Empty)
                    port = "5154";

                ServerHost host = new ServerHost();
                host.hostname = connection.getArg("host");
                host.port = 5154;
                if (connection.hasArg(port))
                     int.TryParse(connection.getArg(port),out host.port);

                GameServer server = null;
                List<GameServer> servers = serverDB.findServersByHost(host);
                if (servers.Count != 0)
                    server = servers[0];
                else
                    server = serverDB.addServer(host);

                if (server == null)
                    return pushError(connection, "invalid server");

                server.description = connection.getArg("desc");
                string playerBlob = connection.getArg("players");
                if (playerBlob != null && playerBlob != string.Empty)
                {
                    // parse players
                    XmlSerializer xml = new XmlSerializer(typeof(List<GamePlayer>));
                    StreamReader reader = new StreamReader(playerBlob);
                    server.players = (List<GamePlayer>)xml.Deserialize(reader);;
                    reader.Close();
                }
                serverDB.updateServer(server);

                return pushOK(connection);
            }
            //update

            return pushError(connection,"unknown command");
        }