Server structure help
#1

Hello. My server is currently structured like this:
  • include/accountsystem.inc
  • include/commands.inc
  • include/dialogs.inc
  • include/mysqlsystem.inc
  • include/settings.inc
  • include/usefulfunctions.inc
  • include/variables.inc
The problem with this is that some files must be included before others, and it is very easy to mess things up, resulting in errors when compiling (like variables that are not declared, and so on).

I have read the topic about this, but there's nothing concrete in it. In which way should I organize my GM to avoid those easy mess-ups? I am hooking my functions with y_hooks, not ALS, if that helps. I just need an idea, something to build my GM on, or some way that I should think this structure.
Reply
#2

I got it, but I have one question regarding global variables. Let's say that I have something like this in the "variables" file:
pawn Код:
enum pData
{
    ID,
    Username[MAX_PLAYER_NAME+1],
    Password[129],
    Salt[129],
    Logged,
    LoginAttempts,
    Admin,
    SkinID,
    Spawned
}

new mysql,
    pInfo[MAX_PLAYERS][pData];
This is the reason that my variables are in another file. If they would have been in the "accountsystem" file, for example, my other files would not recognize the sintax "pInfo[playerid][Username]" or variable "mysql" that holds the connection handle to my SQL server. That's why I have another file: I include it before the others, so that I won't have any problems.

I want a clean layout, and my current setup is not like that at all. What alternatives do I have? How should I integrate this piece of code into the others?
Reply
#3

I may be wrong - but IMHO, what I feel is this.

Instead of separating by type, why don't you separate by function? Instead of clubbing all variables together, why not club the mysql variables AND the mysql connection functions, etc, together? And if a variable is needed by every include, then it shouldn't BE in an include, what I do is simply not include it anywhere, but just declare it right there in the game-mode, making it messy however completely fool-proof. (Sectioning the game-mode into 'native' includes, variables and 'custom' includes)

pawn Код:
#include <a_samp>

new gHilton;

#include <mysqlHouse>
#include <crazyCook>
Reply
#4

Quote:
Originally Posted by Opptur
Посмотреть сообщение
I got it, but I have one question regarding global variables. Let's say that I have something like this in the "variables" file:
pawn Код:
enum pData
{
    ID,
    Username[MAX_PLAYER_NAME+1],
    Password[129],
    Salt[129],
    Logged,
    LoginAttempts,
    Admin,
    SkinID,
    Spawned
}

new mysql,
    pInfo[MAX_PLAYERS][pData];
This is the reason that my variables are in another file. If they would have been in the "accountsystem" file, for example, my other files would not recognize the sintax "pInfo[playerid][Username]" or variable "mysql" that holds the connection handle to my SQL server. That's why I have another file: I include it before the others, so that I won't have any problems.

I want a clean layout, and my current setup is not like that at all. What alternatives do I have? How should I integrate this piece of code into the others?
In your variables file have GetPlayerSkinID and SetPlayerSkinID, etc.
Reply
#5

I still don't get it. Let's take for example the variable mysql, which holds the connection handle. How could I make a function to determine it, because you get that ID when you connect to the database.

I know it's pretty frustating for the ones that know how to do this, but I still don't get the logic behind this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)