예제 #1
0
        private void leaveChatRoom(UserLogicModel user)
        {
            //ExtensionMethods.debugger();
            var room = getRoomFromUser(user);
            if (room == null) throw new Exception("idk");

            foreach (var userLogicModel in room.Users) {
                if (userLogicModel.Hash == user.Hash) {
                    room.Users.Remove(userLogicModel);
                    break;
                }
            }
            myDataManager.ChatData.RemoveUser(room,
                                              user,
                                              (a) => {
                                                  myServerManager.UnregisterChatServer(user);
                                                  var roomToSend = new ChatRoomDataModel(room.RoomName, room.Users, null);

                                                         if (room.Users.Count == 0)
                                                         {
                                                             myDataManager.ChatData.RemoveRoom(room, () => { });
                                                             return;
                                                         }

                                                  foreach (var userLogicModel in room.Users) {
                                                      myServerManager.SendChatInfo(userLogicModel, roomToSend.ToModel());
                                                  }
                                              });
        }
예제 #2
0
        private void OnJoinChatChannel(UserLogicModel user, JoinChatRoomRequest data)
        {
            var cur = getRoomFromUser(user);
            if (cur != null) leaveChatRoom(user);

            ChatRoomDataModel currentRoomData = null;
            foreach (var chatRoomModel in runningRooms) {
                if (chatRoomModel.RoomName == data.Room.ChatChannel)
                    currentRoomData = chatRoomModel;
            }
            if (currentRoomData == null)
                throw new Exception("idk");


            myDataManager.ChatData.AddUser(currentRoomData,
                                           user,
                                           room => {
                                               myServerManager.RegisterChatServer(user);
                                               var roomToSend = new ChatRoomDataModel(room.RoomName, room.Users, room.Messages);

                                               roomToSend.Messages = room.Messages.Extract(room.Messages.Count - 5);
                                               myServerManager.SendChatInfo(user, roomToSend.ToModel());

                                               roomToSend = new ChatRoomDataModel(room.RoomName, room.Users, null);

                                               foreach (var userLogicModel in currentRoomData.Users) {
                                                   myServerManager.SendChatInfo(userLogicModel, roomToSend.ToModel() );
                                               }
                                           });
        }