From 3b7bf8d3f064537f364260dc0b2a2850b0b7dd52 Mon Sep 17 00:00:00 2001 From: jenzur Date: Wed, 23 Sep 2020 11:48:11 +0200 Subject: [PATCH] moved udp connection socket and fixed invalid handle probably --- AutismBotIngame/scripting/autism_bot_info.sp | 36 ++++++++++--------- RaceTimer/scripting/unloze_racetimer_redux.sp | 31 ++++++++-------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/AutismBotIngame/scripting/autism_bot_info.sp b/AutismBotIngame/scripting/autism_bot_info.sp index 3b74ecfe..24a4a19a 100644 --- a/AutismBotIngame/scripting/autism_bot_info.sp +++ b/AutismBotIngame/scripting/autism_bot_info.sp @@ -53,12 +53,9 @@ public void OnPluginStart() HookEntityOutput("trigger_teleport", "OnTrigger", trigger_teleport); HookEntityOutput("trigger_teleport", "OnStartTouch", trigger_teleport); - //socket otherwise declare in public OnConfigsExecuted(){} - Handle socket = SocketCreate(SOCKET_UDP, OnSocketError); - SocketSetOption(socket, SocketReuseAddr, 1); - SocketBind(socket, "127.0.0.1", 48475); - connect(socket); - global_socket = socket; + //UDP connection + connect_socket(); + reset_target_human_tp_coord(); targethuman = 0; } @@ -319,7 +316,7 @@ public Action recursive_pressing(Handle timer, any data) if (targeteam == 3) { float min_distance_target_human = 12800.0; - float min_enemy_distance = min_distance_target_human * 8; + float min_enemy_distance = min_distance_target_human * 15; if (0 < dist_target <= min_distance_target_human && enemy_distance > min_enemy_distance) { chasing_enemy = true; @@ -339,8 +336,8 @@ public Action recursive_pressing(Handle timer, any data) //zombie aiming for human float present_bot_coords[3]; GetClientAbsOrigin(present, present_bot_coords); - z_axis = FloatAbs(Pow(present_bot_coords[2] - pos[2], 5.0)); - float z_axis_cap = 10.0; + z_axis = FloatAbs(Pow(present_bot_coords[2] - pos[2], 2.0)); + float z_axis_cap = 20.0; if ((targeteam == 2 && 0 < enemy_distance && z_axis < z_axis_cap) || dist_target == -1.0) { chasing_enemy = true; @@ -685,14 +682,21 @@ public void OnClientPostAdminCheck(int client) public OnSocketError(Handle socket, const int errorType, const int errorNum, any args) { - LogError("[MR] Socket error: %d (errno %d)", errorType, errorNum); - CreateTimer(120.0, TimerConnect, socket, TIMER_HNDL_CLOSE); + CloseHandle(socket); + LogError("[MR] Socket error: %d (errno %d)", errorType, errorNum); + CreateTimer(10.0, TimerConnect, INVALID_HANDLE, TIMER_HNDL_CLOSE); } -stock void connect(Handle socket) +stock void connect_socket() { - if (!SocketIsConnected(socket)) - SocketConnect(socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, "127.0.0.1", 48475); + if (global_socket == INVALID_HANDLE || !SocketIsConnected(global_socket)) + { + //socket otherwise declare in public OnConfigsExecuted(){} + global_socket = SocketCreate(SOCKET_UDP, OnSocketError); + SocketSetOption(global_socket, SocketReuseAddr, 1); + SocketBind(global_socket, "127.0.0.1", 48475); + SocketConnect(global_socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, "127.0.0.1", 48475); + } } public void OnClientDisconnect(int client) @@ -741,12 +745,12 @@ public OnSocketReceive(Handle socket, char[] receiveData, const dataSize, any hF public OnSocketDisconnected(Handle socket, any arg) { - CreateTimer(120.0, TimerConnect, socket, TIMER_HNDL_CLOSE); + CreateTimer(10.0, TimerConnect, INVALID_HANDLE, TIMER_HNDL_CLOSE); } public Action TimerConnect(Handle timer, any arg) { - connect(arg); + connect_socket(); return Plugin_Handled; } diff --git a/RaceTimer/scripting/unloze_racetimer_redux.sp b/RaceTimer/scripting/unloze_racetimer_redux.sp index 1d9afe72..93e21c21 100644 --- a/RaceTimer/scripting/unloze_racetimer_redux.sp +++ b/RaceTimer/scripting/unloze_racetimer_redux.sp @@ -745,22 +745,25 @@ public void SQL_SelectTop_Callback(Handle db, Handle results, const char[] error } Menu menu = new Menu(MenuHandler1); menu.SetTitle("Maptimer: %s", g_cMapname); - while (SQL_GetRowCount(results) > 0 && SQL_FetchRow(results)) + if (results != INVALID_HANDLE) { - l_iPosition++; - SQL_FetchString(results, 0, g_cPlayerName, MAX_NAME_LENGTH); - l_fRecord = SQL_FetchFloat(results, 1); - l_iMinutes = RoundToFloor(l_fRecord); - l_iSeconds = (l_fRecord - l_iMinutes) * 100; - Format(g_cContent, sizeof(g_cContent), "#%i: Time: 0%i:%.4f - %s", l_iPosition, l_iMinutes, l_iSeconds, g_cPlayerName); - menu.AddItem("-1", g_cContent, ITEMDRAW_DISABLED); + while (SQL_GetRowCount(results) > 0 && SQL_FetchRow(results)) + { + l_iPosition++; + SQL_FetchString(results, 0, g_cPlayerName, MAX_NAME_LENGTH); + l_fRecord = SQL_FetchFloat(results, 1); + l_iMinutes = RoundToFloor(l_fRecord); + l_iSeconds = (l_fRecord - l_iMinutes) * 100; + Format(g_cContent, sizeof(g_cContent), "#%i: Time: 0%i:%.4f - %s", l_iPosition, l_iMinutes, l_iSeconds, g_cPlayerName); + menu.AddItem("-1", g_cContent, ITEMDRAW_DISABLED); + } + if (!l_iPosition) + { + menu.AddItem("-1", "No results. Commands: !toptime !stages", ITEMDRAW_DISABLED); + } + menu.ExitButton = true; + menu.Display(iclient, 0); } - if (!l_iPosition) - { - menu.AddItem("-1", "No results. Commands: !toptime !stages", ITEMDRAW_DISABLED); - } - menu.ExitButton = true; - menu.Display(iclient, 0); } //---------------------------------------------------------------------------------------------------- // Purpose: