public void AskForGame() { Debug.Log("Looking for Game"); Schema.LookingForGame lookingForGame = new Schema.LookingForGame() { Username = this.Id, }; TCPConnection.SendMessage(Any.Pack(lookingForGame)).Wait(); }
private void AskForGame(Schema.LookingForGame playerLookingForGame) { this.Game = Server.FindGame(this); Schema.JoinedGame joinedGame = new Schema.JoinedGame { Username = this.Username, }; Console.WriteLine("Telling player they got a game"); this.SendMessage(Any.Pack(joinedGame)); Console.WriteLine("Telling player initial board state"); this.SendMessage(Any.Pack(Game.Board.GetBoardState())); }
public void Client_HandlePlayerLookingForGame() { Client client = TestObjects.BuildClient(); Schema.LookingForGame playerLookingForGame = client.BuildLookingForGame(); client.ClientSendToServer(Any.Pack(playerLookingForGame)); Assert.IsNotNull(client.Game); CollectionAssert.Contains(client.Game.Players, client); Game originalGame = client.Game; client.ClientSendToServer(Any.Pack(playerLookingForGame)); Assert.AreEqual(1, client.Game.Players.Count); Assert.AreEqual(originalGame, client.Game); Assert.AreEqual(1, client.Server.OpenGames.Count); }
public void Client_ExtractDataFromConnection() { Client client = TestObjects.BuildClient(); Schema.LookingForGame player = new Schema.LookingForGame() { Username = "******" }; byte[] bytes = Any.Pack(player).ToByteArray(); client.TCPConnection.ReceiveBuffer = bytes; Assert.AreEqual(Constants.DEFAULT_BUFFER_SIZE, client.TCPConnection.ReceiveBuffer.Length); client.TCPConnection.ExtractDataFromBuffer(bytes.Length); Schema.LookingForGame readJoinedGame = client.TCPConnection.ReceivedData.Message.Unpack <Schema.LookingForGame>(); Assert.AreEqual(player, readJoinedGame); }