Esempio n. 1
0
 public void PushWriteMsg(BaseMessage baseMsg)
 {
     lock (m_WriteQueue)
     {
         m_WriteQueue.Enqueue(baseMsg);
     }
 }
        private void OnPingPro(MemoryStream ms, UInt64 userID, BaseMessage bs)
        {
            LoginMsg.C2S_Ping msg = new LoginMsg.C2S_Ping();
            msg = ProtoBuf.Serializer.Deserialize<LoginMsg.C2S_Ping>(ms);
            ms.Close();

            m_dicUserinfo[userID].heartTime = MsgResend.GetTime();//记录心跳

            LoginMsg.S2C_Ping rmsg = new LoginMsg.S2C_Ping();
            rmsg.time = msg.time;

            //m_dicUserinfo[_userid].msgSendNum++;
            LoginServerManager.Instance.Server.SendMessage(userID, CmdNum.SC_Ping, rmsg, bs.sender,0.0f,0,false);
        }
        private void OnLoginPro(MemoryStream ms, BaseMessage bs, UInt64 msgNum)
        {
            LoginMsg.C2SLogin msg = new LoginMsg.C2SLogin();
            msg = ProtoBuf.Serializer.Deserialize<LoginMsg.C2SLogin>(ms);
            ms.Close();
            Console.WriteLine("用户名:" + msg.account + ",密码:" + msg.password);

            //回包
            //MemoryStream msmsg = new MemoryStream();
            LoginMsg.S2CLogin rmsg = new LoginMsg.S2CLogin();
            deploy.USER_INFO userinfo = GameConfig.Instance.userInfoData.Exist(msg.account, msg.password);
            if (userinfo != null)
            {
                if (!m_dicUserinfo.ContainsKey((ulong)userinfo.id))
                {
                    IPEndPoint savesender = new IPEndPoint(bs.sender.Address, bs.sender.Port);//记录地址端口
                    UserInfo userInfo = new UserInfo();
                    userInfo.sender = savesender;
                    m_dicUserinfo.Add((ulong)userinfo.id, userInfo);
                }
                else
                {
                    m_dicUserinfo[(ulong)userinfo.id].sender = new IPEndPoint(bs.sender.Address, bs.sender.Port);//记录地址端口
                    Console.WriteLine("重登陆!");
                }

                rmsg.userId = (ulong)userinfo.id;
                m_dicUserinfo[(ulong)userinfo.id].heartTime = MsgResend.GetTime();//记录心跳
                m_dicUserinfo[(ulong)userinfo.id].msgRecvNum = msgNum;//消息接收号  

                m_dicUserinfo[(ulong)userinfo.id].hp = userinfo.hp;
                if (m_dicUserinfo[(ulong)userinfo.id].roomID != 0)
                    BattleManager.Instance.RemoveRoomUserAndSendMsg((ulong)userinfo.id, m_dicUserinfo[(ulong)userinfo.id].roomID);//删除房间用户并发消息                                                       
            }
            else
            {
                rmsg.userId = 0;
            }

            if (rmsg.userId != 0)
            {
                //填写角色数据
                rmsg.type = (int)Enum.Parse(typeof(BaseActor.Type), userinfo.actor_type);//角色类型//字符串转值
                rmsg.hp = m_dicUserinfo[(ulong)userinfo.id].hp;
                rmsg.name = userinfo.name;
                //填写枪信息                            
                string[] use_gun = userinfo.use_gun.Split(',');
                string[] gun_id = userinfo.gun_id.Split(',');
                for (int i = 0; i < gun_id.Length; i++)
                {
                    //枪信息
                    int gunid = Convert.ToInt32(gun_id[i]);
                    bool use = Convert.ToBoolean(use_gun[i]);
                    deploy.GUN_INFO gf = GameConfig.Instance.gunInfoData.GetData(gunid);

                    LoginMsg.GunInfo guninfo = new LoginMsg.GunInfo();
                    rmsg.GunInfo.Add(guninfo);
                    guninfo.id = gunid;
                    guninfo.use = use;
                    guninfo.experience = gf.experience;
                    guninfo.quality = (int)Enum.Parse(typeof(Gun.Quality), gf.quality);
                    guninfo.count = gf.count;
                    guninfo.bullet_quality = gf.bullet_quality;
                    guninfo.caliber = gf.caliber;
                    guninfo.speed = gf.speed;
                    guninfo.frequency = gf.frequency;
                    guninfo.accurate = gf.accurate;
                    guninfo.range = gf.range;
                    guninfo.recoil = gf.recoil;
                    guninfo.weight = gf.weight;
                    guninfo.swap_speed = gf.swap_speed;
                    guninfo.aim_scale = gf.aim_scale;
                }

                rmsg.money = userinfo.money;
                rmsg.diamonds = userinfo.diamonds;
                rmsg.experience = userinfo.experience;
                rmsg.integral = userinfo.integral;
                rmsg.experience_rank = userinfo.experience_rank;
                rmsg.integral_rank = userinfo.integral_rank;
                rmsg.modelType = userinfo.model_type;
            }

            //ProtoBuf.Serializer.Serialize<LoginMsg.S2CLogin>(msmsg, rmsg);

            LoginServerManager.Instance.Server.SendMessage(rmsg.userId, CmdNum.SC_Login, rmsg, bs.sender, LoginServerManager.Instance.sendTime.interval_1, LoginServerManager.Instance.sendTime.count_1,false);
        }