public void PlayerConnected(NetConnection connection) { if (state == ServerState.Lobby) { serverThread.SendDiscoveryResponse(null, connection.RemoteEndPoint); Console.WriteLine("Player " + connection.RemoteEndPoint.Address + " connected!"); Console.WriteLine("Current players: " + serverThread.ConnectionsCount); foreach (NetConnection conn in serverThread.Connections) Console.WriteLine(conn.RemoteEndPoint.Address); ServerPlayer player = new ServerPlayer(++playerIdCounter, connection); players[connection.RemoteEndPoint.Address] = player; } }
private void SendOKHandshake(ServerPlayer player) { NetOutgoingMessage msg = serverThread.CreateMessage(); msg.Write((byte)MessageType.OK); msg.Write(player.PlayerID); msg.Write(genSeed); serverThread.SendMessage(msg, player.Connection, NetDeliveryMethod.Unreliable); Console.WriteLine("Sent OK handshake to player " + player.Connection.RemoteEndPoint.Address); }
private void DistributePlayerPosition(ServerPlayer player) { NetOutgoingMessage msg = serverThread.CreateMessage(); msg.Write((byte)MessageType.PlayerPos); msg.Write(player.PlayerID); msg.Write((byte)(++player.SequenceNo)); msg.Write(player.PlayerPos.x); msg.Write(player.PlayerPos.y); msg.Write(player.PlayerPos.z); msg.Write(player.PlayerPos.rotation); msg.Write(player.PlayerPos.velocity); msg.Write(DateTime.UtcNow.Ticks); SendToAllOtherPlayers(msg, player.Connection); }
private void DistributeRaceTime(ServerPlayer player, long raceTime) { NetOutgoingMessage msg = serverThread.CreateMessage(); msg.Write((byte)MessageType.RaceTime); msg.Write(player.PlayerID); msg.Write(raceTime); SendToAllOtherPlayers(msg, player.Connection); }
private void DistributeChatMessage(ServerPlayer player, string chatMsg) { NetOutgoingMessage msg = serverThread.CreateMessage(); msg.Write((byte)MessageType.Chat); msg.Write(player.PlayerID); msg.Write(chatMsg); SendToAllOtherPlayers(msg, player.Connection); }