Example #1
0
        /// <summary>
        /// 组装战斗队列
        /// </summary>
        /// <param name="player">玩家对象</param>
        /// <param name="queueList">要组装的队伍id</param>
        /// <returns></returns>
        protected List <ClientQueue> BuildQueue(Player player, List <BattleQueueInfo> queueList)
        {
            var list = new List <ClientQueue>();

            foreach (var battleFormation in queueList)
            {
                // 构造队列对象
                var cQueue = new ClientQueue()
                {
                    PlayerID = player.ID, PlayerName = player.Name, QueueList = new List <ClientHero>(), QueueID = battleFormation.QueueID
                };
                var psotList = battleFormation.GetItem_ToList();
                foreach (var item in psotList)
                {
                    // 如果武将ID为null不用组装
                    if (item.HeroID == Guid.Empty || item.ArmyCount == 0)
                    {
                        continue;
                    }

                    // TODO 从玩家缓存里面获取hero对象,我这里级直接new了
                    var hero = new Hero();

                    // 组装槽位数据
                    cQueue.QueueList.Add(BuildClientHero(hero));
                }

                if (cQueue.QueueList.Count > 0)
                {
                    list.Add(cQueue);
                }
            }

            return(list);
        }
        public override void SendCommandRemote(QueueType inQueue,
                                               LibCommon.Network.Types.GameMessage inEvent)
        {
            byte[] msg = ThriftMessageSerialize.SerializeCompact(inEvent);

            if (inQueue == QueueType.Client)
            {
                if (string.IsNullOrEmpty(inEvent.NetworkId))
                {
                    //_internalNetwork.BroadcastAll(NetworkUtils.SerializeEvent(inEvent));

                    _internalNetwork.BroadcastAll(msg);

                    ClientQueue.Enqueue(inEvent);
                }
                else
                {
                    Debug.Log(inEvent.NetworkId);

                    if (inEvent.NetworkId == "-1")
                    {
                        ClientQueue.Enqueue(inEvent);
                    }
                    else
                    {
                        _internalNetwork.SendPacketToClient(inEvent.NetworkId, msg);
                    }
                }
            }
            else
            {
                _internalNetwork.SendToServer(msg);
            }
        }
        public void OnServerPacket(byte[] inValue)
        {
            LibCommon.Network.Types.GameMessage msg = new LibCommon.Network.Types.GameMessage();

            ThriftMessageSerialize.DeSerializeCompact(msg, inValue);
            ClientQueue.Enqueue(msg);
        }
 /// <summary>
 /// Closes the connection with a client, logs a reason, and updates the queue.
 /// </summary>
 /// <param name="reason">Reason to disconnect the client</param>
 public void Close(string reason = "unknown")
 {
     Logging.Log(Logging.LogSeverity.Warning, $"Closing {UserName}({this.User?.ToString() ?? "n/a"}) due to {reason}");
     try
     {
         this.User.Connection = null;
     } catch { }
     try
     {
         Client.Close();
     }
     catch { }
     Listening = false;
     try
     {
         listenThread.Abort();
     }
     catch { }
     lock (LockClient)
     {
         CurrentClients.Remove(this);
         ClientQueue.Remove(this);
         while (CurrentClients.Count < Program.Options.Maximum_Concurrent_Connections)
         {//accepting the next people in the queue
             if (ClientQueue.Count == 0)
             {
                 break;
             }
             ClientQueue[0].AcceptFromQueue();
             CurrentClients.Add(ClientQueue[0]);
             ClientQueue.RemoveAt(0);
         }
     }
 }
        public override void SendCommandRemote(QueueType inQueue,
                                               LibCommon.Network.Types.GameMessage inEvent)
        {
            byte[] msg = ThriftMessageSerialize.SerializeCompact(inEvent);

            if (inQueue == QueueType.Client)
            {
                ClientQueue.Enqueue(inEvent);
            }
            else
            {
                _internalNetwork.SendToServer(msg);
            }
        }
Example #6
0
        public override void SendCommandRemote(QueueType inQueue, LibCommon.Network.Types.GameMessage inMsg)
        {
            string msg = ThriftMessageSerialize.Serialize(inMsg);

            if (inQueue == QueueType.Client)
            {
                ClientQueue.Enqueue(inMsg);
            }
            else
            {
                _wwwSendMessageRequest.PostData = Encoding.UTF8.GetBytes(msg);
                AssetManager.Instance.RequestAssetLoad(_wwwSendMessageRequest);
            }
        }
