Пример #1
0
        public void messageHandler(Socket client, LuaMessage msg)
        {
            switch (msg.command)
            {
            case "validation":
                if (App.gameMask.gameExist(msg.ProcessID))
                {
                    App.gameMask.workOn(msg.ProcessID);
                    luaBridge.sendAnswer(client, "valid success");
                }
                else
                {
                    luaBridge.sendAnswer(client, "valid fail");
                }
                break;

            case "gameended":

                break;
            }
        }
Пример #2
0
        void ReceiveData(IAsyncResult iar)
        {
            Socket client        = (Socket)iar.AsyncState;
            bool   readNoProblem = true;
            int    recv          = new int();

            try
            {
                recv = client.EndReceive(iar);
            }
            catch (Exception ex)
            {
                readNoProblem = false;
            }
            if (readNoProblem)
            {
                if (recv == 0)
                {
                    client.Close();
                    server.BeginAccept(new AsyncCallback(AcceptConn), server);
                    return;
                }
                string receivedData = Encoding.ASCII.GetString(data, 0, recv);

                string[]   words = receivedData.Split('|');
                LuaMessage cmd   = new LuaMessage();
                cmd.ProcessID = int.Parse(words[0]);
                cmd.command   = words[1];
                luaRecieved(client, cmd);
            }

            try
            {
                client.BeginReceive(data, 0, size, SocketFlags.None,
                                    new AsyncCallback(ReceiveData), client);
            }
            catch (Exception ex)
            {
            }
        }