Example #1
0
        public void Dispose()
        {
            //Kick all connected clients and remove the objects
            foreach (networkServer.networkClientInterface item in ActiveConnections)
            {
                item.Dispose();
            }

            //Close network server
            TcpServer.Dispose();

            //Remove instance from CCstData
            if (CCstData.InstanceExists(Application.Hash))
            {
                CCstData.InstanceClose(Application.ID);
            }
        }
Example #2
0
        bool AddUserToActiveConnections(ref networkServer.networkClientInterface ClientInterface, string ApplicationHash, string ComputerID, string architecture, String language, double version)
        {
            if (!CCstData.InstanceExists(ApplicationHash))
            {
                //Instance does not exist. The player must have manipulated the protocol!
                CCstData.GetInstance(ApplicationID).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.SERVER, String.Format("Invalid application hash received in authentification protocol! ComputerID: {0}, ApplicationHash: {1}", ComputerID, ApplicationHash));
                return(false);
            }

            if (CCstData.GetInstance(ApplicationHash).LatestClientVersion != version)
            {
                CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.ERROR, Support.LoggerType.CLIENT, String.Format("Invalid version! Having {0}, expected {1}. Hardware ID {2}", version, CCstData.GetInstance(ApplicationHash).LatestClientVersion, ComputerID));
                SendProtocol("201;35;Antihack Client version outdated!", ClientInterface);
                return(false);
            }

            ////Check if user is already connected
            //foreach (networkServer.networkClientInterface item in ActiveConnections)
            //{
            //    if(item.User.ID==ComputerID
            //        && item.User.Application.Hash==ApplicationHash)
            //    {
            //        //User is already registered
            //        CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.CLIENT, "Authentification: User is already added to list!");
            //        SendProtocol("201;2;Still logged in. Please try again", ClientInterface);
            //        return false;
            //    }
            //}

            CCstData.GetInstance(ApplicationID).Logger.writeInLog(4, LogCategory.OK, Support.LoggerType.DATABASE, "Authentification: Checking user in the database");
            EPlayer dataClient = SPlayer.Authenticate(ComputerID, ApplicationHash, architecture, language, ClientInterface.IP.ToString());

            CCstData.GetInstance(ApplicationID).Logger.writeInLog(4, LogCategory.OK, Support.LoggerType.DATABASE, "Authentification: User found!");

            if (dataClient == null)
            {
                //If a computer ID exists multiple times in the database, a null object is returned
                CCstData.GetInstance(ApplicationID).Logger.writeInLog(1, LogCategory.CRITICAL, Support.LoggerType.DATABASE, "Authentification: Hardware ID exists multiple times in the database");
                SendProtocol("201;3;Contact Admin", ClientInterface);
                return(false);
            }
            dataClient.Application.Hash = ApplicationHash;

            //Check if user is banned
            if (dataClient.isBanned == true)
            {
                //Do something and dont let him enter
                CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, String.Format("Authentification: Banned user tried to authentificate. User: {0}", dataClient.ID));
                //Send protocol to client that user is banned
                SendProtocol("201;4;Too many hacks", ClientInterface);
                return(false);
            }

            //Add EPlayer to ClientInterface and to the list
            ClientInterface.User = dataClient;

            //Generate unique Session ID for network communication
            CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, "Authentification: Start creating a unique session ID");
            while (true)
            {
                string SessionID = AdditionalFunctions.GenerateSessionID(CCstData.GetInstance(ApplicationHash).SessionIDLength);
                //Checks if that connection exists already. Gives back the amount of matching ClientInterfaces
                if (ActiveConnections.Where(Client => Client.SessionID == SessionID).ToList().Count == 0)
                {
                    ClientInterface.SessionID = SessionID;
                    CCstData.GetInstance(ApplicationID).Logger.writeInLog(3, LogCategory.OK, Support.LoggerType.SERVER, String.Format("New user authentificated! HardwareID: {0}, Session ID: {1}", dataClient.ID, SessionID));
                    break;
                }
            }

            //Add the new connection to the list of connected connections
            ClientInterface.SetPingTimer(CCstData.GetInstance(dataClient.Application.ID).PingTimer, KickUser);

            bool IpExistsAlready = false;

            foreach (var Client in ActiveConnections)
            {
                if (Client.IP == ClientInterface.IP)
                {
                    IpExistsAlready = true;
                }
            }


            //Linux takes ages to connect. Therefore contact the client before it sends another request

            if (!IpExistsAlready)
            {
                if (!CCstData.GetInstance(ApplicationID).GameDLL.AllowUser(ClientInterface.IP, ClientInterface.User.ID))
                {
                    //Do something and dont let him enter
                    CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.ERROR, Support.LoggerType.GAMEDLL, String.Format("Linux exception failed. User: {0}", dataClient.ID));
                    //Send protocol to client that user is banned
                    SendProtocol("201;30;Access verification failed", ClientInterface);
                    return(false);
                }
            }
            else
            {
                CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, String.Format("Authentication: IP already exists ({0})", ClientInterface.IP.ToString()));
            }

            ActiveConnections.Add(ClientInterface);

            SendProtocol("200;" + ClientInterface.SessionID, ClientInterface);
            CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, String.Format("Authenticated new user. Computer ID: {0}, Session ID: {1}", ClientInterface.User.ID, ClientInterface.SessionID));

            /*if (!IpExistsAlready)
             * {
             *  //If there is already an IP exception, we dont need another
             *  try
             *  {
             *      ClientInterface.unixSshConnectorAccept.Connect();
             *  }
             *  catch (Exception)
             *  {
             *
             *  }
             *  if (ClientInterface.unixSshConnectorAccept.IsConnected)
             *  {
             *      List<int> Ports = new List<int>();
             *      Ports.Add(50001);
             *      Ports.Add(50002);
             *      Ports.Add(50003);
             *      Ports.Add(50004);
             *      Ports.Add(50005);
             *      Ports.Add(50006);
             *      Ports.Add(50007);
             *      Ports.Add(50008);
             *      Ports.Add(50009);
             *      Ports.Add(50010);
             *      Ports.Add(50011);
             *      Ports.Add(50012);
             *      Ports.Add(50013);
             *      Ports.Add(50014);
             *      Ports.Add(50015);
             *      Ports.Add(50016);
             *      Ports.Add(50017);
             *      Ports.Add(50018);
             *      Ports.Add(50019);
             *      Ports.Add(50020);
             *      string LinuxPorts = "";
             *      foreach (int item in Ports)
             *      {
             *          LinuxPorts += "iptables -I INPUT -p tcp -s " + ClientInterface.IP + " --dport " + item + " -j ACCEPT && ";
             *      }
             *      if(LinuxPorts.Length > 0)
             *      {
             *          LinuxPorts = LinuxPorts.TrimEnd(' ');
             *          LinuxPorts = LinuxPorts.TrimEnd('&');
             *          using (SshCommand Result = ClientInterface.unixSshConnectorAccept.RunCommand(LinuxPorts))
             *          {
             *              if (Result.Error.Length > 0)
             *                  CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.ERROR, Support.LoggerType.GAMEDLL, "Linux exception failed! Session ID: " + ClientInterface.SessionID + ", Error: " + Result.Error);
             *              else
             *                  CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.GAMEDLL, "Linux exception successful. Session ID: " + ClientInterface.SessionID + ", Result: " + Result.Result);
             *          }
             *      }
             *
             *      ClientInterface.unixSshConnectorAccept.Disconnect();
             *  }
             *  else
             *  {
             *      //Fehlerinfo
             *      CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.ERROR, Support.LoggerType.CLIENT, "Client could not be connected to the Linux Server. Session ID: " + ClientInterface.SessionID);
             *      return false;
             *  }
             * }
             * else
             * {
             *  string AllIPs = "";
             *  foreach (var item in ActiveConnections)
             *  {
             *      AllIPs += String.Format(" User: {0}, IP: {1} -", item.User.ID, item.IP);
             *  }
             *  CCstData.GetInstance(ApplicationID).Logger.writeInLog(2, LogCategory.OK, Support.LoggerType.SERVER, String.Format("Authentication: IP already exists ({0})", AllIPs));
             * }*/

            return(true);
        }