Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 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);
 }