Raised This Month: $51 Target: $400
 12% 

Error 147 Help me


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shazam
Junior Member
Join Date: Feb 2021
Old 04-20-2021 , 21:41   Error 147 Help me
Reply With Quote #1

PHP Code:
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <socket>

#define PLUGIN_VERSION "0.9.9"
#define PLUGIN_DESCRIPTION "Provides live server info with join option"
#define MAX_SERVERS 10
#define REFRESH_TIME 60.0
#define SERVER_TIMEOUT 10.0
#define MAX_STR_LEN 160
#define MAX_INFO_LEN 200

int
    g_iServerCount
,
    
g_iAdvertCount,
    
g_iAdvertInterval 1,
    
g_iServerPort[MAX_SERVERS];
char
    g_sServerName
[MAX_SERVERS][MAX_STR_LEN],
    
g_sServerAddress[MAX_SERVERS][MAX_STR_LEN],
    
g_sServerInfo[MAX_SERVERS][MAX_INFO_LEN],
    
g_sAddress[MAXPLAYERS+1][MAX_STR_LEN],
    
g_sServer[MAXPLAYERS+1][MAX_INFO_LEN];
bool
    g_bSocketError
[MAX_SERVERS],
    
g_bConnectedFromFavorites[MAXPLAYERS+1],
    
g_bLateLoad,
    
g_bCoolDown;
Handle
    g_hSocket
[MAX_SERVERS];
ConVar
    g_cvarHopTrigger
,
    
g_cvarServerFormat,
    
g_cvarBroadcastHops,
    
g_cvarAdvert,
    
g_cvarAdvert_Interval;

public 
Plugin myinfo = {
    
name "Server Hop",
    
author "[GRAVE] rig0r, JoinedSenses",
    
description PLUGIN_DESCRIPTION,
    
version PLUGIN_VERSION,
    
url "https://github.com/JoinedSenses/TF2-ServerHop"
};

public 
APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max) {
    if (
GetEngineVersion() == Engine_CSGO) {
        
strcopy(errorerr_max"ServerHop is incompatible with this game");
        return 
APLRes_SilentFailure;        
    }

    
g_bLateLoad late;
    return 
APLRes_Success;
}

public 
void OnPluginStart() {
    
LoadTranslations("serverhop.phrases");

    
CreateConVar("sm_serverhop_version"PLUGIN_VERSIONPLUGIN_DESCRIPTIONFCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD).SetString(PLUGIN_VERSION);
  
// convar setup
    
g_cvarHopTrigger CreateConVar(
        
"sm_hop_trigger",
        
"!servers",
        
"What players have to type in chat to activate the plugin (besides !hop)"
    
);
    
g_cvarServerFormat CreateConVar(
        
"sm_hop_serverformat",
        
"%name - %map (%numplayers/%maxplayers)",
        
"Defines how the server info should be presented"
    
);
    
g_cvarBroadcastHops CreateConVar(
        
"sm_hop_broadcasthops",
        
"1",
        
"Set to 1 if you want a broadcast message when a player hops to another server"
    
);
    
g_cvarAdvert CreateConVar(
        
"sm_hop_advertise",
        
"1",
        
"Set to 1 to enable server advertisements"
    
);
    
g_cvarAdvert_Interval CreateConVar(
        
"sm_hop_advertisement_interval",
        
"1",
        
"Advertisement interval: advertise a server every x minute(s)"
    
);

    
AutoExecConfig(true"plugin.serverhop");

    
Handle timer CreateTimer(REFRESH_TIMERefreshServerInfo_TIMER_REPEAT);

    
RegConsoleCmd("say"Command_Say);
    
RegConsoleCmd("say_team"Command_Say);
    
RegConsoleCmd("sm_hop"Command_Hop"Hop servers.");
    
RegConsoleCmd("sm_servers"Command_Servers"Hop servers.");

    
char path[MAX_STR_LEN];

    
BuildPath(Path_SMpathsizeof(path), "configs/serverhop.cfg");
    
KeyValues kv = new KeyValues("Servers");

    if (!
kv.ImportFromFile(path)) {
        
LogToGame("Error loading server list");
        
SetFailState("Unable to import server list from file.");
    }

    
int i;
    
kv.Rewind();
    if (!
kv.GotoFirstSubKey()) {
        
SetFailState("Unable to find first server in file.");    
    }
    
    do {
        
kv.GetSectionName(g_sServerName[i], MAX_STR_LEN);
        
kv.GetString("address"g_sServerAddress[i], MAX_STR_LEN);
        
g_iServerPort[i] = kv.GetNum("port"27015);
    } while (++
MAX_SERVERS && kv.GotoNextKey());

    if (
== MAX_SERVERS && kv.GotoNextKey()) {
        
LogError("You have exceeded the cap for max servers of %i. To add more, edit the value of MAX_SERVERS and recompile."MAX_SERVERS);
    }

    
delete kv;
    
    
g_iServerCount i;

    
TriggerTimer(timer);
    
    if (
g_bLateLoad) {
        
char clientConnectMethod[64];
        for (
int client 1client <= MaxClientsclient++) {
            if (
IsClientInGame(client) && !IsFakeClient(client)) {
                
GetClientInfo(client"cl_connectmethod"clientConnectMethodsizeof(clientConnectMethod));

                if (!
StrEqual(clientConnectMethod"serverbrowser_internet")) {
                    
g_bConnectedFromFavorites[client] = true;
                }
            }
        }
    }
}

