Example #1
0
        public static (bool, string) SendRecv(string body)
        {
            if (BeforeSetAddress)
            {
                return(false, string.Empty);
            }
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            socket.Connect(Address, Port);
            if (!socket.Connected)
            {
                while (!socket.Connected)
                {
                    socket = Reconnect(socket);
                }
            }
            try
            {
                var withHeader = HeaderProtocol.MakeHeader(body, true);
                var(s, r, recvMsg) = Connection.SendAndRecvMessage(withHeader, socket);
                socket.Close();
                return(r, recvMsg);
            }
            catch (Exception)
            {
                return(false, string.Empty);
            }
        }
        public void ああああ(string input, bool exp)
        {
            var withHeader = HeaderProtocol.MakeHeader(input, true);

            var(s, r, m) = Connection.SendAndRecvMessage(withHeader, _socket);
            Console.WriteLine($"{s} {r} {m}");
        }
 public void GamePlayingTest(string receivedMsg, bool exp)
 {
     var sendingMsg = _handleClient.MakeSendMessage(receivedMsg);
     Console.WriteLine(sendingMsg);
     var (bufSize, isTrueMessage, msg) = HeaderProtocol.ParseHeader(sendingMsg);
     Assert.AreEqual(bufSize, msg.Length);
     Assert.AreEqual(exp, isTrueMessage);
 }
Example #4
0
 public RawPacketHeader(byte[] buffer) : base(buffer)
 {
     HeaderProtocol       = (HeaderProtocol)buffer.ToUInt(8, 4);
     FrameLength          = buffer.ToUInt(12, 4);
     PayloadRemoved       = buffer.ToUInt(16, 4);
     OriginalPacketLength = buffer.ToUInt(20, 4);
     if (HeaderProtocol == HeaderProtocol.Ethernet)
     {
         Header = new EthernetFrame(buffer.AsSpan(24, (int)OriginalPacketLength).ToArray());
     }
 }
        public string MakeSendMessage(string receivedMessage)
        {
            var message = JsonConvert.DeserializeObject <ClientMessage>(receivedMessage);

            var(methodSuccess, sendMessage) = message switch
            {
                CreatePlayerMessage cr => CreatePlayer(cr),
                CloseCreateMessage cl => CloseCreate(cl),
                GetMatchInfoMessage gm => GetMatchInfo(gm),
                GetAllMatchesMessage _ => GetAllMatches(),
                DiceMessage dm => ThrowDice(dm),
                GetStartedMatchMessage gsm => GetStatedMatch(gsm),
                GetRankingMessage gr => GetRanking(gr),
                GetMatchViewImageMessage gmv => GetMatchView(gmv),
                _ => throw new NotImplementedException()
            };

            return(HeaderProtocol.MakeHeader(sendMessage, methodSuccess));
        }
Example #6
0
        public void 作ったマッチが保持されてるか確認するテスト()
        {
            var create1 = (string)((object[])TestCases[0])[0];

            _handleClient.MakeSendMessage(create1);
            var request  = JsonConvert.SerializeObject(new GetAllMatchesMessage());
            var response = _handleClient.MakeSendMessage(request);

            var(_, _, body) = HeaderProtocol.ParseHeader(response);
            Console.WriteLine(body);

            var create2 = (string)((object[])TestCases[1])[0];

            _handleClient.MakeSendMessage(create2);
            request  = JsonConvert.SerializeObject(new GetAllMatchesMessage());
            response = _handleClient.MakeSendMessage(request);

            (_, _, body) = HeaderProtocol.ParseHeader(response);
            Console.WriteLine(body);
        }