int main(int argc, char* argv[]) { LOG_LEVEL_DEBUG; LOG_OUTPUT_CONSOLE; LOG_PREFIX("[Uint128] "); const UnitTest tests[] = { unit_test(test_success), unit_test(test_packet_create_destroy), unit_test(test_packet_emit) }; return run_tests(tests); }
int main(int argc, char* argv[]) { LOG_LEVEL_DEBUG; LOG_OUTPUT_CONSOLE; LOG_PREFIX("[mule] "); random_init(); const UnitTest tests[] = { unit_test(test_success), unit_test(test_mule) }; return run_tests(tests); }
bool kad_session_init( uint16_t tcp_port, uint16_t udp_port, char* nodes_file_path, KAD_SESSION** ks_out ) { bool result = false; KAD_SESSION* ks = NULL; char host_name[HOST_NAME_MAX + 1]; struct hostent* he = NULL; UINT128 zone_idx; uint32_t now = 0; do { LOG_PREFIX("[libkad] "); LOG_LEVEL_DEBUG; LOG_FILE_NAME("libkad.log"); LOG_OUTPUT_CONSOLE_AND_FILE; if (!ks_out) break; ks = (KAD_SESSION*)mem_alloc(sizeof(KAD_SESSION)); if (!ks){ LOG_ERROR("Failed to allocate memory for kad session."); break; } ks->version = KADEMLIA_VERSION; random_init(ticks_now_ms()); gethostname(host_name, HOST_NAME_MAX); LOG_DEBUG("Host name: %s", host_name); he = gethostbyname(host_name); ks->loc_ip4_no = *(uint32_t*)he->h_addr; kad_fw_set_status(&ks->fw, true); kad_fw_set_status_udp(&ks->fw, true); uint128_generate(&ks->kad_id); LOG_DEBUG_UINT128("kad_id: ", ((UINT128*)&ks->kad_id)); for (uint32_t i = 0; i < sizeof(ks->user_hash); i++){ ks->user_hash[i] = random_uint8(); } ks->user_hash[5] = 14; ks->user_hash[14] = 111; kadhlp_gen_udp_key(&ks->udp_key); LOG_DEBUG("udp_key: %.8x", ks->udp_key); ks->udp_port = udp_port; ks->tcp_port = tcp_port; LOG_DEBUG("udp_port = %d", udp_port); LOG_DEBUG("tcp_port = %d", tcp_port); uint128_init(&zone_idx, 0); routing_create_zone(NULL, 0, &zone_idx, &ks->root_zone); list_add_entry(&ks->active_zones, ks->root_zone); now = ticks_now_ms(); ks->timers.self_lookup = now + MIN2MS(3); ks->timers.udp_port_lookup = now; ks->timers.nodes_count_check = now + SEC2MS(10); ks->opts.use_extrn_udp_port = true; queue_create(CONTROL_PACKET_QUEUE_LENGTH, &ks->queue_in_udp); queue_create(CONTROL_PACKET_QUEUE_LENGTH, &ks->queue_out_udp); if (nodes_file_path) kadhlp_add_nodes_from_file(ks, nodes_file_path); kadusr_init(ks); *ks_out = ks; result = true; } while (false); return result; }
int APIENTRY WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR str, int nWinMode){ LOG_PREFIX("logs\\clientLog"); LOG_LEVEL(logger::Debug); // уровень лога в рантайме (например, берём из командной строки) LOG_DEBUG << "WinMain starting.."; Scene=0; hDC=0; int full=0; int WindowX=0; int WindowY=0; int Width=800; int Height=600; full = GetPrivateProfileIntA("Options", "FullScreenEnable", 0, "Data/graph.ini"); WindowX = GetPrivateProfileIntA("Options", "WindowX", 0, "Data/graph.ini"); WindowY = GetPrivateProfileIntA("Options", "WindowY", 0, "Data/graph.ini"); Width = GetPrivateProfileIntA("Options", "Width", 800, "Data/graph.ini"); Height = GetPrivateProfileIntA("Options", "Height", 600, "Data/graph.ini"); Scene = new TScene(); if ( full == 0 ){ WNDCLASSA wcl; wcl.hInstance = hThisInst; wcl.lpszClassName = "OpenGLWinClass"; wcl.lpfnWndProc = WindowFunc; wcl.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; wcl.hIcon = NULL; wcl.hCursor = LoadCursor(NULL,IDC_ARROW); wcl.lpszMenuName = NULL; wcl.cbClsExtra = 0; wcl.cbWndExtra = 0; wcl.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // RegisterClassA(&wcl); if ( !RegisterClassA(&wcl) ) return -1;//throw "RegisterClass"; hWnd = CreateWindowA("OpenGLWinClass", "Elt",WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, WindowX, WindowY, Width, Height, NULL, NULL, hThisInst, NULL); ShowWindow(hWnd, SW_SHOWNORMAL); UpdateWindow(hWnd); } if ( full == 1 ){ DEVMODE ss; WNDCLASSA wcl; memset(&ss, 0, sizeof(ss) ); ss.dmSize = sizeof(ss); ss.dmPelsWidth = Width; ss.dmPelsHeight = Height; ss.dmBitsPerPel = 32; ss.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; if (ChangeDisplaySettings(&ss, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) MessageBoxA(NULL, "Ошибка в ChangeDisplaySettings", "Error", MB_OK | MB_ICONSTOP); memset(&wcl, 0, sizeof(wcl) ); wcl.lpfnWndProc = (WNDPROC)WindowFunc; wcl.hInstance = hThisInst; wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION); wcl.hCursor = LoadCursor(NULL, IDC_ARROW); wcl.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcl.lpszClassName = "OpenGLWinClass"; if ( !RegisterClassA(&wcl) ) return -1;//throw "RegisterClass"; hWnd = CreateWindowA("OpenGLWinClass", "Elt", WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, Width, Height, NULL, NULL, hThisInst, NULL); if ( !hWnd ) return -1;//throw "CreateWindow"; SetWindowPos( hWnd, HWND_TOPMOST, 0, 0, 0, 0, 1 ); ShowWindow(hWnd, SW_SHOWMAXIMIZED); } MSG msg; LOG_DEBUG << "WinMain started end"; LOG_DEBUG << "World Init..."; World->Init(); LOG_DEBUG << "...End World Init"; //---network init LOG_DEBUG << "netClient.Init()"; netClient.Init(World); //World->SetNetStatData(&netClient.mNetStat); netClient.SetTimeBetweenPacketsSend(500); LOG_DEBUG << "netClient.Run()"; netClient.Run(); //--------------- tTick gTick; gTick.Init(20);//50 раз в сек LOG_DEBUG << "Start Main loop"; do{ if(PeekMessage( &msg, NULL, 0, 0, PM_REMOVE )) { if( msg.message == WM_QUIT ) break; TranslateMessage( &msg ); DispatchMessage ( &msg ); } World->CDM(); // Center of Decision Making (Graphics + Logic) gTick.Wait();//Зачем ждать? Перести в World->CDM() и если рано - не ждать а выходить }while(!bGameOver); LOG_DEBUG << "End Main loop"; LOG_DEBUG << "World->Destroy()"; World->Destroy(); //---network release LOG_DEBUG << "netClient.Stop()"; netClient.Stop(); LOG_DEBUG << "netClient.Release()"; netClient.Release(); //---------- if (Scene) delete Scene; LOG_DEBUG << "Scene deleted"; LOG_DEBUG << "World destroy"; DestroyWindow(hWnd); LOG_DEBUG << "Windows destroy"; if ( full == 1 ) ChangeDisplaySettings(NULL, 0); LOG_DEBUG << "EXIT"; return 0; }