ViaThinkSoft CodeLib
This article is in:
CodeLib → Programming aids → C / C++
Als Codevorlage der aufgegebene Battle-Center-Server, geschrieben in Misch-C++. Das MySQL-Passwort wurde aus dem Code entfernt.
#ifndef SERVER_H
#define SERVER_H
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <netdb.h>
#include <unistd.h>
#include <sstream>
#include <string.h>
#include <math.h>
#include <fcntl.h>
#include <errno.h>
#include <pthread.h>
#include <mysql/mysql.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#define PORT_NR 1337
#define MAX_CONNECTION_COUNT 1000
// Kompilieren mit `g++ -lpthread -lmysqlclient server.c`
using namespace std;
struct thread {
pthread_t thread_handle;
int socket_handle;
bool active, cleaned;
} threads[MAX_CONNECTION_COUNT];
enum receive_mode {
RCV_COMMAND,
RCV_PARAM0,
RCV_PARAM1,
RCV_PARAM2,
RCV_PARAM3,
RCV_PARAM4
};
enum verbose_level {
VERBOSE_LEVEL_CRITICAL,
VERBOSE_LEVEL_ERROR,
VERBOSE_LEVEL_WARNING,
VERBOSE_LEVEL_DEBUG
};
string IntToStr(int Value);
char * PChar(string text);
int StrToInt(string text);
int PCharToInt(char * text);
double StrToFloat(string text);
string FloatToStr(double Value);
void socket_sendtext(int socket_id, string text);
void set_nonblocking(int sockfd);
bool _mysql_checkerror();
MYSQL_RES * _mysql_query(string query);
string _mysql_escape_string(string text);
string checkvalue(string table, string fieldask, string fieldanswer, string field);
bool updatevalue(string table, string fieldask, string fieldanswer, string field, string fieldvalue);
void cleanup_threads(void);
void mark_thread_free(int thread_id);
int get_free_thread(void);
void * thread_process(void * tid);
void activate_thread(int * thread_id, int socket_handle);
int main(void);
#endif
Daniel Marschall
ViaThinkSoft Co-Founder
ViaThinkSoft Co-Founder