private void RemovePeerFromCurrentRoomInternal(int reason, string detail)
        {
            // check if the peer already joined another game
            var r = this.RoomReference;

            if (r == null)
            {
                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("RemovePeerFromCurrentRoom: Room Reference is null for p:{0}", this);
                }
                return;
            }

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("RemovePeerFromCurrentRoom: Removing peer from room. p:{0}", this);
            }
            // remove peer from his current game.
            var message = new RoomMessage((byte)GameMessageCodes.RemovePeerFromGame, new object[] { this, reason, detail });

            r.Room.EnqueueMessage(message);

            this.ReleaseRoomReferenceInternal();
        }
示例#2
0
        public async Task <RoomMessage> CreatedMessageAsync(int userId, int roomId, string content)
        {
            var roomUser = await dbContext.RoomUsers.FirstOrDefaultAsync(ru => ru.UserId == userId && ru.RoomId == roomId);

            if (roomUser == null)
            {
                return(null);
            }
            var mess = new RoomMessage {
                Content    = content,
                RoomUserId = roomUser.Id,
            };

            dbContext.Add(mess);
            // ? seem terrible
            await dbContext.SaveChangesAsync();

            mess = await dbContext.RoomMessages
                   .Where(m => m.Id == mess.Id)
                   .Include(rm => rm.RoomUser)
                   .ThenInclude(ru => ru.User)
                   .FirstAsync();

            return(mess);
        }
示例#3
0
    /* 获取到房间信息列表
     * param[list]:包含版本号和类别号
     */
    private void GetRoomMsgList(byte[] list)
    {
        int i = 2;

        for (i = 2; i < list.Length - 4; i += 4)
        {
            uint temp_num = BitConverter.ToUInt32(list, i);
            if (temp_num == 0)
            {
                break;
            }
            RoomMessage temp_room     = new RoomMessage(temp_num);
            ushort      temp_room_num = temp_room.GetRoomNumber();
            GameObject  temp_go       = null;
            if (RoomContainer2.ContainsKey(temp_room_num))
            {
                temp_go = RoomContainer2[temp_room_num];
                UIFunction.SetRoomMessage(temp_go, temp_room);
            }
            else
            {
                //创建新的物体
                temp_go = (GameObject)Instantiate(Resources.Load("Prefabs/RoomBar"));
                temp_go.transform.parent = RoomListPanel.transform;
                UIFunction.SetPosition(temp_go, new Vector2(0, 0));
                temp_go.transform.localScale = new Vector3(1, 1, 1);
                UIFunction.SetRoomMessage(temp_go, temp_room, RoomClick);
                RoomContainer2.Add(temp_room_num, temp_go);
                RoomContainer1.Add(temp_go, temp_room_num);
            }
        }
    }
        /// <summary>
        /// 房间留言
        /// </summary>
        /// <param name="roomId"></param>
        /// <returns></returns>
        public ActionResult _SelMessage(long roomId)
        {
            var hotelId = UserContext.CurrentUser.HotelId;

            ViewBag.HotelId = hotelId;
            ViewBag.RoomId  = roomId;
            var room = RoomBll.GetById(roomId);

            if (room != null)
            {
                var msg = RoomBll.GetMessage(roomId);
                if (msg == null)
                {
                    msg = new RoomMessage();
                }
                ViewBag.Message   = msg;
                ViewBag.RoomRegId = room.RoomRegId;
                ViewBag.Room      = room;
                ViewBag.RoomReg   = RoomRegBll.GetById(room.RoomRegId);
            }
            else
            {
                ViewBag.Message   = new RoomMessage();
                ViewBag.Room      = new Hotel.Model.Room();
                ViewBag.RoomRegId = 0;
                ViewBag.RoomReg   = new Hotel.Model.RoomReg();
            }

            return(View());
        }
示例#5
0
        private void OnRoomMessage(object sender, RoomMessage e)
        {
            e.Username = Users.FindByClient((sender as ClientOperator)?.TcpClient);
            var users = Rooms.FirstOrDefault(kv => kv.Key == e.RoomId).Value;

            UniCast(e, users);
        }
