示例#1
0
        private void btnClientHeaders_Click(object sender, EventArgs e)
        {
            HTTPConnection tmp    = (HTTPConnection)CurrentConnection;
            ClientHeaders  dialog = new ClientHeaders(tmp.ClientHeaders);

            dialog.ShowDialog();
        }
示例#2
0
 private bool pushError(HTTPConnection connection, string error)
 {
     connection.writeToContext("\nError: " + error);
     return false;
 }
示例#3
0
 private bool pushOK(HTTPConnection connection)
 {
     connection.writeToContext("\nOK");
     return false;
 }
示例#4
0
        private bool handleDataRequest(HTTPConnection connection)
        {
            string command = connection.getArg("action");

            // commands
            if (command == "list")
            {
                List<ServerHost> hosts = serverDB.listServers();
                if( hosts.Count == 0)
                    connection.writeToContext("No Results\n");
                else
                {
                    // parse players
                    XmlSerializer xml = new XmlSerializer(typeof(List<ServerHost>));

                    MemoryStream memStream = new MemoryStream();

                    StreamWriter writer = new StreamWriter(memStream);
                    xml.Serialize(writer, hosts);
                    writer.Close();

                    memStream.Seek(0, SeekOrigin.Begin);
                    StreamReader reader = new StreamReader(memStream);
                    string temp = reader.ReadToEnd();
                 //   string temp = new string(System.Text.ASCIIEncoding.ASCII.GetChars(memStream.GetBuffer(),0,(int)memStream.Length));
                    reader.Close();
                    memStream.Close();

                    connection.writeToContext(temp);
                }
                return dataOK(connection);
            }

            return dataError(connection,"unknown request");
        }
示例#5
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");
        }
示例#6
0
 private bool dataOK(HTTPConnection connection)
 {
     connection.writeToContext("\nQuery OK");
     return false;
 }
示例#7
0
 private bool dataError(HTTPConnection connection, string error)
 {
     connection.writeToContext("\nQuery Error: " + error);
     return false;
 }
示例#8
0
        public bool handleURL(HttpListenerContext context)
        {
            HTTPConnection connection = new HTTPConnection(context);

            if (connection.hasArg("isgameserver"))
                return handleDataPush(connection);

            return handleDataRequest(connection);
        }