public void Handle(ISession session) { ChatSession chatSession = session as ChatSession; //if info is validated if (true) { ChatUser user = chatSession.Owner; user.FirstName = FirstName; user.LastName = LastName; user.Town = Town; user.DateOfBirth = DateOfBirth; user.Gender = Gender; user.Save(); GetSelfProfileResponse packet = new GetSelfProfileResponse(); packet.FirstName = user.FirstName; packet.LastName = user.LastName; packet.Email = user.Email; packet.Town = user.Town; packet.DateOfBirth = user.DateOfBirth; packet.Gender = user.Gender; chatSession.Owner.Send(packet); } }
public void Handle(ISession session) { if (TargetID.Equals(Guid.Empty)) { return; } ChatUser targetUser = ChatUserManager.LoadUser(TargetID); if (targetUser == null) { return; } ChatSession chatSession = session as ChatSession; ConversationStore store = new ConversationStore(); Guid resultID = Guid.NewGuid(); bool flag = true; var CommonConversation = targetUser.ConversationID.Intersect(chatSession.Owner.ConversationID); foreach (Guid conversationID in CommonConversation) { AbstractConversation conversation = store.Load(conversationID); if (conversation is SingleConversation) { resultID = conversation.ID; flag = false; break; } } if (flag) { chatSession.Owner.ConversationID.Add(resultID); targetUser.ConversationID.Add(resultID); store.Save(new SingleConversation() { ID = resultID, Members = new HashSet <Guid>() { chatSession.Owner.ID, targetUser.ID }, ConversationName = "~" }); chatSession.Owner.Save(); targetUser.Save(); } SingleConversationFrUserIDResponse response = new SingleConversationFrUserIDResponse(); response.UserID = TargetID; response.ResponseID = resultID; chatSession.Send(response); }
public void Execute(ISender commandSender, string commandLabel, string[] args) { if (args.Length < 2) { return; } Guid id = ProfileCache.Instance.ParseEmailToGuid(args[1].ToLower()); if (id.Equals(Guid.Empty)) { PacChatServer.GetServer().Logger.Error("Email is not exists."); return; } ChatUser user = ChatUserManager.LoadUser(id); user.Banned = true; user.Save(); if (user.IsOnline()) { user.Kick(); } }
public void Handle(ISession session) { ChatSession chatSession = session as ChatSession; RegisterResult responePacket = new RegisterResult(); if (ProfileCache.Instance.ParseEmailToGuid(Email) != Guid.Empty) { responePacket.StatusCode = ResponeCode.Conflict; chatSession.Send(responePacket); chatSession.Disconnect(); return; } Guid id = Guid.NewGuid(); ChatUser user = new ChatUser() { ID = id, Email = this.Email, Password = HashUtils.MD5(PassHashed + id), FirstName = this.FirstName, LastName = this.LastName, DateOfBirth = this.DoB, Gender = this.Gender }; bool added = user.Save(); if (added) { responePacket.StatusCode = ResponeCode.OK; PacChatServer.GetServer().Logger.Info(String.Format("Account {0} has registered successfully.", user.Email)); } else { responePacket.StatusCode = ResponeCode.NotFound; } chatSession.Send(responePacket); chatSession.Disconnect(); }
public void Execute(ISender commandSender, string commandLabel, string[] args) { if (args.Length < 3) { return; } string email = args[2]; if (args[1] == "get") { Guid id = ProfileCache.Instance.ParseEmailToGuid(email); ChatUserProfile profile = ProfileCache.Instance.GetUserProfile(id); if (profile == null) { PacChatServer.GetServer().Logger.Debug("NULL"); } else { PacChatServer.GetServer().Logger.Debug(profile.ID); } } if (args[1] == "add" && args.Length >= 4) { Random r = new Random(); if (ProfileCache.Instance.ParseEmailToGuid(email) != Guid.Empty) { PacChatServer.GetServer().Logger.Error("Create fail: email early existed!!!"); return; } Guid id = Guid.NewGuid(); ChatUser user = new ChatUser() { ID = id, Email = email, Password = HashUtils.MD5(HashUtils.MD5(args[3]) + id), FirstName = "Admin", LastName = "Admin's lastname", DateOfBirth = new DateTime(1998, r.Next(11) + 1, r.Next(29) + 1), Gender = Entity.EntityProperty.Gender.Male }; bool added = user.Save(); if (added) { PacChatServer.GetServer().Logger.Info(String.Format("Account {0} has registered successfully. ID = {1}", user.Email, user.ID)); } else { PacChatServer.GetServer().Logger.Error("Create fail: Database error!!!"); } } if (args[1] == "search" && args.Length >= 3) { //List<String> ids = new ChatUserStore().SearchUserIDByEmail(args[2]); //foreach (string s in ids) //{ // Console.WriteLine(s); //} } if (args[1] == "mkfriend" && args.Length >= 4) { Guid userID1 = ProfileCache.Instance.ParseEmailToGuid(args[2]); Guid userID2 = ProfileCache.Instance.ParseEmailToGuid(args[3]); if (userID1 == Guid.Empty || userID2 == Guid.Empty) { PacChatServer.GetServer().Logger.Warn("One of two emails does not exist."); return; } ChatUser user1 = ChatUserManager.LoadUser(userID1); ChatUser user2 = ChatUserManager.LoadUser(userID2); user1.SetRelation(user2, Relation.Type.Friend, true); } }