private static void testAcpcGame() { using (var game = new AcpcGame(TableType.HeadsUp)) { string gameResponse; /*gameResponse = game.acceptMessageFromServer("MATCHSTATE:0:30::9s8h"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:0:30:c:9s8h|"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:0:30:cc/:9s8h|/8c8d5c"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:0:30:cc/r250:9s8h|/8c8d5c"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:0:30:cc/r250c/:9s8h|/8c8d5c/6s"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:0:30:cc/r250c/r500:9s8h|/8c8d5c/6s"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:0:30:cc/r250c/r500c/:9s8h|/8c8d5c/6s/2d"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE: 0:30:cc/r250c/r500c/r1250:9s8h|/8c8d5c/6s/2d"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:0:30:cc/r250c/r500c/r1250c:9s8h|9c6h/8c8d5c/6s/2d"); * * gameResponse = game.acceptMessageFromServer("MATCHSTATE:1:31::|JdTc"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:1:31:r300:|JdTc"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:1:31:r300r900:|JdTc"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:1:31:r300r900c/:|JdTc/6dJc9c"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:1:31:r300r900c/r1800:|JdTc/6dJc9c"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:1:31:r300r900c/r1800r3600:|JdTc/6dJc9c"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:1:31:r300r900c/r1800r3600r9000:|JdTc/6dJc9c"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:1:31:r300r900c/r1800r3600r9000c/:|JdTc/6dJc9c/Kh"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:1:31:r300r900c/r1800r3600r9000c/r20000:|JdTc/6dJc9c/Kh"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:1:31:r300r900c/r1800r3600r9000c/r20000c/:KsJs|JdTc/6dJc9c/Kh/Qc");*/ /*gameResponse = game.acceptMessageFromServer("MATCHSTATE:0:2::Ah8s|"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:0:2:r8381:Ah8s|"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:0:2:r8381r19900:Ah8s|"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:0:2:r8381r19900r20000:Ah8s|");*/ /*gameResponse = game.acceptMessageFromServer("MATCHSTATE:0:18::AsJh|"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:0:18:r11449:AsJh|"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:0:18:r11449r20000:AsJh|"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:0:18:r11449r20000c///:AsJh|8d2c/7dAh5c/3s/3c"); * gameResponse = game.acceptMessageFromServer("MATCHSTATE:1:19::|7dKc");*/ gameResponse = game.acceptMessageFromServer("MATCHSTATE:1:1571::|QsQd"); gameResponse = game.acceptMessageFromServer("MATCHSTATE:1:1571:r300:|QsQd"); gameResponse = game.acceptMessageFromServer("MATCHSTATE:1:1571:r300r4062:|QsQd"); gameResponse = game.acceptMessageFromServer("MATCHSTATE:1:1571:r300r4062r12186:|QsQd"); gameResponse = game.acceptMessageFromServer("MATCHSTATE:1:1571:r300r4062r12186r20000:|QsQd"); } }
private static void gameLoop(TcpClient tcpClient, NetworkStream stream, AcpcGame game) { var data = new byte[512]; int numberOfBytesRead = 0; var protocolVersion = "VERSION:2.0.0"; Console.WriteLine("Sending protocol version to server '{0}'", protocolVersion); sendMessage(stream, protocolVersion); int nempty = 0; while (true) { Console.WriteLine("Waiting for server input, bytes in buffer {0}", numberOfBytesRead); numberOfBytesRead += stream.Read(data, numberOfBytesRead, data.Length - numberOfBytesRead); int pos = findSplitter(data, numberOfBytesRead); Console.WriteLine("Message arrived, bytes in buffer {0}, fount delimeter at {1}", numberOfBytesRead, pos); if (numberOfBytesRead == 0) { if (tcpClient.Connected && nempty < 20) { nempty++; Console.WriteLine("Recieved {0} empty message.", nempty); System.Threading.Thread.Sleep(50); continue; } else { Console.WriteLine("Recieved too many empty messages or tcpClient is disconected, ending the match."); game.finishHand(); Console.WriteLine("Total Saldo: {0}", game.TotalSaldo); break; } } nempty = 0; while (pos > -1) { if (pos > 0) { string message = System.Text.Encoding.ASCII.GetString(data, 0, pos); //Console.WriteLine("Parsed message: {0}", message); if (message[0] != '#' && message[0] != ';') // Comment or GUI command { string gameResponse = game.acceptMessageFromServer(message); if (gameResponse != null && gameResponse != "") { sendMessage(stream, gameResponse); } } } for (int i = pos + 2; i < numberOfBytesRead; i++) { data[i - pos - 2] = data[i]; } numberOfBytesRead -= pos + 2; pos = findSplitter(data, numberOfBytesRead); if (pos > -1) { Console.WriteLine("Found delimeter at {0}", pos); } } } }