// File: /workspace/github_cpp_makefile_star2_O1/fieryzig[P]GameServer/GateServer/GateServer.cpp
// Function: fieryzig::GateServer::SetConfig(char const*)
RS GateServer::SetConfig(const char* configFile)
{

    string json = GetStringFromFile(configFile);
    if (json == "") {
        cout << configFile << " doesn't exist!" << endl;
        return RS::FAILED;
    }
    using rapidjson::Document;

    Document d;
    d.Parse(json.c_str());

    string type; ServerType st;
    int port = -1;
    string ip; 

    using rapidjson::Value;

    Value& v = d["ServerType"];
    if (v.IsString()) {
        type = v.GetString();                
        if ( type == "CLIENT" ) {
            st = ServerType::CLIENT;
        }
        else if ( type == "GATEWAY" ) {
            st = ServerType::GATEWAY;
        }
        else if ( type == "LOGIC" ) {
            st = ServerType::LOGIC;
        }
        else {
            cout << "Wrong Server Type!" << endl;
            return RS::FAILED;
        }
    }
    v = d["IP"];
    if (v.IsString()) {
        ip = v.GetString();
        /*
        if ( [ip](){ 
                //TODO: Check ip fomat
                return true;
            } == false) {
            cout << "Wrong IP Format!" << endl;
        }
        */
    }
    else {
        cout << "Wrong IP Format!" << endl;
    }

    v = d["PORT"];
    if (v.IsInt()) {
        port = v.GetInt();
    }
//            }
    else {
        cout << "Wrong port !" << endl;
    }

    v = d["LOGIC"];
    if (v.IsArray()) {
        for (int i = 0; i < v.Size(); i++) {
            Value& content = v[i];
            if (content.HasMember("IP") && content["IP"].IsString()) {
                //TODO: Check ip format
                string ip = content["IP"].GetString();
                int port = content["PORT"].GetInt();
                logic_ip.push_back(make_pair(ip,port));
            }
        }
    }
    else {
        cout << "Wrong LOGIC server format" << endl;

    }

    config = new ServerConfig(st, ip, port);        
    return RS::SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rsi, %rbx
movq %rdi, -0x40(%rbp)
leaq -0x110(%rbp), %r14
movq %r14, %rdi
callq 0x290c
leaq 0x6c47(%rip), %rsi      # 0x9b54
movq %r14, %rdi
callq 0x20b0
testl %eax, %eax
je 0x3066
leaq -0x170(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x3828
movq -0x110(%rbp), %rax
leaq -0x90(%rbp), %rsi
movq %rax, (%rsi)
movq %rax, 0x8(%rsi)
leaq -0x170(%rbp), %rdi
callq 0x3d86
leaq -0x50(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0xa0(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x40fa(%rip), %rsi      # 0x7075
leaq -0x170(%rbp), %rdi
callq 0x38b0
movq %rax, %r14
testb $0x4, 0xf(%rax)
movq %rax, -0x38(%rbp)
je 0x3105
movq %r14, %rdi
callq 0x391a
movq %rax, %rbx
leaq -0x60(%rbp), %r15
movq 0x8(%r15), %r12
movq %rax, %rdi
callq 0x2120
movq $0x0, -0x38(%rbp)
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x2320
leaq 0x40ab(%rip), %rsi      # 0x7080
leaq -0x60(%rbp), %rdi
callq 0x20b0
testl %eax, %eax
je 0x3105
leaq 0x409a(%rip), %rsi      # 0x7087
leaq -0x60(%rbp), %rdi
callq 0x20b0
testl %eax, %eax
je 0x30f5
leaq 0x408a(%rip), %rsi      # 0x708f
leaq -0x60(%rbp), %rdi
callq 0x20b0
testl %eax, %eax
je 0x30fc
movq 0x9fbb(%rip), %rbx      # 0xcfd8
leaq 0x4071(%rip), %rsi      # 0x7095
movl $0x12, %edx
movq %rbx, %rdi
callq 0x2290
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2230
movsbl %al, %esi
movq 0x9f89(%rip), %rdi      # 0xcfd8
callq 0x2030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x21b0
jmp 0x3483
testq %rbx, %rbx
je 0x3087
movq %rbx, %rdi
callq 0x2120
movq 0x9f5e(%rip), %rdi      # 0xcfd8
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2290
jmp 0x30a5
movq 0x9f4a(%rip), %rax      # 0xcfd8
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
leaq (%rax,%rcx), %rdi
movl 0x20(%rax,%rcx), %esi
orl $0x1, %esi
callq 0x2350
movq 0x9f2c(%rip), %rbx      # 0xcfd8
leaq 0x3fb2(%rip), %rsi      # 0x7065
movl $0xf, %edx
movq %rbx, %rdi
callq 0x2290
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2230
movsbl %al, %esi
movq 0x9efa(%rip), %rdi      # 0xcfd8
callq 0x2030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x21b0
jmp 0x34b9
movl $0x1, %eax
jmp 0x3101
movl $0x2, %eax
movq %rax, -0x38(%rbp)
leaq 0x3f9c(%rip), %rsi      # 0x70a8
leaq -0x170(%rbp), %rdi
callq 0x38b0
cmpq %rax, %r14
je 0x3501
movups (%rax), %xmm0
movups %xmm0, (%r14)
movw $0x0, 0xe(%rax)
testb $0x4, 0xf(%r14)
jne 0x317d
movq 0x9e9c(%rip), %rbx      # 0xcfd8
leaq 0x3f68(%rip), %rsi      # 0x70ab
movl $0x10, %edx
movq %rbx, %rdi
callq 0x2290
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2230
movsbl %al, %esi
movq 0x9e6a(%rip), %rdi      # 0xcfd8
callq 0x2030
movq %rax, %rdi
callq 0x21b0
jmp 0x31ae
movq %r14, %rdi
callq 0x391a
movq %rax, %rbx
leaq -0xb0(%rbp), %r15
movq 0x8(%r15), %r12
movq %rax, %rdi
callq 0x2120
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x2320
leaq 0x3f07(%rip), %rsi      # 0x70bc
leaq -0x170(%rbp), %rdi
callq 0x38b0
cmpq %rax, %r14
je 0x3501
movups (%rax), %xmm0
movups %xmm0, (%r14)
movw $0x0, 0xe(%rax)
testb $0x20, 0xe(%r14)
jne 0x322d
movq 0x9df3(%rip), %rbx      # 0xcfd8
leaq 0x3ed5(%rip), %rsi      # 0x70c1
movl $0xc, %edx
movq %rbx, %rdi
callq 0x2290
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2230
movsbl %al, %esi
movq 0x9dc1(%rip), %rdi      # 0xcfd8
callq 0x2030
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x21b0
jmp 0x3233
movl (%r14), %eax
movl %eax, -0x2c(%rbp)
leaq 0x3e55(%rip), %rsi      # 0x708f
leaq -0x170(%rbp), %rdi
callq 0x38b0
cmpq %rax, %r14
je 0x3501
movups (%rax), %xmm0
movups %xmm0, (%r14)
movw $0x0, 0xe(%rax)
cmpw $0x4, 0xe(%r14)
jne 0x33ba
cmpw $0x4, 0xe(%r14)
jne 0x339b
movq -0x40(%rbp), %rax
addq $0x180, %rax            # imm = 0x180
movq %rax, -0x68(%rbp)
xorl %r12d, %r12d
leaq -0x90(%rbp), %rbx
cmpl (%r14), %r12d
jae 0x3400
movq %r14, %rdi
movl %r12d, %esi
callq 0x395e
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
leaq 0x3df8(%rip), %rdx      # 0x70a8
callq 0x5bd4
movq -0x90(%rbp), %r13
movq %r15, %rdi
callq 0x5b92
cmpq %rax, %r13
je 0x338c
movq %r15, %rdi
leaq 0x3dd1(%rip), %rsi      # 0x70a8
callq 0x38b0
testb $0x4, 0xf(%rax)
je 0x338c
movq %r15, %rdi
leaq 0x3db8(%rip), %rsi      # 0x70a8
callq 0x38b0
movq %rax, %rdi
callq 0x391a
leaq -0xd0(%rbp), %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x2100
movq %r15, %rdi
leaq 0x3da3(%rip), %rsi      # 0x70bc
callq 0x38b0
testb $0x20, 0xe(%rax)
je 0x34e2
movl (%rax), %r15d
leaq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0xd0(%rbp), %rsi
movq -0xc8(%rbp), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x39fc
movl %r15d, -0x70(%rbp)
movq -0x68(%rbp), %rdi
movq %rbx, %rsi
callq 0x5c4a
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x3374
callq 0x2220
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x338c
callq 0x2220
incl %r12d
cmpw $0x4, 0xe(%r14)
je 0x328c
leaq 0x5a8f(%rip), %rdi      # 0x8e31
leaq 0x3dcb(%rip), %rsi      # 0x7174
leaq 0x5a8b(%rip), %rcx      # 0x8e3b
movl $0x5f1, %edx            # imm = 0x5F1
callq 0x2190
movq 0x9c17(%rip), %rbx      # 0xcfd8
leaq 0x3d06(%rip), %rsi      # 0x70ce
movl $0x19, %edx
movq %rbx, %rdi
callq 0x2290
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2230
movsbl %al, %esi
movq 0x9be5(%rip), %rdi      # 0xcfd8
callq 0x2030
movq %rax, %rdi
callq 0x21b0
movl $0x30, %edi
callq 0x2250
movq %rax, %r14
leaq -0xe0(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
addq %rsi, %rdx
leaq -0xf0(%rbp), %rdi
callq 0x39fc
movq -0x38(%rbp), %rax
movl %eax, (%r14)
leaq 0x8(%r14), %rdi
movq %r14, %rax
addq $0x18, %rax
movq %rax, 0x8(%r14)
movq -0xf0(%rbp), %rsi
movq -0xe8(%rbp), %rdx
addq %rsi, %rdx
callq 0x39fc
movl -0x2c(%rbp), %eax
movl %eax, 0x28(%r14)
movq -0x40(%rbp), %rax
movq %r14, 0x8(%rax)
movq -0xf0(%rbp), %rdi
xorl %ebx, %ebx
cmpq %r15, %rdi
je 0x3483
callq 0x2220
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x349b
callq 0x2220
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x34ad
callq 0x2220
leaq -0x170(%rbp), %rdi
callq 0x39c4
leaq -0x100(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x34ce
callq 0x2220
movl %ebx, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x58a3(%rip), %rdi      # 0x8d8c
leaq 0x3c84(%rip), %rsi      # 0x7174
leaq 0x58ae(%rip), %rcx      # 0x8da5
movl $0x69f, %edx            # imm = 0x69F
callq 0x2190
leaq 0x57ac(%rip), %rdi      # 0x8cb4
leaq 0x3c65(%rip), %rsi      # 0x7174
leaq 0x57ab(%rip), %rcx      # 0x8cc1
movl $0x326, %edx            # imm = 0x326
callq 0x2190
movq %rax, %rbx
movq -0xf0(%rbp), %rdi
cmpq %r15, %rdi
je 0x3539
callq 0x2220
jmp 0x3539
movq %rax, %rbx
movq %r14, %rdi
jmp 0x357c
movq %rax, %rbx
jmp 0x35b6
jmp 0x3545
movq %rax, %rbx
jmp 0x35c2
jmp 0x354c
movq %rax, %rbx
jmp 0x3569
movq %rax, %rbx
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x3569
callq 0x2220
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x358c
callq 0x2220
jmp 0x358c
jmp 0x3589
jmp 0x3589
jmp 0x3589
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x35a4
callq 0x2220
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x35b6
callq 0x2220
leaq -0x170(%rbp), %rdi
callq 0x39c4
leaq -0x100(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x35d7
callq 0x2220
movq %rbx, %rdi
callq 0x2370
nop