示例#6
0
        public async Task <IActionResult> AssignTenantToRoom(Guid tenantId, [FromQuery] Guid roomId)
        {
            try
            {
                _logger.LogInformation("Assigning tenant to room");

                var tenant = await _repo2.GetByIdAsync(tenantId);

                tenant.RoomId = roomId;
                _repo2.Put(tenant);
                await _repo2.SaveAsync();

                var roomMessage = new RoomMessage()
                {
                    Gender        = tenant.Gender,
                    RoomId        = roomId,
                    OperationType = 0
                };

                _logger.LogInformation("Alerting room service to assign tenant to room");
                await _serviceBusSender.SendRoomIdMessage(roomMessage);

                _logger.LogInformation("Success! Room service has been alerted");

                return(NoContent());
            }
            catch (ArgumentNullException ex)
            {
                _logger.LogInformation("Tenant cannot be found", ex);
                return(NotFound());
            }
        }
示例#7
0
        public static RoomMessage Handler(Session session, params PacketReader[] packets)
        {
            RoomMessage msg = RoomMessage.Unknown;

            foreach (PacketReader packet in packets)
            {
                //			Parse(player, packet);
                ushort id = packet.ReadByte();
                if (msg == RoomMessage.Unknown)
                {
                    if (RoomMessage.IsDefined(typeof(RoomMessage), (byte)id))
                    {
                        msg = (RoomMessage)id;
                    }
                    else
                    {
                        Logger.Warn("unknown id:" + id);
                    }
                }
                if ((session.IsLogin || session.IsClient) || (msg == RoomMessage.Info && session.Name == null) || msg == RoomMessage.PlayerInfo || msg == RoomMessage.NETWORK_CLIENT_ID)
                {
                    EventHandler.Do(id, session, packet);
                }
                else
                {
                    Logger.Warn("don't deal id:" + msg);
                }
                packet.Close();
                //}
            }
            return(msg);
        }
示例#8
0
        private void ClientOnNotification(object sender, NotificationResponse e)
        {
            var data = new NotificationData
            {
                Title       = e.Title,
                Content     = e.Text,
                Attribution = Host
            };

            if (e.Payload is JObject jobj)
            {
                var payload = jobj.ToObject <NotificationPayload>();
                if (payload != null)
                {
                    if (RoomMessage?.Invoke(payload.Rid) != true)
                    {
                        Rooms.FirstOrDefault(it => it.RoomsResult.Id == payload.Rid)
                        ?.Let(it => it.SubscriptionResult.Alert = true);
                    }

                    data.Image = $"https://{Host}/avatar/{payload.Sender.Username}";
                }
            }

            _notification?.Show(data);
        }
示例#9
0
        /// <summary>
        /// Receives messages from the server after it has routed them by the room Id
        /// </summary>
        /// <param name="msg"></param>
        public void HandleMessage(RoomMessage msg)
        {
            switch (msg.RoomMessageId)
            {
            case RoomMessageIds.RoomConfirmation:
                var confirmation = msg.Contents.ToString().Deserialize <RoomConfirmation>();
                if (confirmation.ClientMac == ClientAId)
                {
                    ClientAConfirmed = true;
                }
                else if (confirmation.ClientMac == ClientBId)
                {
                    ClientBConfirmed = true;
                }

                if (ClientAConfirmed && ClientBConfirmed)
                {
                    // start game
                    Game.Start();
                }

                break;

            case RoomMessageIds.GameInputUpdate:
                var update = msg.Contents.ToString().Deserialize <GameInputUpdate>();
                Game.QueueInput(update);
                break;
            }
        }
示例#10
0
        private static void ProcessRoomMessage(dynamic message, string room)
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    var from    = message.User.Name.Value;
                    var content = message.Content.Value;

                    if (from.Equals(BotName, StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }

                    var roomMessage = new RoomMessage(room, from, WebUtility.HtmlDecode(content));

                    foreach (var sprocket in Container.Sprockets)
                    {
                        if (sprocket.CanHandle(roomMessage))
                        {
                            Logger.Info(string.Format("Message received from: '{0}' > '{1}'", from, content));
                            IncrementSprocketUsage(sprocket.Name);
                            sprocket.Handle(roomMessage, JabbRClient);
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    var exception = ex.GetBaseException();
                    Logger.ErrorException("An error occured while processing a room message.", exception);
                }
            });
        }
示例#11
0
 public IActionResult AddRoom(RoomMessage message)
 {
     if (IsLoginValid(message))
     {
         return(Ok(roomRepository.AddRoom(message.Room)));
     }
     return(BadRequest());
 }
