Exemplo n.º 1
0
        public static void Warp(ISender sender, ArgumentList args)
        {
            if (sender is Player)
            {
                string warpName = args.GetString(0);
                Player player   = sender as Player;

                Warp warp = WarpManager.GetWarp(warpName);

                if (warp == default(Warp) || !warp.IsUserAccessible(player))
                {
                    throw new CommandError("Warp not found!");
                }

                if (warp.Location == default(Vector2))
                {
                    throw new CommandError("Warp Location is invalid!");
                }

                if (!player.Teleport(warp.Location))
                {
                    throw new CommandError("There was an error in the Teleport.");
                }
            }
        }
Exemplo n.º 2
0
        public static void SetWarp(ISender sender, ArgumentList args)
        {
            Vector2 Location = default(Vector2);

            if (!(sender is Player))
            {
                int x, y;
                if (!args.TryParseTwo <Int32, Int32>("", out x, "", out y))
                {
                    throw new CommandError("Non Player Senders need to provide -x & -y tile indices.");
                }
            }
            else
            {
                Location = (sender as Player).Position / 16;
            }

            string name = args.GetString(0);

            Warp warp = new Warp()
            {
                Name     = name,
                Location = Location,
                Type     = WarpType.PUBLIC,
                Users    = new List <String>()
            };

            WarpManager.WarpList.Add(warp);
            WarpManager.Save((args.Plugin as Essentials).WarpFile, "warp");

            sender.Message("Warp {0} has been created.", warp.Name);
        }
Exemplo n.º 3
0
    public void WarpExterior() // (this is the game mechanic!!!)
    {
        if (_spriteRenderer.isVisible || !_warpable)
        {
            return;
        }
        Vector3     pos    = transform.position;
        WarpManager wm     = WarpManager.Instance;
        Vector2     camPos = wm._mainCamera.transform.position;

        if (Mathf.Abs(pos.x - camPos.x) < wm._cameraSizeWC.x / 2 &&
            Mathf.Abs(pos.y - camPos.y) < wm._cameraSizeWC.y / 2)
        {
            return;
        }
        Vector2 gridCenter = wm.ClosestCenter(camPos);

        if (Mathf.Abs(pos.x - gridCenter.x) > wm._cameraSizeWC.x / 2 ||
            Mathf.Abs(pos.y - gridCenter.y) > wm._cameraSizeWC.y / 2)
        {
            return;
        }
        Vector2 newPosition = wm.CamLLCorner + (Vector2)wm.ModPos(wm.CamLLCorner, pos, wm._cameraSizeWC);

        if ((newPosition - (Vector2)transform.position).magnitude > 0.05)
        {
            StartCoroutineSafely(WarpRemnant(newPosition));
        }
    }
Exemplo n.º 4
0
 public ShipFactory(IGalaxyRegistrationManager rm, WarpManager wm, ILocalIDManager galaxyIdManager, LocatorService ls, IDatabaseManager dbm)
 {
     _galaxyRegistrationManager = rm;
     _warpManager     = wm;
     _galaxyIdManager = galaxyIdManager;
     _locatorService  = ls;
     _databaseManager = dbm;
 }
Exemplo n.º 5
0
        /* Following few are untested */
        public static void ManageWarp(ISender sender, ArgumentList args)
        {
            //remove/add players, delete warp
            bool   delete   = args.TryPop("delete");
            bool   remove   = args.TryPop("removeplayer");
            bool   add      = args.TryPop("addplayer");
            string username = args.GetString(0);

            int warpIndex;

            if (!WarpManager.ContainsWarp(username, out warpIndex))
            {
                throw new CommandError("No Warp by that name exists.");
            }

            if (delete)
            {
                WarpManager.WarpList.RemoveAt(warpIndex);
                sender.sendMessage("Warp successfully removed.");
            }
            else if (remove)
            {
                Warp warp = WarpManager.WarpList.ElementAt(warpIndex);

                int usrIndex;
                if (warp.ContainsUser(username, out usrIndex))
                {
                    warp.Users.RemoveAt(usrIndex);
                    WarpManager.UpdateWarp(warp);
                    sender.Message("{0} has been removed from {1}", username, warp.Name);
                }
                else
                {
                    throw new CommandError("No user exists.");
                }
            }
            else if (add)
            {
                Warp warp = WarpManager.WarpList.ElementAt(warpIndex);

                int usrIndex;
                if (!warp.ContainsUser(username, out usrIndex))
                {
                    warp.Users.Add(WarpManager.CleanUserName(username));
                    WarpManager.UpdateWarp(warp);
                    sender.Message("{0} has been added to {1}", username, warp.Name);
                }
                else
                {
                    throw new CommandError("User exists already.");
                }
            }
            else
            {
                throw new CommandError("No Manage Action defined.");
            }
        }
