Beispiel #1
0
        public void OutStats(ILogContext context)
        {
            Hashtable createdItemsHash  = new Hashtable();
            Hashtable disposedItemsHash = new Hashtable();

            lock (createdSync)
            {
                createdItemsHash = this.createdItems.toHash <ItemType, int>();
            }
            lock (disposedSync)
            {
                disposedItemsHash = this.disposedItems.toHash <ItemType, int>();
            }

            Hashtable resultInfo = new Hashtable
            {
                { "Created Items", createdItemsHash },
                { "Disposed Items", disposedItemsHash },
                { "Worlds", MmoWorldCache.Instance(m_App).GetStats() }
            };

            var builder = resultInfo.ToStringBuilder();

            context.Log(LogFilter.STATS, builder.ToString());
        }
Beispiel #2
0
 private void DeleteAllFromWorlds()
 {
     try {
         foreach (var pActor in application.serverActors)
         {
             pActor.Value.Peer.Disconnect();
         }
         application.serverActors.Clear();
         MmoWorldCache.Instance(application).Clear();
     } catch (Exception exception) {
         log.ErrorFormat(exception.Message);
         log.ErrorFormat(exception.StackTrace);
     }
 }
Beispiel #3
0
    protected override void OnStopRequested()
    {
        MmoWorldCache.Instance(this).SaveState();

        log.InfoFormat("OnStopRequested: serverId={0}", ServerId);
        if (this.masterConnectRetryTimer != null)
        {
            this.masterConnectRetryTimer.Dispose();
        }
        if (this.MasterPeer != null)
        {
            this.MasterPeer.Disconnect();
        }
        if (updater != null)
        {
            updater.TearDown();
            updater = null;
        }
        base.OnStopRequested();
    }
Beispiel #4
0
    protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
    {
        this.IsRegistered = false;
        this.StopUpdateLoop();
        MmoWorldCache.Instance(m_App).Clear();

        if (!this.redirected)
        {
            log.InfoFormat("connection to master closed (id={0}, reason={1}, detail={2}), serverId={3}",
                           this.ConnectionId, reasonCode, reasonDetail, GameApplication.ServerId);
            m_App.ReconnectToMaster();
        }
        else
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("{0} disconnected from master server: reason={1}, detail={2}, serverId={3}",
                                this.ConnectionId, reasonCode, reasonDetail, GameApplication.ServerId);
            }
        }
    }
Beispiel #5
0
 private void HandleGroupUpdateEvent(IEventData eventData)
 {
     try {
         log.InfoFormat("OutgoinfMasterServerPeer.HandleGroupUpdateEvent()");
         m_App.updater.EnqueueFiberAction(() => {
             try {
                 Hashtable groupHash = (Hashtable)eventData.Parameters[(byte)ServerToServerParameterCode.Group];
                 Group group         = new Group();
                 group.ParseInfo(groupHash);
                 foreach (var member in group.members)
                 {
                     if (string.IsNullOrEmpty(member.Value.worldID))
                     {
                         continue;
                     }
                     MmoWorld world;
                     if (MmoWorldCache.Instance(m_App).TryGet(member.Value.worldID, out world))
                     {
                         Item item;
                         if (world.ItemCache.TryGetItem((byte)ItemType.Avatar, member.Value.gameRefID, out item))
                         {
                             log.InfoFormat("set group at player = {0}", item.Id);
                             item.GetComponent <PlayerCharacterObject>().SetGroup(group);
                         }
                     }
                 }
             } catch (Exception ex) {
                 log.Info("exception");
                 log.Info(ex.Message);
                 log.Info(ex.StackTrace);
             }
         });
     } catch (Exception ex) {
         log.Info("exception");
         log.Info(ex.Message);
         log.Info(ex.StackTrace);
     }
 }