public 
Action Command_Hop(int clientint args) {
    
ServerMenu(client);
    return 
Plugin_Handled;
}

public 
Action Command_Servers(int clientint args) {
    
ServerMenu(client);
    return 
Plugin_Handled;
}

public 
Action Command_Say(int clientint args) {
    
char text[MAX_STR_LEN];
    
int startidx 0;

    if (!
GetCmdArgString(textsizeof(text))) {
        return 
Plugin_Continue;
    }

    if (
text[strlen(text)-1] == '\0') {
        
text[strlen(text)-1] = '\0';
        
startidx 1;
    }

    
char trigger[MAX_STR_LEN];
    
g_cvarHopTrigger.GetString(triggersizeof(trigger));

    if (
strcmp(text[startidx], triggerfalse) == || strcmp(text[startidx], "!hop"false) == 0) {
        
ServerMenu(client);
    }

    return 
Plugin_Continue;
}


public 
void OnClientPutInServer(int client) {
    
char clientConnectMethod[64];
    
GetClientInfo(client"cl_connectmethod"clientConnectMethodsizeof(clientConnectMethod));
    if (!
StrEqual(clientConnectMethod"serverbrowser_internet")) {
        
g_bConnectedFromFavorites[client] = true;
    }
}

public 
void OnClientDisconnect(int client) {
    
g_bConnectedFromFavorites[client] = false;
}

public 
Action ServerMenu(int client) {
    
char serverNumStr[MAX_STR_LEN];
    
char menuTitle[MAX_STR_LEN];

    
Menu menu = new Menu(Menu_HandlerMENU_ACTIONS_DEFAULT);
    
Format(menuTitlesizeof(menuTitle), "%T""SelectServer"client);
    
menu.SetTitle(menuTitle);

    for (
int i 0g_iServerCounti++) {
        if (
strlen(g_sServerInfo[i]) > 0) {
            
IntToString(iserverNumStrsizeof(serverNumStr));
            
menu.AddItem(serverNumStrg_sServerInfo[i]);
        }
    }
    
menu.Display(client20);
    return 
Plugin_Handled;
}

public 
int Menu_Handler(Menu menuMenuAction actionint param1int param2) {
    if (
action == MenuAction_Select) {
        
char infobuf[MAX_STR_LEN];

        
menu.GetItem(param2infobufsizeof(infobuf));
        
int serverNum StringToInt(infobuf);
        
char menuTitle[MAX_STR_LEN];
        
Format(menuTitlesizeof(menuTitle), "%T""AboutToJoinServer"param1);
        
Format(g_sAddress[param1], MAX_STR_LEN"%s:%i"g_sServerAddress[serverNum], g_iServerPort[serverNum]);
        
g_sServer[param1] = g_sServerInfo[serverNum];

        if (!
g_bConnectedFromFavorites[param1]) {
            
PrintToChat(param1"\x01[\x03ServerHop\x01] Due to Valve game change, clients must connect via favorites to be redirected by server.");
            
PrintToChat(param1"\x01[\x03ServerHop\x01] %s:\x03 %s"g_sServer[param1], g_sAddress[param1]);
            return;
        }

        
Panel panel = new Panel();
        
panel.SetTitle(menuTitle);
        
panel.DrawText(g_sServerInfo[serverNum]);
        
panel.DrawText("Is this correct?");
        
panel.CurrentKey 3;
        
panel.DrawItem("Accept");
        
panel.DrawItem("Decline");
        
panel.Send(param1MenuConfirmHandler15);

        
delete panel;
    }
    else if (
action == MenuAction_End) {
        
delete menu;
    }
}

