Пример #1
0
 private static void LogPostHandler(ContextEventArgs e)
 {
     NameValueCollection postValues = MiniUtility.GetFormValues(e.Context.Request);
     string model     = postValues["model"] == null ? postValues["model"] : string.Empty;
     string dateStart = postValues["dateStart"] == null ? postValues["dateStart"] : string.Empty;
     string dateEnd   = postValues["dateEnd"] == null ? postValues["dateEnd"] : string.Empty;
 }
Пример #2
0
    public static bool UnRegister(string serverAddress, int serverPort, MiniHostData hostData)
    {
        TcpClient socket  = null;
        bool      success = false;

        try
        {
            socket = new TcpClient(serverAddress, serverPort);

            if (MiniUtility.Write(socket, "unregister"))
            {
                string s = MiniUtility.Serialize(hostData);
                if (!string.IsNullOrEmpty(s))
                {
                    success = MiniUtility.Write(socket, s);
                }
            }
        }
        catch (SocketException socketException)
        {
            Debug.LogError("MiniClient::UnRegister: Socket exception: " + socketException);
        }

        if (socket != null && socket.Connected)
        {
            socket.Close();
        }

        return(success);
    }
Пример #3
0
    public static List <MiniHostData> GetServerList(string serverAddress, int serverPort)
    {
        List <MiniHostData> serverList = new List <MiniHostData>();
        TcpClient           socket     = null;

        try
        {
            socket = new TcpClient(serverAddress, serverPort);

            if (MiniUtility.Write(socket, "list"))
            {
                string s = MiniUtility.Read(socket);
                if (!string.IsNullOrEmpty(s))
                {
                    serverList = (List <MiniHostData>)MiniUtility.Deserialize(s);
                }
            }
        }
        catch (SocketException socketException)
        {
            Debug.LogError("MiniClient::GetServerList: Socket exception: " + socketException);
        }

        if (socket != null && socket.Connected)
        {
            socket.Close();
        }

        return(serverList);
    }
Пример #4
0
    private void Start()
    {
        if (testing)
        {
            // get real ip address
            MiniUtility.IpInfo ipInfo = MiniUtility.GetIpInfo();

            testHostData = new MiniHostData
            {
                version   = "1.0",
                name      = "Test Server",
                comment   = "Some usefull data",
                password  = "******",
                map       = "superMap",
                country   = ipInfo.country,
                ip        = ipInfo.ip,
                port      = 8090,
                mapTime   = 1000,
                roundTime = 100,
                playerNow = Random.Range(0, 10),
                playerMax = 10
            };
        }
    }
Пример #5
0
    private void ClientCommand(TcpClient socket)
    {
        //Debug.Log("MiniServer::ClientCommand: new client thread: " + socket.Client.LocalEndPoint.ToString());

        string cmd = MiniUtility.Read(socket);

        if (cmd == "list")
        {
            //Debug.Log("MiniServer::ClientCommand: server list requested");
            mutex.WaitOne();
            string s = MiniUtility.Serialize(serverList);
            mutex.ReleaseMutex();
            if (!MiniUtility.Write(socket, s))
            {
                Debug.LogError("MiniServer::ClientCommand: could not send server list to client: "
                               + socket.Client.LocalEndPoint.ToString());
            }
        }
        else if (cmd == "register")
        {
            //Debug.Log("MiniServer::ClientCommand: requesting client registration");
            string s = MiniUtility.Read(socket);
            if (!string.IsNullOrEmpty(s))
            {
                MiniHostData hostData = (MiniHostData)MiniUtility.Deserialize(s);
                if (hostData != null)
                {
                    mutex.WaitOne();
                    MiniHostData registredHost = serverList.Find(h => h.ip == hostData.ip && h.port == hostData.port);
                    if (registredHost != null)
                    {
                        Debug.Log("MiniServer::ClientCommand: updating host data: " + hostData.ip);
                        serverList[serverList.IndexOf(registredHost)] = hostData;
                    }
                    else
                    {
                        Debug.Log("MiniServer::ClientCommand: registred host: " + hostData.ip);
                        serverList.Add(hostData);
                    }
                    mutex.ReleaseMutex();
                }
                else
                {
                    Debug.LogError("MiniServer::ClientCommand: could not deserialize host data");
                }
            }
        }
        else if (cmd == "unregister")
        {
            //Debug.Log("MiniServer::ClientCommand: requesting host deletion");
            string s = MiniUtility.Read(socket);
            if (!string.IsNullOrEmpty(s))
            {
                MiniHostData hostData = (MiniHostData)MiniUtility.Deserialize(s);
                if (hostData != null)
                {
                    mutex.WaitOne();
                    MiniHostData registredHost = serverList.Find(h => h.ip == hostData.ip && h.port == hostData.port);
                    if (registredHost != null)
                    {
                        Debug.Log("MiniServer::ClientCommand: removing host: " + hostData.ip);
                        serverList.Remove(registredHost);
                    }
                    else
                    {
                        Debug.Log("MiniServer::ClientCommand: could not remove host, host not found: " + hostData.ip);
                    }
                    mutex.ReleaseMutex();
                }
                else
                {
                    Debug.LogError("MiniServer::ClientCommand: could not deserialize host data");
                }
            }
        }

        socket.Close();
    }