This topic is now archived and is closed to further replies.


Changeable game server settings

Recommended Posts

Sand_Hawk    108
I am currently writing a text MUD server. Things work out pretty neat but I have 1 thing I can't really figure out. How do I make the server have changeable settings in such a fashion the user(I think it will be only me) can load the settings file into a text editor like notepad and change them. e.g. The file must be looking something like this(or similar, the user needs to be able to understand what is it changing):
ServerPassword = password
Port = 4000
MaxUsers = 250 
AllowNewAccounts = 1
What is the best approach for this? [EDIT] 25x 500 error [/EDIT] Sand Hawk ---------------- (Inspired by Pouya) [edited by - sand_hawk on March 4, 2003 8:01:27 PM]

Share this post

Link to post
Share on other sites
Indeterminatus    129
I fear nobody can really tell you what to do BEST ;-) ...

I would do this the following:
* write a small text-parsing engine that can handle expressions like "MaxUsers = 250". At first, implement it as a text-based console into the server application (e.g. user is able to enter this and the text is sent to the text-parser which will then trigger some action)
* fill a file, e.g. "autoexec.cfg" with some lines you could also enter into the text-console (like "MaxUsers = 250"). this file will be loaded automatically on server startup. simply read out every line after the other and let it be parsed and evaluated.

within the console you could do some fancy stuff, for example the following (and very easy to realize debug thingie):
"MaxUsers = 250"
maximal users allowed are set to 250
"MaxUsers ="
maybe print out the maximum number of users on the console.
''Maximum amount of users allowed: 250''

you get what i mean? *gg*

hope i could help you a little bit!



--si tacuisses, philosophus mansisses--

Share this post

Link to post
Share on other sites
Programmer One    746
How I did it in Cyclone:

You have a text file. The text file is opened and then read one line into a string.
You then run the string through strtok so that it seperate based on the equal sign ''=''.
Now you will have two seperate strings. The identifier, and the value.
You eat all the white space at the end and beginning of each string. This is if the person who made the file put a space between the equal sign and the values. (ex: MyValue = Pie)
If the identifier is valid, you use the value. Otherwise you thorw it out, issue a warning or whatever.
You check if the file contains each identifier. If not, then you used whatever value that would be a reasonable default.

Anyway, you know where to IM me tool, if you need clarification

Share this post

Link to post
Share on other sites
krez    443
i did something similiar, but my implementation is crappy because i just wanted it to work for the moment.

the server app automatically loads "config.dat" (just a text file) and applies any settings in the file. but, it also allows for a command-line parameter to specify an alternate config file... so you can have a couple of them lying around, and switch them up without destroying the original.

Share this post

Link to post
Share on other sites
Sand_Hawk    108
Well, I think I got the general idea. I have layed the foundation of the class, it looks like this:

class CConfigFile
CConfigFile(char *szFileName);

int SetConfigFile(char *szFilename);

// Variable function, used to get/set or add a variable
int GetVariable(char *szVar, char *szValue); // Get the variable
int SetVariable(char *szVar, char *szValue); // Set the variable
int AddVariable(char *szVar, char *szValue); // Add new variable

// Sections
int AddSection(char *szSection); // Add new section
int SetSection(char *szSection); // Set current section
int GetSection(char *szSection); // Get current section

char szConfigFile[512];
char szCurrentSection[256];
long lSectionStart;
long lSectionEnd;
bool bSetup;

I code it up today and tomorrow and see if it works.

Sand Hawk

Share this post

Link to post
Share on other sites