public void OnPong(IObjectConnection connection, PongObject pongObject) { var info = Connections[connection]; info.HasPonged = true; info.LastTicks = DateTime.Now.Ticks; }
public void OnClientConnected(IObjectConnection connection) { lock (connectionLock) if (this.connection != null) { var manager = new TicTacToeManager(this.connection, connection); this.connection.AddEventHandler(manager); connection.AddEventHandler(manager); // Between creating the TicTacToeManager and adding it as an eventhandler to each connection // the other connection could disconnect and the other would be stuck in a ghost game // so check if one the connections has disconnected and notify the manager. if (this.connection.IsStopped) { manager.OnDisconnect(this.connection); } if (connection.IsStopped) { manager.OnDisconnect(connection); } this.connection.RemoveEventHandlers(this); connection.RemoveEventHandlers(this); this.connection = null; } else { this.connection = connection; } }
public void OnClientDisconnected(IObjectConnection connection) { lock (connectionLock) if (this.connection == connection) { this.connection = null; } }
public void OnClientConnected(IObjectConnection connection) { var name = GenerateUniqueName(); clients[connection] = name; BroadCast(new ClientConnected { Name = name }); }
public void OnChatMessageReceived(IObjectConnection connection, string message) { var name = clients[connection]; BroadCast(new Message { SenderName = name, Content = message }); }
public void OnClientDisconnected(IObjectConnection connection) { var name = clients[connection]; clients.Remove(connection); BroadCast(new ClientDisconnected { Name = name }); }
public TicTacToeManager(IObjectConnection player1, IObjectConnection player2) { for (int x = 0; x < grid.Length; x++) { grid[x] = new object[3]; } this.player1 = player1; this.player2 = player2; StartGame(); }
private void RandomTurn() { if (r.Next(2) == 1) { playerTurn = player1; } else { playerTurn = player2; } }
public void OnDisconnect(IObjectConnection connection) { if (connection == player1) { player2.SendObject(new YouWon()); } else { player1.SendObject(new YouWon()); } EndGame(); }
public void OnGameStarted(IObjectConnection connection, GameStarted started) { if (started.YourTurn) { OutputBoard(); Task.Run(YourTurn); } else { OutputBoard(); Console.WriteLine("Waiting for your opponent to make his play"); } }
public void CallDisconnect(IObjectConnection connection) { var previous = DisconnectObject; while (previous != null) { if (previous.CanExecute?.Invoke(connection) ?? true) { previous.Action.Invoke(connection); } previous = previous.Next; } }
private void NextPlayerTurn(int x, int y) { if (playerTurn == player1) { playerTurn = player2; } else { playerTurn = player1; } playerTurn.SendObject(new YourTurn { X = x, Y = y }); }
public void CallCommand(string protocol, object parameter, IObjectConnection connection) { if (CommandObjects.ContainsKey(protocol)) { var commandObj = CommandObjects[protocol]; if (commandObj.CanExecute?.Invoke(connection) ?? true) { var deserializedObject = commandObj.DeserializerMethod((dynamic)parameter); if (deserializedObject != null) { commandObj.CommandMethod(connection, deserializedObject); } } } }
public void OnMove(IObjectConnection connection, Move move) { if (connection != playerTurn) { return; } if (CanPlace(move.X, move.Y)) { Place(move.X, move.Y); if (HasPlayerWon()) { EndGame(); } else { NextPlayerTurn(move.X, move.Y); } } }
public void OnChatMessageReceived(IObjectConnection connection, Message message) { Console.WriteLine("[" + message.SenderName + "]: " + message.Content); }
public void BadOnDisconnect(IObjectConnection con, int data) { HasBadOnDisconnectBeenCalled = true; }
public void OnCommand(IObjectConnection con, string connection) { HasOnCommandBeenCalled = true; }
public void OnDisconnect(IObjectConnection connection) { Connections.Remove(connection); }
public void OnYouLost(IObjectConnection connection, YouWon won) { Console.Clear(); Console.WriteLine("You won."); }
public void OnYouLost(IObjectConnection connection, YouLost lost) { Console.Clear(); Console.WriteLine("You lost."); }
public void OnYourTurn(IObjectConnection connection, YourTurn turn) { grid[turn.X][turn.Y] = 2; OutputBoard(); Task.Run(YourTurn); }
public void OnPing(IObjectConnection connection, PingObject pingObject) { connection.SendObject(new PongObject()); }
public void OnConnected(IObjectConnection connection) { Console.WriteLine("Connected to the server."); Console.WriteLine("Waiting for another player..."); this.connection = connection; }
public void BadOnCommand(string connection, IObjectConnection con) { HasBadOnCommandBeenCalled = true; }
public void OnConnect(IObjectConnection connection) { Connections[connection] = new IdleInfo { LastTicks = DateTime.Now.Ticks, HasPonged = true }; }
public void OnDisconnect(IObjectConnection con) { HasOnDisconnectBeenCalled = true; }
public void OnClientDisconnected(IObjectConnection connection, ClientDisconnected info) { Console.WriteLine(info.Name + " has disconnected"); }
public void OnDisconnect(IObjectConnection connection) { Console.WriteLine("You have been disconnected from the server"); }
public void BadOnConnect(IObjectConnection con, string data) { HasBadOnConnectBeenCalled = true; }