コード例 #1
0
ファイル: HappyMessageProcess.cs プロジェクト: xxy1991/cozy
        private static bool OnProcessHappyLogin(NetServer server, int id, NetIncomingMessage msg)
        {
            var r               = new Msg_HappyPlayerLogin();
            r.R(msg);

            uint uid            = HappyGameId;
            int x               = RandomMaker.Next(10);
            int y               = RandomMaker.Next(10);
            uint sid            = (uint)RandomMaker.Next(83);
            var selfMsg         = new Msg_HappyPlayerLoginRsp();
            selfMsg.Uid         = uid;
            selfMsg.X           = x;
            selfMsg.Y           = y;
            selfMsg.SpriteId    = sid;
            SendMessage(server, selfMsg, msg.SenderConnection);

            // 更新链接对应的ID
            HappyConnMgr.Modify(msg.SenderConnection, uid);

            var playerPackMsg = new Msg_HappyPlayerPack();

            // 为新玩家推送旧玩家信息
            var playerList = HappyPlayerMgr.ToList();
            var playerPackList =
                from f
                in playerList
                select Tuple.Create<uint, int, int, bool, uint>(f.Key, f.Value.X, f.Value.Y, f.Value.IsAlive, f.Value.SpriteId);
            playerPackMsg.PlayerPack = playerPackList.ToList();
            SendMessage(server, playerPackMsg, msg.SenderConnection);

            // 为旧玩家推送新玩家信息
            var otherMsg        = new Msg_HappyOtherPlayerLogin();
            otherMsg.Uid        = uid;
            otherMsg.X          = x;
            otherMsg.Y          = y;
            otherMsg.SpriteId   = sid;
            SendMessageExceptOne(server, otherMsg, msg.SenderConnection);

            // 添加新玩家到玩家管理中
            var player      = new HappyPlayer();
            player.X        = x;
            player.Y        = y;
            player.IsAlive  = true;
            player.SpriteId = sid;
            HappyPlayerMgr.Add(uid, player);

            return true;
        }
コード例 #2
0
ファイル: NetClientHelper.cs プロジェクト: xxy1991/cozy
 public void OnDataMessage(object sender, NetIncomingMessage im)
 {
     if (DataMessage != null)
     {
         int id = im.ReadInt32();
         if (id == MsgId.ChatToAll)
         {
             MsgBase msg = new Msg_ChatToAll();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if (id == MsgId.AccountRegRsp)
         {
             MsgBase msg = new Msg_AccountRegRsp();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.AgarLoginRsp)
         {
             MsgBase msg = new Msg_AgarLoginRsp();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.AgarFixedBall)
         {
             MsgBase msg = new Msg_AgarFixedBall();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.AgarPlayInfo)
         {
             MsgBase msg = new Msg_AgarPlayInfo();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.AgarFixBallPack)
         {
             MsgBase msg = new Msg_AgarFixBallPack();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.AgarPlayInfoPack)
         {
             MsgBase msg = new Msg_AgarPlayInfoPack();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.AgarSelf)
         {
             MsgBase msg = new Msg_AgarSelf();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.AgarMarkListPark)
         {
             MsgBase msg = new Msg_AgarMarkListPack();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.HappyPlayerLoginRsp)
         {
             MsgBase msg = new Msg_HappyPlayerLoginRsp();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.HappyOtherPlayerLogin)
         {
             MsgBase msg = new Msg_HappyOtherPlayerLogin();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.HappyPlayerMove)
         {
             MsgBase msg = new Msg_HappyPlayerMove();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.HappyPlayerQuit)
         {
             MsgBase msg = new Msg_HappyPlayerQuit();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
         else if(id == MsgId.HappyPlayerPack)
         {
             MsgBase msg = new Msg_HappyPlayerPack();
             msg.R(im);
             DataMessage(sender, new DataMessageArgs(msg));
         }
     }
 }