Example #7
0
 public override void SendCommandRemote(QueueType inQueue, GameMessage inMsg)
 {
     lock (_lockObject)
     {
         if (inQueue == QueueType.Client)
         {
             ClientQueue.Enqueue(inMsg);
         }
         else
         {
             ServerQueue.Enqueue(inMsg);
         }
     }
 }
Example #8
0
 public override void SendCommandLocal(QueueType inQueue, LibCommon.Network.Types.GameMessage inMsg)
 {
     if (inQueue == QueueType.Client)
     {
         ClientQueue.Enqueue(inMsg);
     }
     else
     {
         if (inQueue == QueueType.Server)
         {
             ServerQueue.Enqueue(inMsg);
         }
     }
 }
        public override void SendCommandLocal(QueueType inQueue,
                                              LibCommon.Network.Types.GameMessage inEvent)
        {
            switch (inQueue)
            {
            case QueueType.Client:
                ClientQueue.Enqueue(inEvent);
                break;

            case QueueType.Server:
                ServerQueue.Enqueue(inEvent);
                break;
            }
        }
        public override LibCommon.Network.Types.GameMessage PopCommand(QueueType inQueue)
        {
            LibCommon.Network.Types.GameMessage ee = null;
            switch (inQueue)
            {
            case QueueType.Client:
                ee = ClientQueue.Dequeue();
                break;

            case QueueType.Server:
                ee = ServerQueue.Dequeue();
                break;
            }

            return(ee);
        }
Example #11
0
 public override GameMessage PopCommand(QueueType inQueue)
 {
     lock (_lockObject)
     {
         GameMessage ee = null;
         if (inQueue == QueueType.Client)
         {
             ee = ClientQueue.Dequeue();
         }
         else
         {
             ee = ServerQueue.Dequeue();
         }
         return(ee);
     }
 }
Example #12
0
        public override LibCommon.Network.Types.GameMessage PopCommand(QueueType inQueue)
        {
            LibCommon.Network.Types.GameMessage ee = null;
            if (inQueue == QueueType.Client)
            {
                ee = ClientQueue.Dequeue();
            }
            else
            {
                if (inQueue == QueueType.Server)
                {
                    ee = ServerQueue.Dequeue();
                }
            }

            return(ee);
        }
Example #13
0
        /// <summary>
        /// Set the SequenceNumber property for the specified item, then enqueue it.
        /// </summary>
        /// <param name="sp"></param>
        public void Enqueue(SendParameters sp, ParticipantModel participant)
        {
            lock (this) {
                sp.SequenceNumber = m_NextSequenceNumber;
                m_NextSequenceNumber++;

                if (m_QueueList.ContainsKey(sp.Id))
                {
                    ((ClientQueue)m_QueueList[sp.Id]).Enqueue(sp);
                }
                else
                {
                    ClientQueue cq = new ClientQueue(sp.Id, participant);
                    cq.Enqueue(sp);
                    m_QueueList.Add(sp.Id, cq);
                }
                //Trace.WriteLine("Enqueue guid=" + sp.Tags.SlideID.ToString() + "; seq =" + sp.SequenceNumber.ToString(), this.GetType().ToString());
            }
        }
Example #14
0
        /// <summary>
        /// Get the next item from the queue which is not in the provided exclusion list.
        /// Return null if the queue is empty or if there are no qualifying items.
        /// </summary>
        /// <returns></returns>
        public SendParameters Dequeue(Hashtable exclusionList, Guid currentSlide)
        {
            lock (this) {
                ClientQueue    bestClient  = null;
                SendParameters bestMessage = null;
                foreach (ClientQueue cq in m_QueueList.Values)
                {
                    //Block student messages when sending public messages.
                    if ((exclusionList.ContainsKey(cq.Id)) && (cq.IsPublicNode) && !((ReferenceCounter)exclusionList[cq.Id]).IsZero)
                    {
                        return(cq.Dequeue(currentSlide));
                    }

                    if (m_DisabledClients.ContainsKey(cq.Id))
                    {
                        continue;
                    }
                    if (((exclusionList.ContainsKey(cq.Id)) && (((ReferenceCounter)exclusionList[cq.Id]).IsZero)) ||
                        (!exclusionList.ContainsKey(cq.Id)))
                    {
                        SendParameters thisSp = cq.Peek(currentSlide);
                        if (thisSp != null)
                        {
                            if (thisSp.CompareTo(bestMessage, currentSlide) < 0)
                            {
                                bestMessage = thisSp;
                                bestClient  = cq;
                            }
                        }
                    }
                }
                if (bestClient != null)
                {
                    //Trace.WriteLine("Dequeue: best message tag: " + bestMessage.Tags.SlideID.ToString() +
                    //    "; current slide=" + currentSlide.ToString() +
                    //    "; seq number=" + bestMessage.SequenceNumber.ToString(), this.GetType().ToString());
                    return(bestClient.Dequeue(currentSlide));
                }
            }
            return(null);
        }
