Пример #1
0
        private string DoLogin(string formatString)
        {
            AnalysisStr analy  = new AnalysisStr(formatString);
            DBFunction  dbf    = new DBFunction();
            string      format = "Server#" + OpType.LOGIN_RES + "#";

            format += (dbf.Login(analy.GetParaIndexOf(0), analy.GetParaIndexOf(1)) == true?1:0);
            if (dbf.Login(analy.GetParaIndexOf(0), analy.GetParaIndexOf(1)))
            {
                string IP   = endPoint.Address.ToString();
                int    Port = endPoint.Port;
                OLList.OnLined(new SmallUser(analy.GetUserID(), IP, Port));

                string msg = "Server#" + OpType.INFORM_FRIENDS + "#" + analy.GetParaIndexOf(0);
                foreach (string userID in OLList.GetAllOLUsersID())
                {
                    if (dbf.IsFriend(analy.GetParaIndexOf(0), userID))
                    {
                        SmallUser sUser  = OLList.GetUserByID(userID);
                        CClient   client = new CClient(sUser.IPAddress, sUser.IPPort);
                        client.ConnectToServer();
                        client.GetNetworkStream();
                        client.Communicate(msg);
                        client.ReLeaseAll();
                    }
                }
            }
            return(format);
        }
Пример #2
0
        //检测函数,检测客户端是否关闭,检测异常关闭以及挂掉
        public void TrueOnLineUsers()
        {
            foreach (string userID in OLList.GetAllOLUsersID())
            {
                if (OLList.IsOnLine(userID))
                {
                    try
                    {
                        CClient client = new CClient(OLList.GetUserByID(userID).IPAddress, OLList.GetUserByID(userID).IPPort);
                        client.ConnectToServer();
                        client.GetNetworkStream();
                        client.Communicate("###");
                        client.ReLeaseAll();
                    }
                    catch (Exception e)
                    {
                        OLList.OffLined(userID);

                        System.Console.WriteLine(userID + "客户端异常关闭,现在在线用户数量:" + OLList.Length());
                    }
                }
            }
        }
Пример #3
0
        public string DistributeTasks(string formatString)
        {
            AnalysisStr analy = new AnalysisStr(formatString);

            if (analy.GetKindOfReq() != OpType.RIGISTER && analy.GetKindOfReq() != OpType.LOGIN)
            {
                if (OLList.GetUserByID(analy.GetUserID()) == null)
                {
                    return("###");
                }
                endPoint.Address = IPAddress.Parse(OLList.GetUserByID(analy.GetUserID()).IPAddress);
                endPoint.Port    = OLList.GetUserByID(analy.GetUserID()).IPPort;
            }
            switch (analy.GetKindOfReq())
            {
            case OpType.RIGISTER:
                return(DoRegister(formatString));

            case OpType.LOGIN:
                return(DoLogin(formatString));

            case OpType.ALL_GROUPS:
                return(DoGetAllGroupJoined(formatString));

            case OpType.ALL_FRIENDS:
                return(DoGetAllFriends(formatString));

            case OpType.ALL_ONLINE_FRIENDS:
                return(DoGetAllFriendsOL(formatString));

            case OpType.ALL_FRIEND_REQUESTS_REC:
                return(DoGetAllRecievedFriendRequests(formatString));

            case OpType.ALL_FRIEND_REQUESTS_SED:
                return(DoGetAllSentFriendRequests(formatString));

            case OpType.ALL_OFFLINE_MSG:
                return(DoGetAllOffLineMsg(formatString));

            case OpType.FRIEND_IP:
                return(DoGetFriendIP(formatString));

            case OpType.DELETE_FRIEND:
                DoDeleteFriend(formatString);
                break;

            case OpType.SEND_FRIEND_REQUEST:
                return(DoSendFriendRequest(formatString));

            case OpType.AGREE_FRIEND_REQUEST:
                DoAgreeFriendRequest(formatString);
                break;

            case OpType.DISAGREE_FRIEND_REQUEST:
                DoDisagreeFriendRequest(formatString);
                break;

            case OpType.SEND_OFFLINE_MSG:
                return(DoSendOffLineMsg(formatString));

            case OpType.RECIEVE_OFFLINE_MSG:
                DoRecieveOffLineMsg(formatString);
                break;

            case OpType.CREATE_GROUP:
                return(DoCreateGroup(formatString));

            case OpType.JOIN_GROUP:
                return(DoJoinGroup(formatString));

            case OpType.ALL_GROUP_REQUEST:
                return(DoGetAllJoinGroupRequests(formatString));

            case OpType.AGREE_JOIN_GROUP:
                DoAgreeJoinGroup(formatString);
                break;

            case OpType.DISAGREE_JOIN_GROUP:
                DoDisagreeJoinGroup(formatString);
                break;

            case OpType.ALTER_USER_INFO:
                DoAlterUserInfo(formatString);
                break;

            case OpType.USER_INFO:
                return(DoGetUserInfo(formatString));

            case OpType.GROUP_INFO:
                return(DoGetGroupInfo(formatString));

            case OpType.ALTER_GROUP_INFO:
                DoAlterGroupInfo(formatString);
                break;

            case OpType.SEND_NET_FILE:
                return(DoSendNetFile(formatString));

            case OpType.SEND_GRUOP_MSG:
                DoSendGroupMsg(formatString);
                break;

            case OpType.MEMBERS_IN_GROUP:
                return(DoGetGroupMembers(formatString));

            case OpType.LEAVE_GROUP:
                DoLeaveGroup(formatString);
                break;

            case OpType.FIND_USERS:
                return(DoFindUsers(formatString));

            case OpType.FIND_GROUPS:
                return(DoFindGroups(formatString));

            case OpType.IS_FRIEND:
                return(DoIsFriend(formatString));

            case OpType.IS_IN_GROUP:
                return(DoIsInGroup(formatString));

            case OpType.LOGOUT:
                DoLogout(formatString);
                break;

            default:
                break;
            }

            return("###");                 //表示调用函数无返回值
        }