// File: /workspace/github_cpp_makefile_star2_O2/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, -0x38(%rbp)
leaq -0xe0(%rbp), %r14
movq %r14, %rdi
callq 0x254c
leaq 0x7213(%rip), %rsi      # 0x9c34
movq %r14, %rdi
callq 0x3006
testb %al, %al
je 0x2a5b
movq 0xa5a4(%rip), %rdi      # 0xcfd8
movq %rbx, %rsi
callq 0x2210
leaq 0x4622(%rip), %rsi      # 0x7065
movq %rax, %rdi
callq 0x2210
movq %rax, %rdi
callq 0x2150
pushq $0x1
popq %rbx
jmp 0x2d5d
leaq -0x140(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x3016
movq -0xe0(%rbp), %rsi
leaq -0x140(%rbp), %rdi
callq 0x3560
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq -0x70(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x45cb(%rip), %rsi      # 0x7075
leaq -0x140(%rbp), %rdi
callq 0x3092
movq %rax, %r14
testb $0x4, 0xf(%rax)
je 0x2b24
movq %r14, %rdi
callq 0x30de
leaq -0x60(%rbp), %rdi
movq %rax, %rsi
callq 0x2380
leaq 0x45a6(%rip), %rsi      # 0x7080
leaq -0x60(%rbp), %rdi
callq 0x3006
movl $0x0, -0x2c(%rbp)
testb %al, %al
jne 0x2b24
leaq 0x4592(%rip), %rsi      # 0x7087
leaq -0x60(%rbp), %rdi
callq 0x3006
testb %al, %al
je 0x2b06
pushq $0x1
jmp 0x2b20
leaq 0x4582(%rip), %rsi      # 0x708f
leaq -0x60(%rbp), %rdi
callq 0x3006
testb %al, %al
je 0x2d7d
pushq $0x2
popq %rax
movl %eax, -0x2c(%rbp)
leaq 0x457d(%rip), %rsi      # 0x70a8
leaq -0x140(%rbp), %rdi
callq 0x3092
movq %r14, %rdi
movq %rax, %rsi
callq 0x3122
testb $0x4, 0xf(%r14)
jne 0x2b66
movq 0xa488(%rip), %rdi      # 0xcfd8
leaq 0x4554(%rip), %rsi      # 0x70ab
callq 0x2210
movq %rax, %rdi
callq 0x2150
jmp 0x2b7a
movq %r14, %rdi
callq 0x30de
leaq -0x80(%rbp), %rdi
movq %rax, %rsi
callq 0x2380
leaq 0x453b(%rip), %rsi      # 0x70bc
leaq -0x140(%rbp), %rdi
callq 0x3092
movq %r14, %rdi
movq %rax, %rsi
callq 0x3122
testb $0x20, 0xe(%r14)
jne 0x2bbf
movq 0xa432(%rip), %rdi      # 0xcfd8
leaq 0x4514(%rip), %rsi      # 0x70c1
callq 0x2210
movq %rax, %rdi
callq 0x2150
pushq $-0x1
popq %rax
jmp 0x2bc7
movq %r14, %rdi
callq 0x315a
movl %eax, -0x30(%rbp)
leaq 0x44be(%rip), %rsi      # 0x708f
leaq -0x140(%rbp), %rdi
callq 0x3092
movq %r14, %rdi
movq %rax, %rsi
callq 0x3122
cmpw $0x4, 0xe(%r14)
jne 0x2cd3
movq -0x38(%rbp), %rax
addq $0x180, %rax            # imm = 0x180
movq %rax, -0x40(%rbp)
xorl %r13d, %r13d
leaq 0x449c(%rip), %rbx      # 0x70a8
leaq -0x168(%rbp), %r12
movq %r14, %rdi
callq 0x3186
cmpl %eax, %r13d
jae 0x2cee
movq %r14, %rdi
movl %r13d, %esi
callq 0x31b4
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
callq 0x321a
testb %al, %al
je 0x2ccb
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3092
testb $0x4, 0xf(%rax)
je 0x2ccb
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3092
movq %rax, %rdi
callq 0x30de
leaq -0xc0(%rbp), %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x20f0
movq %r15, %rdi
leaq 0x4437(%rip), %rsi      # 0x70bc
callq 0x3092
movq %rax, %rdi
callq 0x315a
movl %eax, %r15d
movq %r12, %rdi
leaq -0xc0(%rbp), %rsi
callq 0x22c0
movl %r15d, -0x148(%rbp)
movq -0x40(%rbp), %rdi
movq %r12, %rsi
callq 0x5718
movq %r12, %rdi
callq 0x2130
leaq -0xc0(%rbp), %rdi
callq 0x2130
incl %r13d
jmp 0x2c13
movq 0xa2fe(%rip), %rdi      # 0xcfd8
leaq 0x43ed(%rip), %rsi      # 0x70ce
callq 0x2210
movq %rax, %rdi
callq 0x2150
pushq $0x30
popq %rdi
callq 0x2220
movq %rax, %r14
leaq -0xa0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x22c0
movl -0x2c(%rbp), %eax
movl %eax, (%r14)
movq %r14, %rdi
addq $0x8, %rdi
leaq -0xa0(%rbp), %rsi
callq 0x22c0
movl -0x30(%rbp), %eax
movl %eax, 0x28(%r14)
movq -0x38(%rbp), %rax
movq %r14, 0x8(%rax)
leaq -0xa0(%rbp), %rdi
callq 0x2130
xorl %ebx, %ebx
leaq -0x80(%rbp), %rdi
callq 0x2130
leaq -0x60(%rbp), %rdi
callq 0x2130
leaq -0x140(%rbp), %rdi
callq 0x3240
leaq -0xe0(%rbp), %rdi
callq 0x2130
movl %ebx, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xa254(%rip), %rdi      # 0xcfd8
leaq 0x430a(%rip), %rsi      # 0x7095
callq 0x2210
movq %rax, %rdi
callq 0x2150
pushq $0x1
popq %rbx
jmp 0x2d3f
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x2130
jmp 0x2db1
movq %rax, %rbx
movq %r14, %rdi
callq 0x2200
jmp 0x2df4
movq %rax, %rbx
jmp 0x2e06
jmp 0x2dc2
movq %rax, %rbx
jmp 0x2e12
movq %rax, %rbx
leaq -0x168(%rbp), %rdi
callq 0x2130
jmp 0x2ddf
jmp 0x2ddc
jmp 0x2df1
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x2130
jmp 0x2df4
jmp 0x2df1
jmp 0x2df1
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x2130
leaq -0x60(%rbp), %rdi
callq 0x2130
leaq -0x140(%rbp), %rdi
callq 0x3240
leaq -0xe0(%rbp), %rdi
callq 0x2130
movq %rbx, %rdi
callq 0x2340