public 
int MenuConfirmHandler(Menu menuMenuAction actionint param1int param2) {
    if (
param2 == 3) {
        
ClientCommand(param1"redirect %s"g_sAddress[param1]);
        
// broadcast to all
        
if (g_cvarBroadcastHops.BoolValue) {
            
char clientName[MAX_NAME_LENGTH];
            
GetClientName(param1clientNamesizeof(clientName));
            
PrintToChatAll("\x01[\x03hop\x01] %t""HopNotification"clientNameg_sServer[param1]);
        }
    }
    
g_sAddress[param1][0] = '\0';
    
g_sServer[param1][0] = '\0';
}

public 
Action RefreshServerInfo(Handle timer) {
    for (
int i 0g_iServerCounti++) {
        
g_sServerInfo[i][0] = '\0';
        
g_bSocketError[i] = false;
        
g_hSocket[i] = SocketCreate(SOCKET_UDPOnSocketError);
        
SocketSetArg(g_hSocket[i], i);
        
SocketConnect(g_hSocket[i], OnSocketConnectedOnSocketReceiveOnSocketDisconnectedg_sServerAddress[i], g_iServerPort[i]);
    }

    
CreateTimer(SERVER_TIMEOUTCleanUp);
}

public 
Action CleanUp(Handle timer) {
    for (
int i 0g_iServerCounti++) {
        if (
strlen(g_sServerInfo[i]) == && !g_bSocketError[i]) {
            
LogError("Server %s:%i is down, no reply received within %0.0f seconds."g_sServerAddress[i], g_iServerPort[i], SERVER_TIMEOUT);
            
delete g_hSocket[i];
        }
    }

    
// all server info is up to date: advertise
    
if (g_cvarAdvert.BoolValue) {
        if (
g_iAdvertInterval == g_cvarAdvert_Interval.FloatValue) {
            
Advertise();
        }
        if (++
g_iAdvertInterval g_cvarAdvert_Interval.FloatValue) {
            
g_iAdvertInterval 1;
        }
    }
}

public 
void Advertise() {
    
char trigger[MAX_STR_LEN];
    
g_cvarHopTrigger.GetString(triggersizeof(trigger));

    
// skip servers being marked as down
    
while (strlen(g_sServerInfo[g_iAdvertCount]) == 0) {
        if (++
g_iAdvertCount >= g_iServerCount) {
            
g_iAdvertCount 0;
            break;
        }
    }

    if (
strlen(g_sServerInfo[g_iAdvertCount]) > 0) {
        
PrintToChatAll("\x01[\x03hop\x01] %t""Advert"g_sServerInfo[g_iAdvertCount], trigger);

        if (++
g_iAdvertCount >= g_iServerCount) {
            
g_iAdvertCount 0;
        }
    }
}

public 
void OnSocketConnected(Handle sockany i) {
    
char requestStr[25];
    
Format(requestStrsizeof(requestStr), "%s""\xFF\xFF\xFF\xFF\x54Source Engine Query");
    
SocketSend(sockrequestStr25);
}

char GetString(char[] receiveDataint dataSizeint offset) {
    
char serverStr[MAX_STR_LEN] = "";
    
int j 0;
    for (
int i offsetdataSizei++) {
        
serverStr[j++] = receiveData[i];
        if (
receiveData[i] == '\x0') {
            break;
        }
    }
    return 
serverStr;
}