Example #15
0
        public void OnServerPacker(AssetLoadRequest inValue)
        {
            if (!_running)
            {
                return;
            }

            if (!inValue.HasFailed)
            {
                AsyncPollingWebLoader asyncPollingWebLoader = inValue as AsyncPollingWebLoader;
                byte[] jsonData = asyncPollingWebLoader?.WebData;

                if (jsonData != null)
                {
                    string jsonString = Encoding.UTF8.GetString(jsonData);
                    try
                    {
                        GameMessageList mm = new GameMessageList();
                        ThriftMessageSerialize.DeSerialize(mm, jsonString);

                        foreach (string item in mm.Messages)
                        {
                            LibCommon.Network.Types.GameMessage gm = new LibCommon.Network.Types.GameMessage();
                            ThriftMessageSerialize.DeSerialize(gm, item);

                            ClientQueue.Enqueue(gm);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.LogErrorFormat("Error Message: {0} {1}", ex.Message, jsonString);
                    }
                }
            }

            _requestingCurrently = false;
        }
        /// <summary>
        /// Set the SequenceNumber property for the specified item, then enqueue it.
        /// </summary>
        /// <param name="sp"></param>
        public void Enqueue(SendParameters sp, ParticipantModel participant)
        {
            lock (this) {
                sp.SequenceNumber = m_NextSequenceNumber;
                m_NextSequenceNumber++;

                if (m_QueueList.ContainsKey(sp.Id)) {
                    ((ClientQueue)m_QueueList[sp.Id]).Enqueue(sp);
                }
                else {
                    ClientQueue cq = new ClientQueue(sp.Id, participant);
                    cq.Enqueue(sp);
                    m_QueueList.Add(sp.Id, cq);
                }
                //Trace.WriteLine("Enqueue guid=" + sp.Tags.SlideID.ToString() + "; seq =" + sp.SequenceNumber.ToString(), this.GetType().ToString());
            }
        }
Example #17
0
        /// <summary>
        /// Aggregate Data and return UnitInfo List
        /// </summary>
        public IList<UnitInfo> AggregateData()
        {
            var logLines = LogReader.GetLogLines(FahLogFilePath);
             _logInterpreterLegacy = new LogInterpreterLegacy(logLines, LogReader.GetClientRuns(logLines));
             _currentClientRun = _logInterpreterLegacy.CurrentClientRun;
             _currentClientRunLogLines = _logInterpreterLegacy.CurrentClientRunLogLines;

             // report errors that came back from log parsing
             foreach (var s in _logInterpreterLegacy.LogLineParsingErrors)
             {
            _logger.Debug(Constants.ClientNameFormat, ClientName, s);
             }

             IList<UnitInfo> parsedUnits;
             // Decision Time: If Queue Read fails parse from logs only
             QueueData qData = ReadQueueFile();
             if (qData != null)
             {
            parsedUnits = GenerateUnitInfoDataFromQueue(qData);
            _clientQueue = BuildClientQueue(qData);
             }
             else
             {
            _logger.Warn(Constants.ClientNameFormat, ClientName,
               "Queue unavailable or failed read.  Parsing logs without queue.");

            parsedUnits = GenerateUnitInfoDataFromLogs();
            _clientQueue = null;
             }

             _logInterpreterLegacy = null;

             return parsedUnits;
        }
Example #18
0
    private void Start()
    {
        Main.instance.eventManager.SubscribeToEvent(GameEvent.StartNewDay, OpenForBussines);

        _clientQueue = FindObjectOfType <ClientQueue>();
    }
      private static ClientQueue BuildClientQueue(IEnumerable<Unit> unitCollection, Info info, SlotOptions slotOptions, int slotId)
      {
         ClientQueue cq = null;
         foreach (var unit in unitCollection.Where(unit => unit.Slot == slotId))
         {
            // don't create a queue until we find a unit that matches this slot id
            if (cq == null)
            {
               cq = new ClientQueue { ClientType = ClientType.FahClient, CurrentIndex = -1 };
            }

            var cqe = new ClientQueueEntry();
            cqe.EntryStatusLiteral = unit.StateEnum.ToString();
            cqe.WaitingOn = unit.WaitingOn;
            cqe.Attempts = unit.Attempts;
            cqe.NextAttempt = unit.NextAttemptTimeSpan.GetValueOrDefault();
            cqe.NumberOfSmpCores = info.System.CpuCount;
            cqe.BeginTimeUtc = unit.AssignedDateTime.GetValueOrDefault();
            cqe.BeginTimeLocal = unit.AssignedDateTime.GetValueOrDefault().ToLocalTime();
            cqe.ProjectID = unit.Project;
            cqe.ProjectRun = unit.Run;
            cqe.ProjectClone = unit.Clone;
            cqe.ProjectGen = unit.Gen;
            cqe.MachineID = slotId;
            cqe.ServerIP = unit.WorkServer;
            cqe.CpuString = GetCpuString(info, slotOptions);
            cqe.OsString = info.System.OperatingSystemEnum.ToOperatingSystemString(info.System.OperatingSystemArchitectureEnum);
            // Memory Value is in Gigabytes - turn into Megabytes and truncate
            cqe.Memory = (int)(info.System.MemoryValue.GetValueOrDefault() * 1024);
            cq.Add(unit.Id, cqe);

            if (unit.StateEnum == FahUnitStatus.Running)
            {
               cq.CurrentIndex = unit.Id;
            }
         }

         if (cq != null)
         {
            // if no running index and at least something in the queue
            if (cq.CurrentIndex == -1 && cq.Count != 0)
            {
               // take the minimum queue id
               cq.CurrentIndex = cq.Keys.First();
            }
         }

         return cq;
      }
Example #20
0
        public void SetQueue(ClientQueue queue)
        {
            if (InvokeRequired)
             {
            Invoke(new Action<ClientQueue>(SetQueue), queue);
            return;
             }

             queueControl.SetQueue(queue);
        }
Example #21
0
 public void SetQueue(ClientQueue qBase)
 {
     SetQueue(qBase, SlotType.Unknown, false);
 }
Example #22
0
        public void SetQueue(ClientQueue queue, SlotType slotType, bool utcOffsetIsZero)
        {
            if (InvokeRequired)
             {
            Invoke(new Action<ClientQueue, SlotType, bool>(SetQueue), queue, slotType, utcOffsetIsZero);
            return;
             }

             queueControl.SetQueue(queue, slotType, utcOffsetIsZero);
        }
Example #23
0
        public void SetQueue(ClientQueue qBase, SlotType type, bool utcOffsetIsZero)
        {
            if (qBase != null)
             {
            _queue = qBase;
            _slotType = type;
            _utcOffsetIsZero = utcOffsetIsZero;

            cboQueueIndex.SelectedIndexChanged -= cboQueueIndex_SelectedIndexChanged;
            cboQueueIndex.DataSource = _queue.EntryNameCollection;
            cboQueueIndex.DisplayMember = "DisplayMember";
            cboQueueIndex.ValueMember = "ValueMember";
            cboQueueIndex.SelectedIndex = -1;
            cboQueueIndex.SelectedIndexChanged += cboQueueIndex_SelectedIndexChanged;

            cboQueueIndex.SelectedValue = _queue.CurrentIndex;
             }
             else
             {
            _queue = null;
            _slotType = SlotType.Unknown;
            _utcOffsetIsZero = false;
            SetControlsVisible(false);
             }
        }
        /// <summary>
        /// Aggregate Data and return UnitInfo Dictionary.
        /// </summary>
        public IDictionary<int, UnitInfo> AggregateData(ICollection<LogLine> logLines, UnitCollection unitCollection, Info info, Options options, 
            SlotOptions slotOptions, UnitInfo currentUnitInfo, int slotId)
        {
            if (logLines == null) throw new ArgumentNullException("logLines");
             if (unitCollection == null) throw new ArgumentNullException("unitCollection");
             if (options == null) throw new ArgumentNullException("options");
             if (slotOptions == null) throw new ArgumentNullException("slotOptions");
             if (currentUnitInfo == null) throw new ArgumentNullException("currentUnitInfo");

             _currentUnitIndex = -1;
             // only take up to the last MaxDisplayableLogLines
             _currentLogLines = logLines.Skip(Math.Max(0, logLines.Count - Constants.MaxDisplayableLogLines)).ToList();
             _logInterpreter = new LogInterpreter(logLines, LogReader.GetClientRuns(logLines, LogFileType.FahClient));
             _currentClientRun = _logInterpreter.CurrentClientRun;

             // report errors that came back from log parsing
             foreach (var s in _logInterpreter.LogLineParsingErrors)
             {
            _logger.Debug(Constants.ClientNameFormat, ClientName, s);
             }

             IDictionary<int, UnitInfo> parsedUnits = GenerateUnitInfoDataFromQueue(unitCollection, options, slotOptions, currentUnitInfo, slotId);
             _clientQueue = BuildClientQueue(unitCollection, info, slotOptions, slotId);
             _logInterpreter = null;

             return parsedUnits;
        }