// File: /workspace/github_cpp_makefile_star2_O1/Unreality3D[P]Unreality3D/indie-studio/source/Network/Broker.cpp
// Function: network::Broker::onPacketMessage(int, IndieProtocol::Message)
void	Broker::onPacketMessage(int fd, IndieProtocol::Message msg)
  {
    std::cout << "FD : " << fd << " : MESSAGE" << std::endl;
    std::cout << msg.target << std::endl;
    std::cout << msg.topic << std::endl;
    std::cout << msg.event << std::endl;

    auto from = _clients.find(fd);
    if (from == _clients.end() || !(*from).second.connected)
      {
	std::cout << "FROM client not connected. Not forwarding the message" << std::endl;
	return ;
      }

    IndieProtocol::Serialized serialed = _serializer(msg);

    // broadcast
    if (msg.target == "")
      {
	IndieProtocol::Serialized tmpSerialed;
	for (auto c = _clients.begin(); c != _clients.end(); ++c)
	  {
	    if ((*c).second.connected && (*c).second.fd != fd)
	      {
		std::cout << "Forwarding to " << (*c).second.name << std::endl;
		tmpSerialed = serialed;
		(*c).second.writeBuffer.push_back(tmpSerialed);
	      }
	  }
      }
    else
      {
	auto c = std::find_if(_clients.begin(), _clients.end(),
			      [&msg](std::pair<SOCKET, Client> const &elem)
			      {
				return (elem.second.name == msg.target && elem.second.connected);
			      });
	if (c != _clients.end())
	  {
	    std::cout << "Forwarding to " << (*c).second.name << std::endl;
	    (*c).second.writeBuffer.push_back(serialed);
	  }
      }
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdx, %r14
movl %esi, %ebx
movq %rdi, %r15
movq 0xb6a0(%rip), %r12      # 0x1afb8
leaq 0x5996(%rip), %rsi      # 0x152b5
movl $0x5, %edx
movq %r12, %rdi
callq 0xb870
movq %r12, %rdi
movl %ebx, %esi
callq 0xbc80
movq %rax, %r13
leaq 0x598e(%rip), %rsi      # 0x152ce
movl $0xa, %edx
movq %rax, %rdi
callq 0xb870
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0xb750
movsbl %al, %esi
movq %r13, %rdi
callq 0xb040
movq %rax, %rdi
callq 0xb540
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %r12, %rdi
callq 0xb870
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0xb750
movsbl %al, %esi
movq %r13, %rdi
callq 0xb040
movq %rax, %rdi
callq 0xb540
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
movq %r12, %rdi
callq 0xb870
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0xb750
movsbl %al, %esi
movq %r13, %rdi
callq 0xb040
movq %rax, %rdi
callq 0xb540
movq 0x40(%r14), %rsi
movq 0x48(%r14), %rdx
movq %r12, %rdi
callq 0xb870
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0xb750
movsbl %al, %esi
movq %r13, %rdi
callq 0xb040
movq %rax, %rdi
callq 0xb540
movq 0x190(%r15), %rcx
leaq 0x188(%r15), %r13
movq %r13, %rax
testq %rcx, %rcx
je 0xfa51
movq %r13, %rax
xorl %edx, %edx
cmpl %ebx, 0x20(%rcx)
setl %dl
cmovgeq %rcx, %rax
movq 0x10(%rcx,%rdx,8), %rcx
testq %rcx, %rcx
jne 0xfa3b
movq %r13, %rcx
cmpq %r13, %rax
je 0xfa63
cmpl %ebx, 0x20(%rax)
cmovgq %r13, %rax
movq %rax, %rcx
cmpq %r13, %rcx
je 0xfb84
cmpb $0x0, 0x28(%rcx)
je 0xfb84
movq %rsp, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0xbda0
leaq 0x582f(%rip), %rsi      # 0x152ba
movq %r14, %rdi
callq 0xb170
testl %eax, %eax
je 0xfbd1
movq 0x198(%r15), %rbx
cmpq %r13, %rbx
je 0xfb0e
leaq 0x10(%rsp), %r12
leaq 0x20(%rbx), %rsi
movq %r12, %rdi
callq 0xb260
movq 0x28(%rsp), %rdx
cmpq 0x8(%r14), %rdx
jne 0xfadd
testq %rdx, %rdx
je 0xfae1
movq (%r14), %rsi
movq 0x20(%rsp), %rdi
callq 0xb800
testl %eax, %eax
sete %bpl
jmp 0xfae4
xorl %ebp, %ebp
jmp 0xfae4
movb $0x1, %bpl
movb 0x18(%rsp), %r15b
leaq 0x18(%rsp), %rdi
callq 0xb8c0
testb %bpl, %bpl
je 0xfafe
testb $0x1, %r15b
jne 0xfb0e
movq %rbx, %rdi
callq 0xb570
movq %rax, %rbx
cmpq %r13, %rax
jne 0xfaac
cmpq %r13, %rbx
je 0xfcd0
movq 0xb49a(%rip), %rdi      # 0x1afb8
leaq 0x57ea(%rip), %rsi      # 0x1530f
movl $0xe, %edx
callq 0xb870
movq 0x30(%rbx), %rsi
movq 0x38(%rbx), %rdx
movq 0xb47a(%rip), %rdi      # 0x1afb8
callq 0xb870
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0xb750
movsbl %al, %esi
movq %r14, %rdi
callq 0xb040
movq %rax, %rdi
callq 0xb540
addq $0xe0, %rbx
movq %rsp, %rsi
movq %rbx, %rdi
callq 0xb3c0
jmp 0xfcd0
leaq 0x574e(%rip), %rsi      # 0x152d9
movl $0x35, %edx
movq %r12, %rdi
callq 0xb870
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0xb750
movsbl %al, %esi
movq %r12, %rdi
callq 0xb040
movq %rax, %rdi
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb540
movl $0x0, 0x10(%rsp)
movl $0x1, %edi
callq 0xb030
movq %rax, 0x18(%rsp)
movq 0x198(%r15), %r14
cmpq %r13, %r14
je 0xfcc1
movq 0xb3b9(%rip), %r15      # 0x1afb8
leaq 0x10(%rsp), %r12
cmpb $0x1, 0x28(%r14)
jne 0xfcad
cmpl %ebx, 0x2c(%r14)
je 0xfcad
movl $0xe, %edx
movq %r15, %rdi
leaq 0x56e7(%rip), %rsi      # 0x1530f
callq 0xb870
movq 0x30(%r14), %rsi
movq 0x38(%r14), %rdx
movq %r15, %rdi
callq 0xb870
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0xb750
movsbl %al, %esi
movq %rbp, %rdi
callq 0xb040
movq %rax, %rdi
callq 0xb540
movl (%rsp), %eax
movl %eax, 0x10(%rsp)
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xfc7d
callq 0xb990
movl 0x10(%rsp), %ebp
movq %rbp, %rdi
callq 0xb030
movq %rax, 0x18(%rsp)
movq 0x8(%rsp), %rsi
movq %rax, %rdi
movq %rbp, %rdx
callq 0xb670
leaq 0xe0(%r14), %rdi
movq %r12, %rsi
callq 0xb3c0
movq %r14, %rdi
callq 0xb570
movq %rax, %r14
cmpq %r13, %rax
jne 0xfc04
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xfcd0
callq 0xb990
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xfcdf
callq 0xb990
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xfcf5
jmp 0xfcf5
movq %rax, %rbx
jmp 0xfd0c
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xfd0c
callq 0xb990
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xfd1b
callq 0xb990
movq %rbx, %rdi
callq 0xbce0
nop