Esempio n. 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());
                                                  }
                                              });
        }
 public CardGameQuestion(UserLogicModel user, string question, string[] answers, GameCardGame cardGame)
 {
     User = user;
     Question = question;
     Answers = answers;
     CardGame = cardGame;
 }
Esempio n. 3
0
 public QueueMessage(string name, UserLogicModel user, string eventChannel, object content)
 {
     Name = name;
     User = user;
     EventChannel = eventChannel;
     Content = content;
 }
Esempio n. 4
0
 public void Message(string channel, string name, UserLogicModel user, string eventChannel, object content)
 {
     var message = new QueueMessage(name, user, eventChannel, content);
     var value = Json.Stringify(message, Help.Sanitize);
     if (CommonLibraries.Help.Verbose)
         Logger.Log(channel + "  \n " + value, LogLevel.Information);
     client1.RPush(channel, value); //todo:maybe sanitize
 }
 public void CreateChatChannel(string roomName, UserLogicModel user, Action<ChatRoomModel> complete)
 {
     manager.client.Collection("ChatRoom",
                               (err, collection) => {
                                   ChatRoomModel chatRoomModel = new ChatRoomModel(roomName, new List<UserLogicModel>() {user}, new List<ChatMessageRoomModel>());
                                 collection.Insert(chatRoomModel);
                                   complete(chatRoomModel);
                               });
 }
 public void Room_GetRoomByUser(UserLogicModel user, Action<RoomDataModel> results)
 {
     manager.client.Collection("Room",
         (err, collection) =>
         {
             JsDictionary<string, object> j = new JsDictionary<string, object>();
             j["players.userName"] = user.UserName;
             MongoHelper.Where<RoomDataModel>(collection, j, (a, b) => results(b.Count > 0 ? b[0] : null));
         });
 }
Esempio n. 7
0
 private ChatRoomDataModel getRoomFromUser(UserLogicModel user)
 {
     ChatRoomDataModel currentRoomData = null;
     foreach (var chatRoomModel in runningRooms) {
         foreach (var item in chatRoomModel.Users) {
             if (item.UserName == user.UserName) currentRoomData = chatRoomModel;
         }
     }
     return currentRoomData;
 }
Esempio n. 8
0
        private void messageReceived(string name, UserLogicModel user, string eventChannel, object content)
        {
            //todo?        user.Gateway = name;
            try {
                if (channels[eventChannel] != null)
                    channels[eventChannel](user, content);

            } catch (Exception ex) {
                Console.WriteLine(ex.ToString());
            }
        }
Esempio n. 9
0
 public UserLogicModel ToLogicModel()
 {
     var m = localLogicModel ?? ( localLogicModel = new UserLogicModel() );
     m.Gateway = Gateway;
     m.Hash = Hash;
     m.CurrentChatServer = CurrentChatServer;
     m.CurrentGameServer = CurrentGameServer;
     m.Password = Password;
     m.UserName = UserName;
     return m;
 }
Esempio n. 10
0
        public void SendMessage(string channel, string eventChannel, UserLogicModel user , object content)
        {
            if (qpCollection.GetByChannel(channel) == null) {
                ServerLogger.LogError(string.Format("Cannot send message:{0} - {1} No Existy", channel, eventChannel), content);
                return;
            }

            var pusher = ( (QueuePusher) qpCollection.GetByChannel(channel) );
            ServerLogger.LogTransport("Channel: " + eventChannel, content);

            pusher.Message(channel, Name, user, eventChannel, content);
        }
Esempio n. 11
0
        public void SendMessage(string channel, string eventChannel, UserLogicModel user , object content)
        {
            if (qpCollection.GetByChannel(channel) == null) {
                Logger.Log("Cannot send message:" + channel + " No Existy",LogLevel.Error);
                Logger.Log("       " + eventChannel + " " + Json.Stringify(content),LogLevel.Error);
                return;
            }

            var pusher = ( (QueuePusher) qpCollection.GetByChannel(channel) );
            // Logger.Log(string.Format("- Channel: {0}  Name: {1}  User: {2}  EventChannel: {3}  Content: {4}", channel, Name, user , eventChannel, content));
            pusher.Message(channel, Name, user, eventChannel, content);
        }
