Exemplo n.º 1
0
    public static int UserHearbeat = 0;//记录心跳异常次数
    /// <summary>
    /// 心跳包
    /// </summary>
    /// <returns></returns>
    public static int Xintiao()
    {
        var hear = new MaintainHeartbeat();

        hear.state    = 1;
        hear.openid   = GameInfo.OpenID;
        hear.userID   = userID;
        hear.Latitude = GameInfo.Latitude;
        if (cs.serverType == ServerType.GameServer)
        {
            hear.RoomID = room_id.ToString();
        }

        byte[] body = ProtobufUtility.GetByteFromProtoBuf(hear);
        byte[] data = CreateHead.CreateMessage(CreateHead.CSXYNUM + 1, body.Length, 0, body);

        try
        {
            GameInfo.cs.Send(data);
            UserHearbeat++;
            return(UserHearbeat);
        }
        catch (Exception ex)
        {
            UserHearbeat++;
            return(UserHearbeat);
        }
    }
Exemplo n.º 2
0
    public static int UserHearbeat = 0;//记录心跳异常次数,未完成
    /// <summary>
    /// 心跳包
    /// </summary>
    /// <returns></returns>
    public static int Xintiao()
    {
        //MaintainHeartbeat()来自Google.ProtocolBuffers
        var hear = new MaintainHeartbeat();

        hear.state = 1;
        //openID是设备唯一标识符
        hear.openid = GameInfo.OpenID;
        //用户ID
        hear.userID = userID;
        //经纬度
        hear.Latitude = GameInfo.Latitude;
        //还是设备唯一标识符
        hear.unionid = GameInfo.unionid;
        //当Server的状态为game服务器时,房间ID也要上传至心跳包
        if (cs.serverType == ServerType.GameServer)
        {
            hear.RoomID = room_id.ToString();
        }

        byte[] body = ProtobufUtility.GetByteFromProtoBuf(hear);
        byte[] data = CreateHead.CreateMessage(CreateHead.CSXYNUM + 1, body.Length, 0, body);

        try
        {
            GameInfo.cs.Send(data);
            UserHearbeat++;

            return(UserHearbeat);
        }
        catch (Exception ex)
        {
            UserHearbeat++;
            return(UserHearbeat);
        }
    }
Exemplo n.º 3
0
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            if (!Gongyong.userlist.Any(w => w.session.SessionID.Equals(session.SessionID)))
            {
                session.Logger.Debug(" Heartbeat : 非法连接" + session.SessionID);
                session.Close();
                return;
            }

            var info     = MaintainHeartbeat.ParseFrom(requestInfo.Body);
            var userInfo = Gongyong.userlist.Find(w => w.openid.Equals(info.Openid));

            if (userInfo != null)
            {
                if (info.HasLatitude)
                {
                    userInfo.Lat = info.Latitude;
                }
                userInfo.UserIP = session.RemoteEndPoint.Address.ToString();
                //session.Logger.Debug("定位" + userInfo.Lat+"名称"+userInfo.nickname);
            }
            session.TrySend(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1, requestInfo.Body.Length, requestInfo.MessageNum, requestInfo.Body)));
            Gongyong.msg.Remove(null);
            var messageList = Gongyong.msg.FindAll(w => w.openid.Equals(info.Openid));

            if (messageList.Count > 0)
            {
                while (messageList.Count > 0)
                {
                    session.TrySend(messageList[0].msg);

                    Gongyong.msg.Remove(messageList[0]);
                    messageList.RemoveAt(0);
                }
            }


            //UserInfo user = Gongyong.userlist.Find(u => u.openid == info.Openid);
            //if (user == null)
            //    return;
            //if (user.session.SessionID != session.SessionID)
            //{
            //    user.session = session;
            //}
            //List<MsgLog> list = Gongyong.msg.FindAll(u => u.openid == user.openid);
            //if (list.Count > 0)
            //{

            //    var usermsg = ReturnMsgList.CreateBuilder();
            //    foreach (var item in list)
            //    {

            //        Google.ProtocolBuffers.ByteString bytes = Google.ProtocolBuffers.ByteString.CopyFrom(item.msg.ToArray());
            //        usermsg.AddMsg(bytes);
            //        Gongyong.msg.Remove(item);
            //    }
            //    byte[] arr = usermsg.Build().ToByteArray();
            //    session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7002, arr.Length, requestInfo.MessageNum, arr)));
            //}


            //}
            //catch (Exception ex)
            //{
            //    //  Logger .Error()
            //    session.Logger.Error(ex.ToString());
            //    session.Close();

            //}
        }
