コード例 #1
0
ファイル: Server.cs プロジェクト: kvangcxworkspace/LaserTag
        private byte[] handleData(ClientOperationData clientOpeartionData)
        {
            string response = "";

            switch (clientOpeartionData.OPERATION_CODE)
            {
            case (byte)'1':     // connecting get username
                string uniqueKey  = Encoding.ASCII.GetString(clientOpeartionData.OPERATION_DATA);
                string mysqlQuery = "SELECT username FROM clientuserdata WHERE unique_key = @uniquekey";

                MySqlCommand cmd = new MySqlCommand(mysqlQuery, DBCONNECTION);
                cmd.Parameters.AddWithValue("@uniquekey", uniqueKey);

                string username = queryDatabase(cmd);

                if (username != "")
                {
                    response = "1" + username;
                }

                break;

            case (byte)'2':     // join game
                break;

            default:
                response = "0";
                break;
            }

            return(Encoding.ASCII.GetBytes(response));
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: kvangcxworkspace/LaserTag
        public void Run()
        {
            Console.Write("Listening For Incomming Messages...");
            IPEndPoint client = new IPEndPoint(IPAddress.Any, 0);

            while (RUNNING)
            {
                byte[] data = SOCK.Receive(ref client);
                Console.Write("Message received from {0} : ", client.ToString());
                Console.WriteLine(Encoding.ASCII.GetString(data, 0, data.Length));

                ClientOperationData clientOperationData = ParseData(data);
                byte[] response = handleData(clientOperationData);

                Console.WriteLine("Responding with: {0}", Encoding.ASCII.GetString(response, 0, response.Length));
                SOCK.Send(response, response.Length, client);
            }
        }