Esempio n. 12
0
        public void Room_CreateRoom(string gameType, string roomName, UserLogicModel user, Action<RoomData> onRoomCreated)
        {
            ExtensionMethods.debugger();

            RoomData rd = new RoomData(gameType, roomName, roomName + "RoomName", roomName + "GameRoom", new List<UserLogicModel>() { user });
            manager.client.Collection("Room",
                                      (err, collection) =>
                                      {
                                          collection.Insert(rd);

                                          onRoomCreated(rd);
                                      });
        }
Esempio n. 13
0
        public static int AskQuestion(UserLogicModel user, string question, string[] answers, GameCardGame cardGame)
        {
            cardGame.Emulating = false;
            if (cardGame.Answers.Count - 1 > cardGame.AnswerIndex) {
                cardGame.Emulating = true;
                return cardGame.Answers[cardGame.AnswerIndex++].Value; //todo .value
            }
            var m = new CardGameQuestion(user, question, answers, cardGame);

            var answer = Fiber<CardGameAnswer>.Yield(new FiberYieldResponse(FiberYieldResponseType.AskQuestion, m));
            cardGame.AnswerIndex++;
            return answer == null ? 0 : answer.Value;
        }
 private void UserDisconnect(UserLogicModel user, UserDisconnectModel data)
 {
     foreach (var gameRoom in rooms)
     {
         foreach (var player in gameRoom.Players)
         {
             if (player.UserName == user.UserName)
             {
                 ServerLogger.LogDebug("22User Left: " + player.UserName, player);
                 gameRoom.PlayerLeave(player);
                 break;
             }
         }
     }
 }
Esempio n. 15
0
        private void OnSendMessage(UserLogicModel user, SendChatMessageModel data)
        {
            var room = getRoomFromUser(user);
            if (room == null)
                throw new Exception("idk");

            myDataManager.ChatData.AddChatLine(user,
                                               room,
                                               data.Message,
                                               a => {
                                                   foreach (var userLogicModel in room.Users) {
                                                       myServerManager.SendChatLines(userLogicModel, new ChatMessagesModel(new List<ChatMessageRoomModel>() {a}));
                                                   }
                                               });
        }
Esempio n. 16
0
        private void OnCreateChatChannel(UserLogicModel user, CreateChatRoomRequest data)
        {
            var cur = getRoomFromUser(user);
            if (cur != null)
                leaveChatRoom(user);
            myDataManager.SiteData.Room_SetChatServer(data.Room,
                                                      myServerManager.ChatServerIndex,
                                                      (r) => {
                                                          myDataManager.ChatData.CreateChatChannel(data.Room.ChatChannel,
                                                                                                   user,
                                                                                                   a => {
                                                                                                       myServerManager.RegisterChatServer(user);

                                                                                                       runningRooms.Add(a);
                                                                                                       myServerManager.SendChatInfo(user, a);
                                                                                                   });
                                                      });
        }
Esempio n. 17
0
        private void OnCreateRoom(UserLogicModel user, CreateRoomRequest data)
        {
            Logger.Log(user.UserName + " create room", LogLevel.DebugInformation);
            removeUserFromRoom(user,
                               disconnectedRoom =>
                               {
                                   myDataManager.SiteData.Room_CreateRoom(data.GameType,
                                                                          data.RoomName,
                                                                          user,
                                                                          (room) =>
                                                                          {
                                                                              mySiteClientManager.CreateChatRoom(user, new CreateChatRoomRequest(room));

                                                                              mySiteClientManager.RoomJoined(user, new RoomJoinResponse(room));
                                                                              myDataManager.SiteData.Room_GetAllByGameType(data.GameType, a => { mySiteClientManager.SendRooms(user, new GetRoomsResponse(a)); });
                                                                          });
                               });
        }
Esempio n. 18
0
        public void RemoveUser(ChatRoomModel room, UserLogicModel user, Action<ChatRoomModel> complete)
        {
            manager.client.Collection("ChatRoom",
                                      (err, collection) => {
                                          JsDictionary<string, object> query = new JsDictionary<string, object>();

                                          query["$pop"] = new {users = user};

                                          collection.Update(new { _id = MongoDocument.GetID(room.ID) },
                                                            query,
                                                            (err2) => {
                                                                if (err2 != null) Logger.Log("Data Error: " + err2, LogLevel.Error);
                                                                room.Users.Remove(user);

                                                                complete(room);
                                                            });
                                      });
        }
        public void AddUser(ChatRoomDataModel roomData, UserLogicModel user, Action<ChatRoomDataModel> complete)
        {
            manager.client.Collection("ChatRoom",
                                      (err, collection) => {
                                          JsDictionary<string, object> query = new JsDictionary<string, object>();

                                          query["$push"] = new {users = user};

                                          collection.Update(new { _id = MongoDocument.GetID(roomData.ID) },
                                                            query,
                                                            (err2) => {
                                                                if (err2 != null) 
                                                                    ServerLogger.LogError("Data Error: " + err2, user);

                                                                roomData.Users.Add(user);

                                                                complete(roomData);
                                                            });
                                      });
        }
Esempio n. 20
0
        public void AddChatLine(UserLogicModel user, ChatRoomModel room, string message, Action<ChatMessageRoomModel> complete)
        {
            manager.client.Collection("ChatRoom",
                                      (err, collection) => {
                                          ChatMessageRoomModel messageModel = new ChatMessageRoomModel(user, message, DateTime.Now);

                                          JsDictionary<string, object> query = new JsDictionary<string, object>();

                                          query["$push"] = new {messages = messageModel};

                                          collection.Update(new { _id = MongoDocument.GetID(room.ID )},
                                                            query,
                                                            (err2) => {
                                                                if (err2 != null)
                                                                    Logger.Log("Data Error: " + err2,LogLevel.Error);
                                                                room.Messages.Add(messageModel);
                                                                complete(messageModel);
                                                            });
                                      });
        }
Esempio n. 21
0
        private void removeUserFromRoom(UserLogicModel user, Action<RoomModel> result)
        {
            ServerLogger.LogDebug(user.UserName + " removing", user);
            myDataManager.SiteData.Room_GetRoomByUser(user,
                                                      room =>
                                                      {
                                                          if (room == null)
                                                          {
                                                              result(null);
                                                              return;
                                                          }
                                                          if (user.CurrentChatServer != null)
                                                              mySiteClientManager.LeaveChatRoom(user);
                                                          if (user.CurrentGameServer != null)
                                                          {
                                                              mySiteClientManager.LeaveGameRoom(user);
                                                              ServerLogger.LogDebug(user.UserName + " left Game room", user);
                                                              user.CurrentGameServer = null;
                                                          }
                                                          foreach (var player in room.Players)
                                                          {
                                                              if (player.UserName == user.UserName) room.Players.Remove(player);
                                                          }
                                                          if (room.Players.Count == 0)
                                                              myDataManager.SiteData.Room_DeleteRoom(room);
                                                          else
                                                          {
                                                              myDataManager.SiteData.Room_RemovePlayer(room, user, (ro) =>
                                                              {
                                                                  foreach (var userLogicModel in room.Players)
                                                                  {
                                                                      mySiteClientManager.SendRoomInfo(userLogicModel, new GetRoomInfoResponse(room.ToModel()));
                                                                  }

                                                              });
                                                          }
                                                          result(room.ToModel());
                                                      });
        }
Esempio n. 22
0
        public void Room_AddPlayer(RoomData room, UserLogicModel user, Action<RoomData> complete)
        {
            manager.client.Collection("Room",
                          (err, collection) =>
                          {

                              JsDictionary<string, object> query = new JsDictionary<string, object>();

                              query["$push"] = new { players = user };

                              collection.Update(new { _id = MongoDocument.GetID(room.ID) },
                                                query,
                                                (err2) =>
                                                {
                                                    if (err2 != null)
                                                        Logger.Log("Data Error: " + err2, LogLevel.Error);
                                                    room.Players.Add(user);

                                                    complete(room);
                                                });
                          });
        }
Esempio n. 23
0
        private void OnJoinRoom(UserLogicModel user, RoomJoinRequest data)
        {
            Logger.Log(user.UserName + " join room", LogLevel.DebugInformation);

            removeUserFromRoom(user,
                               disconnectedRoom =>
                               {
                                   myDataManager.SiteData.Room_JoinRoom(data.GameType,
                                                                        data.RoomName,
                                                                        user,
                                                                        (room) =>
                                                                        {
                                                                            mySiteClientManager.RoomJoined(user, new RoomJoinResponse(room));
                                                                            mySiteClientManager.JoinChatRoom(user, new JoinChatRoomRequest(room));

                                                                            foreach (var UserLogicModel in room.Players)
                                                                            {
                                                                                mySiteClientManager.SendRoomInfo(UserLogicModel, new GetRoomInfoResponse(room));
                                                                            }
                                                                        }
                                           );
                               });
        }
Esempio n. 24
0
        private void messageReceived(string gateway, UserLogicModel user, string eventChannel, object content)
        {
            if (users.ContainsKey(user.UserName))
            {
                var u = users[user.UserName];

                sendMessage(u, eventChannel, content);
            }
        }
Esempio n. 25
0
 private void OnGetRooms(UserLogicModel user, GetRoomsRequest data)
 {
     myDataManager.SiteData.Room_GetAllByGameType(data.GameType, a => { mySiteClientManager.SendRooms(user, new GetRoomsResponse(a)); });
 }
Esempio n. 26
0
 private void OnGetRoomInfo(UserLogicModel user, GetRoomInfoRequest data)
 {
     myDataManager.SiteData.Room_GetByRoomName(data.GameType, data.RoomName, a => { mySiteClientManager.SendRoomInfo(user, new GetRoomInfoResponse(a)); });
 }
Esempio n. 27
0
        private void OnGetGameTypes(UserLogicModel user)
        {
            var types = new List<GameTypeModel>() { new GameTypeModel("Blackjack"), new GameTypeModel("Sevens") };

            mySiteClientManager.SendGameTypes(user, new GetGameTypesReceivedResponse(types));
        }
Esempio n. 28
0
 private void OnUserLogin(UserLogicModel user, SiteLoginRequest data)
 {
     mySiteClientManager.SendLoginResponse(user);
 }
Esempio n. 29
0
 private void OnUserDisconnect(UserLogicModel user, UserDisconnectModel data)
 {
     Logger.Log(user.UserName + " disconnected", LogLevel.DebugInformation);
     removeUserFromRoom(data.User, (room) => { });
 }
Esempio n. 30
0
        private void OnStartGame(UserLogicModel user, StartGameRequest data)
        {
            //   Logger.Log("--game started 1 ", LogLevel.DebugInformation);

            myDataManager.SiteData.Room_GetRoomByUser(user,
                                          room =>
                                          {
                                              if (room == null)
                                              {
                                                  throw new Exception("idk");
                                                  return;
                                              }
                                              //       Logger.Log("--game started 2", LogLevel.DebugInformation);

                                              mySiteClientManager.CreateGame(new GameCreateRequestModel(room.GameType, room.Players));
                                          });
        }