示例#12
0
        public void AddRoomMessage(string roomID, string author, string message)
        {
            RoomMessage roomMessage = CreateChatboxMessage(author, message);
            Room        room        = (Room)GetRoom(roomID);

            room.AddMessage(roomMessage);
            MessageAdded?.Invoke(room, roomMessage);
            Console.WriteLine("Message added in RoomID : " + room.ID + " \n   Author : " + roomMessage.Author + " \n   Message : " + roomMessage.Message);
        }
示例#13
0
        private void ShowChatMessage(RoomMessage msg)
        {
            if (msg.MsgResult == MessageResult.Succeed)
            {
                //The message comes from me, just dispay it as the face (image) has the correct path
                string contentWithHeader = string.Empty;
                if (msg.SenderId != Me.Id)
                {
                    //Need to read the face(image) bytes to file
                    string root = System.IO.Path.Combine(Environment.CurrentDirectory, "Images\\ReceiveMessageImage\\" + msg.SenderId);
                    if (!Directory.Exists(root))
                    {
                        Directory.CreateDirectory(root);
                    }
                    foreach (MotionImagesMessage mImageMsg in msg.MotionMessages)
                    {
                        if (mImageMsg.IsCustomizedImage) //customized motion, need to store first
                        {
                            string filePath = Path.Combine(root, mImageMsg.Path);
                            if (!File.Exists(filePath))
                            {
                                File.WriteAllBytes(filePath, mImageMsg.Bytes);
                            }
                            //msg.Content = UpdateMessageImagePath(msg.Content, mImageMsg.Offset, filePath);
                        }
                    }
                }

                JavaScriptSerializer js = new JavaScriptSerializer();
                if (msg.MessageType == RoomMessageType.PublicChatMessage)
                    CallJavaScript("ShowPublicChatMessage", js.Serialize(msg.Content), true);
                else if (msg.MessageType == RoomMessageType.PrivateChatMessage)
                    CallJavaScript("ShowPrivateChatMessage", js.Serialize(msg.Content), true);
            }
            else
            {
                msg.Content = string.Empty;
                switch (msg.MsgResult)
                {
                    case MessageResult.UnkownError:
                        msg.Content = Resource.Messages.GeneralError;
                        break;
                    case MessageResult.NotEnoughMoney:
                        msg.Content = Resource.Messages.NotEnoughMoney;
                        break;
                    case MessageResult.NotEnoughPrivilege:
                        msg.Content = Resource.Messages.NoPrivilege;
                        break;
                    default:
                        break;
                }
                JavaScriptSerializer js = new JavaScriptSerializer();
                CallJavaScript("AlertMessage", js.Serialize(msg.Content));
            }

        }
示例#14
0
 private RoomMessage InitAnnouncementMsg(RoomMessageType type, string message)
 {
     RoomMessage msg = new RoomMessage();
     msg.MessageType = type;
     msg.Content = message;
     msg.SenderId = Me.Id;
     msg.IsHorn = true;
     msg.Time = DateTime.Now.ToString();
     return msg;
 }
示例#15
0
        public void RoomMessage(string message)
        {
            RoomMessage roomMessage = new RoomMessage(0)
            {
                Name    = player.WeixinName,
                Message = message
            };

            ClientWebsocketsManager.Send(roomMessage);
        }
示例#16
0
 private void HandleRoomMessage(RoomMessage roomMessage)
 {
     foreach (var clientHandler in clients)
     {
         if (IsRoomParticipantClient(roomMessage.RoomId, clientHandler.id))
         {
             SendMessageToClient(roomMessage, clientHandler);
         }
     }
 }
示例#17
0
        public void SendRoomMessage(string sendMessage, Guid roomId)
        {
            var command = new RoomMessage()
            {
                RoomId  = roomId,
                Message = sendMessage
            };

            Write(command);
        }
示例#18
0
        /// <summary>
        /// ServiceBus message for sending a tenant room id
        /// </summary>
        /// <param name="roomMessage">The details room service needs to update their rooms</param>
        public async Task SendRoomIdMessage(RoomMessage roomMessage)
        {
            var data    = JsonSerializer.Serialize(roomMessage);
            var message = new Message(Encoding.UTF8.GetBytes(data));

            _logger.LogInformation("Service Bus is sending message with room id, gender, and operation type", data);
            await _queueClient.SendAsync(message);

            _logger.LogInformation("Message sent!");
        }