Exemplo n.º 4
0
        public void ExecuteCommand(GameSession session, ProtobufRequestInfo requestInfo)
        {
            try
            {
                GroupInfoDAL groupInfoDAL = new GroupInfoDAL();
                var          info         = MaintainHeartbeat.ParseFrom(requestInfo.Body);
                var          userInfo     = RedisUtility.Get <RedisUserInfoModel>(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERINFO, info.Openid, info.Unionid));
                if (userInfo != null)
                {
                    var olduser = RedisUtility.Get <RedisLoginModel>(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERLIST, info.Openid, info.Unionid));
                    if (olduser == null)
                    {
                        RedisUtility.Set(RedisUtility.GetKey(GameInformationBase.COMMUNITYUSERLIST, userInfo.Openid, userInfo.Unionid), new RedisLoginModel {
                            Openid = userInfo.Openid, ServerName = GameInformationBase.serverName, Unionid = userInfo.Unionid
                        });
                    }
                    if (!Gongyong.userlist.Any(w => w.unionid.Equals(userInfo.Unionid)))
                    {
                        Gongyong.userlist.Add(new UserInfo
                        {
                            city     = userInfo.City,
                            ConnTime = userInfo.ConnTime,
                            GroupID  = userInfo.GroupID,
                            headimg  = userInfo.Headimg,
                            Lat      = userInfo.Lat,
                            nickname = userInfo.Nickname,
                            openid   = userInfo.Openid,
                            province = userInfo.Province,
                            session  = session,
                            sex      = userInfo.Sex,
                            unionid  = userInfo.Unionid,
                            UserID   = userInfo.UserID,
                            UserIP   = session.RemoteEndPoint.Address.ToString(),
                            Type     = userInfo.Type
                        });
                    }
                    session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1, requestInfo.Body.Length, requestInfo.MessageNum, requestInfo.Body)));
                    var list = groupInfoDAL.GetUpdateTipsByUserID(info.UserID);
                    if (list.Any())
                    {
                        var data = ReturnMessgaeList.CreateBuilder().AddRangeMessgaeList(list).Build().ToByteArray();
                        session.Send(new ArraySegment <byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 1111, data.Length, requestInfo.MessageNum, data)));
                    }
                }
                //UserInfo user = Gongyong.userlist.Find(u => u.openid == info.Openid);
                //if (user == null)
                //    return;
                //if (user.session.SessionID != session.SessionID)
                //{
                //    user.session = session;
                //}
                //List<MsgLog> list = Gongyong.msg.FindAll(u => u.openid == user.openid);
                //if (list.Count > 0)
                //{

                //    var usermsg = ReturnMsgList.CreateBuilder();
                //    foreach (var item in list)
                //    {

                //        Google.ProtocolBuffers.ByteString bytes = Google.ProtocolBuffers.ByteString.CopyFrom(item.msg.ToArray());
                //        usermsg.AddMsg(bytes);
                //        Gongyong.msg.Remove(item);
                //    }
                //    byte[] arr = usermsg.Build().ToByteArray();
                //    session.TrySend(new ArraySegment<byte>(CreateHead.CreateMessage(GameInformationBase.BASEAGREEMENTNUMBER + 7002, arr.Length, requestInfo.MessageNum, arr)));
                //}
            }
            catch (Exception ex)
            {
                //  Logger .Error()
                session.Logger.Error(ex.ToString());
                session.Close();
            }
        }