Exemplo n.º 1
0
        private void SendCustomNotification(CustomMessageType messageType, string objectId, string eventId,
                                            params string[] data)
        {
            using (Trace.Main.scope())
            {
                try
                {
                    Trace.Main.note("SendCustomNotification request\nCustomMessageType: {}\nOID: {}\nEID: {}\nData:\n{}", messageType, objectId, eventId,
                                    data == null ? "*NO DATA*" : data.Aggregate((a, b) => a + "\n" + b));

                    switch (messageType)
                    {
                    case CustomMessageType.ServerNotification:
                    {
                        var requestServerNotification =
                            new CustomRequest(new CustomMessageHeader(messageType, objectId, eventId));
                        if (data != null && data.Length > 0)
                        {
                            requestServerNotification.Write(data);
                        }
                        _customNotification.SendServerRequestNoResponse(requestServerNotification);
                        break;
                    }

                    case CustomMessageType.ApplicationRequest:
                    {
                        var requestApplicationRequest =
                            new CustomRequest(new CustomMessageHeader(messageType, objectId, eventId));
                        if (data != null && data.Length > 0)
                        {
                            requestApplicationRequest.Write(data);
                        }
                        _customNotification.SendApplicationRequest(requestApplicationRequest);
                        break;
                    }

                    case CustomMessageType.ApplicationResponse:
                    {
                        var responseApplicationResponse =
                            new CustomResponse(
                                new CustomMessage(new CustomMessageHeader(messageType, objectId, eventId)));
                        if (data != null && data.Length > 0)
                        {
                            responseApplicationResponse.Write(data);
                        }
                        _customNotification.SendApplicationResponse(responseApplicationResponse);
                        break;
                    }

                    default:
                        throw new Exception("Unsupported message type: " + messageType);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Trace.Main.exception(ex);
                }
            }
        }
Exemplo n.º 2
0
        public async Task EnqueueAsync_CanInvokeWithCustomMessageType()
        {
            // Arrange
            var content = new CustomMessageType
            {
                Message = Guid.NewGuid().ToString()
            };

            // Act
            await _sut.EnqueueAsync(content, CancellationToken.None);
        }
Exemplo n.º 3
0
        public async Task EnqueueBatchAsync_CanInvokeWithCustomMessageTypeCollection()
        {
            // Arrange
            var batch = new CustomMessageType[]
            {
                new CustomMessageType {
                    Message = Guid.NewGuid().ToString()
                },
                new CustomMessageType {
                    Message = Guid.NewGuid().ToString()
                }
            };

            // Act
            await _sut.EnqueueBatchAsync(batch, CancellationToken.None);
        }
	void OnCustomMessage( BitReader reader )
	{
		CustomMessageType message = (CustomMessageType)reader.Byte();

		if( message != CustomMessageType.RoomNameResponse )
		{
			_settings.display.text += $"Unexpected custom message type: {message}\n";
			return;
		}

		int length = reader.ArrayPacked<char>( _charBuffer );
		_sb.Clear();
		_sb.Append( _charBuffer, 0, length );
		_world.SetClientRoom( _sb.ToString() );
		_settings.display.text += "Got room scene from server: '" + _world.GetClientRoom() + "'\n";

		_exitTime = Time.time + _world.GetMinimumDisplayTime();
	}
        public async Task EnqueueAsync_CanInvokeWithCustomMessageTypeAndSessionId()
        {
            // Arrange
            var content = new CustomMessageType
            {
                Message = Guid.NewGuid().ToString()
            };

            var sessionId = Guid.NewGuid().ToString();

            // Act
            await _sut.EnqueueAsync(content, sessionId, CancellationToken.None);

            // Clean up
            var message = await _sut.DequeueAsync(CancellationToken.None);

            await _sut.CompleteAsync(message, CancellationToken.None);
        }
Exemplo n.º 6
0
    // PRIVATE

    void OnCustomMessage(NodeIndex clientIndex, BitReader reader)
    {
        CustomMessageType message = (CustomMessageType)reader.Byte();

        switch (message)
        {
        case CustomMessageType.RoomNameRequest:
            SendRoomNameResponse(clientIndex);
            break;

        case CustomMessageType.SpawnAvatarRequest:
            SpawnAvatar(clientIndex);
            break;

        default:
            Log.Error("FATAL ERROR: unexpected network message type: " + message);
            return;
        }
    }
        public async Task EnqueueAsync_InvokeWithCustomMessageTypeSetsSessionId()
        {
            // Arrange
            var content = new CustomMessageType
            {
                Message = Guid.NewGuid().ToString()
            };

            var sessionId = "session-id";

            // Act
            await _sut.EnqueueAsync(content, sessionId, CancellationToken.None);

            var message = await _sut.DequeueAsync(CancellationToken.None);

            // Assert
            Assert.Equal(sessionId, message.SessionId);

            // Clean up
            await _sut.CompleteAsync(message, CancellationToken.None);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Send Message to defined Internal Channel.
 /// </summary>
 public void SendToChannel(InternalChannels channel, CustomMessageType color, string message)
 {
     SendToChannel(channel, color, "KTibiaX®", 0x0, message);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Send Message to defined Internal Channel.
        /// </summary>
        public void SendToChannel(InternalChannels channel, CustomMessageType color, string charname, uint level, string message)
        {
            #region "[rgn] Packet Structure Analyze "
            //--------------------------------------------------------------------------------------------------------------
            //SZ    ID ?? ?? ?? ?? SZ    [                   NAME                ] LV    CR CH    SZ    [        MSG       ]
            //--------------------------------------------------------------------------------------------------------------
            //23 00 AA 00 00 00 00 0E 00 4F 6D 65 67 61 20 4C 61 6D 62 61 20 4C 61 04 00 0C 0A 00 07 00 68 65 6C 6C 6F 00 00
            //.  .  .  .  S  .  .  .  .  N  i  g  h  t  .  C  r  e  a  t  u  r  e  .  .  .  .  .  .  .  H  e  l  l  o  .  .
            //--------------------------------------------------------------------------------------------------------------
            //00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
            //--------------------------------------------------------------------------------------------------------------
            #endregion

            PacketBuilder Builder = new PacketBuilder(0xAA, Connection);
            Builder.Append(0x00);
            Builder.Append(0x00);
            Builder.Append(0x00);
            Builder.Append(0x00);
            Builder.Append(charname, true);
            Builder.Append(level, 2);
            Builder.Append(color.GetHashCode());
            Builder.Append(GetChannelInfo(channel).Key, 2);
            Builder.Append(message, true, true);

            Builder.SetPacketSource(PacketSource.Server);
            Connection.Send(Builder.GetPacket());
        }