public 
void OnSocketReceive(Handle sockchar[] receiveData, const int dataSizeany i) {
    
// parse server info
    
int offset 2;
    
char srvName[MAX_STR_LEN];
    
srvName GetString(receiveDatadataSizeoffset);
    
offset += strlen(srvName) + 1;

    
char mapName[MAX_STR_LEN];
    
mapName GetString(receiveDatadataSizeoffset);
    
offset += strlen(mapName) + 1;

    
char gameDir[MAX_STR_LEN];
    
gameDir GetString(receiveDatadataSizeoffset);
    
offset += strlen(gameDir) + 1;

    
char gameDesc[MAX_STR_LEN];
    
gameDesc GetString(receiveDatadataSizeoffset);
    
offset += strlen(gameDesc) + 1;

    
offset += 2;
    
char numPlayers[4];
    
int players receiveData[offset];
    
IntToString(playersnumPlayerssizeof(numPlayers));

    ++
offset;
    
char maxPlayers[4];
    
IntToString(receiveData[offset], maxPlayerssizeof(maxPlayers));

    ++
offset;
    
char numBots[4];
    
int bots receiveData[offset];
    
IntToString(botsnumBotssizeof(numBots));

    
char humans[4];
    
IntToString(players botshumanssizeof(humans));

    
char format[MAX_STR_LEN];
    
g_cvarServerFormat.GetString(formatsizeof(format));
    
ReplaceString(formatstrlen(format), "%name"g_sServerName[i], false);
    
ReplaceString(formatstrlen(format), "%map"mapNamefalse);
    
ReplaceString(formatstrlen(format), "%numplayers"numPlayersfalse);
    
ReplaceString(formatstrlen(format), "%maxplayers"maxPlayersfalse);
    
ReplaceString(formatstrlen(format), "%humans"humansfalse);
    
ReplaceString(formatstrlen(format), "%bots"numBotsfalse);

    
g_sServerInfo[i] = format;

    
delete sock;
}

public 
void OnSocketDisconnected(Handle sockany i) {
    
delete sock;
}

public 
void OnSocketError(Handle sock, const int errorType, const int errorNumany i) {
    if (!
g_bCoolDown) {
        
LogError("Server %s:%i is down: socket error %d (errno %d)"g_sServerAddress[i], g_iServerPort[i], errorTypeerrorNum);
        
CreateTimer(600.0timerErrorCooldown);
        
g_bCoolDown true;
    }
    
    
g_bSocketError[i] = true;
    
delete sock;
}

Action timerErrorCooldown(Handle timer) {
    
g_bCoolDown false;


HTML Code:
...\include\socket.inc(297) : error 147: new-style declarations are required
...\include\socket.inc(309) : error 147: new-style declarations are required
...\include\socket.inc(319) : error 147: new-style declarations are required
...\include\socket.inc(319) : error 147: new-style declarations are required
...\include\socket.inc(336) : error 147: new-style declarations are required
...\include\socket.inc(336) : error 147: new-style declarations are required
...\include\socket.inc(346) : error 147: new-style declarations are required
...\include\socket.inc(355) : error 147: new-style declarations are required
...\include\socket.inc(371) : error 147: new-style declarations are required
...\include\socket.inc(371) : error 147: new-style declarations are required
...\include\socket.inc(389) : error 147: new-style declarations are required
...\include\socket.inc(389) : error 147: new-style declarations are required
...\include\socket.inc(389) : error 147: new-style declarations are required
...\include\socket.inc(389) : fatal error 190: too many error messages on one line
Could you help me solve these errors?
Thanks.
Shazam is offline
andi67
Veteran Member
Join Date: Mar 2007
Location: Somewhere near you!!!
Old 04-20-2021 , 22:48   Re: Error 147 Help me
Reply With Quote #2

Just comment this out:
Quote:
#pragma newdecls required

To:
Quote:
//#pragma newdecls required
__________________
Waiting for HL3,Day of Defeat3 ,but will it ever come? So I'm gonna play COD WW2.>>>>SM_SKINCHOOSER<<<<
>>You need Models for DODS/CSS/CSGO , than click here!!!<<
andi67 is offline
Maxximou5
AlliedModders Donor
Join Date: Feb 2013
Old 04-21-2021 , 11:14   Re: Error 147 Help me
Reply With Quote #3

If you still want to use it for the rest of your code, you can move
PHP Code:
#pragma newdecls required 
to after your includes.

PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <socket> 
#pragma newdecls required 
Maxximou5 is offline
Shazam
Junior Member
Join Date: Feb 2021
Old 04-22-2021 , 11:39   Re: Error 147 Help me
Reply With Quote #4

Quote:
Originally Posted by andi67 View Post
Just comment this out:



To:
Tks!!!!
Shazam is offline
Shazam
Junior Member
Join Date: Feb 2021
Old 04-22-2021 , 11:40   Re: Error 147 Help me
Reply With Quote #5

Quote:
Originally Posted by Maxximou5 View Post
If you still want to use it for the rest of your code, you can move
PHP Code:
#pragma newdecls required 
to after your includes.

PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <socket> 
#pragma newdecls required 
Tks!!!!
Shazam is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:53.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode