Beispiel #1
0
        //public static SRequest GetRequest(byte[] data, int length)
        //{
        //	if (data[0] != SRequest.BoundByte && data[length-1] != SRequest.BoundByte)
        //	{

        //	}

        //	SRequest result = new SRequest();
        //	result.Command = BitConverter.ToInt32(data, 0);
        //	result.UserId = BitConverter.ToUInt64(data, sizeof(int));
        //	Array.Copy(data, sizeof(byte) + sizeof(int) + sizeof(ulong), result.DataStream, 0, length);
        //}

        public static byte[] GridAnswerToByteArray(SGridResponce answer)
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            int size = answer.Grid.GetLength(0);

            writer.Write(size);

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    writer.Write(Convert.ToByte(answer.Grid[i, j]));
                }
            }

            return(stream.GetBuffer());
        }
Beispiel #2
0
        public static SGridResponce ByteArrayToGridAnswer(byte[] data)
        {
            MemoryStream stream = new MemoryStream(data);
            BinaryReader reader = new BinaryReader(stream);

            int size = reader.ReadInt32();

            SGridResponce answer = new SGridResponce();

            answer.Grid = new int[9, 9];

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    answer.Grid[i, j] = reader.ReadByte();
                }
            }

            return(answer);
        }
Beispiel #3
0
        private static byte[] ProcessRequest(byte[] data)
        {
            short request_value = BitConverter.ToInt16(data, 0);
            var   request_name  = Enum.GetName(typeof(ECommands), request_value);

            if (request_name == null)
            {
                //TODO Log.
                Console.WriteLine("Error");
                return(new byte[3]);
            }

            //TODO Log.
            byte[] result = new byte[3];

            switch ((ECommands)request_value)
            {
            case ECommands.Ping:
            {
                break;
            }

            case ECommands.Connect:
            {
                break;
            }

            case ECommands.MakeLobby:
            {
                break;
            }

            case ECommands.LobbyList:
            {
                break;
            }

            case ECommands.ConnectToLobby:
            {
                break;
            }

            case ECommands.GetLobbyInfo:
            {
                break;
            }

            case ECommands.GetPlayerInfo:
            {
                break;
            }

            case ECommands.GetGrid:
            {
                SGridResponce answer = new SudokuCore.Protocol.SGridResponce(grid);
                return(ProtocolHelper.GridAnswerToByteArray(answer));

                break;
            }

            case ECommands.GetMarks:
            {
                break;
            }

            case ECommands.UpdateGrid:
            {
                break;
            }

            case ECommands.GetServerTime:
            {
                break;
            }

            case ECommands.EnterNumber:
            {
                break;
            }

            case ECommands.EnterMark:
            {
                break;
            }

            case ECommands.CheckWin:
            {
                break;
            }

            case ECommands.GiveUp:
            {
                break;
            }
            }

            return(result);
        }