IEnumerator RunLocalTest(Action prepare, Func <bool> check, Action validate) { var server = new NetworkGameServer(typeof(T), new NetworkServerConfig { Port = 8888 }); Host = new NetworkHost { Server = server, Client = server.CreateLocalClient() }; int count = 0; while (Host.Server.Clients.Count <= 0) { Host.Update(); yield return(null); count++; } prepare(); for (var i = 0; i < 1000; i++) { Host.Update(); if (check()) { break; } yield return(null); } validate(); }
static void Main(string[] args) { var server = new NetworkGameServer(); EventRunner.RegisterGameServer(server); Handshake(server); var gameLoop = new GameLoop(new NetworkEventProvider(server), MakePlayerDeck(), MakePlayerDeck()); gameLoop.PlayGame(); Console.ReadKey(); }
private static void Handshake(NetworkGameServer server) { string guid = Guid.NewGuid().ToString(); var handshake = new HandshakeEvent(guid); server.Send(new GameMessage(handshake)); GameMessage received = server.Receive(); if (received.ContentType != typeof(HandshakeEvent)) { throw new Exception("server expected handshake."); } HandshakeEvent internalEvent = received.DeserializeContent <HandshakeEvent>(); if (internalEvent.HandshakeMessage != guid) { throw new Exception($"The client did not respond with the expected handshake message. Expected: {guid}\nSaw: {internalEvent.HandshakeMessage}"); } Debug.Log("Handshake succeeded."); }