示例#19
0
        /// <summary>
        /// Invoked when a local user is posting a message to the hosting chat room
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _HostingRoom_IsSendingMessage(object sender, RoomMessageEventArgs e)
        {
            /// <summary>
            /// The message filtering action taken by the application after filter/format logic is run
            /// </summary>
            RoomMessageFilteringAction messageAction;


            //Get the pending message
            RoomMessage messageToFilter = e.Message;

            //Extract the plain-text version of the message.
            string pendingPostText = e.Message.MessageDictionary[RoomMessageFormat.PlainText].ToString();

            //Update UI with the text of the pending message.
            this.Dispatcher.BeginInvoke(new ShowPendingMessageDelegate(ShowPendingMessage), new object[] { pendingPostText });

            //Check message string to see if the message contains the sub-string entered on the add-in UI
            if (FilterMessagePost(pendingPostText, FilterTextString.Text))
            {
                //The message string contains the sub-string so the message action is canceled.
                //Update the UI with the message filtering action and do not update the UpdatedMessage text block.
                this.Dispatcher.BeginInvoke(new ShowFilterMessageActionDelegate(ShowFilterMessageAction), new object[] { RoomMessageFilteringAction.Canceled });
                messageAction = RoomMessageFilteringAction.Canceled;
            }
            else
            {
                //The message string DOES NOT contain the filter sub-string.

                //If the pending message starts with "do not reformat" in any letter case then
                //update the UI with the message filter action, update the UI updated message box with the original message text,
                //and set the message filtering action to Passed
                if (pendingPostText.ToUpper().StartsWith("DO NOT REFORMAT:"))
                {
                    this.Dispatcher.BeginInvoke(new ShowUpdatedMessageDelegate(ShowUpdatedMessage), new object[] { pendingPostText });
                    this.Dispatcher.BeginInvoke(new ShowFilterMessageActionDelegate(ShowFilterMessageAction), new object[] { RoomMessageFilteringAction.Passed });
                    messageAction = RoomMessageFilteringAction.Passed;
                }
                else
                {
                    //Reformat the original message text by setting all characters to upper case.
                    //Update the UI with the message filter action, update the UI updated message box with the reformatted message text
                    //and set the message filtering action to Replaced
                    this.Dispatcher.BeginInvoke(new ShowUpdatedMessageDelegate(ShowUpdatedMessage), new object[] { FormatMessagePost(pendingPostText) });
                    this.Dispatcher.BeginInvoke(new ShowFilterMessageActionDelegate(ShowFilterMessageAction), new object[] { RoomMessageFilteringAction.Replaced });
                    messageAction = RoomMessageFilteringAction.Replaced;
                }
            }

            //Update the pending message with the updated message text UI text block
            messageToFilter.MessageDictionary[RoomMessageFormat.PlainText] = UpdatedPost.Text;

            //Send the filtered message with whatever message filtering action was set in the previous code.
            _HostingRoom.SendFilteredMessage(messageToFilter, messageAction);
        }
示例#20
0
 public static RoomMessageResponse FromRoomMessage(RoomMessage roomMessage, bool self = false)
 {
     return(new RoomMessageResponse()
     {
         Timestamp = roomMessage.Timestamp,
         Username = roomMessage.Username,
         Message = roomMessage.Message,
         RoomName = roomMessage.RoomName,
         Self = self ? self : (bool?)null,
     });
 }
示例#21
0
    //房间信息更改事件
    private void ChangeRoomMsgMessage(byte[] msg, int startIndex = 2)
    {
        uint        roomMsg = BitConverter.ToUInt32(msg, startIndex);
        RoomMessage rm      = new RoomMessage(roomMsg);
        ushort      roomNum = rm.GetRoomNumber();

        if (roomNum != LocalMessage.LocalRoomNumber)
        {
            return;
        }
        Difficult.captionText.text  = rm.GetDifficulty().ToString();
        CheckPoint.captionText.text = rm.GetCheckpoint().ToString();
    }
示例#22
0
        private void _client_RoomMessageReceived(object sender, RoomMessage e)
        {
            var message = new MessageViewModel()
            {
                Username   = e.Username,
                DateTime   = e.DateTime,
                Message    = e.Message,
                TargetInfo = e.RoomId.ToString()
            };

            _messagesRevieved.Add(message);
            MessageWpfShow?.Invoke(message, "Recieved");
        }