Exemplo n.º 6
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            // get default mesh positions
            base.OnPopulateMesh(vh);

            if (m_warpManager == null)
            {
                m_warpManager = new WarpManager();
            }

            if (m_warpedMeshData == null)
            {
                m_warpedMeshData = new WarpManager.WarpManagerMeshData();
            }

            PopulateWarpManagerData();

            if (m_meshVerts == null)
            {
                m_meshVerts     = new List <UIVertex> ();
                m_meshVertsVec3 = new Vector3[4];
                m_meshUvsVec2   = new Vector2[4];
            }

            // Grab the default calculated mesh vert positions
            vh.GetUIVertexStream(m_meshVerts);

            // Populate vector3 array of mesh vert positions
            m_meshVertsVec3 [0] = m_meshVerts [0].position;
            m_meshVertsVec3 [1] = m_meshVerts [1].position;
            m_meshVertsVec3 [2] = m_meshVerts [2].position;
            m_meshVertsVec3 [3] = m_meshVerts [4].position;

            // Populate vector2 array of mesh vert uvs
            m_meshUvsVec2 [0] = uvRect.min;                                 // BL
            m_meshUvsVec2 [1] = uvRect.min + new Vector2(0, uvRect.height); // TL
            m_meshUvsVec2 [2] = uvRect.max;                                 // TR
            m_meshUvsVec2 [3] = uvRect.min + new Vector2(uvRect.width, 0);  // BR

            // Get warp mesh data
            m_warpManager.PopulateMesh(m_meshVertsVec3, m_meshUvsVec2, m_warpManagerData, ref m_warpedMeshData);


            // Repopulate mesh data with Warped data
            vh.Clear();

            for (int idx = 0; idx < m_warpedMeshData.m_positions.Length; idx++)
            {
                vh.AddVert(m_warpedMeshData.m_positions[idx], color, m_warpedMeshData.m_uvs[idx]);
            }

            for (int idx = 0; idx < m_warpedMeshData.m_indices.Length; idx += 3)
            {
                vh.AddTriangle(m_warpedMeshData.m_indices[idx], m_warpedMeshData.m_indices[idx + 1], m_warpedMeshData.m_indices[idx + 2]);
            }
        }
 public ServerGameStateManager(IPlayerLocator pl, IAreaLocator al, ITeamLocator tl, MessageManager mm, WarpManager wm, ChatManager cm, ITradeTerminator tt)
 {
     _playerLocator = pl;
     _areaLocator = al;
     _teamLocator = tl;
     _messageManager = mm;
     _warpManager = wm;
     _chatManager = cm;
     _tradeTerminator = tt;
 }
Exemplo n.º 8
0
 void Start()
 {
     currentWarp = 1;
     singleton   = this;
     warps       = new List <Warp>();
     for (int i = 0; i < currentWarp; i++)
     {
         GameObject heart = GameObject.Instantiate(WarpUIPrefab);
         heart.transform.SetParent(WarpPool.transform);
         heart.transform.localScale = new Vector3(1, 1, 1);
     }
 }
