Пример #1
0
        private void ClearUnActiveUserInfo()
        {
            List <string> unActivedUserList = new List <string>();

            while (true)
            {
                unActivedUserList.Clear();
                lock (_lockObj)
                {
                    foreach (KeyValuePair <string, DateTime> kvp in _onlineUserMap)
                    {
                        if ((DateTime.Now - kvp.Value).TotalSeconds > 5)
                        {
                            unActivedUserList.Add(kvp.Key);
                        }
                    }
                    foreach (string uid in unActivedUserList)
                    {
                        _onlineUserMap.Remove(uid);
                    }
                }
                foreach (string uid in unActivedUserList)
                {
                    UserPolicyData policyData = new UserPolicyData();
                    policyData.UserID     = uid;
                    policyData.RemoveSelf = true;
                    _UIControl.SyncUpdatePolicyList(ref policyData);
                }
                if (_activeCheckWaitEvent.WaitOne(1000 * 2))
                {
                    //收到信号退出当前线程
                    return;
                }
            }
        }
Пример #2
0
        public void OnCondBroadcastMessage(Message msg)
        {
            switch (msg.Header.CommandValue)
            {
            case LOGMSGID:
            {
                MessageV2ReaderHelper reader     = new MessageV2ReaderHelper(msg);
                UserPolicyData        policyData = new UserPolicyData(reader);
                if (!policyData.RemoveSelf)
                {
                    UpdateUserOnlineInfo(policyData.UserID);
                }
                else
                {
                    lock (_lockObj)
                    {
                        DateTime lastActiveTime;
                        if (_onlineUserMap.TryGetValue(policyData.UserID, out lastActiveTime))
                        {
                            _onlineUserMap.Remove(policyData.UserID);
                        }
                    }
                }
                _UIControl.SyncUpdatePolicyList(ref policyData);
                break;
            }

            case CHANGESERVERMSGID:
            {
                MessageV2ReaderHelper reader = new MessageV2ReaderHelper(msg);
                string userID = reader.ReadStr();
                if (userID.Equals(_userID, StringComparison.OrdinalIgnoreCase))
                {
                    _UIControl.ChangeServerIP();
                }
                break;
            }

            case CHANGEPOLICYMSGID:
            {
                MessageV2ReaderHelper reader = new MessageV2ReaderHelper(msg);
                string         adminUserID   = reader.ReadStr();
                UserPolicyData policyData    = new UserPolicyData(reader);
                if (policyData.UserID.Equals(_userID, StringComparison.OrdinalIgnoreCase))
                {
                    _UIControl.AsyncUpdatePolicy(adminUserID, ref policyData);
                }
                break;
            }

            default:
            {
                break;
            }
            }
        }
Пример #3
0
        public bool loginToServer(string userID)
        {
            if (_logined)
            {
                return(true);
            }
            if (_UIControl.SyncCheckUserExists(userID))
            {
                return(false);
            }
            if (_PolicyBroadcastThread != null)
            {
                return(false);
            }


            _PolicyBroadcastThread = new Thread((obj) => {
                while (true)
                {
                    UserPolicyData policyData = new UserPolicyData();
                    policyData.UserID         = obj as string;
                    _UIControl.SyncGetSelfPolicyData(ref policyData);
                    _UIControl.SyncUpdatePolicyList(ref policyData);
                    //Console.WriteLine(policyData.ToString());
                    Message msg = new Message();
                    msg.SetCommand(3100, LOGMSGID);
                    MessageV2BuilderHelper helper = new MessageV2BuilderHelper();
                    helper.WriteUserPolicyData2Msg(policyData);
                    msg.setMsgBody(helper.GetMsgBody());
                    _server.conBroadcast(msg, PacketHeader.ExpoDealType.InterGroup);
                    //Thread.Sleep(500);
                    if (_policySyncWaitEvent.WaitOne(1000))
                    {
                        //收到信号退出当前线程
                        return;
                    }
                }
            });
            _PolicyBroadcastThread.Start(userID);
            _userID  = userID;
            _logined = true;

            return(_logined);
        }
Пример #4
0
 public static void WriteUserPolicyData2Msg(this MessageV2BuilderHelper helper, UserPolicyData policyData)
 {
     helper.WriteString(policyData.UserID);
     helper.WriteDouble(policyData.OfferTime);
     helper.WriteString(policyData.PriceMarkup);
     helper.WriteDouble(policyData.Submit400);
     helper.WriteDouble(policyData.Submit500);
     helper.WriteDouble(policyData.SubmitForce);
     helper.WriteString(policyData.ServerIP);
     helper.WriteBool(policyData.RemoveSelf);
     helper.WriteBool(policyData.CanRemoteControl);
 }