Beispiel #6
0
 private void Update()
 {
     try {
         //if(GameApplication.Instance.CurrentRole().RoleName == "BorguzandsGame") {
         //    log.InfoFormat("borguzands tick");
         //} else {
         //    log.InfoFormat("invalid role name: {0}", GameApplication.Instance.CurrentRole().RoleName);
         //}
         //log.InfoFormat("server  = {0} tick", GameApplication.Instance.ApplicationName);
         Time.Tick();
         //log.InfoFormat("STARTED: tick at time: {0}, delta = {1}", Time.curtime(), Time.deltaTime());
         MmoWorldCache.Instance(application).Tick(Time.deltaTime());
         m_UpdateTime = CommonUtils.SecondsFrom1970();
         if (false == m_UpdateOnceCalled)
         {
             m_UpdateOnceCalled = true;
         }
         //log.InfoFormat("Ticked: {0}", Time.deltaTime());
     } catch (Exception exception) {
         log.Error(exception);
         log.Error(exception.StackTrace);
     }
 }
Beispiel #7
0
    private void HandleWorldRaceChanged(IEventData eventData, SendParameters sendParameters)
    {
        log.InfoFormat("MasterPeer: received world race changed event... [red]");

        m_App.updater.EnqueueFiberAction(() => {
            try {
                string worldID    = (string)eventData.Parameters[(byte)ServerToServerParameterCode.WorldId];
                byte previousRace = (byte)eventData.Parameters[(byte)ServerToServerParameterCode.PreviousRace];
                byte currentRace  = (byte)eventData.Parameters[(byte)ServerToServerParameterCode.CurrentRace];

                Hashtable info = new Hashtable {
                    { (int)SPC.WorldId, worldID },
                    { (int)SPC.PreviousRace, previousRace },
                    { (int)SPC.CurrentRace, currentRace }
                };

                MmoWorldCache.Instance(m_App).SendWorldRaceChanged(info);
            }catch (Exception exception) {
                log.InfoFormat(exception.Message + " [red]");
                log.InfoFormat(exception.StackTrace + " [red]");
            }
        });
    }
Beispiel #8
0
 private void HandleGroupRemovedEvent(IEventData eventData)
 {
     log.InfoFormat("OutgoinfMasterServerPeer.HandleGroupRemovedEvent()");
     try {
         string groupID = (string)eventData.Parameters[(byte)ServerToServerParameterCode.Group];
         foreach (var location in m_App.CurrentRole().Locations)
         {
             MmoWorld world;
             if (MmoWorldCache.Instance(m_App).TryGet(location, out world))
             {
                 var items = world.GetItems((it) => it.Type == (byte)ItemType.Avatar);
                 foreach (var item in items)
                 {
                     item.Value.SendMessage(ComponentMessages.OnGroupRemoved, groupID);
                 }
             }
         }
     } catch (Exception ex) {
         log.Info("exception");
         log.Info(ex.Message);
         log.Info(ex.StackTrace);
     }
 }
Beispiel #9
0
    /// <summary>
    /// Handle race status update from Select Character Server
    /// </summary>
    private void HandleRaceStatusChanged(IEventData eventData, SendParameters sendParameters)
    {
        string gameRefID   = (string)eventData[(byte)ServerToServerParameterCode.GameRefId];
        string characterID = (string)eventData[(byte)ServerToServerParameterCode.CharacterId];
        int    raceStatus  = (int)eventData[(byte)ServerToServerParameterCode.RaceStatus];

        foreach (string locationID in m_App.CurrentRole().Locations)
        {
            MmoWorld world;
            if (MmoWorldCache.Instance(m_App).TryGet(locationID, out world))
            {
                NebulaObject playerObj;
                if (world.TryGetObject((byte)ItemType.Avatar, gameRefID, out playerObj))
                {
                    if (playerObj.GetComponent <PlayerCharacterObject>())
                    {
                        playerObj.GetComponent <PlayerCharacterObject>().SetRaceStatus(raceStatus);
                        log.InfoFormat("send player {0} race status {1}", gameRefID, (RaceStatus)raceStatus);
                        break;
                    }
                }
            }
        }
    }
