public PlayerManager(NetworkContext context) { _context = context; if (_context.IsServer) { _players.Add(_context.LocalPlayer); } }
private LobbyHost(NetworkContext context, IMapManager mapManager, string map) : base(context) { _mapHandler = new MapDownloadServerMessageHandler(context, mapManager, map); _context.AddConnectionMonitor(_mapHandler); _context.AddMessageHandler(_mapHandler); _readinessHandler = new LobbyHostPlayerReadinessMessageHandler(context); _context.AddConnectionMonitor(_readinessHandler); _context.AddMessageHandler(_readinessHandler); }
public GameEngineManager(string snapshotJson, string templateJson, int targetUpdatesPerSecond) { // allocate the engine // TODO: examine the maybe, make sure the game actually loaded _gameEngine = GameEngineFactory.CreateEngine(snapshotJson, templateJson).Value; // create the event monitors CreateEventMonitors(_gameEngine.EventNotifier); _networkContext = NetworkContext.CreateServer(new Player("test-player"), ""); _turnGame = new AutomaticTurnGame(_networkContext, targetUpdatesPerSecond); }
internal LobbyCommon(NetworkContext context) { _context = context; _lobbyLaunchedHandler = new LobbyLaunchedHandler(); _context.AddMessageHandler(_lobbyLaunchedHandler); _playerManager = new PlayerManager(_context); _context.AddMessageHandler(_playerManager); if (_context.IsServer) { _context.AddConnectionMonitor(_playerManager); } }
/// <summary> /// Create a new AutomaticTurnGame. /// </summary> /// <param name="context">The networking context.</param> /// <param name="targetUpdatesPerSecond">The number of updates/turns that will occur every /// second.</param> public AutomaticTurnGame(NetworkContext context, int targetUpdatesPerSecond) { TargetUpdatesPerSecond = targetUpdatesPerSecond; _context = context; if (_context.IsServer) { _serverHandler = new GameServerHandler(_context); _context.AddMessageHandler(_serverHandler); } _clientHandler = new GameClientHandler(); _context.AddMessageHandler(_clientHandler); }
/// <summary> /// Creates a new server. /// </summary> /// <param name="player">The player that is running this server.</param> /// <param name="password">The password that clients have to have to connect.</param> /// <returns>A network context for the created server.</returns> public static NetworkContext CreateServer(Player player, string password) { NetworkContext context = new NetworkContext(player); context._serverPassword = password; // we create and start the server before assigning it to the context because assigning // it to the context enables UPnP, which is not available before the server has started NetServer server = new NetServer(Configuration.GetConfiguration(server: true)); server.Start(); context._server = server; Log <NetworkContext> .Info("Created server (LocalPlayer={0}, Password={1})", player, password); return(context); }
public GameServerHandler(NetworkContext context) { _context = context; _turnDelay = DefaultTurnDelay; _commands = new DelayedMessageAccumulator(DefaultTurnDelay); }
public ChatMessageHandler(NetworkContext context) { _localPlayer = context.LocalPlayer; AllMessages = new List<ReceivedChatMessage>(); DisplayableMessages = new List<ReceivedChatMessage>(); }
/// <summary> /// Creates a new client connection connected to the given IP end point. This method blocks /// until we know if the client has either connected or disconnected. /// </summary> /// <param name="ip">The IP to connect to.</param> /// <param name="player">This computer's player.</param> /// <param name="password">The password that the server is expecting.</param> /// <returns></returns> public static Maybe <NetworkContext> CreateClient(string ip, Player player, string password) { NetClient client = new NetClient(Configuration.GetConfiguration(server: false)); client.Start(); // Write out our hail message { NetOutgoingMessage hailMsg = client.CreateMessage(); HailMessageFormat hail = new HailMessageFormat() { Player = player, Password = password }; string serializedHail = SerializationHelpers.Serialize(hail); hailMsg.Write(serializedHail); Log <NetworkContext> .Info("Trying to connect to " + ip + " on port " + Configuration.Port + " with hailing message " + serializedHail); // Try to connect to the server client.Connect(ip, Configuration.Port, hailMsg); } // Block until we know if we have connected or disconnected. while (true) { NetIncomingMessage msg; while ((msg = client.ReadMessage()) != null) { if (msg.MessageType != NetIncomingMessageType.StatusChanged) { Log <NetworkContext> .Error("While attempting to connect to server, got unexpected message type " + msg.MessageType); continue; } NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte(); Log <NetworkContext> .Info("While attempting to connect to server, status changed to " + status); goto gotConnectionAttemptResult; } Thread.Sleep(0); } gotConnectionAttemptResult: // If the connection status is not connected, then we failed, so just return an empty // network context if (client.ConnectionStatus != NetConnectionStatus.Connected) { return(Maybe <NetworkContext> .Empty); } // We're connected to the server! Read in the hail message to populate our server // connection with the server player instance { NetIncomingMessage msg = client.ServerConnection.RemoteHailMessage; Player serverPlayer = SerializationHelpers.Deserialize <Player>(msg.ReadString()); client.ServerConnection.Tag = serverPlayer; NetworkContext context = new NetworkContext(player) { _client = client }; return(Maybe.Just(context)); } }
public LobbyHostPlayerReadinessMessageHandler(NetworkContext context) { _context = context; }
/// <summary> /// Creates a new server. /// </summary> /// <param name="player">The player that is running this server.</param> /// <param name="password">The password that clients have to have to connect.</param> /// <returns>A network context for the created server.</returns> public static NetworkContext CreateServer(Player player, string password) { NetworkContext context = new NetworkContext(player); context._serverPassword = password; // we create and start the server before assigning it to the context because assigning // it to the context enables UPnP, which is not available before the server has started NetServer server = new NetServer(Configuration.GetConfiguration(server: true)); server.Start(); context._server = server; Log<NetworkContext>.Info("Created server (LocalPlayer={0}, Password={1})", player, password); return context; }
protected void OnEnable() { _networkContext = NetworkContext.CreateServer(HostPlayer, ""); _game = new AutomaticTurnGame(_networkContext, TargetUpdatesPerSecond); }
/// <summary> /// Construct a new ChatManager using the given networking context and the given object for /// mapping network players to a directed player relation graph. /// </summary> /// <param name="context">The networking context.</param> public ChatManager(NetworkContext context) { _context = context; _handler = new ChatMessageHandler(_context); _context.AddMessageHandler(_handler); }
public MapDownloadServerMessageHandler(NetworkContext context, IMapManager mapManager, string map) { _context = context; _mapManager = mapManager; ChangeMap(map); }
public MapDownloadClientMessageHandler(NetworkContext context, IMapManager mapManager) { _context = context; _mapManager = mapManager; }
private LobbyMember(NetworkContext context, IMapManager mapManager) : base(context) { _mapHandler = new MapDownloadClientMessageHandler(context, mapManager); context.AddMessageHandler(_mapHandler); }
/// <summary> /// Create a new PauseManager instance. /// </summary> /// <param name="context">The networking context to use.</param> public PauseManager(NetworkContext context) { _context = context; _handler = new PauseMessageHandler(); _context.AddMessageHandler(_handler); }
/// <summary> /// Creates a new client connection connected to the given IP end point. This method blocks /// until we know if the client has either connected or disconnected. /// </summary> /// <param name="ip">The IP to connect to.</param> /// <param name="player">This computer's player.</param> /// <param name="password">The password that the server is expecting.</param> /// <returns></returns> public static Maybe<NetworkContext> CreateClient(string ip, Player player, string password) { NetClient client = new NetClient(Configuration.GetConfiguration(server: false)); client.Start(); // Write out our hail message { NetOutgoingMessage hailMsg = client.CreateMessage(); HailMessageFormat hail = new HailMessageFormat() { Player = player, Password = password }; string serializedHail = SerializationHelpers.Serialize(hail); hailMsg.Write(serializedHail); Log<NetworkContext>.Info("Trying to connect to " + ip + " on port " + Configuration.Port + " with hailing message " + serializedHail); // Try to connect to the server client.Connect(ip, Configuration.Port, hailMsg); } // Block until we know if we have connected or disconnected. while (true) { NetIncomingMessage msg; while ((msg = client.ReadMessage()) != null) { if (msg.MessageType != NetIncomingMessageType.StatusChanged) { Log<NetworkContext>.Error("While attempting to connect to server, got unexpected message type " + msg.MessageType); continue; } NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte(); Log<NetworkContext>.Info("While attempting to connect to server, status changed to " + status); goto gotConnectionAttemptResult; } Thread.Sleep(0); } gotConnectionAttemptResult: // If the connection status is not connected, then we failed, so just return an empty // network context if (client.ConnectionStatus != NetConnectionStatus.Connected) { return Maybe<NetworkContext>.Empty; } // We're connected to the server! Read in the hail message to populate our server // connection with the server player instance { NetIncomingMessage msg = client.ServerConnection.RemoteHailMessage; Player serverPlayer = SerializationHelpers.Deserialize<Player>(msg.ReadString()); client.ServerConnection.Tag = serverPlayer; NetworkContext context = new NetworkContext(player) { _client = client }; return Maybe.Just(context); } }