mirror of
https://github.com/dashr9230/SA-MP.git
synced 2024-12-23 06:57:31 +08:00
[bot] Implement command line parser
This commit is contained in:
parent
7a0c525559
commit
af4346b14b
BIN
bot/bot.ncb
BIN
bot/bot.ncb
Binary file not shown.
BIN
bot/bot.suo
BIN
bot/bot.suo
Binary file not shown.
@ -114,6 +114,9 @@
|
||||
<File
|
||||
RelativePath=".\main.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\main.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resource.h">
|
||||
</File>
|
||||
|
93
bot/main.cpp
93
bot/main.cpp
@ -1,7 +1,98 @@
|
||||
|
||||
int main()
|
||||
#include "main.h"
|
||||
|
||||
GAME_SETTINGS tSettings;
|
||||
|
||||
void InitSettingsFromCommandLine(char * szCmdLine);
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
/*
|
||||
Argument format:
|
||||
"-h %s -p %d -n %s -m %s"
|
||||
|
||||
-h -> either server's bind address or 127.0.0.1
|
||||
-p -> server's port number
|
||||
-n -> NPC's name
|
||||
-m -> script name
|
||||
*/
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
char szCmdLine[1024];
|
||||
memset(szCmdLine,0,1024);
|
||||
|
||||
int cmdcnt=1;
|
||||
if(argc > 1) {
|
||||
while(cmdcnt != argc) {
|
||||
strcat(szCmdLine, argv[cmdcnt]);
|
||||
strcat(szCmdLine, " ");
|
||||
cmdcnt++;
|
||||
}
|
||||
}
|
||||
InitSettingsFromCommandLine(szCmdLine);
|
||||
|
||||
// TODO: main
|
||||
// Absolutely no indication it is named npc or bot...
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
void SetStringFromCommandLine(char* szCmdLine, char* szString);
|
||||
|
||||
void InitSettingsFromCommandLine(char * szCmdLine)
|
||||
{
|
||||
logprintf(szCmdLine);
|
||||
|
||||
memset(&tSettings,0,sizeof(GAME_SETTINGS));
|
||||
|
||||
while(*szCmdLine) {
|
||||
|
||||
if(*szCmdLine == '-' || *szCmdLine == '/') {
|
||||
szCmdLine++;
|
||||
switch(*szCmdLine) {
|
||||
case 'z':
|
||||
szCmdLine++;
|
||||
SetStringFromCommandLine(szCmdLine,tSettings.szConnectPass);
|
||||
break;
|
||||
case 'h':
|
||||
szCmdLine++;
|
||||
SetStringFromCommandLine(szCmdLine,tSettings.szConnectHost);
|
||||
break;
|
||||
case 'p':
|
||||
szCmdLine++;
|
||||
SetStringFromCommandLine(szCmdLine,tSettings.szConnectPort);
|
||||
break;
|
||||
case 'n':
|
||||
szCmdLine++;
|
||||
SetStringFromCommandLine(szCmdLine,tSettings.szNickName);
|
||||
break;
|
||||
case 'm':
|
||||
szCmdLine++;
|
||||
SetStringFromCommandLine(szCmdLine,tSettings.szModeName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
szCmdLine++;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
void SetStringFromCommandLine(char* szCmdLine, char* szString)
|
||||
{
|
||||
while(*szCmdLine == ' ') szCmdLine++;
|
||||
while(*szCmdLine &&
|
||||
*szCmdLine != ' ' &&
|
||||
*szCmdLine != '-' &&
|
||||
*szCmdLine != '/')
|
||||
{
|
||||
*szString = *szCmdLine;
|
||||
szString++; szCmdLine++;
|
||||
}
|
||||
*szString = '\0';
|
||||
}
|
||||
|
||||
//----------------------------------------------------
|
||||
|
22
bot/main.h
Normal file
22
bot/main.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include <windows.h>
|
||||
#else
|
||||
#endif
|
||||
|
||||
#define MAX_SETTINGS_STRING 256
|
||||
|
||||
typedef struct _GAME_SETTINGS {
|
||||
CHAR szConnectPass[MAX_SETTINGS_STRING+1];
|
||||
CHAR szConnectHost[MAX_SETTINGS_STRING+1];
|
||||
CHAR szConnectPort[MAX_SETTINGS_STRING+1];
|
||||
CHAR szNickName[MAX_SETTINGS_STRING+1];
|
||||
CHAR szModeName[MAX_SETTINGS_STRING+1];
|
||||
} GAME_SETTINGS;
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
Loading…
Reference in New Issue
Block a user