moved udp connection socket and fixed invalid handle probably
This commit is contained in:
parent
3afffae783
commit
3b7bf8d3f0
@ -53,12 +53,9 @@ public void OnPluginStart()
|
|||||||
HookEntityOutput("trigger_teleport", "OnTrigger", trigger_teleport);
|
HookEntityOutput("trigger_teleport", "OnTrigger", trigger_teleport);
|
||||||
HookEntityOutput("trigger_teleport", "OnStartTouch", trigger_teleport);
|
HookEntityOutput("trigger_teleport", "OnStartTouch", trigger_teleport);
|
||||||
|
|
||||||
//socket otherwise declare in public OnConfigsExecuted(){}
|
//UDP connection
|
||||||
Handle socket = SocketCreate(SOCKET_UDP, OnSocketError);
|
connect_socket();
|
||||||
SocketSetOption(socket, SocketReuseAddr, 1);
|
|
||||||
SocketBind(socket, "127.0.0.1", 48475);
|
|
||||||
connect(socket);
|
|
||||||
global_socket = socket;
|
|
||||||
reset_target_human_tp_coord();
|
reset_target_human_tp_coord();
|
||||||
targethuman = 0;
|
targethuman = 0;
|
||||||
}
|
}
|
||||||
@ -319,7 +316,7 @@ public Action recursive_pressing(Handle timer, any data)
|
|||||||
if (targeteam == 3)
|
if (targeteam == 3)
|
||||||
{
|
{
|
||||||
float min_distance_target_human = 12800.0;
|
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)
|
if (0 < dist_target <= min_distance_target_human && enemy_distance > min_enemy_distance)
|
||||||
{
|
{
|
||||||
chasing_enemy = true;
|
chasing_enemy = true;
|
||||||
@ -339,8 +336,8 @@ public Action recursive_pressing(Handle timer, any data)
|
|||||||
//zombie aiming for human
|
//zombie aiming for human
|
||||||
float present_bot_coords[3];
|
float present_bot_coords[3];
|
||||||
GetClientAbsOrigin(present, present_bot_coords);
|
GetClientAbsOrigin(present, present_bot_coords);
|
||||||
z_axis = FloatAbs(Pow(present_bot_coords[2] - pos[2], 5.0));
|
z_axis = FloatAbs(Pow(present_bot_coords[2] - pos[2], 2.0));
|
||||||
float z_axis_cap = 10.0;
|
float z_axis_cap = 20.0;
|
||||||
if ((targeteam == 2 && 0 < enemy_distance && z_axis < z_axis_cap) || dist_target == -1.0)
|
if ((targeteam == 2 && 0 < enemy_distance && z_axis < z_axis_cap) || dist_target == -1.0)
|
||||||
{
|
{
|
||||||
chasing_enemy = true;
|
chasing_enemy = true;
|
||||||
@ -685,14 +682,21 @@ public void OnClientPostAdminCheck(int client)
|
|||||||
|
|
||||||
public OnSocketError(Handle socket, const int errorType, const int errorNum, any args)
|
public OnSocketError(Handle socket, const int errorType, const int errorNum, any args)
|
||||||
{
|
{
|
||||||
LogError("[MR] Socket error: %d (errno %d)", errorType, errorNum);
|
CloseHandle(socket);
|
||||||
CreateTimer(120.0, TimerConnect, socket, TIMER_HNDL_CLOSE);
|
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))
|
if (global_socket == INVALID_HANDLE || !SocketIsConnected(global_socket))
|
||||||
SocketConnect(socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, "127.0.0.1", 48475);
|
{
|
||||||
|
//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)
|
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)
|
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)
|
public Action TimerConnect(Handle timer, any arg)
|
||||||
{
|
{
|
||||||
connect(arg);
|
connect_socket();
|
||||||
return Plugin_Handled;
|
return Plugin_Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -745,22 +745,25 @@ public void SQL_SelectTop_Callback(Handle db, Handle results, const char[] error
|
|||||||
}
|
}
|
||||||
Menu menu = new Menu(MenuHandler1);
|
Menu menu = new Menu(MenuHandler1);
|
||||||
menu.SetTitle("Maptimer: %s", g_cMapname);
|
menu.SetTitle("Maptimer: %s", g_cMapname);
|
||||||
while (SQL_GetRowCount(results) > 0 && SQL_FetchRow(results))
|
if (results != INVALID_HANDLE)
|
||||||
{
|
{
|
||||||
l_iPosition++;
|
while (SQL_GetRowCount(results) > 0 && SQL_FetchRow(results))
|
||||||
SQL_FetchString(results, 0, g_cPlayerName, MAX_NAME_LENGTH);
|
{
|
||||||
l_fRecord = SQL_FetchFloat(results, 1);
|
l_iPosition++;
|
||||||
l_iMinutes = RoundToFloor(l_fRecord);
|
SQL_FetchString(results, 0, g_cPlayerName, MAX_NAME_LENGTH);
|
||||||
l_iSeconds = (l_fRecord - l_iMinutes) * 100;
|
l_fRecord = SQL_FetchFloat(results, 1);
|
||||||
Format(g_cContent, sizeof(g_cContent), "#%i: Time: 0%i:%.4f - %s", l_iPosition, l_iMinutes, l_iSeconds, g_cPlayerName);
|
l_iMinutes = RoundToFloor(l_fRecord);
|
||||||
menu.AddItem("-1", g_cContent, ITEMDRAW_DISABLED);
|
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:
|
// Purpose:
|
||||||
|
Loading…
Reference in New Issue
Block a user