Exemplo n.º 9
0
    void Start()
    {
        // rigidbody = GetComponent<Rigidbody>();
        // rigidbody.centerOfMass = new Vector3(1, 0, 1);
        angle     = 0;
        movetime  = 600f;
        warptime  = limitwarptime;
        warplist  = GetComponent <WarpManager>();
        bossshoot = gameObject.GetComponent <Bossshoot>();

        en = true;
    }
        public bool PSystemsLoaded;//Signals that all PSystems have been loaded and the server is ready
        //TODO: Implement pause to object updating when additional systems need to be loaded while server is up

        public MasterServerMessageHandler(
            int mySlaveID,
            RedisServer redisServer,
            ConnectionManager connectionManager,
            LocatorService ls,
            AccountManager accountManager,
            LocalIDManager accountIdManager,
            IDatabaseManager databaseManager,
            GalaxyManager galaxyManager,
            LocalIDManager galaxyIDManager,
            PlayerManager playerManager,
            ShipManager shipManager,
            GalaxyRegistrationManager rm,
            LocalIDManager teamIDManager,
            MessageManager messageManager,
            GlobalTeamManager teamManager,
            WarpManager warpManager,
            LocalIDManager transactionIdManager,
            EventHandler <NetworkMessageContainer> routedMessageProcessor
            )
        {
            _connectionManager    = connectionManager;
            _accountManager       = accountManager;
            _accountIdManager     = accountIdManager;
            _databaseManager      = databaseManager;
            _galaxyIDManager      = galaxyIDManager;
            _galaxyManager        = galaxyManager;
            _teamIDManager        = teamIDManager;
            _playerManager        = playerManager;
            _shipManager          = shipManager;
            _registrationManager  = rm;
            _locatorService       = ls;
            _messageManager       = messageManager;
            _teamManager          = teamManager;
            _redisServer          = redisServer;
            _warpManager          = warpManager;
            _transactionIdManager = transactionIdManager;

            _mySlaveID = mySlaveID;

            _routedMessageProcessor = routedMessageProcessor;

            _redisServer.Subscribe(MessageTypes.Redis_LoginDataRequest, _handleLoginDataRequest);
            _redisServer.Subscribe(MessageTypes.Redis_ColonyDataPush, _handleColonyDataPush);
            _redisServer.Subscribe(MessageTypes.Redis_ClientHandoff, _handleHandoff);
            _redisServer.Subscribe(MessageTypes.Redis_StartUpdatingSystems, _handleMessageStartUpdatingSystems);
            _redisServer.Subscribe(MessageTypes.Redis_IDResponse, _handleMessageIDResponse);
            _redisServer.Subscribe(MessageTypes.Redis_AdminWarpPlayer, _handleAdminWarpPlayer);
        }
