Esempio n. 1
0
 private void InitClient()
 {
     Client = new ClientConnect(true);
     Client.SetOnReceiveEvent((c, m) =>
     {
         LemonMessage msg = (LemonMessage)m;
         if (msg.StateCode == 0)
         {
             lock (ClientLock)
             {
                 //Debug.Log("receive:" + msg.Body);
                 Battle battle = (Battle)SerializeObject.DeserializeFromString(msg.Body, typeof(Battle));
                 ReceiveCommandObj.PostAsyncMethod(battle.Step.ToString(), battle);
             }
         }
     });
     Client.OnErrorEvent = (c, e) =>
     {
         //Debug.Log("出错了" + e.Message);
     };
     Client.OnConnectEvent = (c) =>
     {
         //Debug.Log("连接上了");
     };
     Client.OnDisconnectEvent = (c) =>
     {
         //Debug.Log("连接断开了");
     };
     Client.Connect <LemonMessage>(IP, Port);
 }
Esempio n. 2
0
 public void InitClient()
 {
     Client = new ClientConnect(true);
     Client.SetOnReceiveEvent((c, m) =>
     {
         LemonMessage msg = (LemonMessage)m;
         if (msg.StateCode == 0)
         {
             lock (ClientLock)
             {
                 PokerBattle battle = (PokerBattle)SerializeObject.DeserializeFromString(msg.Body, typeof(PokerBattle));
                 //Debug.Log("接收到命令" + battle.Step);
                 MsgList.Enqueue(battle);
             }
         }
     });
     Client.OnErrorEvent = (c, e) =>
     {
         //Debug.Log("出错了" + e.Message);
     };
     Client.OnConnectEvent = (c) =>
     {
         //Debug.Log("连接上了");
     };
     Client.OnDisconnectEvent = (c) =>
     {
         //Debug.Log("连接断开了");
     };
     Client.Connect <LemonMessage>(IP, Port);
 }
Esempio n. 3
0
        public static void SendToClient(PokerCommand command, PokerBattle battle)
        {
            battle.Step = command;
            LemonMessage msg = new LemonMessage();

            msg.Body = new JsonSerialize().SerializeToString(battle);
            SendMsgToAllClient(command, battle, msg);
        }
Esempio n. 4
0
        public void ReConnect(string accountid)
        {
            SocketServer socketServer = FightServer.Instance.GetServer();
            LemonMessage msg          = new LemonMessage();

            msg.Body = new JsonSerialize().SerializeToString(Battle);

            ToCleintCommand.SendMsgToOneClient(Battle.Step, accountid, Battle, msg);
        }
Esempio n. 5
0
        public void Dissolve(string otherid)
        {
            //清除正在战斗的状态
            new BattleService().ClearBattleSidesState(Battle);
            BattlegroundManager.Instance.DeleteBattle(this);
            //通知
            SocketServer socketServer = FightServer.Instance.GetServer();
            LemonMessage msg          = new LemonMessage();

            Battle.Step = BattleCommand.NoticeDissolve;
            msg.Body    = new JsonSerialize().SerializeToString(Battle);

            ToCleintCommand.SendMsgToAllClient(BattleCommand.NoticeDissolve, Battle, msg);
        }
Esempio n. 6
0
        public static void SendToClient(BattleCommand command, Battle battle, string askAccountID = null)
        {
            LemonMessage msg = new LemonMessage();

            msg.Body = new JsonSerialize().SerializeToString(battle);
            if (command == BattleCommand.AskTouchCard)
            {
                SendMsgToOneClient(command, askAccountID, battle, msg);
            }
            else
            {
                SendMsgToAllClient(command, battle, msg);
            }
        }
Esempio n. 7
0
        public void SendSoundMsg(string battleCode, string accountID, string soundData)
        {
            LogHelper.DebugLog("收到:" + accountID + "  发来的SendSoundMsg");
            Battleground bg           = BattlegroundManager.Instance.Find(battleCode);
            SocketServer socketServer = FightServer.Instance.GetServer();
            LemonMessage msg          = new LemonMessage();
            Battle       soundBattle  = new Battle();
            OneSide      currentSide  = bg.Battle.Sides.FirstOrDefault(c => c.AccountID == accountID);

            soundBattle.CurrentSide = currentSide;
            soundBattle.Sides       = bg.Battle.Sides;
            soundBattle.Step        = BattleCommand.SendSoundMsg;
            soundBattle.Msg         = soundData;
            msg.Body = new JsonSerialize().SerializeToString(soundBattle);

            ToCleintCommand.SendMsgToAllClient(BattleCommand.SendSoundMsg, soundBattle, msg);
        }