Beispiel #10
0
        private void Init()
        {
            Res.SetLogger(new NebulaLogger());
            for (int i = 0; i < 10; i++)
            {
                log.Info("NEW SERVER++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            }
            if (GameApplication.ResourcePool() == null)
            {
                GameApplication.SetResourcePool(new ResourcePool(GameApplication.Instance.BinaryPath));
            }
            var globalResourceCheck = GameApplication.ResourcePool().Resource("global");

            /*
             #if LOCAL
             * if(application.CurrentRole().RoleName.ToLower().Contains("human")) {
             *  log.InfoFormat("connect as: {0} [red]", "mongodb://*****:*****@localhost/nebula");
             *  GameApplication.Instance.DatabaseManager.Setup("mongodb://*****:*****@localhost:27017/nebula");
             *
             * } else if(application.CurrentRole().RoleName.ToLower().Contains("borg")) {
             *  log.InfoFormat("connect as: {0} [red]", "mongodb://*****:*****@localhost/nebula");
             *  GameApplication.Instance.DatabaseManager.Setup("mongodb://*****:*****@localhost:27017/nebula");
             * } else if(application.CurrentRole().RoleName.ToLower().Contains("crip")) {
             *  log.InfoFormat("connect as: {0} [red]", "mongodb://*****:*****@localhost/nebula");
             *  GameApplication.Instance.DatabaseManager.Setup("mongodb://*****:*****@localhost:27017/nebula");
             * } else if(application.CurrentRole().RoleName.ToLower().Contains("neutral")) {
             *  log.InfoFormat("connect as: {0} [red]", "mongodb://*****:*****@localhost/nebula");
             *  GameApplication.Instance.DatabaseManager.Setup("mongodb://*****:*****@localhost:27017/nebula");
             * } else {
             *  log.InfoFormat("unknown role = {0} [red]", application.CurrentRole().RoleName);
             * }
             #else
             *
             * GameApplication.Instance.DatabaseManager.Setup(GameServerSettings.Default.DatabaseConnectionString);
             #endif
             */

            foreach (string loc in application.CurrentRole().Locations)
            {
                log.InfoFormat("Localtion: " + loc);
            }

            foreach (string locationID in application.CurrentRole().Locations)
            {
                MmoWorld world;
                Res      resource = GameApplication.ResourcePool().Resource(locationID);
                if (!MmoWorldCache.Instance(application).TryCreate(locationID, Settings.CornerMin, Settings.CornerMax, Settings.TileDimensions, out world, resource))
                {
                    log.ErrorFormat("error of creating world {0}", locationID);
                }
            }

            foreach (var locationID in application.CurrentRole().Locations)
            {
                MmoWorld world;
                if (MmoWorldCache.Instance(application).TryGet(locationID, out world))
                {
                    world.Initialize();
                }
                else
                {
                    log.ErrorFormat("world not found = {0}", locationID);
                }
            }

            log.InfoFormat("before updater start");

            lock (fiberLock) {
                mFiber = new PoolFiber();
                mFiber.Start();
                mLoop = mFiber.ScheduleOnInterval(Update, UPDATE_INTERVAL, UPDATE_INTERVAL);
            }
            log.InfoFormat("after updater start");
            log.Info(string.Format("MONGO: Computed wait queue size: {0}", MongoDefaults.ComputedWaitQueueSize));
            log.Info(string.Format("MONGO: Connect Timeout: {0}", MongoDefaults.ConnectTimeout));
            log.Info(string.Format("MONGO: Max Batch count: {0}", MongoDefaults.MaxBatchCount));
            log.Info(string.Format("MONGO: Max Connection Idle Time: {0}", MongoDefaults.MaxConnectionIdleTime));
            log.Info(string.Format("MONGO: Max Connection Life Time: {0}", MongoDefaults.MaxConnectionLifeTime));
            log.Info(string.Format("MONGO: Max Connection Pool Size: {0}", MongoDefaults.MaxConnectionPoolSize));
            log.Info(string.Format("MONGO: Socket Timeout: {0}", MongoDefaults.SocketTimeout));
            log.Info(string.Format("MONGO: TCP Receive Buffer Size: {0}", MongoDefaults.TcpReceiveBufferSize));
            log.Info(string.Format("MONGO: TCP  Send Buffer Size: {0}", MongoDefaults.TcpSendBufferSize));
            log.Info(string.Format("MONGO: Wait Queue Multiple: {0}", MongoDefaults.WaitQueueMultiple));
            log.Info(string.Format("MONGO: Wait queue Size: {0}", MongoDefaults.WaitQueueSize));
            log.Info(string.Format("MONGO: WAIT queue Timeout: {0}", MongoDefaults.WaitQueueTimeout));
        }