| 804 | } |
| 805 | |
| 806 | int CMain::ReadConfig() |
| 807 | { |
| 808 | // read and parse config |
| 809 | IOHANDLE File = io_open(m_Config.m_aConfigFile, IOFLAG_READ); |
| 810 | if(!File) |
| 811 | { |
| 812 | dbg_msg("main", "Couldn't open %s", m_Config.m_aConfigFile); |
| 813 | return 1; |
| 814 | } |
| 815 | int FileSize = (int)io_length(File); |
| 816 | char *pFileData = (char *)mem_alloc(FileSize + 1, 1); |
| 817 | |
| 818 | io_read(File, pFileData, FileSize); |
| 819 | pFileData[FileSize] = 0; |
| 820 | io_close(File); |
| 821 | |
| 822 | // parse json data |
| 823 | json_settings JsonSettings; |
| 824 | mem_zero(&JsonSettings, sizeof(JsonSettings)); |
| 825 | char aError[256]; |
| 826 | json_value *pJsonData = json_parse_ex(&JsonSettings, pFileData, strlen(pFileData), aError); |
| 827 | if(!pJsonData) |
| 828 | { |
| 829 | dbg_msg("main", "JSON Error in file %s: %s", m_Config.m_aConfigFile, aError); |
| 830 | mem_free(pFileData); |
| 831 | return 1; |
| 832 | } |
| 833 | |
| 834 | // reset clients |
| 835 | for(int i = 0; i < NET_MAX_CLIENTS; i++) |
| 836 | { |
| 837 | if(!Client(i)->m_Active || !Client(i)->m_Connected) |
| 838 | continue; |
| 839 | |
| 840 | m_Server.Network()->Drop(Client(i)->m_ClientNetID, "Server reloading..."); |
| 841 | } |
| 842 | mem_zero(m_aClients, sizeof(m_aClients)); |
| 843 | for(int i = 0; i < NET_MAX_CLIENTS; i++) |
| 844 | m_aClients[i].m_ClientNetID = -1; |
| 845 | |
| 846 | // extract data |
| 847 | int ID = 0; |
| 848 | const json_value &rStart = (*pJsonData)["servers"]; |
| 849 | if(rStart.type == json_array) |
| 850 | { |
| 851 | for(unsigned i = 0; i < rStart.u.array.length; i++) |
| 852 | { |
| 853 | if(ID < 0 || ID >= NET_MAX_CLIENTS) |
| 854 | continue; |
| 855 | |
| 856 | Client(ID)->m_Active = true; |
| 857 | Client(ID)->m_Disabled = rStart[i]["disabled"].u.boolean; |
| 858 | str_copy(Client(ID)->m_aName, rStart[i]["name"].u.string.ptr, sizeof(Client(ID)->m_aName)); |
| 859 | str_copy(Client(ID)->m_aUsername, rStart[i]["username"].u.string.ptr, sizeof(Client(ID)->m_aUsername)); |
| 860 | str_copy(Client(ID)->m_aType, rStart[i]["type"].u.string.ptr, sizeof(Client(ID)->m_aType)); |
| 861 | str_copy(Client(ID)->m_aHost, rStart[i]["host"].u.string.ptr, sizeof(Client(ID)->m_aHost)); |
| 862 | str_copy(Client(ID)->m_aLocation, rStart[i]["location"].u.string.ptr, sizeof(Client(ID)->m_aLocation)); |
| 863 | str_copy(Client(ID)->m_aPassword, rStart[i]["password"].u.string.ptr, sizeof(Client(ID)->m_aPassword)); |
nothing calls this directly
no test coverage detected