// File: /workspace/github_cpp_makefile_star2_O3/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 0x2dfc
leaq 0x6751(%rip), %rsi      # 0x9b54
movq %r14, %rdi
callq 0x20b0
testl %eax, %eax
je 0x355c
leaq -0x170(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x3d12
movq -0x110(%rbp), %rax
leaq -0x90(%rbp), %rsi
movq %rax, (%rsi)
movq %rax, 0x8(%rsi)
leaq -0x170(%rbp), %rdi
callq 0x4246
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 0x3c04(%rip), %rsi      # 0x7075
leaq -0x170(%rbp), %rdi
callq 0x3d92
movq %rax, %r14
testb $0x4, 0xf(%rax)
movq %rax, -0x38(%rbp)
je 0x35fb
movq %r14, %rdi
callq 0x3dfc
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 0x3bb5(%rip), %rsi      # 0x7080
leaq -0x60(%rbp), %rdi
callq 0x20b0
testl %eax, %eax
je 0x35fb
leaq 0x3ba4(%rip), %rsi      # 0x7087
leaq -0x60(%rbp), %rdi
callq 0x20b0
testl %eax, %eax
je 0x35eb
leaq 0x3b94(%rip), %rsi      # 0x708f
leaq -0x60(%rbp), %rdi
callq 0x20b0
testl %eax, %eax
je 0x35f2
movq 0x9ac5(%rip), %rbx      # 0xcfd8
leaq 0x3b7b(%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 0x9a93(%rip), %rdi      # 0xcfd8
callq 0x2030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x21b0
jmp 0x396d
testq %rbx, %rbx
je 0x357d
movq %rbx, %rdi
callq 0x2120
movq 0x9a68(%rip), %rdi      # 0xcfd8
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2290
jmp 0x359b
movq 0x9a54(%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 0x9a36(%rip), %rbx      # 0xcfd8
leaq 0x3abc(%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 0x9a04(%rip), %rdi      # 0xcfd8
callq 0x2030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x21b0
jmp 0x39a3
movl $0x1, %eax
jmp 0x35f7
movl $0x2, %eax
movq %rax, -0x38(%rbp)
leaq 0x3aa6(%rip), %rsi      # 0x70a8
leaq -0x170(%rbp), %rdi
callq 0x3d92
cmpq %rax, %r14
je 0x39eb
movups (%rax), %xmm0
movups %xmm0, (%r14)
movw $0x0, 0xe(%rax)
testb $0x4, 0xf(%r14)
jne 0x3673
movq 0x99a6(%rip), %rbx      # 0xcfd8
leaq 0x3a72(%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 0x9974(%rip), %rdi      # 0xcfd8
callq 0x2030
movq %rax, %rdi
callq 0x21b0
jmp 0x36a4
movq %r14, %rdi
callq 0x3dfc
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 0x3a11(%rip), %rsi      # 0x70bc
leaq -0x170(%rbp), %rdi
callq 0x3d92
cmpq %rax, %r14
je 0x39eb
movups (%rax), %xmm0
movups %xmm0, (%r14)
movw $0x0, 0xe(%rax)
testb $0x20, 0xe(%r14)
jne 0x3723
movq 0x98fd(%rip), %rbx      # 0xcfd8
leaq 0x39df(%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 0x98cb(%rip), %rdi      # 0xcfd8
callq 0x2030
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x21b0
jmp 0x3729
movl (%r14), %eax
movl %eax, -0x2c(%rbp)
leaq 0x395f(%rip), %rsi      # 0x708f
leaq -0x170(%rbp), %rdi
callq 0x3d92
cmpq %rax, %r14
je 0x39eb
movups (%rax), %xmm0
movups %xmm0, (%r14)
movw $0x0, 0xe(%rax)
cmpw $0x4, 0xe(%r14)
jne 0x38a4
movq -0x40(%rbp), %rax
addq $0x180, %rax            # imm = 0x180
movq %rax, -0x68(%rbp)
xorl %r12d, %r12d
leaq -0x90(%rbp), %rbx
cmpl (%r14), %r12d
jae 0x38ea
movq %r14, %rdi
movl %r12d, %esi
callq 0x3e40
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
leaq 0x390e(%rip), %rdx      # 0x70a8
callq 0x5996
movq -0x90(%rbp), %r13
movq %r15, %rdi
callq 0x5954
cmpq %rax, %r13
je 0x3876
movq %r15, %rdi
leaq 0x38e7(%rip), %rsi      # 0x70a8
callq 0x3d92
testb $0x4, 0xf(%rax)
je 0x3876
movq %r15, %rdi
leaq 0x38ce(%rip), %rsi      # 0x70a8
callq 0x3d92
movq %rax, %rdi
callq 0x3dfc
leaq -0xd0(%rbp), %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x2100
movq %r15, %rdi
leaq 0x38b9(%rip), %rsi      # 0x70bc
callq 0x3d92
testb $0x20, 0xe(%rax)
je 0x39cc
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 0x3eda
movl %r15d, -0x70(%rbp)
movq -0x68(%rbp), %rdi
movq %rbx, %rsi
callq 0x5a0c
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x385e
callq 0x2220
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x3876
callq 0x2220
incl %r12d
cmpw $0x4, 0xe(%r14)
je 0x3776
leaq 0x55a5(%rip), %rdi      # 0x8e31
leaq 0x38e1(%rip), %rsi      # 0x7174
leaq 0x55a1(%rip), %rcx      # 0x8e3b
movl $0x5f1, %edx            # imm = 0x5F1
callq 0x2190
movq 0x972d(%rip), %rbx      # 0xcfd8
leaq 0x381c(%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 0x96fb(%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 0x3eda
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 0x3eda
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 0x396d
callq 0x2220
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x3985
callq 0x2220
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x3997
callq 0x2220
leaq -0x170(%rbp), %rdi
callq 0x3ea6
leaq -0x100(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x39b8
callq 0x2220
movl %ebx, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x53b9(%rip), %rdi      # 0x8d8c
leaq 0x379a(%rip), %rsi      # 0x7174
leaq 0x53c4(%rip), %rcx      # 0x8da5
movl $0x69f, %edx            # imm = 0x69F
callq 0x2190
leaq 0x52c2(%rip), %rdi      # 0x8cb4
leaq 0x377b(%rip), %rsi      # 0x7174
leaq 0x52c1(%rip), %rcx      # 0x8cc1
movl $0x326, %edx            # imm = 0x326
callq 0x2190
movq %rax, %rbx
movq -0xf0(%rbp), %rdi
cmpq %r15, %rdi
je 0x3a23
callq 0x2220
jmp 0x3a23
movq %rax, %rbx
movq %r14, %rdi
jmp 0x3a66
movq %rax, %rbx
jmp 0x3aa0
jmp 0x3a2f
movq %rax, %rbx
jmp 0x3aac
jmp 0x3a36
movq %rax, %rbx
jmp 0x3a53
movq %rax, %rbx
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x3a53
callq 0x2220
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x3a76
callq 0x2220
jmp 0x3a76
jmp 0x3a73
jmp 0x3a73
jmp 0x3a73
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x3a8e
callq 0x2220
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x3aa0
callq 0x2220
leaq -0x170(%rbp), %rdi
callq 0x3ea6
leaq -0x100(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3ac1
callq 0x2220
movq %rbx, %rdi
callq 0x2370
nop