コード例 #1
0
 private static void InitializeServerData()
 {
     for (var i = 1; i <= MaxPlayers; i++)
     {
         Clients.Add(i, new Client(i));
     }
     PacketHandlers = new Dictionary <int, PacketHandler>()
     {
         { (int)ClientPackets.welcomereceived, ServerHandle.WelcomeReceived },
         { (int)ClientPackets.playerMovement, ServerHandle.PlayerMovement },
         { (int)ClientPackets.sendLoginInfo, ServerHandle.LoginInformation },
         { (int)ClientPackets.sendInviteClient, ServerHandle.SendInvitationServer },
         { (int)ClientPackets.inviteAnswer, ServerHandle.SendInviteAnswer },
         { (int)ClientPackets.startMatchMaking, ServerHandle.AddToMatchMaking },
         { (int)ClientPackets.stopMatchMaking, ServerHandle.RemoveFromMatchMaking },
         { (int)ClientPackets.mmPopUpAnswer, ServerHandle.MatchAnswer },
         { (int)ClientPackets.notifyPickUpdate, ServerHandle.HandleLobbyPlayer },
         { (int)ClientPackets.sceneLoaded, ServerHandle.HandleSceneUpdate },
         { (int)ClientPackets.sceneCompleted, ServerHandle.HandleSceneCompleted },
         { (int)ClientPackets.enteredConflictZone, ServerHandle.HandleGamePlayConflictZone },
         { (int)ClientPackets.enteredNeutralZone, ServerHandle.HandleGamePlayConflictZone },
         { (int)ClientPackets.enteredBeneficialZone, ServerHandle.HandleGamePlayConflictZone },
     };
     ServerConsoleWriter.WriteLine("Initialized packets.");
 }
コード例 #2
0
 private void Start()
 {
     QualitySettings.vSyncCount  = 0;
     Application.targetFrameRate = 30;
     Server.Start(50, 27017);
     ServerConsoleWriter.WriteLine($"Animal Wars Server Started ON : {DateTime.UtcNow}   PORT : {Server.Port}");
 }
コード例 #3
0
        /// <summary>Reads incoming data from the stream.</summary>
        private void ReceiveCallback(IAsyncResult result)
        {
            try
            {
                var byteLength = stream.EndRead(result);
                if (byteLength <= 0)
                {
                    if (Server.Clients.ContainsKey(id))
                    {
                        Server.Clients[id].Disconnect();
                    }
                    return;
                }

                var data = new byte[byteLength];
                Array.Copy(receiveBuffer, data, byteLength);

                receivedData.Reset(HandleData(data)); // Reset receivedData if all data was handled
                stream.BeginRead(receiveBuffer, 0, DataBufferSize, ReceiveCallback, null);
            }
            catch (Exception ex)
            {
                //
                ServerConsoleWriter.WriteLine($"Error receiving TCP data: {ex}");
                Server.Clients[id].Disconnect();
            }
        }
コード例 #4
0
    /// <summary>Disconnects the client and stops all network traffic.</summary>
    private void Disconnect()
    {
        TcpInstance.Disconnect();
        UdpInstance.Disconnect();

        ServerSend.PlayerDisconnected(id);
        ServerConsoleWriter.WriteLine($"Player {id} has successfully disconnected from the server");
    }
コード例 #5
0
 public static void RemoveFromQueue(PlayerDataHolder playerDataHolder)
 {
     ServerConsoleWriter.WriteLine($"{playerDataHolder.Username} has left the match Queue");
     if (MatchQueue.Contains(playerDataHolder))
     {
         MatchQueue.Remove(playerDataHolder);
     }
 }
コード例 #6
0
 public static void MatchFound(int _playerId, int _matchId)
 {
     using (Packet _packet = new Packet((int)ServerPackets.matchFound))
     {
         _packet.Write(_matchId);
         try {
             SendTcpData(_playerId, _packet);
         } catch {
             ServerConsoleWriter.WriteLine($"Error sending {_packet} to {_playerId}");
         }
     }
 }
コード例 #7
0
 private static List <PlayerDataHolder> MatchQueue = new List <PlayerDataHolder>(); //This list stores the PlayerDataHolder's of Clients looking for match
 //public List<Maps> availableMaps = new List<Maps>();
 public static void AddToQueue(PlayerDataHolder playerDataHolder)
 {
     ServerConsoleWriter.WriteLine($"{playerDataHolder.Username} has joined the match Queue");
     if (playerDataHolder.GetMatchId() != 0)
     {
         //This user was on a match so he should rejoin it :)
     }
     else
     {
         MatchQueue.Add(playerDataHolder);
     }
 }
コード例 #8
0
    private static void TcpConnectCallback(IAsyncResult result)
    {
        TcpClient client = _tcpListener.EndAcceptTcpClient(result);

        _tcpListener.BeginAcceptTcpClient(TcpConnectCallback, null);
        ServerConsoleWriter.WriteLine($"Incoming connection from {client.Client.RemoteEndPoint}...");
        for (int i = 1; i <= MaxPlayers; i++)
        {
            if (Clients[i].TcpInstance.Socket == null)
            {
                Clients[i].TcpInstance.Connect(client);
                return;
            }
        }
        ServerConsoleWriter.WriteLine($"{client.Client.RemoteEndPoint} failed to connect: Server full!");
    }