Esempio n. 8
0
 public void Start()
 {
     Client = new ClientConnect(true);
     Client.SetOnReceiveEvent((c, m) =>
     {
         LemonMessage msg = (LemonMessage)m;
         if (msg.StateCode == 0)
         {
             Battle battle = (Battle) new JsonSerialize().DeserializeFromString(msg.Body, typeof(Battle));
             //ReceiveCommandObj.PostAsyncMethod(battle.Step.ToString(), battle);
         }
     });
     Client.OnErrorEvent = (c, e) =>
     {
     };
     Client.OnConnectEvent = (c) =>
     {
     };
     Client.Connect <LemonMessage>(IP, Port);
 }
Esempio n. 9
0
        public void SendTextMsg(string battleID, string accountID, string textData)
        {
            LogHelper.DebugLog("Poker收到:" + accountID + "  发来的SendTextMsg");
            PokerBattleground bg           = PokerBattlegroundManager.Instance.Find(battleID);
            SocketServer      socketServer = PokerServer.Instance.GetServer();

            PokerBattle soundBattle = new PokerBattle();
            PokerSide   currentSide = bg.Battle.Sides.FirstOrDefault(c => c.AccountID == accountID);

            soundBattle.CurrentSideOrder = currentSide.Order;
            soundBattle.Sides            = bg.Battle.Sides;
            soundBattle.Step             = PokerCommand.SendTextMsg;
            soundBattle.Msg = textData;

            LemonMessage msg = new LemonMessage();

            msg.Body = new JsonSerialize().SerializeToString(soundBattle);

            ToPokerCleintCommand.SendMsgToAllClient(PokerCommand.SendTextMsg, soundBattle, msg);
        }
Esempio n. 10
0
        public static void SendMsgToAllClient(BattleCommand command, Battle battle, LemonMessage msg)
        {
            SocketServer socketServer = FightServer.Instance.GetServer();

            foreach (var c in socketServer.AllConnect())
            {
                if (!battle.Sides.Any(s => s.AccountID == c.ConnectID))
                {
                    continue;
                }
                try
                {
                    c.SendMessage(msg);
                }
                catch (Exception ex)
                {
                    LogHelper.LogError("发送出错:" + ex.Message + " " + ex.StackTrace);
                }
                LogHelper.DebugLog("send " + command);
            }
            BattleAIServerManager.Instance.SendToAllAIUser(command, battle);
        }
Esempio n. 11
0
        public int GoOut(string otherid)
        {
            new BattleService().ClearBattleOneSideState(Battle, otherid);
            Battle.Sides.RemoveAll(c => c.AccountID == otherid);
            //通知
            SocketServer  socketServer = FightServer.Instance.GetServer();
            LemonMessage  msg          = new LemonMessage();
            BattleCommand oldSetp      = Battle.Step;

            Battle.Step = BattleCommand.NoticeGoOut;
            msg.Body    = new JsonSerialize().SerializeToString(Battle);
            Battle.Step = oldSetp;

            ToCleintCommand.SendMsgToAllClient(BattleCommand.NoticeGoOut, Battle, msg);
            //foreach (var c in socketServer.AllConnect())
            //{
            //    if (!Battle.Sides.Any(s => s.AccountID == c.ConnectID) && c.ConnectID != otherid)
            //        continue;
            //    c.SendMessage(msg);
            //    LogHelper.DebugLog("server send " + BattleCommand.NoticeGoOut);
            //}
            //BattleAIServerManager.Instance.SendToAllAIUser(BattleCommand.NoticeGoOut, Battle);
            return(0);
        }
Esempio n. 12
0
 protected virtual int SortOrderLmTime(LemonMessage lmA, LemonMessage lmb)
 {
     return(lmA.RecordTime.CompareTo(lmb.RecordTime));
 }
Esempio n. 13
0
        public static void SendMsgToOneClient(BattleCommand command, string accountID, Battle battle, LemonMessage msg)
        {
            SocketServer socketServer = FightServer.Instance.GetServer();

            try
            {
                ConnectBase conn = socketServer.GetConnect(accountID);
                if (conn != null)
                {
                    conn.SendMessage(msg);
                }
                //socketServer.SendMessage(accountID, msg);
            }
            catch (Exception ex)
            {
                LogHelper.LogError("AskTouchCard发送出错:" + ex.Message + " " + ex.StackTrace);
            }
            BattleAIServerManager.Instance.SendToAIUser(accountID, command, battle);
            LogHelper.DebugLog("send " + command);
        }