Esempio n. 1
0
 /// <summary>
 /// Returns the instance of the Server class.
 /// </summary>
 /// <returns></returns>
 public static Fougerite.Server GetServer()
 {
     if (server == null)
     {
         server = new Fougerite.Server();
     }
     return(server);
 }
Esempio n. 2
0
        public static Fougerite.Server GetServer()
        {
            Contract.Ensures(Contract.Result<Server>() != null);

            if (server == null)
            {
                server = new Fougerite.Server();
            }
            return server;
        }
Esempio n. 3
0
        public static Fougerite.Server GetServer()
        {
            Contract.Ensures(Contract.Result <Server>() != null);

            if (server == null)
            {
                server = new Fougerite.Server();
            }
            return(server);
        }
Esempio n. 4
0
        public static bool PlayerConnect(NetUser user)
        {
            bool connected = false;

            if (user.playerClient == null)
            {
                Logger.LogDebug("PlayerConnect user.playerClient is null");
                return(connected);
            }
            ulong uid = user.userID;

            Fougerite.Server server = Fougerite.Server.GetServer();
            Fougerite.Player player = new Fougerite.Player(user.playerClient);
            if (!Fougerite.Server.Cache.ContainsKey(uid))
            {
                Fougerite.Server.Cache.Add(uid, player);
            }
            else
            {
                Fougerite.Server.Cache[uid] = player;
            }

            if (server.Players.Contains(player))
            {
                Logger.LogError(string.Format("[PlayerConnect] Server.Players already contains {0} {1}", player.Name, player.SteamID));
                connected = user.connected;
                return(connected);
            }
            server.Players.Add(player);

            try
            {
                if (OnPlayerConnected != null)
                {
                    OnPlayerConnected(player);
                }
            }
            catch (Exception ex)
            {
                Logger.LogDebug("Failed to call OnConnected event. " + ex.ToString());
                return(connected);
            }

            connected = user.connected;

            if (Fougerite.Config.GetBoolValue("Fougerite", "tellversion"))
            {
                player.Message(string.Format("This server is powered by Fougerite v.{0}!", Bootstrap.Version));
            }
            Logger.LogDebug("User Connected: " + player.Name + " (" + player.SteamID + ")" + " (" + player.IP + ")");
            return(connected);
        }
Esempio n. 5
0
 public static void PlayerApproval(ConnectionAcceptor ca, NetworkPlayerApproval approval)
 {
     if (ca.m_Connections.Count >= server.maxplayers)
     {
         approval.Deny(uLink.NetworkConnectionError.TooManyConnectedPlayers);
     }
     else
     {
         ClientConnection clientConnection = new ClientConnection();
         if (!clientConnection.ReadConnectionData(approval.loginData))
         {
             approval.Deny(uLink.NetworkConnectionError.IncorrectParameters);
             return;
         }
         Fougerite.Server srv  = Fougerite.Server.GetServer();
         ulong            uid  = clientConnection.UserID;
         string           ip   = approval.ipAddress;
         string           name = clientConnection.UserName;
         if (clientConnection.Protocol != 1069)
         {
             Debug.Log((object)("Denying entry to client with invalid protocol version (" + ip + ")"));
             approval.Deny(uLink.NetworkConnectionError.IncompatibleVersions);
         }
         else if (BanList.Contains(uid))
         {
             Debug.Log((object)("Rejecting client (" + uid.ToString() + "in banlist)"));
             approval.Deny(uLink.NetworkConnectionError.ConnectionBanned);
         }
         else if (srv.IsBannedID(uid.ToString()) || srv.IsBannedIP(ip))
         {
             if (!srv.IsBannedIP(ip))
             {
                 srv.BanPlayerIP(ip, name + "-Console");
                 Logger.LogDebug("[FougeriteBan] Detected banned ID, but IP is not banned: "
                                 + name + " - " + ip + " - " + uid);
             }
             if (!srv.IsBannedID(uid.ToString()))
             {
                 srv.BanPlayerID(uid.ToString(), name + "-Console");
                 Logger.LogDebug("[FougeriteBan] Detected banned IP, but ID is not banned: "
                                 + name + " - " + ip + " - " + uid);
             }
             Debug.Log("[FougeriteBan]  Disconnected: " + name
                       + " - " + ip + " - " + uid, null);
             Logger.LogDebug("[FougeriteBan] Disconnected: " + name
                             + " - " + ip + " - " + uid);
             approval.Deny(uLink.NetworkConnectionError.ConnectionBanned);
         }
         else if (ca.IsConnected(clientConnection.UserID))
         {
             PlayerApprovalEvent ape = new PlayerApprovalEvent(ca, approval, clientConnection, true);
             if (OnPlayerApproval != null)
             {
                 OnPlayerApproval(ape);
             }
             if (ape.ForceAccept && !ape.ServerHasPlayer)
             {
                 Accept(ca, approval, clientConnection);
                 return;
             }
             Debug.Log((object)("Denying entry to " + uid.ToString() + " because they're already connected"));
             approval.Deny(uLink.NetworkConnectionError.AlreadyConnectedToAnotherServer);
         }
         else
         {
             PlayerApprovalEvent ape = new PlayerApprovalEvent(ca, approval, clientConnection, false);
             if (OnPlayerApproval != null)
             {
                 OnPlayerApproval(ape);
             }
             Accept(ca, approval, clientConnection);
         }
     }
 }