private EntityDictionary <ServerInfo> GetServerInfoListFromDataTable(DataTable dt)
        {
            var result = new EntityDictionary <ServerInfo>();

            if (dt == null || dt.Rows.Count == 0)
            {
                return(result);
            }

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                result.Add(new ServerInfo
                {
                    Id            = GetInt(dt.Rows[i]["id"]),
                    Address       = GetString(dt.Rows[i]["address"]),
                    Name          = GetString(dt.Rows[i]["name"]),
                    Ports         = GetString(dt.Rows[i]["ports"]),
                    Region        = GetString(dt.Rows[i]["region"]),
                    ActualizedOn  = GetNullableDateTime(dt.Rows[i]["actualized_on"]),
                    ClientVersion = GetString(dt.Rows[i]["client_version"]),
                    PeerCount     = GetInt(dt.Rows[i]["peers_count"]),
                    IsApproved    = GetBoolean(dt.Rows[i]["is_approved"]),
                    ServerRole    = (ServerRole)GetByte(dt.Rows[i]["server_role"]),
                    HttpPort      = GetUshort(dt.Rows[i]["http_port"]),
                    HttpsPort     = GetUshort(dt.Rows[i]["https_port"]),
                });
            }

            return(result);
        }
        public static EntityDictionary <T> ReadEntityDictionary <T>(this ITypeReader typeReader)
            where T : EntityBase, new()
        {
            var result = new EntityDictionary <T>();

            try
            {
                var length = typeReader.ReadInt();

                if (length != 0)
                {
                    for (int i = 0; i < length; i++)
                    {
                        var item = new T();
                        item.Deserialize(typeReader);
                        result.Add(item);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception($"Error deserializing EntityDictionary<{typeof(T)}>: {e}");
            }


            return(result);
        }
Exemplo n.º 3
0
 public void AddServer(ServerInfo serverInfo)
 {
     lock (_mutex)
     {
         serverInfo.Id = GetIndex();
         _gameServerList.Add(serverInfo);
         _logger.Info($"Registered game server: {serverInfo.Identity}");
     }
 }
Exemplo n.º 4
0
 protected IEntity AddEntity(IEntity entity, string ID)
 {
     if (entity is EventSink)
     {
         var sink = entity.AsEventSink();
         MouseScrolled += sink.OnMouseScrolled;
         MousePressed  += sink.OnMousePressed;
         MouseMoved    += sink.OnMouseMoved;
         KeyPressed    += sink.OnKeyPressed;
         KeyReleassed  += sink.OnKeyReleassed;
     }
     EntityDictionary.Add(ID, entity);
     return(entity);
 }
        public FakeServerProvider(bool fillServers = true, bool returnEmptyGuid = false)
        {
            _returnEmptyGuid = returnEmptyGuid;

            if (fillServers)
            {
                _gameServers.Add(new ServerInfo(
                                     new ServerIdentity("0.0.0.0", new List <ushort> {
                    7777
                }, ServerRole.GameServer), "game1", "region1",
                                     8000)
                {
                    Id = 1
                });
            }
        }
        public void Visit(ref VisitorContext context)
        {
            var dataVisitNodeBuilder = (DataVisitNodeBuilder)context.Visitor;

            if (context.Instance is EntityHierarchyData)
            {
                // Create alternative "proxy" object to run diff on
                var entityHierarchy = (EntityHierarchyData)context.Instance;

                var entitiesById = new EntityDictionary(entityHierarchy);
                foreach (var entity in entityHierarchy.Entities)
                {
                    entitiesById.Add(entity.Id, entity);
                }

                // Add this object as member, so that it gets processed instead
                dataVisitNodeBuilder.VisitObjectMember(context.Instance, context.Descriptor, new ConvertedDescriptor(context.DescriptorFactory, "EntitiesById", entitiesById), entitiesById);
            }
        }
        private EntityDictionary <BundleInfo> GetBundleInfoListFromDataTable(DataTable dt)
        {
            var result = new EntityDictionary <BundleInfo>();

            if (dt == null || dt.Rows.Count == 0)
            {
                return(result);
            }

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                result.Add(new BundleInfo
                {
                    Id       = GetInt(dt.Rows[i]["id"]),
                    ServerId = GetInt(dt.Rows[i]["server_id"]),
                    Uri      = GetString(dt.Rows[i]["uri"])
                });
            }

            return(result);
        }
        private EntityDictionary <ServerInfo> BuildGameServersList()
        {
            var me = GetMe();

            if (me == null)
            {
                throw new Exception($"There is no me in server list");
            }

            var newGameServerList = new EntityDictionary <ServerInfo>();
            var serverList        = GetMyMmList().ToList();

            // var versions = new List<string>();
            // foreach (var id in idList)
            // {
            //     versions.Add(_serverList[id].ClientVersion);
            // }

            foreach (var server in _serverList)
            {
                // if (server.ServerRole == ServerRole.GameServer && versions.Contains(server.ClientVersion) && server.Region == me.Region)
                if (server.ServerRole == ServerRole.GameServer && serverList.Any(s => s.AreVersionsIntersect(server)) && server.Region == me.Region)
                {
                    if (server.IsActual(_config.ServerUnregisterTimeoutMs))
                    {
                        newGameServerList.Add(server);
                    }
                    else if (server.IsApproved)
                    {
                        _logger.Error($"Not actual server: {JsonConvert.SerializeObject(server)}");
                    }
                }
            }

            return(newGameServerList);
        }
 public void Start()
 {
     servers.Add(new ServerInfo(new ServerIdentity(_gameServerAddress, _gameServerPorts, ServerRole.GameServer), "", "", 7000, 0));
 }