Exemplo n.º 11
0
        public MinimalMockServer(GalacticProperties gp, IDatabaseManager databaseManager, IDbIdIoService dbIdIoService)
        {
            Logger.Initialize();

            DatabaseManager = databaseManager;
            DbIdIoService   = dbIdIoService;

            //Minimal initializations
            GalaxyIDManager  = new LocalIDManager(null, IDTypes.GalaxyID);
            TeamIDManager    = new LocalIDManager(null, IDTypes.TeamID);
            accountIDManager = new LocalIDManager(null, IDTypes.AccountID);

            InitializeIdData(gp);

            globalGalaxyIDManager = new GlobalGalaxyIDManager(dbIdIoService, gp);
            GenerateIDsForLocalIDManager(globalGalaxyIDManager, GalaxyIDManager, gp.IdProperties[IDTypes.GalaxyID].LastIDAdded);

            globalTeamIDManager = new GlobalTeamIDManager(dbIdIoService, gp);
            GenerateIDsForLocalIDManager(globalTeamIDManager, TeamIDManager, gp.IdProperties[IDTypes.TeamID].LastIDAdded);

            globalAccountIDManager = new GlobalAccountIDManager(dbIdIoService, gp);
            GenerateIDsForLocalIDManager(globalAccountIDManager, accountIDManager, gp.IdProperties[IDTypes.AccountID].LastIDAdded);

            _redisServer = new RedisServer(Logger.LogRedisError, Logger.LogRedisInfo, new RedisConfig().Address);


            TeamManager        = new GlobalTeamManager(TeamIDManager, null, null, null, DatabaseManager);
            PlayerManager      = new PlayerManager(DatabaseManager, null, _redisServer, GalaxyIDManager, null);
            GalaxyManager      = new GalaxyManager(gp.SolID, TeamManager);
            shipManager        = new ShipManager(null, GalaxyManager, null, null, DatabaseManager);
            CollisionManager   = new CollisionManager(GalaxyManager, null, null, null);
            GalaxyGenerator    = new DebugGalaxyGenerator(PlayerManager, GalaxyManager, shipManager);
            AccountManager     = new AccountManager_MasterServer(accountIDManager, DatabaseManager, false);
            CargoSynchronizer  = new Server.Managers.CargoSynchronizer();
            StructureManager   = new StructureManager(DatabaseManager, GalaxyManager, GalaxyIDManager, CargoSynchronizer);
            RegistrationManger = new GalaxyRegistrationManager(GalaxyManager, shipManager, CollisionManager, GalaxyIDManager, PlayerManager, null, CargoSynchronizer, StructureManager);
            ColonyFactory.Initialize(GalaxyIDManager, RegistrationManger);
            StructureFactory.Initialize(GalaxyIDManager, RegistrationManger);
            LocatorService = new LocatorService(RegistrationManger, PlayerManager, GalaxyManager, shipManager, AccountManager, TeamManager, TeamManager, null, StructureManager, null);

            WarpManager = new WarpManager(GalaxyManager, null, null, _redisServer, AccountManager, null);

            CargoSynchronizer.Start(10, 4);
        }
Exemplo n.º 12
0
    void OnTriggerEnter2D(Collider2D other)
    {
        //teleports objects as long as they are not bullets
        if (other.gameObject.tag == "Player")
        {
            warpScript = GameObject.FindWithTag("Manager").GetComponent <WarpManager>();
            warpTarget = warpScript.warpList;

            thisRoom = gameObject.transform.parent.gameObject;
            rdmIndex = Random.Range(0, warpTarget.Count);

            nextRoom   = warpTarget[rdmIndex].transform.GetChild(0).gameObject;
            nextVector = warpTarget[rdmIndex].position;

            warpScript.removeWarp(rdmIndex);

            nextRoom.SetActive(true);
            other.gameObject.transform.position = nextVector;
            thisRoom.SetActive(false);
        }
    }
Exemplo n.º 13
0
        public override void UpdateMesh(bool a_changeMesh = true)
        {
            base.UpdateMesh(false);

            if (m_warpManager == null)
            {
                m_warpManager = new WarpManager();
            }

            if (m_warpedMeshData == null)
            {
                m_warpedMeshData = new WarpManager.WarpManagerMeshData();
            }

            PopulateWarpManagerData();

            // Get warp mesh data
            m_warpManager.PopulateMesh(MeshVerts, m_warpManagerData, ref m_warpedMeshData);

            // Construct the colours array
            if (m_meshColours == null || m_meshColours.Length != m_warpedMeshData.m_positions.Length || m_meshColours[0].Equals(m_colour) == false)
            {
                m_meshColours = new Color[m_warpedMeshData.m_positions.Length];

                for (int idx = 0; idx < m_meshColours.Length; idx++)
                {
                    m_meshColours [idx] = m_colour;
                }
            }

            // Update Mesh Values
            if (m_warpedMeshData.m_positions.Length > m_mesh.vertexCount)
            {
                m_mesh.vertices  = m_warpedMeshData.m_positions;
                m_mesh.uv        = m_warpedMeshData.m_uvs;
                m_mesh.triangles = m_warpedMeshData.m_indices;
            }
            else
            {
                m_mesh.triangles = m_warpedMeshData.m_indices;
                m_mesh.vertices  = m_warpedMeshData.m_positions;
                m_mesh.uv        = m_warpedMeshData.m_uvs;
            }

            m_mesh.colors = m_meshColours;

            // Update Cached values
            SetStruct <float> (ref m_cropLeftCache, m_cropLeft);
            SetStruct <float> (ref m_cropTopCache, m_cropTop);
            SetStruct <float> (ref m_cropRightCache, m_cropRight);
            SetStruct <float> (ref m_cropBottomCache, m_cropBottom);

            SetStruct <Vector3> (ref m_cornerOffsetBLCache, m_cornerOffsetBL);
            SetStruct <Vector3> (ref m_cornerOffsetBRCache, m_cornerOffsetBR);
            SetStruct <Vector3> (ref m_cornerOffsetTLCache, m_cornerOffsetTL);
            SetStruct <Vector3> (ref m_cornerOffsetTRCache, m_cornerOffsetTR);

            SetStruct <int> (ref m_numSubdivisionsCache, m_numSubdivisions);
            SetStruct <bool> (ref m_bezierEdgesCache, m_bezierEdges);

            if (m_bezierEdges)
            {
                SetStruct <Vector3> (ref m_leftBezierHandleACache, m_leftBezierHandleA);
                SetStruct <Vector3> (ref m_leftBezierHandleBCache, m_leftBezierHandleB);
                SetStruct <Vector3> (ref m_topBezierHandleACache, m_topBezierHandleA);
                SetStruct <Vector3> (ref m_topBezierHandleBCache, m_topBezierHandleB);
                SetStruct <Vector3> (ref m_rightBezierHandleACache, m_rightBezierHandleA);
                SetStruct <Vector3> (ref m_rightBezierHandleBCache, m_rightBezierHandleB);
                SetStruct <Vector3> (ref m_bottomBezierHandleACache, m_bottomBezierHandleA);
                SetStruct <Vector3> (ref m_bottomBezierHandleBCache, m_bottomBezierHandleB);
            }
        }
Exemplo n.º 14
0
 private void Awake() =>
 Main = this;
Exemplo n.º 15
0
        protected override void OnPopulateMesh(VertexHelper vh)
        {
            // get default mesh positions
            base.OnPopulateMesh(vh);

            if (type != Type.Simple)
            {
                Debug.LogWarning("Slice, Tiled and Filled sprite types aren't supported by UIImageWarp. Please set to 'Simple'.");
                return;
            }

            if (m_warpManager == null)
            {
                m_warpManager = new WarpManager();
            }

            if (m_warpedMeshData == null)
            {
                m_warpedMeshData = new WarpManager.WarpManagerMeshData();
            }

            PopulateWarpManagerData();

            if (m_meshVerts == null)
            {
                m_meshVerts     = new List <UIVertex> ();
                m_meshVertsVec3 = new Vector3[4];
                m_meshUvsVec2   = new Vector2[4];
            }

            // Grab the default calculated mesh vert positions
            vh.GetUIVertexStream(m_meshVerts);

            // Populate vector3 array of mesh vert positions
            m_meshVertsVec3 [0] = m_meshVerts [0].position;
            m_meshVertsVec3 [1] = m_meshVerts [1].position;
            m_meshVertsVec3 [2] = m_meshVerts [2].position;
            m_meshVertsVec3 [3] = m_meshVerts [4].position;

            // Populate vector2 array of mesh vert uvs
            m_meshUvsVec2 [0] = m_meshVerts[0].uv0;
            m_meshUvsVec2 [1] = m_meshVerts[1].uv0;
            m_meshUvsVec2 [2] = m_meshVerts[2].uv0;
            m_meshUvsVec2 [3] = m_meshVerts[4].uv0;

            // Get warp mesh data
            m_warpManager.PopulateMesh(m_meshVertsVec3, m_meshUvsVec2, m_warpManagerData, ref m_warpedMeshData);


            // Repopulate mesh data with Warped data
            vh.Clear();

            for (int idx = 0; idx < m_warpedMeshData.m_positions.Length; idx++)
            {
                vh.AddVert(m_warpedMeshData.m_positions[idx], color, m_warpedMeshData.m_uvs[idx]);
            }

            for (int idx = 0; idx < m_warpedMeshData.m_indices.Length; idx += 3)
            {
                vh.AddTriangle(m_warpedMeshData.m_indices[idx], m_warpedMeshData.m_indices[idx + 1], m_warpedMeshData.m_indices[idx + 2]);
            }
        }
