示例#1
0
        public ICommandResult Handle(CreateServerCommand command)
        {
            command.Validate();
            if (command.IsInvalid)
            {
                return(new DefaultCommandResult(CommandResultStatus.InvalidCommand, command.Notifications));
            }

            try
            {
                var server = new Entities.Server()
                {
                    Name = command.Name,
                    Ip   = command.Ip,
                    Port = command.Port
                };
                _serverRepository.Save(server);
                return(new DefaultCommandResult(server.Id));
            }
            catch (Exception e)
            {
                Console.WriteLine($"Fail to execute CreateServerHandler. Fail stack ===> {e.ToString()}");
                return(new DefaultCommandResult(CommandResultStatus.Exception));
            }
        }
示例#2
0
        protected override void Process(Entities.Server s)
        {
            uint errorCode = GetuInt(0);
            //    dateTimeTicks   = GetuInt(1); //TODO: UNUSED
            ushort playerCount = GetUShort(2);
            ushort roomCount   = GetUShort(3);

            if (s.Authorized && errorCode == 1)
            {
                try
                {
                    foreach (Entities.Server server in Managers.ServerManager.Instance.GetAllAuthorized())
                    {
                        if (server.ID == s.ID)
                        {
                            server.AddPlayers(playerCount);
                            server.AddRooms(roomCount);

                            //TODO: LOG TO DB?
                        }
                    }
                }
                catch
                {
                    //Log.Instance.WriteLine("An unregistered gameserver sent ping");
                }
            }
        }
示例#3
0
        public int Link(Entities.Server server, int tenant)
        {
            var query = new SqlInsert(TenantXServerTable.TABLE_NAME, true)
                        .InColumnValue(TenantXServerTable.Columns.ServerId, server.Id)
                        .InColumnValue(TenantXServerTable.Columns.Tenant, tenant);

            return(Db.ExecuteNonQuery(query));
        }
示例#4
0
        public int UnLink(Entities.Server server, int tenant)
        {
            var query = new SqlDelete(TenantXServerTable.TABLE_NAME)
                        .Where(TenantXServerTable.Columns.ServerId, server.Id)
                        .Where(TenantXServerTable.Columns.Tenant, tenant);

            var result = Db.ExecuteNonQuery(query);

            return(result);
        }
        private void OnAcceptConnection(IAsyncResult iAr)
        {
            try {
                Socket          s  = socket.EndAccept(iAr);
                Entities.Server gs = new Entities.Server(s);
            } catch { }

            if (socket != null)
            {
                socket.BeginAccept(new AsyncCallback(this.OnAcceptConnection), null);
            }
        }
示例#6
0
        public void Link(Entities.Server server, int tenant)
        {
            if (server == null)
            {
                return;
            }

            using (var daoFactory = new DaoFactory())
            {
                Link(daoFactory, server, tenant);
            }
        }
示例#7
0
        protected Entities.Server ToServer(object[] r)
        {
            var s = new Entities.Server
            {
                Id               = Convert.ToInt32(r[0]),
                MxRecord         = Convert.ToString(r[1]),
                ConnectionString = Convert.ToString(r[2]),
                Type             = Convert.ToInt32(r[3]),
                SmtpSettingsId   = Convert.ToInt32(r[4]),
                ImapSettingsId   = Convert.ToInt32(r[5])
            };

            return(s);
        }
示例#8
0
        public void UnLink(Entities.Server server, int tenant)
        {
            if (server == null)
            {
                return;
            }

            using (var daoFactory = new DaoFactory())
            {
                var serverDao = daoFactory.CreateServerDao();

                serverDao.UnLink(server, Tenant);
            }
        }
示例#9
0
        public int Save(Entities.Server server)
        {
            var query = new SqlInsert(ServerTable.TABLE_NAME, true)
                        .InColumnValue(ServerTable.Columns.Id, server.Id)
                        .InColumnValue(ServerTable.Columns.MxRecord, server.MxRecord)
                        .InColumnValue(ServerTable.Columns.ConnectionString, server.ConnectionString)
                        .InColumnValue(ServerTable.Columns.ServerType, server.Type)
                        .InColumnValue(ServerTable.Columns.SmtpSettingsId, server.SmtpSettingsId)
                        .InColumnValue(ServerTable.Columns.ImapSettingsId, server.ImapSettingsId)
                        .Identity(0, 0, true);

            var id = Db.ExecuteScalar <int>(query);

            return(id);
        }
示例#10
0
        public void Link(IDaoFactory daoFactory, Entities.Server server, int tenant)
        {
            if (server == null)
            {
                return;
            }

            var serverDao = daoFactory.CreateServerDao();

            var result = serverDao.Link(server, Tenant);

            if (result <= 0)
            {
                throw new Exception("Invalid insert operation");
            }
        }
示例#11
0
        public int Save(Entities.Server server)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            using (var daoFactory = new DaoFactory())
            {
                var serverDao = daoFactory.CreateServerDao();

                var id = serverDao.Save(server);

                return(id);
            }
        }
示例#12
0
        private void OnAcceptConnection(IAsyncResult iAr)
        {
            Socket s = socket.EndAccept(iAr);

            if (!_isGameServerListener)
            {
                Entities.User User = new Entities.User(s);
            }
            else
            {
                Entities.Server GameServer = new Entities.Server(s);
            }
            if (socket != null)
            {
                socket.BeginAccept(new AsyncCallback(this.OnAcceptConnection), null);
            }
        }
示例#13
0
        public static int InsertServerInfo(BE.Entities.Request.ServerInfoReq serverInfo)
        {
            try
            {
                var server = new Entities.Server()
                {
                    Name       = serverInfo.Name,
                    Address    = serverInfo.Address,
                    Tel        = serverInfo.Tel,
                    IsActive   = true,
                    CategoryId = serverInfo.CategoryId
                };
                using (var dbCtx = new MSDbContext())
                {
                    dbCtx.Servers.Add(server);
                    int result = dbCtx.SaveChanges();

                    if (result == 1)
                    {
                        foreach (var serverPhoto in serverInfo.Photos)
                        {
                            byte[] photoByte      = Convert.FromBase64String(serverPhoto);
                            var    serverPhotoEnt = new Entities.ServerPhoto()
                            {
                                Photo    = photoByte,
                                ServerId = server.Id
                            };
                            dbCtx.ServerPhotos.Add(serverPhotoEnt);
                            dbCtx.SaveChanges();
                        }
                        return(server.Id);
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
            }
            catch (Exception e)
            {
                var ex = new InsertIntoDataBaseException(ExceptionMessage.InsertIntoServersException, e);
                Logger.Log.Error(ex.Message, ex);
                throw ex;
            }
        }
示例#14
0
        public byte Add(Entities.Server s, string name, string ip, int port, Core.Enums.ServerTypes type) {

            byte serverId = 0;

            for (byte i = 1; i <= MAX_SERVERS; i++) {
                if (!servers.ContainsKey(i)) {
                    serverId = i;
                    break;
                }
            }

            if (serverId > 0) {
                // Add server to the hashtable :p
                 s.OnAuthorize(serverId, name, ip, port, type);
                 servers.Add(serverId, s);
            }

            return serverId;
        }
        protected override void Process(Entities.Server s)
        {
            uint ErrorCode = GetuInt(0);

            if (ErrorCode == 1)
            {
                string globalKey  = GetString(1);
                string serverName = GetString(2);
                string ipAddress  = GetString(3);
                int    port       = GetInt(4);
                byte   type       = GetByte(5);

                Core.Enums.ServerTypes enumType = Core.Enums.ServerTypes.Normal;
                if (System.Enum.IsDefined(typeof(Core.Enums.ServerTypes), type))
                {
                    enumType = (Core.Enums.ServerTypes)type;
                }
                else
                {
                    s.Disconnect(); return;
                }

                byte serverId = Managers.ServerManager.Instance.Add(s, serverName, ipAddress, port, enumType);
                if (serverId > 0)
                {
                    s.Send(new Packets.Internal.Authorize(serverId));
                    ServerLogger.Instance.Append(ServerLogger.AlertLevel.Information, "Authorized a new server as " + serverId.ToString());
                }
                else
                {
                    s.Send(new Packets.Internal.Authorize(Core.Enums.Internal.AuthorizationErrorCodes.MaxServersReached));
                    s.Disconnect();
                    ServerLogger.Instance.Append(ServerLogger.AlertLevel.ServerError, "Rejecting Server " + s.Displayname + ". Limit reached");
                }
            }
            else
            {
                s.Disconnect();
            }
        }
 public void Delete(Entities.Server server)
 {
     //nothing
 }
示例#17
0
        protected override void Process(Entities.Server s)
        {
            ushort errorCode = GetUShort(0);

            if (Enum.IsDefined(typeof(PlayerAuthorizationErrorCodes), errorCode))
            {
                PlayerAuthorizationErrorCodes enumErrorCode = (PlayerAuthorizationErrorCodes)errorCode;
                uint   targetId    = GetuInt(1);
                string username    = GetString(3);
                byte   accessLevel = GetByte(4);
                switch (enumErrorCode)
                {
                // A new player logs in.
                //Raptor 1/6/18: Added more checks just in case someone managed to perform a MiM while another player is choosing server.
                //That would lead to a registered, not active session which could be stolen if targetId is known
                case PlayerAuthorizationErrorCodes.Login: {
                    Session session = Managers.SessionManager.Instance.Get(targetId);
                    if (session != null)
                    {
                        if (!session.IsActivated && session.Name == username && session.AccessLevel == accessLevel)
                        {
                            session.Activate((byte)s.ID);
                            s.Send(new Packets.Internal.PlayerAuthorization(session));
                            ServerLogger.Instance.Append(ServerLogger.AlertLevel.Information, "Player with ID " + targetId.ToString() + " has been authorized");
                        }
                        else
                        {
                            s.Send(new Packets.Internal.PlayerAuthorization(PlayerAuthorizationErrorCodes.SessionAlreadyActivated, targetId));
                            ServerLogger.Instance.Append(ServerLogger.AlertLevel.ServerError, "Player with ID " + targetId.ToString() + " was not authorized because the session is already active");
                        }
                    }
                    else
                    {
                        s.Send(new Packets.Internal.PlayerAuthorization(PlayerAuthorizationErrorCodes.InvalidSession, targetId));
                        ServerLogger.Instance.Append(ServerLogger.AlertLevel.ServerError, "Player with ID " + targetId.ToString() + "rejected because the session is NOT valid");
                    }

                    break;
                }

                // Update the information of a player.
                //TODO: DARK INVESTIGATE THIS
                case PlayerAuthorizationErrorCodes.Update: {
                    Session session = Managers.SessionManager.Instance.Get(targetId);
                    if (session != null)
                    {
                        /* Packet Structure v2
                         *
                         * Connection Time
                         * Ping
                         *
                         * [Sub Type]
                         *  - 1 - Update Channel
                         *  - 2 - Update Session Information
                         *  - 3 - Update Action
                         *  - 4 - Update Lobby Room information
                         *  - 5 - Update Ingame Room information
                         *
                         * [Data Blocks]
                         *  - [1] - Update Channel
                         *      - Current channel Id
                         *      - Channel Slot
                         *
                         *  - [2] - Update Session Information
                         *      - Session - Kills
                         *      - Session - Deaths
                         *      - Session - Xp Earned
                         *      - Session - Dinar Earned
                         *      - Session - Dinar Spend
                         *
                         *  - [3] - Update Action
                         *      - Update Type:
                         *
                         *          [1]: Join Room
                         *               - Room ID
                         *               - Room Slot
                         *               - Room Is Master
                         *
                         *          [2]: Leave Room
                         *              - Room ID
                         *              - Room Old Slot
                         *              - Room Was Master?
                         *                  - New master slot
                         *
                         *          [3]: Room Start
                         *              - Team
                         *
                         *          [4]: Room Stop
                         *              - Kills
                         *              - Deaths
                         *              - Flags
                         *              - Points
                         *              - Xp Earned
                         *              - Dinar Earned
                         *              - xp Bonusses (%-Name:%-Name)
                         *              - dinar bonusses (%-Name:%-Name)
                         *
                         *  - [4] - Update Lobby Room information
                         *      - Update Type:
                         *
                         *          [1]: Switch Side
                         *               - Room ID
                         *               - Room Slot
                         *               - Room Is Master
                         *
                         *          [2]:
                         *
                         *  - [5] - Update Ingame Room information
                         *      - Update Type:
                         *
                         *          [1]: Score Update (Player Kill/Player Death)
                         *               - Room ID
                         *               - Room Kills
                         *               - Room Deaths
                         *               - Room Flags
                         *               - Room Points
                         *
                         *          [2]:
                         */
                    }
                    else
                    {
                        // Force a closure of the connection.
                        s.Send(new Packets.Internal.PlayerAuthorization(PlayerAuthorizationErrorCodes.InvalidSession, targetId));
                    }

                    break;
                }

                // A player logs out of the server.
                case PlayerAuthorizationErrorCodes.Logout: {
                    Session session = Managers.SessionManager.Instance.Get(targetId);
                    if (session != null)
                    {
                        if (session.IsActivated)
                        {
                            session.End();
                            ServerLogger.Instance.Append(ServerLogger.AlertLevel.Information, "Player with ID " + targetId.ToString() + " has logged out");
                        }
                    }
                    break;
                }

                default: {
                    // Unused.
                    break;
                }
                }
            }
            else
            {
                Console.WriteLine(string.Concat("Unknown PlayerAuthorization error: ", errorCode));
            }
        }
示例#18
0
 public Task AddAsync(Entities.Server server)
 {
     _dbContext.Add(server);
     return(_dbContext.SaveChangesAsync());
 }
 public void Update(Entities.Server server)
 {
     _dataContext.Entry(server).State = EntityState.Modified;
     _dataContext.SaveChanges();
 }
 public void Save(Entities.Server server)
 {
     _dataContext.Servers.Add(server);
     _dataContext.SaveChanges();
 }
 public void Delete(Entities.Server server)
 {
     _dataContext.Servers.Remove(server);
     _dataContext.SaveChanges();
 }
示例#22
0
 protected virtual void Process(Entities.Server s)
 {
     Console.WriteLine(string.Concat("No server handler for PacketID: ", this.inPacket.Id));
 }
示例#23
0
        protected override void Process(Entities.Server s)
        {
            uint ErrorCode = GetuInt(0);

            if (ErrorCode == Core.Networking.Constants.ERROR_OK)
            {
                string globalKey  = GetString(1);
                string serverName = GetString(2);
                string ipAddress  = GetString(3);
                int    port       = GetInt(4);
                byte   type       = GetByte(5);

                if (globalKey == Config.GAMESERVERKEY) //attempt to match server keys
                {
                    Core.GameConstants.ServerTypes serverType;

                    //check for an existing server type.
                    if (System.Enum.IsDefined(typeof(Core.GameConstants.ServerTypes), type))
                    {
                        serverType = (Core.GameConstants.ServerTypes)type;

                        //check if name is already in use, reject server if affirmative
                        foreach (Entities.Server authorizedServer in Managers.ServerManager.Instance.GetAllAuthorized())
                        {
                            //Already authorized?
                            if (authorizedServer.IP == ipAddress)
                            {
                                s.Send(new Packets.Internal.Authorize(Core.Networking.ErrorCodes.EntityAlreadyAuthorized));
                                Log.Information("Rejected server " + serverName + " . Server already authorized");
                                s.Disconnect();
                                return;
                            }

                            if (authorizedServer.ServerName == serverName)
                            {
                                s.Send(new Packets.Internal.Authorize(Core.Networking.ErrorCodes.ServerNameInUse));
                                Log.Information("Rejected server " + serverName + " . Name already in use");
                                s.Disconnect();
                                return;
                            }
                        }

                        byte serverId = Managers.ServerManager.Instance.Add(s, serverName, ipAddress, port, serverType);

                        if (serverId > 0)
                        {
                            s.Send(new Packets.Internal.Authorize(serverId));
                            Log.Information("New server registered as: " + serverName);
                        }
                        else
                        {
                            s.Send(new Packets.Internal.Authorize(Core.Networking.ErrorCodes.ServerLimitReached));
                            s.Disconnect();
                        }
                    }
                    else
                    {
                        s.Send(new Packets.Internal.Authorize(Core.Networking.ErrorCodes.InvalidServerType));
                        s.Disconnect();
                    }
                }
                else
                {
                    s.Send(new Packets.Internal.Authorize(Core.Networking.ErrorCodes.InvalidKeyOrSession));
                    Log.Information("Rejecting server " + serverName + ": invalid key");
                    s.Disconnect();
                }
            }
            else
            {
                s.Disconnect();
            }
        }
示例#24
0
        protected override void Process(Entities.Server s)
        {
            ushort errorCode = GetUShort(0);

            if (Enum.IsDefined(typeof(Core.Networking.ErrorCodes), errorCode))
            {
                Core.Networking.ErrorCodes enumErrorCode = (Core.Networking.ErrorCodes)errorCode;
                uint   targetId    = GetuInt(1);
                string username    = GetString(3);
                byte   accessLevel = GetByte(4);
                switch (enumErrorCode)
                {
                // A new player logs in.
                //Raptor 1/6/18: Added more checks just in case someone managed to perform a MiM while another player is choosing server.
                //That would lead to a registered, not active session which could be stolen if targetId is known

                case Core.Networking.ErrorCodes.Success:
                {
                    Session session = Managers.SessionManager.Instance.Get(targetId);
                    if (session != null)
                    {
                        if (!session.IsActivated && session.Name == username && (byte)session.AccessLevel == accessLevel)
                        {
                            session.Activate((byte)s.ID);
                            s.Send(new Packets.Internal.PlayerAuthentication(session));
                        }
                        else
                        {
                            s.Send(new Packets.Internal.PlayerAuthentication(Core.Networking.ErrorCodes.EntityAlreadyAuthorized, targetId));
                        }
                    }
                    else
                    {
                        s.Send(new Packets.Internal.PlayerAuthentication(Core.Networking.ErrorCodes.InvalidKeyOrSession, targetId));
                    }

                    break;
                }

                // Update the information of a player.
                //TODO: DARK INVESTIGATE THIS
                case Core.Networking.ErrorCodes.Update:
                {
                    Session session = Managers.SessionManager.Instance.Get(targetId);
                    if (session != null)
                    {
                    }
                    else
                    {
                        // Force a closure of the connection.
                        s.Send(new Packets.Internal.PlayerAuthentication(Core.Networking.ErrorCodes.InvalidKeyOrSession, targetId));
                    }

                    break;
                }

                // A player logs out of the server.
                case Core.Networking.ErrorCodes.EndConnection:
                {
                    Session session = Managers.SessionManager.Instance.Get(targetId);
                    if (session != null)
                    {
                        if (session.IsActivated)
                        {
                            session.End();
                        }
                    }
                    break;
                }

                default:
                {
                    // Unused.
                    break;
                }
                }
            }
            else
            {
                Console.WriteLine(string.Concat("Unknown PlayerAuthorization error: ", errorCode));
            }
        }
 public void Update(Entities.Server server)
 {
     //nothing
 }
示例#26
0
 protected virtual void Process(Entities.Server s)
 {
     Log.Error(string.Concat("No server handler for PacketID: ", this.inPacket.Id));
 }
示例#27
0
 public void Delete(Entities.Server server)
 {
     throw new Exception("Force fail");
 }
示例#28
0
        public ServerDomainDnsData GetOrCreateUnusedDnsData(IDaoFactory daoFactory, Entities.Server server)
        {
            var serverDnsDao = daoFactory.CreateServerDnsDao(Tenant, User);

            var dnsSettings = serverDnsDao.GetFree();

            if (dnsSettings == null)
            {
                string privateKey, publicKey;
                CryptoUtil.GenerateDkimKeys(out privateKey, out publicKey);

                var domainCheckValue = PasswordGenerator.GenerateNewPassword(16);
                var domainCheck      = Defines.ServerDnsDomainCheckPrefix + ": " + domainCheckValue;

                var serverDns = new ServerDns
                {
                    Id              = 0,
                    Tenant          = Tenant,
                    User            = User,
                    DomainId        = Defines.UNUSED_DNS_SETTING_DOMAIN_ID,
                    DomainCheck     = domainCheck,
                    DkimSelector    = Defines.ServerDnsDkimSelector,
                    DkimPrivateKey  = privateKey,
                    DkimPublicKey   = publicKey,
                    DkimTtl         = Defines.ServerDnsDefaultTtl,
                    DkimVerified    = false,
                    DkimDateChecked = null,
                    Spf             = Defines.ServerDnsSpfRecordValue,
                    SpfTtl          = Defines.ServerDnsDefaultTtl,
                    SpfVerified     = false,
                    SpfDateChecked  = null,
                    Mx              = server.MxRecord,
                    MxTtl           = Defines.ServerDnsDefaultTtl,
                    MxVerified      = false,
                    MxDateChecked   = null,
                    TimeModified    = DateTime.UtcNow
                };

                serverDns.Id = serverDnsDao.Save(serverDns);

                dnsSettings = serverDns;
            }

            var dnsData = new ServerDomainDnsData
            {
                Id       = dnsSettings.Id,
                MxRecord = new ServerDomainMxRecordData
                {
                    Host       = dnsSettings.Mx,
                    IsVerified = false,
                    Priority   = Defines.ServerDnsMxRecordPriority
                },
                DkimRecord = new ServerDomainDkimRecordData
                {
                    Selector   = dnsSettings.DkimSelector,
                    IsVerified = false,
                    PublicKey  = dnsSettings.DkimPublicKey
                },
                DomainCheckRecord = new ServerDomainDnsRecordData
                {
                    Name       = Defines.DNS_DEFAULT_ORIGIN,
                    IsVerified = false,
                    Value      = dnsSettings.DomainCheck
                },
                SpfRecord = new ServerDomainDnsRecordData
                {
                    Name       = Defines.DNS_DEFAULT_ORIGIN,
                    IsVerified = false,
                    Value      = dnsSettings.Spf
                }
            };

            return(dnsData);
        }
 public void Save(Entities.Server server)
 {
     server.Id = new Guid();
     _dataContext.Servers.Add(server);
 }