コード例 #1
0
ファイル: DSService.cs プロジェクト: ratiel/Vindictus
        public void RegisterTcpClientHolder(Devcat.Core.Net.TcpClient tcpClient)
        {
            tcpClient.ConnectionSucceed += delegate(object sender, EventArgs evt)
            {
                string text = string.Format("[Peer {0}:{1}]", tcpClient.LocalEndPoint.Address.ToString(), tcpClient.LocalEndPoint.Port.ToString());
                Log <DSService> .Logger.WarnFormat("{0} Connect ", text);

                object typeConverter = DSService.Instance.MessageHandlerFactory.GetTypeConverter();
                tcpClient.Transmit(SerializeWriter.ToBinary(typeConverter));
                DSHostConnectionQuery value = new DSHostConnectionQuery();
                tcpClient.Transmit(SerializeWriter.ToBinary <DSHostConnectionQuery>(value));
                TcpClientHolder tcpClientHolder = new TcpClientHolder();
                tcpClientHolder.BindTcpClient(tcpClient);
                tcpClientHolder.TimeoutShedID = Scheduler.Schedule(this.Thread, Job.Create <TcpClientHolder>(new Action <TcpClientHolder>(this.UnregisterTcpClientHolder), tcpClientHolder), 30000);
                this.TcpClientHolders.Add(tcpClientHolder);
            };
            tcpClient.ExceptionOccur += delegate(object sender, EventArgs <Exception> evt)
            {
                string text = string.Format("[Peer {0}:{1}]", tcpClient.LocalEndPoint.Address.ToString(), tcpClient.LocalEndPoint.Port.ToString());
                Log <DSService> .Logger.ErrorFormat("{0} ExceptionOccur", text);

                DSLog.AddLog(-1, null, -1L, -1, "ExceptionOccur", text);
            };
            tcpClient.ConnectionFail += delegate(object sender, EventArgs <Exception> evt)
            {
                string text = string.Format("[Peer {0}:{1}]", tcpClient.LocalEndPoint.Address.ToString(), tcpClient.LocalEndPoint.Port.ToString());
                Log <DSService> .Logger.ErrorFormat("{0} ConnectionFail", text);

                DSLog.AddLog(-1, null, -1L, -1, "ConnectionFail", text);
            };
        }
コード例 #2
0
ファイル: DSService.cs プロジェクト: ratiel/Vindictus
        public void RemoveDSEntity(int dsID)
        {
            DSEntity dsentity;

            if (this.DSEntities.TryGetValue(dsID, out dsentity))
            {
                DSLog.AddLog(dsentity, "RemoveDSEntity", "");
                Log <DSService> .Logger.WarnFormat("{0} DS 제거", dsID);

                if (dsentity.Process != null)
                {
                    try
                    {
                        dsentity.Process.Kill();
                        DSLog.AddLog(dsentity, "KillProcess (RemoveDSEntity)", "");
                    }
                    catch (Exception ex)
                    {
                        Log <DSEntity> .Logger.FatalFormat("KillProcess Failed!!\n - {0}", ex);

                        DSLog.AddLog(dsentity, "KillProcess Failed", "");
                    }
                    dsentity.Process = null;
                }
                else
                {
                    UpdateDSShipInfo op = new UpdateDSShipInfo(DSService.Instance.ID, dsID, 0L, UpdateDSShipInfo.CommandEnum.PVPClosed, "");
                    DSService.RequestDSBossOperation(op);
                }
                if (dsentity.TcpClient != null)
                {
                    try
                    {
                        dsentity.TcpClient.Disconnect();
                        DSLog.AddLog(dsentity, "DisconnectTcp", "");
                    }
                    catch (Exception ex2)
                    {
                        Log <DSEntity> .Logger.FatalFormat("DisconnectTcp Failed!!\n - {0}", ex2);

                        DSLog.AddLog(dsentity, "DisconnectTcp Failed", "");
                    }
                    dsentity.TcpClient = null;
                }
            }
        }
コード例 #3
0
        public void ProcessMessage(object message)
        {
            if (message is DSHostConnectionEstablish)
            {
                DSHostConnectionEstablish dshostConnectionEstablish = message as DSHostConnectionEstablish;
                Log <TcpClientHolder> .Logger.InfoFormat("Process DSHostConnectionEstablish Message", new object[0]);

                DSEntity dsentity = null;
                foreach (DSEntity dsentity2 in DSService.Instance.DSEntities.Values)
                {
                    if (dsentity2.Process != null && dsentity2.DSID == dshostConnectionEstablish.DSID)
                    {
                        dsentity = dsentity2;
                        break;
                    }
                }
                if (dsentity != null)
                {
                    if (dsentity.PvpConfig == null)
                    {
                        dsentity.RegisterConnection(this.TcpClient);
                    }
                    else
                    {
                        dsentity.RegisterConnectionPvp(this.TcpClient);
                    }
                    this.HasTransfered = true;
                }
                else
                {
                    string text = string.Format("[Peer {0}:{1}]", this.TcpClient.LocalEndPoint.Address.ToString(), this.TcpClient.LocalEndPoint.Port.ToString());
                    Log <DSService> .Logger.ErrorFormat("{0} has no target DS Entity!", text);

                    DSLog.AddLog(-1, null, -1L, -1, "No DSEntity", string.Format("{0} dsid{1}", text, dshostConnectionEstablish.DSID));
                    this.DisconnectTcpClient();
                }
                this.UnBindTcpClient();
            }
        }