just updating plugins to 64bit support
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
"Games"
|
||||
{
|
||||
"#default"
|
||||
{
|
||||
"Keys"
|
||||
{
|
||||
"EngineInterface" "VEngineServer021"
|
||||
}
|
||||
"Signatures"
|
||||
{
|
||||
"CreateInterface"
|
||||
{
|
||||
"library" "engine"
|
||||
"linux" "@CreateInterface"
|
||||
"linux64" "@CreateInterface"
|
||||
"windows" "@CreateInterface"
|
||||
"windows64" "@CreateInterface"
|
||||
}
|
||||
}
|
||||
"Offsets"
|
||||
{
|
||||
"GetPlayerNetInfo"
|
||||
{
|
||||
"linux" "20"
|
||||
"linux64" "20"
|
||||
"windows" "20"
|
||||
"windows64" "20"
|
||||
}
|
||||
}
|
||||
"Functions"
|
||||
{
|
||||
"CGameClient::FileReceived"
|
||||
{
|
||||
"signature" "CGameClient::FileReceived"
|
||||
"callconv" "thiscall"
|
||||
"return" "void"
|
||||
"this" "address"
|
||||
"arguments"
|
||||
{
|
||||
"fileName"
|
||||
{
|
||||
"type" "charptr"
|
||||
}
|
||||
"transferID"
|
||||
{
|
||||
"type" "int"
|
||||
}
|
||||
}
|
||||
}
|
||||
"CGameClient::FileDenied"
|
||||
{
|
||||
"signature" "CGameClient::FileDenied"
|
||||
"callconv" "thiscall"
|
||||
"return" "void"
|
||||
"this" "address"
|
||||
"arguments"
|
||||
{
|
||||
"fileName"
|
||||
{
|
||||
"type" "charptr"
|
||||
}
|
||||
"transferID"
|
||||
{
|
||||
"type" "int"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"cstrike"
|
||||
{
|
||||
"Keys"
|
||||
{
|
||||
"EngineInterface" "VEngineServer023"
|
||||
}
|
||||
"Signatures"
|
||||
{
|
||||
"CNetChan::SendFile"
|
||||
{
|
||||
"library" "engine"
|
||||
"linux" "@_ZN8CNetChan8SendFileEPKcj"
|
||||
"linux64" "@_ZN8CNetChan8SendFileEPKcj"
|
||||
"windows" "\x55\x8B\xEC\x57\x8B\xF9\x8D\x8F\x94\x00\x00\x00\xE8\x2A\x2A\x2A\x2A\x85\xC0\x75\x2A\xB0\x01\x5F\x5D\xC2\x08\x00"
|
||||
"windows64" "\x48\x89\x5C\x24\x08\x48\x89\x74\x24\x10\x57\x48\x83\xEC\x20\x48\x8B\xF9\x41\x8B\xF0\x48\x81\xC1\xC0\x00\x00\x00"
|
||||
// "SendFile: %s (ID %i)\n"
|
||||
}
|
||||
"CNetChan::RequestFile"
|
||||
{
|
||||
"library" "engine"
|
||||
"linux" "@_ZN8CNetChan11RequestFileEPKc"
|
||||
"linux64" "@_ZN8CNetChan11RequestFileEPKc"
|
||||
"windows" "\x55\x8B\xEC\x83\xEC\x14\x53\x8B\xD9\x56\x89\x5D\xF8"
|
||||
"windows64" "\x40\x55\x56\x48\x83\xEC\x28\x44\x8B\x81\xB8\x04\x00\x00"
|
||||
// "RequestFile: %s (ID %i)\n"
|
||||
}
|
||||
"CNetChan::IsFileInWaitingList"
|
||||
{
|
||||
"library" "engine"
|
||||
"linux" "@_ZN8CNetChan19IsFileInWaitingListEPKc"
|
||||
"linux64" "@_ZN8CNetChan19IsFileInWaitingListEPKc"
|
||||
// "CreateFragmentsFromFile: '%s' doesn't e" -> CNetChan::CreateFragmentsFromFile
|
||||
// Top Call -> CNetChan::IsFileInWaitingList
|
||||
}
|
||||
"CNetChan::CreateFragmentsFromFile"
|
||||
{
|
||||
"library" "engine"
|
||||
"windows" "\x55\x8B\xEC\x83\xEC\x0C\x53\x8B\x5D\x08\x8B\xD1"
|
||||
"windows64" "\x48\x89\x5C\x24\x08\x48\x89\x6C\x24\x18\x56\x57\x41\x54\x41\x56\x41\x57\x48\x83\xEC\x20\x4D\x63\xF8"
|
||||
// "CreateFragmentsFromFile: '%s' doesn't e"
|
||||
}
|
||||
"CGameClient::FileReceived"
|
||||
{
|
||||
"library" "engine"
|
||||
"linux" "\x55\x31\xC0\x89\xE5\x53\x8B\x55\x08\x8B\x5D\x0C\x8B\x4D\x10\x39\x8C\xC2\xA4\x00\x00\x00"
|
||||
"linux64" "\x48\x8D\x87\xC0\x00\x00\x00\x48\x8D\x8F\xE0\x00\x00\x00"
|
||||
// cant use base words, need full sig for linux.
|
||||
//"@_ZN11CGameClient12FileReceivedEPKcj"
|
||||
"windows" "\x55\x8B\xEC\x56\x8B\x75\x0C\x33\xD2\x57\x8B\xF9"
|
||||
"windows64" "\x4C\x8B\xD2\x48\x8D\x81\xB8\x00\x00\x00"
|
||||
// "CGameClient::FileReceived: %s not wanted.\n"
|
||||
}
|
||||
"CGameClient::FileDenied"
|
||||
{
|
||||
"library" "engine"
|
||||
"linux" "@_ZN11CGameClient10FileDeniedEPKcj"
|
||||
"linux64" "@_ZN11CGameClient10FileDeniedEPKcj"
|
||||
"windows" "\x55\x8B\xEC\x8B\x01\xFF\x50\x44\x50\xFF\x75\x08\x68"
|
||||
"windows64" "\x40\x53\x48\x83\xEC\x20\x48\x8B\x01\x48\x8B\xDA\xFF\x90\x88\x00\x00\x00\x48\x8B\xD3\x48\x8D\x0D\x14\x56\x26\x00"
|
||||
// "Downloading file '%s' from client %s failed.\n"
|
||||
}
|
||||
"CBaseClient::GetNetChannel"
|
||||
{
|
||||
"library" "engine"
|
||||
"linux" "@_ZN11CBaseClient13GetNetChannelEv"
|
||||
"linux64" "@_ZN11CBaseClient13GetNetChannelEv"
|
||||
"windows" "\x8B\x81\xC0\x00\x00\x00"
|
||||
"windows64" "\x48\x8B\x81\xD8\x00\x00\x00\xC3"
|
||||
// Good Luck
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,714 @@
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
#include <dhooks>
|
||||
|
||||
#pragma semicolon 1
|
||||
#pragma newdecls required
|
||||
|
||||
#define PLUGIN_VERSION "manual"
|
||||
|
||||
#define TIMEOUT_PERIOD 90 // How long until we consider a requested file to be timed out
|
||||
|
||||
enum struct FileEnum
|
||||
{
|
||||
int Client;
|
||||
char Filename[PLATFORM_MAX_PATH];
|
||||
Handle Plugin;
|
||||
Function Func;
|
||||
any Data;
|
||||
|
||||
int Id;
|
||||
int Timeout;
|
||||
}
|
||||
|
||||
Handle SDKGetPlayerNetInfo;
|
||||
Handle SDKSendFile;
|
||||
Handle SDKRequestFile;
|
||||
Handle SDKIsFileInWaitingList;
|
||||
Handle SDKCreateFragmentsFromFile;
|
||||
Handle SDKGetNetChannel;
|
||||
Address EngineAddress;
|
||||
ConVar CvarMaxFileSize;
|
||||
|
||||
// Sending
|
||||
int TransferID;
|
||||
ArrayList SendListing;
|
||||
Handle SendingTimer[MAXPLAYERS+1];
|
||||
char CurrentlySending[MAXPLAYERS+1][PLATFORM_MAX_PATH];
|
||||
|
||||
// Requesting
|
||||
ArrayList RequestListing;
|
||||
Handle RequestingTimer[MAXPLAYERS+1];
|
||||
int CurrentlyRequesting[MAXPLAYERS+1] = {-1, ...};
|
||||
int FailRequestingAt[MAXPLAYERS+1];
|
||||
|
||||
// CNetChan pointers are handled as Address (int64 on SourceMod 1.13 x64 builds).
|
||||
// SDKType_Address return values are written into the Address variable passed right after
|
||||
// the |this| pointer (or as the first argument for static calls).
|
||||
Address GetNetChan(int client)
|
||||
{
|
||||
Address chan = Address_Null;
|
||||
SDKCall(SDKGetPlayerNetInfo, EngineAddress, chan, client);
|
||||
return chan;
|
||||
}
|
||||
|
||||
Address GetNetChannelOfClient(Address baseClient)
|
||||
{
|
||||
Address chan = Address_Null;
|
||||
SDKCall(SDKGetNetChannel, baseClient, chan);
|
||||
return chan;
|
||||
}
|
||||
|
||||
bool NetChan_SendFile(Address chan, const char[] filename)
|
||||
{
|
||||
return SDKCall(SDKSendFile, chan, filename, TransferID++);
|
||||
}
|
||||
|
||||
int NetChan_RequestFile(Address chan, const char[] filename)
|
||||
{
|
||||
int id = SDKCall(SDKRequestFile, chan, filename);
|
||||
return id;
|
||||
}
|
||||
|
||||
bool NetChan_IsFileInWaitingList(Address chan, const char[] filename)
|
||||
{
|
||||
bool result;
|
||||
|
||||
if(SDKIsFileInWaitingList)
|
||||
{
|
||||
result = SDKCall(SDKIsFileInWaitingList, chan, filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
int value = CvarMaxFileSize.IntValue;
|
||||
CvarMaxFileSize.IntValue = -1;
|
||||
result = SDKCall(SDKCreateFragmentsFromFile, chan, filename, 0, 0);
|
||||
CvarMaxFileSize.IntValue = value;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "File Network",
|
||||
author = "Batfoxkid, Artvin",
|
||||
description = "But what if, no loading screen",
|
||||
version = PLUGIN_VERSION,
|
||||
url = "github.com/Batfoxkid/File-Network"
|
||||
}
|
||||
|
||||
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
|
||||
{
|
||||
CreateNative("FileNet_SendFile", Native_SendFile);
|
||||
CreateNative("FileNet_RequestFile", Native_RequestFile);
|
||||
CreateNative("FileNet_IsFileInWaitingList", Native_IsFileInWaitingList);
|
||||
CreateNative("FileNet_GetNetChanPtr", Native_GetNetChanPtr);
|
||||
|
||||
RegPluginLibrary("filenetwork");
|
||||
return APLRes_Success;
|
||||
}
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
GameData gamedata = new GameData("filenetwork");
|
||||
|
||||
char identifier[64];
|
||||
if(!gamedata.GetKeyValue("EngineInterface", identifier, sizeof(identifier)))
|
||||
SetFailState("[Gamedata] Could not find EngineInterface");
|
||||
|
||||
StartPrepSDKCall(SDKCall_Static);
|
||||
PrepSDKCall_SetFromConf(gamedata, SDKConf_Signature, "CreateInterface");
|
||||
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
|
||||
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Pointer, VDECODE_FLAG_ALLOWNULL);
|
||||
PrepSDKCall_SetReturnInfo(SDKType_Address, SDKPass_Plain);
|
||||
Handle sdkcall = EndPrepSDKCall();
|
||||
if(!sdkcall)
|
||||
SetFailState("[Gamedata] Could not find CreateInterface");
|
||||
|
||||
EngineAddress = Address_Null;
|
||||
SDKCall(sdkcall, EngineAddress, identifier, 0);
|
||||
if(EngineAddress == Address_Null)
|
||||
SetFailState("[Gamedata] EngineInterface is incorrect for mod");
|
||||
|
||||
delete sdkcall;
|
||||
|
||||
bool failed;
|
||||
|
||||
StartPrepSDKCall(SDKCall_Raw);
|
||||
PrepSDKCall_SetFromConf(gamedata, SDKConf_Virtual, "GetPlayerNetInfo");
|
||||
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
|
||||
PrepSDKCall_SetReturnInfo(SDKType_Address, SDKPass_Plain);
|
||||
SDKGetPlayerNetInfo = EndPrepSDKCall();
|
||||
if(!SDKGetPlayerNetInfo)
|
||||
{
|
||||
LogError("[Gamedata] Could not find GetPlayerNetInfo");
|
||||
failed = true;
|
||||
}
|
||||
|
||||
StartPrepSDKCall(SDKCall_Raw);
|
||||
PrepSDKCall_SetFromConf(gamedata, SDKConf_Signature, "CNetChan::SendFile");
|
||||
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
|
||||
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
|
||||
PrepSDKCall_SetReturnInfo(SDKType_Bool, SDKPass_ByValue);
|
||||
SDKSendFile = EndPrepSDKCall();
|
||||
if(!SDKSendFile)
|
||||
{
|
||||
LogError("[Gamedata] Could not find CNetChan::SendFile");
|
||||
failed = true;
|
||||
}
|
||||
|
||||
StartPrepSDKCall(SDKCall_Raw);
|
||||
PrepSDKCall_SetFromConf(gamedata, SDKConf_Signature, "CNetChan::RequestFile");
|
||||
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
|
||||
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_ByValue);
|
||||
SDKRequestFile = EndPrepSDKCall();
|
||||
if(!SDKRequestFile)
|
||||
{
|
||||
LogError("[Gamedata] Could not find CNetChan::RequestFile");
|
||||
failed = true;
|
||||
}
|
||||
|
||||
StartPrepSDKCall(SDKCall_Raw);
|
||||
PrepSDKCall_SetFromConf(gamedata, SDKConf_Signature, "CNetChan::IsFileInWaitingList");
|
||||
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
|
||||
PrepSDKCall_SetReturnInfo(SDKType_Bool, SDKPass_ByValue);
|
||||
SDKIsFileInWaitingList = EndPrepSDKCall();
|
||||
if(!SDKIsFileInWaitingList)
|
||||
{
|
||||
CvarMaxFileSize = FindConVar("net_maxfilesize");
|
||||
if(!CvarMaxFileSize)
|
||||
{
|
||||
LogError("[Game] Could not find net_maxfilesize");
|
||||
failed = true;
|
||||
}
|
||||
|
||||
StartPrepSDKCall(SDKCall_Raw);
|
||||
PrepSDKCall_SetFromConf(gamedata, SDKConf_Signature, "CNetChan::CreateFragmentsFromFile");
|
||||
PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer);
|
||||
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
|
||||
PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
|
||||
PrepSDKCall_SetReturnInfo(SDKType_Bool, SDKPass_ByValue);
|
||||
SDKCreateFragmentsFromFile = EndPrepSDKCall();
|
||||
if(!SDKCreateFragmentsFromFile)
|
||||
{
|
||||
LogError("[Gamedata] Could not find CNetChan::IsFileInWaitingList or CNetChan::CreateFragmentsFromFile");
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
StartPrepSDKCall(SDKCall_Raw);
|
||||
PrepSDKCall_SetFromConf(gamedata, SDKConf_Signature, "CBaseClient::GetNetChannel");
|
||||
PrepSDKCall_SetReturnInfo(SDKType_Address, SDKPass_Plain);
|
||||
SDKGetNetChannel = EndPrepSDKCall();
|
||||
if(!SDKGetNetChannel)
|
||||
{
|
||||
LogError("[Gamedata] Could not find CBaseClient::GetNetChannel");
|
||||
failed = true;
|
||||
}
|
||||
|
||||
DynamicDetour detour = DynamicDetour.FromConf(gamedata, "CGameClient::FileReceived");
|
||||
if(detour)
|
||||
{
|
||||
if(!detour.Enable(Hook_Post, OnFileReceived))
|
||||
{
|
||||
LogError("[Gamedata] Failed to enable detour: CGameClient::FileReceived");
|
||||
failed = true;
|
||||
}
|
||||
|
||||
delete detour;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogError("[Gamedata] Could not find CGameClient::FileReceived");
|
||||
failed = true;
|
||||
}
|
||||
|
||||
detour = DynamicDetour.FromConf(gamedata, "CGameClient::FileDenied");
|
||||
if(detour)
|
||||
{
|
||||
if(!detour.Enable(Hook_Post, OnFileDenied))
|
||||
{
|
||||
LogError("[Gamedata] Failed to enable detour: CGameClient::FileDenied");
|
||||
failed = true;
|
||||
}
|
||||
|
||||
delete detour;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogError("[Gamedata] Could not find CGameClient::FileDenied");
|
||||
failed = true;
|
||||
}
|
||||
|
||||
if(failed)
|
||||
ThrowError("Gamedata failed, see error logs");
|
||||
|
||||
SendListing = new ArrayList(sizeof(FileEnum));
|
||||
RequestListing = new ArrayList(sizeof(FileEnum));
|
||||
RegAdminCmd("sm_filenet_send", Command_TestSend, ADMFLAG_ROOT, "Test using send file");
|
||||
RegAdminCmd("sm_filenet_request", Command_TestRequest, ADMFLAG_ROOT, "Test using request file");
|
||||
}
|
||||
|
||||
public Action Command_TestSend(int client, int args)
|
||||
{
|
||||
char buffer[PLATFORM_MAX_PATH];
|
||||
GetCmdArgString(buffer, sizeof(buffer));
|
||||
ReplaceString(buffer, sizeof(buffer), "\"", "");
|
||||
|
||||
Address chan = GetNetChan(client);
|
||||
if(chan == Address_Null)
|
||||
{
|
||||
ReplyToCommand(client, "Address invalid");
|
||||
}
|
||||
else if(NetChan_IsFileInWaitingList(chan, buffer))
|
||||
{
|
||||
ReplyToCommand(client, "File already in waiting list");
|
||||
}
|
||||
else if(NetChan_SendFile(chan, buffer))
|
||||
{
|
||||
ReplyToCommand(client, "Sent file to client");
|
||||
}
|
||||
else
|
||||
{
|
||||
ReplyToCommand(client, "File failed to send");
|
||||
}
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action Command_TestRequest(int client, int args)
|
||||
{
|
||||
char buffer[PLATFORM_MAX_PATH];
|
||||
GetCmdArgString(buffer, sizeof(buffer));
|
||||
ReplaceString(buffer, sizeof(buffer), "\"", "");
|
||||
|
||||
Address chan = GetNetChan(client);
|
||||
if(chan == Address_Null)
|
||||
{
|
||||
ReplyToCommand(client, "Address invalid");
|
||||
}
|
||||
else
|
||||
{
|
||||
NetChan_RequestFile(chan, buffer);
|
||||
ReplyToCommand(client, "Requested file from client");
|
||||
}
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public void OnClientDisconnect_Post(int client)
|
||||
{
|
||||
static FileEnum info;
|
||||
|
||||
int match = -1;
|
||||
while((match = SendListing.FindValue(client, FileEnum::Client)) != -1)
|
||||
{
|
||||
SendListing.GetArray(match, info);
|
||||
SendListing.Erase(match);
|
||||
|
||||
CallSentFileFinish(info, false);
|
||||
}
|
||||
|
||||
match = -1;
|
||||
while((match = RequestListing.FindValue(client, FileEnum::Client)) != -1)
|
||||
{
|
||||
RequestListing.GetArray(match, info);
|
||||
RequestListing.Erase(match);
|
||||
|
||||
CallRequestFileFinish(info, false);
|
||||
}
|
||||
|
||||
delete SendingTimer[client];
|
||||
CurrentlySending[client][0] = 0;
|
||||
|
||||
delete RequestingTimer[client];
|
||||
CurrentlyRequesting[client] = -1;
|
||||
}
|
||||
|
||||
public void OnNotifyPluginUnloaded(Handle plugin)
|
||||
{
|
||||
int match = -1;
|
||||
while((match = SendListing.FindValue(plugin, FileEnum::Plugin)) != -1)
|
||||
{
|
||||
SendListing.Erase(match);
|
||||
}
|
||||
|
||||
match = -1;
|
||||
while((match = RequestListing.FindValue(plugin, FileEnum::Plugin)) != -1)
|
||||
{
|
||||
RequestListing.Erase(match);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Requesting Files
|
||||
*/
|
||||
|
||||
public MRESReturn OnFileReceived(Address address, DHookParam param)
|
||||
{
|
||||
int id = param.Get(2);
|
||||
Address chan = GetNetChannelOfClient(address);
|
||||
|
||||
int length = RequestListing.Length;
|
||||
for(int i; i < length; i++)
|
||||
{
|
||||
static FileEnum info;
|
||||
RequestListing.GetArray(i, info);
|
||||
if(info.Id == id && chan == GetNetChan(info.Client))
|
||||
{
|
||||
if(CurrentlyRequesting[info.Client] == id)
|
||||
CurrentlyRequesting[info.Client] = -1;
|
||||
|
||||
RequestListing.Erase(i);
|
||||
CallRequestFileFinish(info, true);
|
||||
|
||||
delete RequestingTimer[info.Client];
|
||||
SendNextRequest(info.Client);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
return MRES_Ignored;
|
||||
}
|
||||
|
||||
public MRESReturn OnFileDenied(Address address, DHookParam param)
|
||||
{
|
||||
int id = param.Get(2);
|
||||
Address chan = GetNetChannelOfClient(address);
|
||||
|
||||
int length = RequestListing.Length;
|
||||
for(int i; i < length; i++)
|
||||
{
|
||||
static FileEnum info;
|
||||
RequestListing.GetArray(i, info);
|
||||
if(info.Id == id && chan == GetNetChan(info.Client))
|
||||
{
|
||||
if(CurrentlyRequesting[info.Client] == id)
|
||||
CurrentlyRequesting[info.Client] = -1;
|
||||
|
||||
RequestListing.Erase(i);
|
||||
CallRequestFileFinish(info, false);
|
||||
|
||||
delete RequestingTimer[info.Client];
|
||||
SendNextRequest(info.Client);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
return MRES_Ignored;
|
||||
}
|
||||
|
||||
void StartRequestingClient(int client)
|
||||
{
|
||||
// Small delay between requesting files, Linux Server issue
|
||||
if(!RequestingTimer[client])
|
||||
RequestingTimer[client] = CreateTimer(1.5, Timer_RequestingClient, client, TIMER_REPEAT);
|
||||
}
|
||||
|
||||
void SendNextRequest(int client)
|
||||
{
|
||||
if(CurrentlyRequesting[client] == -1)
|
||||
{
|
||||
Address chan = GetNetChan(client);
|
||||
if(chan != Address_Null)
|
||||
{
|
||||
int length = RequestListing.Length;
|
||||
for(int i; i < length; i++)
|
||||
{
|
||||
static FileEnum info;
|
||||
RequestListing.GetArray(i, info);
|
||||
if(info.Client == client)
|
||||
{
|
||||
info.Id = NetChan_RequestFile(chan, info.Filename);
|
||||
RequestListing.SetArray(i, info);
|
||||
|
||||
CurrentlyRequesting[client] = info.Id;
|
||||
FailRequestingAt[client] = GetTime() + info.Timeout;
|
||||
StartRequestingClient(client);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
StartRequestingClient(client);
|
||||
}
|
||||
}
|
||||
|
||||
public Action Timer_RequestingClient(Handle timer, int client)
|
||||
{
|
||||
if(CurrentlyRequesting[client] == -1)
|
||||
{
|
||||
SendNextRequest(client);
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
// Client still giving this file
|
||||
if(FailRequestingAt[client] > GetTime())
|
||||
return Plugin_Continue;
|
||||
|
||||
/*
|
||||
We timed out!
|
||||
|
||||
1. This can be a case of the client getting stuck from too many missing file requests.
|
||||
2. A Linux server may not get the notice that the file was missing on the client.
|
||||
|
||||
Request a different file that exists to fix issue 1,
|
||||
fail and return the callback to fix issue 2.
|
||||
*/
|
||||
|
||||
Address chan = GetNetChan(client);
|
||||
if(chan == Address_Null)
|
||||
return Plugin_Continue;
|
||||
|
||||
static FileEnum info;
|
||||
int length = RequestListing.Length;
|
||||
for(int i; i < length; i++)
|
||||
{
|
||||
RequestListing.GetArray(i, info);
|
||||
if(info.Id == CurrentlyRequesting[client] && info.Client == client)
|
||||
{
|
||||
CurrentlyRequesting[info.Client] = -1;
|
||||
|
||||
RequestListing.Erase(i);
|
||||
CallRequestFileFinish(info, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(info.Plugin == null)
|
||||
{
|
||||
// We already tried unstucking with this method, don't try it again
|
||||
SendNextRequest(client);
|
||||
}
|
||||
else
|
||||
{
|
||||
DeleteFile("download/scripts/cheatcodes.txt");
|
||||
|
||||
info.Plugin = null;
|
||||
info.Client = client;
|
||||
strcopy(info.Filename, sizeof(info.Filename), "scripts/cheatcodes.txt");
|
||||
info.Func = INVALID_FUNCTION;
|
||||
info.Id = NetChan_RequestFile(chan, info.Filename);
|
||||
info.Timeout = 30;
|
||||
RequestListing.PushArray(info);
|
||||
|
||||
CurrentlyRequesting[client] = info.Id;
|
||||
FailRequestingAt[client] = GetTime() + info.Timeout;
|
||||
}
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
static void CallRequestFileFinish(const FileEnum info, bool success)
|
||||
{
|
||||
if(info.Func && info.Func != INVALID_FUNCTION)
|
||||
{
|
||||
Call_StartFunction(info.Plugin, info.Func);
|
||||
Call_PushCell(info.Client);
|
||||
Call_PushString(info.Filename);
|
||||
Call_PushCell(info.Id);
|
||||
Call_PushCell(success);
|
||||
Call_PushCell(info.Data);
|
||||
Call_Finish();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Sending Files
|
||||
*/
|
||||
|
||||
void StartSendingClient(int client)
|
||||
{
|
||||
if(!SendingTimer[client])
|
||||
{
|
||||
SendingTimer[client] = CreateTimer(0.1, Timer_SendingClient, client, TIMER_REPEAT);
|
||||
TriggerTimer(SendingTimer[client]);
|
||||
}
|
||||
}
|
||||
|
||||
public Action Timer_SendingClient(Handle timer, int client)
|
||||
{
|
||||
Address chan = GetNetChan(client);
|
||||
if(chan == Address_Null)
|
||||
return Plugin_Continue;
|
||||
|
||||
if(CurrentlySending[client][0])
|
||||
{
|
||||
// Client still downloading this file
|
||||
if(NetChan_IsFileInWaitingList(chan, CurrentlySending[client]))
|
||||
{
|
||||
return Plugin_Continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// We finished this file
|
||||
int length = SendListing.Length;
|
||||
for(int i; i < length; i++)
|
||||
{
|
||||
static FileEnum info;
|
||||
SendListing.GetArray(i, info);
|
||||
if(info.Client == client && StrEqual(info.Filename, CurrentlySending[client], false))
|
||||
{
|
||||
SendListing.Erase(i);
|
||||
CallSentFileFinish(info, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CurrentlySending[client][0] = 0;
|
||||
}
|
||||
|
||||
int length = SendListing.Length;
|
||||
for(int i; i < length; i++)
|
||||
{
|
||||
static FileEnum info;
|
||||
SendListing.GetArray(i, info);
|
||||
if(info.Client == client)
|
||||
{
|
||||
if(NetChan_SendFile(chan, info.Filename))
|
||||
{
|
||||
strcopy(CurrentlySending[client], sizeof(CurrentlySending[]), info.Filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Failed reasons tend to be bad names, bad sizes, etc.
|
||||
SendListing.Erase(i);
|
||||
CallSentFileFinish(info, false);
|
||||
}
|
||||
|
||||
return Plugin_Continue;
|
||||
}
|
||||
}
|
||||
|
||||
// No more files to send
|
||||
SendingTimer[client] = null;
|
||||
return Plugin_Stop;
|
||||
}
|
||||
|
||||
static void CallSentFileFinish(const FileEnum info, bool success)
|
||||
{
|
||||
if(info.Func && info.Func != INVALID_FUNCTION)
|
||||
{
|
||||
Call_StartFunction(info.Plugin, info.Func);
|
||||
Call_PushCell(info.Client);
|
||||
Call_PushString(info.Filename);
|
||||
Call_PushCell(success);
|
||||
Call_PushCell(info.Data);
|
||||
Call_Finish();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Natives
|
||||
*/
|
||||
|
||||
void StartNative()
|
||||
{
|
||||
if(!SendListing)
|
||||
ThrowNativeError(SP_ERROR_NATIVE, "Please wait until OnAllPluginsLoaded");
|
||||
}
|
||||
|
||||
int GetNativeClient(int param)
|
||||
{
|
||||
int client = GetNativeCell(param);
|
||||
if(client < 1 || client > MaxClients)
|
||||
ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index %d", client);
|
||||
|
||||
if(!IsClientInGame(client))
|
||||
ThrowNativeError(SP_ERROR_NATIVE, "Client %d is not in-game", client);
|
||||
|
||||
if(IsFakeClient(client))
|
||||
ThrowNativeError(SP_ERROR_NATIVE, "Client %d is a bot player", client);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
bool FileExistsForClient(int client, const char[] filename)
|
||||
{
|
||||
int length = SendListing.Length;
|
||||
for(int i; i < length; i++)
|
||||
{
|
||||
static FileEnum info;
|
||||
SendListing.GetArray(i, info);
|
||||
if(info.Client == client)
|
||||
{
|
||||
if(StrEqual(info.Filename, filename, false))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public any Native_SendFile(Handle plugin, int params)
|
||||
{
|
||||
StartNative();
|
||||
|
||||
FileEnum info;
|
||||
info.Client = GetNativeClient(1);
|
||||
GetNativeString(2, info.Filename, sizeof(info.Filename));
|
||||
|
||||
info.Plugin = plugin;
|
||||
info.Func = GetNativeFunction(3);
|
||||
info.Data = GetNativeCell(4);
|
||||
|
||||
SendListing.PushArray(info);
|
||||
|
||||
StartSendingClient(info.Client);
|
||||
return true;
|
||||
}
|
||||
|
||||
public any Native_RequestFile(Handle plugin, int params)
|
||||
{
|
||||
StartNative();
|
||||
|
||||
FileEnum info;
|
||||
info.Client = GetNativeClient(1);
|
||||
GetNativeString(2, info.Filename, sizeof(info.Filename));
|
||||
|
||||
info.Plugin = plugin;
|
||||
info.Func = GetNativeFunction(3);
|
||||
info.Data = GetNativeCell(4);
|
||||
info.Timeout = params < 5 ? TIMEOUT_PERIOD : GetNativeCell(5);
|
||||
|
||||
RequestListing.PushArray(info);
|
||||
|
||||
StartRequestingClient(info.Client);
|
||||
return CurrentlyRequesting[info.Client];
|
||||
}
|
||||
|
||||
public any Native_IsFileInWaitingList(Handle plugin, int params)
|
||||
{
|
||||
StartNative();
|
||||
|
||||
int client = GetNativeCell(1);
|
||||
|
||||
if(SendingTimer[client]) // Just to double check with CNetChan::IsFileInWaitingList
|
||||
TriggerTimer(SendingTimer[client], true);
|
||||
|
||||
int length;
|
||||
GetNativeStringLength(2, length);
|
||||
char[] filename = new char[++length];
|
||||
GetNativeString(2, filename, length);
|
||||
|
||||
return FileExistsForClient(client, filename);
|
||||
}
|
||||
|
||||
public any Native_GetNetChanPtr(Handle plugin, int params)
|
||||
{
|
||||
StartNative();
|
||||
|
||||
int client = GetNativeCell(1);
|
||||
|
||||
Address chan = GetNetChan(client);
|
||||
|
||||
// Address is 64-bit, which doesn't fit in a native's return value.
|
||||
// Write it into the caller's Address variable instead (2 cells, little endian).
|
||||
int parts[2];
|
||||
parts[0] = view_as<int>(chan & view_as<Address>(0xFFFFFFFF));
|
||||
parts[1] = view_as<int>(chan >> 32);
|
||||
SetNativeArray(2, parts, 2);
|
||||
|
||||
return chan != Address_Null;
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
#if defined _filenetwork_included
|
||||
#endinput
|
||||
#endif
|
||||
#define _filenetwork_included
|
||||
|
||||
#pragma semicolon 1
|
||||
#pragma newdecls required
|
||||
|
||||
/**
|
||||
* Called when file sending is finished
|
||||
*/
|
||||
typeset FileNet_SendFileResult
|
||||
{
|
||||
/**
|
||||
* @param client Client index
|
||||
* @param file Filepath of sent file
|
||||
* @param success If the file was sent
|
||||
* @param data Value that was passed
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
function void(int client, const char[] file, bool success, any data);
|
||||
|
||||
/**
|
||||
* @param client Client index
|
||||
* @param file Filepath of sent file
|
||||
* @param success If the file was sent
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
function void(int client, const char[] file, bool success);
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when file request is finished
|
||||
*/
|
||||
typeset FileNet_RequestFileResult
|
||||
{
|
||||
/**
|
||||
* @note May be written to the downloads folder
|
||||
*
|
||||
* @param client Client index
|
||||
* @param file Filepath of requested file
|
||||
* @param id Request ID
|
||||
* @param success If the file was sent
|
||||
* @param data Value that was passed
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
function void(int client, const char[] file, int id, bool success, any data);
|
||||
|
||||
/**
|
||||
* @note May be written to the downloads folder
|
||||
*
|
||||
* @param client Client index
|
||||
* @param file Filepath of requested file
|
||||
* @param id Request ID
|
||||
* @param success If the file was sent
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
function void(int client, const char[] file, int id, bool success);
|
||||
};
|
||||
|
||||
/**
|
||||
* If a file is currently in queue for that client
|
||||
*
|
||||
* @param client Client index
|
||||
* @param file Filepath of sent file
|
||||
*
|
||||
* @return True if the file in is queue, false otherwise
|
||||
*/
|
||||
native bool FileNet_IsFileInWaitingList(int client, const char[] file);
|
||||
|
||||
/**
|
||||
* Adds a file in a queue to be sent over to the client
|
||||
*
|
||||
* @param client Client index
|
||||
* @param file Filepath of sent file
|
||||
* @param callback Optional callback when file is done
|
||||
* @param data Optional value to pass to the callback function
|
||||
*
|
||||
* @error Invalid client index, client is not in game, or a fake client
|
||||
*
|
||||
* @return True if the file is now queued to be sent, false otherwise
|
||||
*/
|
||||
native bool FileNet_SendFile(int client, const char[] file, FileNet_SendFileResult callback = INVALID_FUNCTION, any data = 0);
|
||||
|
||||
/**
|
||||
* Requests a file to be sent from the client
|
||||
*
|
||||
* @param client Client index
|
||||
* @param file Filepath of requested file
|
||||
* @param callback Optional callback when file is done
|
||||
* @param data Optional value to pass to the callback function
|
||||
* @param timeout Timeout period in seconds
|
||||
*
|
||||
* @error Invalid client index, client is not in game, or a fake client
|
||||
*
|
||||
* @noreturn
|
||||
*/
|
||||
native void FileNet_RequestFile(int client, const char[] file, FileNet_RequestFileResult callback = INVALID_FUNCTION, any data = 0, int timeout = 90);
|
||||
|
||||
/**
|
||||
* Gets the CNetChan object of a specific client
|
||||
*
|
||||
* @param client Client index
|
||||
* @param chan Address variable that receives the CNetChan object, Address_Null if none.
|
||||
* (Address is 64-bit on x64 SourceMod, so it is returned by reference.)
|
||||
*
|
||||
* @return True if the client has a CNetChan object, false otherwise
|
||||
*/
|
||||
native bool FileNet_GetNetChanPtr(int client, Address &chan);
|
||||
|
||||
public SharedPlugin __pl_filenetwork =
|
||||
{
|
||||
name = "filenetwork",
|
||||
file = "filenetwork.smx",
|
||||
#if defined REQUIRE_PLUGIN
|
||||
required = 1,
|
||||
#else
|
||||
required = 0,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if !defined REQUIRE_PLUGIN
|
||||
public void __pl_filenetwork_SetNTVOptional()
|
||||
{
|
||||
MarkNativeAsOptional("FileNet_SendFile");
|
||||
MarkNativeAsOptional("FileNet_IsFileInWaitingList");
|
||||
MarkNativeAsOptional("FileNet_RequestFile");
|
||||
MarkNativeAsOptional("FileNet_GetNetChanPtr");
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user