示例#23
0
        protected virtual void RemovePeerFromCurrentRoom()
        {
            // check if the peer already joined another game
            if (RoomReference != null)
            {
                // remove peer from his current game.
                var message = new RoomMessage((byte)GameMessageCodes.RemovePeerFromGame, this);
                RoomReference.Room.EnqueueMessage(message);

                // release room reference
                RoomReference.Dispose();
                RoomReference = null;
            }
        }
示例#24
0
        public void RoomMessageShouldCreate()
        {
            var result = new RoomMessage()
            {
                Gender        = _gender,
                RoomId        = _roomId,
                OperationType = 0
            };

            Assert.NotNull(result);
            Assert.True(result.Gender == _gender);
            Assert.True(result.RoomId == _roomId);
            Assert.True(result.OperationType == 0);
        }
示例#25
0
        /// <summary>
        ///   Updates the lobby if necessary.
        /// </summary>
        private void UpdateLobby()
        {
            if (this.lobbyReference == null)
            {
                return;
            }

            // if a game is listed, find the lobby game and send it a message to
            // de-list or update the list info
            RoomMessage message = this.Actors.Count == 0
                                      ? new RoomMessage((byte)LobbyMessageCode.RemoveGame, new[] { this.Name, "0" })
                                      : new RoomMessage((byte)LobbyMessageCode.AddGame, new[] { this.Name, this.Actors.Count.ToString() });

            this.lobbyReference.Room.EnqueueMessage(message);
        }
        public ActionResult _SelTyly(long roomId)
        {
            ViewBag.RoomId = roomId;
            var room = RoomBll.GetById(roomId);
            var msg  = RoomBll.GetSpecialMessage(roomId);

            if (msg == null)
            {
                msg = new RoomMessage();
            }
            ViewBag.Message = msg;

            ViewBag.LockBz = room.LockBz;
            return(View());
        }
示例#27
0
 public bool OnCheck()
 {
     byte[] data;
     if (Client.GetPacketData(2, out data))
     {
         PacketReader packet = new PacketReader(data);
         RoomMessage  msg    = ClinetEvent.Handler(this, packet);
         if (msg == RoomMessage.Info || msg == RoomMessage.PlayerInfo || msg == RoomMessage.NETWORK_CLIENT_ID)
         {
             return(true);
         }
     }
     Close();
     return(false);
 }
示例#28
0
 private void lstList_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (lstList.SelectedIndices.Count == 1)
     {
         RoomMessage message = _messages[lstList.SelectedIndices[0]];
         txtMessage.Text            = message.Text;
         chkAutoRemove.Checked      = message.AutoRemoveAfterTime;
         chkShowNextMessage.Checked = message.DisplayNextMessageAfter;
         cmbDisplayAs.SelectedIndex = (message.ShowAsSpeech) ? message.CharacterID + 1 : 0;
         grpMessageDetails.Enabled  = true;
     }
     else
     {
         grpMessageDetails.Enabled = false;
     }
 }
示例#29
0
        public HttpResponseMessage Message(RoomMessage message)
        {
            try
            {
                var hub = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();
                hub.Clients.Group(message.Item.Room.Id).roomMessage(message.Item.Room.Id,
                                                                    message.Item.Message.From.name ?? "Self",
                                                                    message.Item.Message.MessageText,
                                                                    message.Item.Message.File != null ? message.Item.Message.File.Url : null);

                return(Request.CreateResponse(HttpStatusCode.Accepted, true));
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message));
            }
        }
示例#30
0
        /// <summary>
        ///   Called when client disconnects.
        ///   Ensures that disconnected players leave the game <see cref = "Room" />.
        ///   The player is not removed immediately but a message is sent to the room. This avoids
        ///   threading issues by making sure the player remove is not done concurrently with operations.
        /// </summary>
        protected override void OnDisconnect(DisconnectReason reasonCode, string reasonDetail)
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("OnDisconnect: conId={0}, reason={1}, reasonDetail={2}", this.ConnectionId, reasonCode, reasonDetail);
            }

            if (this.RoomReference == null)
            {
                return;
            }

            var message = new RoomMessage((byte)GameMessageCodes.RemovePeerFromGame, this);

            this.RoomReference.Room.EnqueueMessage(message);
            this.RoomReference.Dispose();
            this.RoomReference = null;
        }