Exemplo n.º 16
0
 private void Awake()
 {
     Instance = this;
 }
Exemplo n.º 17
0
 public DBFillerUtils(IDatabaseManager databaseManager, GalaxyManager galaxyManager, LocatorService locatorService, WarpManager warpManager, LocalIDManager galaxyIdManager)
 {
     _databaseManager = databaseManager;
     _galaxyManager   = galaxyManager;
     _locatorService  = locatorService;
     ShipFactory      = new ShipFactory(locatorService.RegistrationManager, warpManager, galaxyIdManager, locatorService, databaseManager);
 }
Exemplo n.º 18
0
        public override void Initialize()
        {
            if (!Directory.Exists(SavePath))
            {
                Directory.CreateDirectory(SavePath);
            }

#if DEBUG
            Log.Initialize(Path.Combine(SavePath, "log.txt"), LogLevel.All, false);
#else
            Log.Initialize(Path.Combine(SavePath, "log.txt"), LogLevel.All & ~LogLevel.Debug, false);
#endif
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;


            try
            {
                if (File.Exists(Path.Combine(SavePath, "tshock.pid")))
                {
                    Log.ConsoleInfo("TShock was improperly shut down. Deleting invalid pid file...");
                    File.Delete(Path.Combine(SavePath, "tshock.pid"));
                }
                File.WriteAllText(Path.Combine(SavePath, "tshock.pid"), Process.GetCurrentProcess().Id.ToString());

                ConfigFile.ConfigRead += OnConfigRead;
                FileTools.SetupConfig();

                HandleCommandLine(Environment.GetCommandLineArgs());

                if (Config.StorageType.ToLower() == "sqlite")
                {
                    string sql = Path.Combine(SavePath, "tshock.sqlite");
                    DB = new SqliteConnection(string.Format("uri=file://{0},Version=3", sql));
                }
                else if (Config.StorageType.ToLower() == "mysql")
                {
                    try
                    {
                        var hostport = Config.MySqlHost.Split(':');
                        DB = new MySqlConnection();
                        DB.ConnectionString =
                            String.Format("Server={0}; Port={1}; Database={2}; Uid={3}; Pwd={4};",
                                          hostport[0],
                                          hostport.Length > 1 ? hostport[1] : "3306",
                                          Config.MySqlDbName,
                                          Config.MySqlUsername,
                                          Config.MySqlPassword
                                          );
                    }
                    catch (MySqlException ex)
                    {
                        Log.Error(ex.ToString());
                        throw new Exception("MySql not setup correctly");
                    }
                }
                else
                {
                    throw new Exception("Invalid storage type");
                }

                Backups          = new BackupManager(Path.Combine(SavePath, "backups"));
                Backups.KeepFor  = Config.BackupKeepFor;
                Backups.Interval = Config.BackupInterval;
                Bans             = new BanManager(DB);
                Warps            = new WarpManager(DB);
                Users            = new UserManager(DB);
                Groups           = new GroupManager(DB);
                Groups.LoadPermisions();
                Regions         = new RegionManager(DB);
                Itembans        = new ItemManager(DB);
                RememberedPos   = new RemeberedPosManager(DB);
                RestApi         = new SecureRest(Netplay.serverListenIP, 8080);
                RestApi.Verify += RestApi_Verify;
                RestApi.Port    = Config.RestApiPort;
                RestManager     = new RestManager(RestApi);
                RestManager.RegisterRestfulCommands();

                var geoippath = Path.Combine(SavePath, "GeoIP.dat");
                if (Config.EnableGeoIP && File.Exists(geoippath))
                {
                    Geo = new MaxMind.GeoIPCountry(geoippath);
                }

                Log.ConsoleInfo(string.Format("TShock Version {0} ({1}) now running.", Version, VersionCodename));

                GameHooks.PostInitialize += OnPostInit;
                GameHooks.Update         += OnUpdate;
                ServerHooks.Join         += OnJoin;
                ServerHooks.Leave        += OnLeave;
                ServerHooks.Chat         += OnChat;
                ServerHooks.Command      += ServerHooks_OnCommand;
                NetHooks.GetData         += OnGetData;
                NetHooks.SendData        += NetHooks_SendData;
                NetHooks.GreetPlayer     += OnGreetPlayer;
                NpcHooks.StrikeNpc       += NpcHooks_OnStrikeNpc;

                GetDataHandlers.InitGetDataHandler();
                Commands.InitCommands();
                //RconHandler.StartThread();

                if (Config.BufferPackets)
                {
                    PacketBuffer = new PacketBufferer();
                }

                Log.ConsoleInfo("AutoSave " + (Config.AutoSave ? "Enabled" : "Disabled"));
                Log.ConsoleInfo("Backups " + (Backups.Interval > 0 ? "Enabled" : "Disabled"));

                if (Initialized != null)
                {
                    Initialized();
                }
            }
            catch (Exception ex)
            {
                Log.Error("Fatal Startup Exception");
                Log.Error(ex.ToString());
                Environment.Exit(1);
            }
        }
