// File: Gydo194[P]server/controller/controller.cpp
// Function: Controller::handleServerInput(unsigned short, char*)
void Controller::handleServerInput(uint16_t fd, char *buffer)
{
	cout << "Controller: got input '" << buffer << "'from " << fd << endl;
	prs.parse(buffer);
	for(string i : prs.values)
	{
		cout << "Controller::handleServerInput -> for: input: '" << i << "'.\n";
	}


	//get the first argument name
	string key;
	try
	{
		key = prs.values.at(0);
	}
	catch(out_of_range oor)
	{
		cerr << "no action" << endl;
	}

	//look it up in the handlers map
	Controller::handler h = NULL;
	if(map_get<string,Controller::handler>(&handlers, key, &h))
	{
		printf("Controller: handler address = '%x'\n",h);
		//call the callback function
		h(&prs.values);
	}
	else
	{
		cerr << "[ERROR] Controller: No such action (" << key << ")\n";
	}

	prs.values.clear();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movw %di, %ax
movw %ax, -0x2(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x6dd3(%rip), %rdi      # 0x9fd0
leaq 0x2f67(%rip), %rsi      # 0x616b
callq 0x2240
movq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0x2240
movq %rax, %rdi
leaq 0x2f64(%rip), %rsi      # 0x6183
callq 0x2240
movq %rax, %rdi
movzwl -0x2(%rbp), %esi
callq 0x23a0
movq %rax, %rdi
movq 0x6d7e(%rip), %rsi      # 0x9fb8
callq 0x2280
movq -0x10(%rbp), %rsi
leaq 0x6ff6(%rip), %rdi      # 0xa240
callq 0x5000
leaq 0x6fea(%rip), %rax      # 0xa240
movq %rax, -0x18(%rbp)
leaq 0x6fdf(%rip), %rdi      # 0xa240
callq 0x3030
movq %rax, -0x20(%rbp)
leaq 0x6fcf(%rip), %rdi      # 0xa240
callq 0x3060
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x3090
testb $0x1, %al
jne 0x3290
jmp 0x3320
leaq -0x20(%rbp), %rdi
callq 0x30d0
movq %rax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x2120
movq 0x6d24(%rip), %rdi      # 0x9fd0
leaq 0x2ed7(%rip), %rsi      # 0x618a
callq 0x2240
movq %rax, -0xb8(%rbp)
jmp 0x32c1
movq -0xb8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x2220
movq %rax, -0xc0(%rbp)
jmp 0x32da
movq -0xc0(%rbp), %rdi
leaq 0x2ed1(%rip), %rsi      # 0x61b9
callq 0x2240
jmp 0x32ef
leaq -0x48(%rbp), %rdi
callq 0x2190
leaq -0x20(%rbp), %rdi
callq 0x30f0
jmp 0x327a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x2190
jmp 0x352d
leaq -0x78(%rbp), %rdi
callq 0x2320
leaq 0x6f10(%rip), %rdi      # 0xa240
xorl %eax, %eax
movl %eax, %esi
callq 0x3690
movq %rax, -0xc8(%rbp)
jmp 0x3342
movq -0xc8(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x2040
jmp 0x3354
jmp 0x33e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x3524
movq -0x50(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x22f0
movq %rax, %rsi
leaq -0x88(%rbp), %rdi
callq 0x36d0
movq -0xd8(%rbp), %rdi
callq 0x2100
movq 0x6c49(%rip), %rdi      # 0x9ff0
leaq 0x2e0f(%rip), %rsi      # 0x61bd
callq 0x2240
movq %rax, -0xd0(%rbp)
jmp 0x33bc
movq -0xd0(%rbp), %rdi
movq 0x6bee(%rip), %rsi      # 0x9fb8
callq 0x2280
jmp 0x33d1
leaq -0x88(%rbp), %rdi
callq 0x2330
callq 0x2380
jmp 0x33e4
jmp 0x33e6
movq $0x0, -0x90(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x2120
jmp 0x3403
leaq 0x6e4e(%rip), %rdi      # 0xa258
leaq -0xb0(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x3710
movb %al, -0xd9(%rbp)
jmp 0x3425
leaq -0xb0(%rbp), %rdi
callq 0x2190
movb -0xd9(%rbp), %al
testb $0x1, %al
jne 0x343d
jmp 0x34ba
movq -0x90(%rbp), %rsi
leaq 0x2d7c(%rip), %rdi      # 0x61c7
xorl %eax, %eax
callq 0x2050
jmp 0x3454
movq -0x90(%rbp), %rax
leaq 0x6dde(%rip), %rdi      # 0xa240
callq *%rax
jmp 0x3466
jmp 0x3506
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x2330
callq 0x2380
jmp 0x349b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x3524
jmp 0x3524
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x2190
jmp 0x3524
movq 0x6b2f(%rip), %rdi      # 0x9ff0
leaq 0x2d23(%rip), %rsi      # 0x61eb
callq 0x2240
movq %rax, -0xe8(%rbp)
jmp 0x34d6
movq -0xe8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x2220
movq %rax, -0xf0(%rbp)
jmp 0x34ef
movq -0xf0(%rbp), %rdi
leaq 0x2d13(%rip), %rsi      # 0x6210
callq 0x2240
jmp 0x3504
jmp 0x3506
leaq 0x6d33(%rip), %rdi      # 0xa240
callq 0x37b0
leaq -0x78(%rbp), %rdi
callq 0x2190
addq $0xf0, %rsp
popq %rbp
retq
leaq -0x78(%rbp), %rdi
callq 0x2190
movq -0x50(%rbp), %rdi
callq 0x23c0
movq %rax, %rdi
callq 0x2ef0
nop