Exemplo n.º 19
0
    // ----------------------------------- INITIALIZATION ----------------------------------

    protected void Awake()
    {
        Instance = this;
    }
Exemplo n.º 20
0
 void Awake()
 {
     singleton = this;
 }
Exemplo n.º 21
0
        /// <summary>
        /// Initializes the entire server
        /// </summary>
        private void Initialize()
        {
            for (int i = 0; i < 20; i++)
            {
                msgAvgQue.Enqueue(0);
            }

            var rand = new Random(3);

            // Logging Enabled
            Logger.Initialize();

            _synchronizers = new List <ISynchronizer>();


            //Load configs
            ConnectionManagerConfig connectionManagerConfig = new ConnectionManagerConfig(new CoreNetworkConfig());
            GalacticProperties      galacticProperties      = new GalacticProperties();

            _consoleManager = new ConsoleManager();

            _projectileManager = new ProjectileManager();

            ConsoleManager.WriteLine("Starting database...", ConsoleMessageType.Startup);
            _databaseManager = new MongoDatabaseManager();

            ShipStatManager.ReadShipsFromDBSList(_databaseManager.GetStatsFromDBAsync().Result);
            ConsoleManager.WriteLine("Ship types loaded.", ConsoleMessageType.Startup);

            RedisConfig rc = new RedisConfig();

            _redisServer = new RedisServer(LogRedisError, LogRedisInfo, rc.Address);

            var slaveId = SlaveServerConfigService.GetFreeSlaveID(_redisServer).Result;

            _slaveServerConfigService = new SlaveServerConfigService(_redisServer, slaveId);

            _masterServerManager = new MasterServerManager(new MasterServerConfig(), new GalacticProperties(), _databaseManager, _databaseManager, _redisServer, _slaveServerConfigService);

            _cargoSynchronizer = new CargoSynchronizer();
            _synchronizers.Add(_cargoSynchronizer);

            connectionManagerConfig.MyConfig.Port = ConnectionManager.GetFreePort(28002, 28010);
            _connectionManager = new ConnectionManager();
            _connectionManager.Initialize(connectionManagerConfig);

            //Poll to listen to Lidgren until it is ready
            //LidgrenMessagePoller_Init initializationPoller = new LidgrenMessagePoller_Init(_connectionManager.Server, this);
            //initializationPoller.Poll();

            _galaxyIDManager      = new LocalIDManager(_masterServerManager, IDTypes.GalaxyID);
            _teamIDManager        = new LocalIDManager(_masterServerManager, IDTypes.TeamID);
            _accountIDManager     = new LocalIDManager(_masterServerManager, IDTypes.AccountID);
            _transactionIDManager = new LocalIDManager(_masterServerManager, IDTypes.TransactionID);

            _accountManager = new AccountManager(_accountIDManager, _databaseManager);

            _messageManager = new MessageManager(_connectionManager);

            _clientUpdateManager = new ClientUpdateManager(_playerManager);

            _playerManager = new PlayerManager(_databaseManager, _connectionManager, _redisServer, _galaxyIDManager, _clientUpdateManager);

            var chatCommands = new List <IChatCommand>()
            {
                new HelpCommand(),
                new ShoutCommand(_redisServer),
                new RadioCommand(),
                new TellCommand(_playerManager)
            };

            var asyncChatCommands = new List <IAsyncChatCommand>()
            {
                new AdminWarpCommand(_databaseManager, _redisServer, new Random())
            };

            _teamManager = new GlobalTeamManager(_teamIDManager, _connectionManager, _redisServer, _playerManager, _databaseManager);

            _galaxyManager = new GalaxyManager(galacticProperties.SolID, _teamManager);

            _chatManager = new ChatManager(chatCommands, asyncChatCommands, _playerManager, _messageManager, _redisServer);

            _warpManager = new WarpManager(_galaxyManager, _messageManager, _chatManager, _redisServer, _accountManager, _databaseManager);

            _shipManager = new ShipManager(_messageManager, _galaxyManager, _warpManager, _connectionManager, _databaseManager);

            _structureManager = new StructureManager(_databaseManager, _galaxyManager, _galaxyIDManager, _cargoSynchronizer);

            loginManager = new LoginManager(_accountManager, _playerManager, _connectionManager, _redisServer);

            // Todo: Convert everything over to ServerNetworkMessage to propogate full request context.
            _simulatorManager = new SimulatorManager(new SimulatorConfig(), _redisServer, (sender, container) => ProcessMessage(sender, new ServerNetworkMessage(container, null)));

            StructureStatManager.Initialize();

            ConsoleManager.WriteLine("Completed Initialization", ConsoleMessageType.Startup);

            _economyManager      = new EconomyManager(_transactionIDManager, _playerManager, _galaxyManager, _cargoSynchronizer, _shipManager, _databaseManager, _masterServerManager);
            _killManager         = new KillManager(_cargoSynchronizer, _playerManager, _galaxyManager, _messageManager, _connectionManager, _warpManager, _chatManager, _economyManager);
            _collisionManager    = new CollisionManager(_galaxyManager, _messageManager, _killManager, _projectileManager);
            _registrationManager = new GalaxyRegistrationManager(_galaxyManager, _shipManager, _collisionManager, _galaxyIDManager, _playerManager, _accountManager, _cargoSynchronizer, _structureManager);
            _warpManager.SetRegistrationManager(_registrationManager);//Gross, I know.
            _locatorService   = new LocatorService(_registrationManager, _playerManager, _galaxyManager, _shipManager, _accountManager, _teamManager, _teamManager, _messageManager, _structureManager, _masterServerManager);
            _msMessageHandler = new MasterServerMessageHandler((int)_masterServerManager.SlaveID, _redisServer, _connectionManager, _locatorService, _accountManager, _accountIDManager, _databaseManager, _galaxyManager, _galaxyIDManager, _playerManager, _shipManager, _registrationManager, _teamIDManager, _messageManager, _teamManager, _warpManager, _transactionIDManager, ProcessRoutedMessage);

            StructureFactory.Initialize(_galaxyIDManager, _registrationManager);
            ColonyFactory.Initialize(_galaxyIDManager, _registrationManager);

            dbSyncer = new DBSyncer(_databaseManager, _galaxyManager, _shipManager, _playerManager, _accountManager, _structureManager);

#if DEBUG
            _typesToExcludeIgnore.Add(MessageTypes.PositionUpdateData);
            _typesToExcludeIgnore.Add(MessageTypes.ShipFireRequest);
            _typesToExcludeIgnore.Add(MessageTypes.ProjectileCollisionReport);
            _typesToExcludeIgnore.Add(MessageTypes.StructureFireRequest);
            _typesToExcludeIgnore.Add(MessageTypes.ObjectPickupRequest);
#endif
        }