-#include "include/ctdl_module.h"
-HashList *CfgTypeHash = NULL;
-HashList *RoomConfigs = NULL;
-/*-----------------------------------------------------------------------------*
- * Per room network configs *
- *-----------------------------------------------------------------------------*/
-void RegisterRoomCfgType(const char* Name, long len, RoomNetCfg eCfg, CfgLineParser p, int uniq, int nSegments, CfgLineSerializer s, CfgLineDeAllocator d)
-{
- CfgLineType *pCfg;
-
- pCfg = (CfgLineType*) malloc(sizeof(CfgLineType));
- pCfg->Parser = p;
- pCfg->Serializer = s;
- pCfg->C = eCfg;
- pCfg->Str.Key = Name;
- pCfg->Str.len = len;
- pCfg->IsSingleLine = uniq;
- pCfg->nSegments = nSegments;
- if (CfgTypeHash == NULL)
- CfgTypeHash = NewHash(1, NULL);
- Put(CfgTypeHash, Name, len, pCfg, NULL);
-}
-
-
-const CfgLineType *GetCfgTypeByStr(const char *Key, long len)
-{
- void *pv;
-
- if (GetHash(CfgTypeHash, Key, len, &pv) && (pv != NULL))
- {
- return (const CfgLineType *) pv;
- }
- else
- {
- return NULL;
- }
-}
-
-const CfgLineType *GetCfgTypeByEnum(RoomNetCfg eCfg, HashPos *It)
-{
- const char *Key;
- long len;
- void *pv;
- CfgLineType *pCfg;
-
- RewindHashPos(CfgTypeHash, It, 1);
- while (GetNextHashPos(CfgTypeHash, It, &len, &Key, &pv) && (pv != NULL))
- {
- pCfg = (CfgLineType*) pv;
- if (pCfg->C == eCfg)
- return pCfg;
- }
- return NULL;
-}
-void ParseGeneric(const CfgLineType *ThisOne, StrBuf *Line, const char *LinePos, OneRoomNetCfg *OneRNCFG)
-{
- RoomNetCfgLine *nptr;
- int i;
-
- nptr = (RoomNetCfgLine *)
- malloc(sizeof(RoomNetCfgLine));
- nptr->next = OneRNCFG->NetConfigs[ThisOne->C];
- nptr->Value = malloc(sizeof(StrBuf*) * ThisOne->nSegments);
- memset(nptr->Value, 0, sizeof(StrBuf*) * ThisOne->nSegments);
- if (ThisOne->nSegments == 1)
- {
- nptr->Value[0] = NewStrBufPlain(LinePos, StrLength(Line) - ( LinePos - ChrPtr(Line)) );
- }
- else for (i = 0; i < ThisOne->nSegments; i++)
- {
- nptr->Value[i] = NewStrBufPlain(NULL, StrLength(Line) - ( LinePos - ChrPtr(Line)) );
- StrBufExtract_NextToken(nptr->Value[i], Line, &LinePos, '|');
- }
-
- OneRNCFG->NetConfigs[ThisOne->C] = nptr;
-}
-
-void SerializeGeneric(const CfgLineType *ThisOne, StrBuf *OutputBuffer, OneRoomNetCfg *OneRNCFG, RoomNetCfgLine *data)
-{
- int i;
-
- StrBufAppendBufPlain(OutputBuffer, CKEY(ThisOne->Str), 0);
- for (i = 0; i < ThisOne->nSegments; i++)
- {
- StrBufAppendBuf(OutputBuffer, data->Value[i], 0);
- if (i + 1 < ThisOne->nSegments)
- StrBufAppendBufPlain(OutputBuffer, HKEY("|"), 0);
- }
- StrBufAppendBufPlain(OutputBuffer, HKEY("\n"), 0);
-}
-
-void DeleteGenericCfgLine(const CfgLineType *ThisOne, RoomNetCfgLine **data)
-{
- int i;
-
- for (i = 0; i < ThisOne->nSegments; i++)
- {
- FreeStrBuf(&(*data)->Value[i]);
- }
- free ((*data)->Value);
- free(*data);
- *data = NULL;
-}
-int ReadRoomNetConfigFile(OneRoomNetCfg **pOneRNCFG, char *filename)
-{
- int fd;
- const char *ErrStr = NULL;
- const char *Pos;
- const CfgLineType *pCfg;
- StrBuf *Line;
- StrBuf *InStr;
- OneRoomNetCfg *OneRNCFG;
-
- fd = open(filename, O_NONBLOCK|O_RDONLY);
- if (fd == -1) {
- *pOneRNCFG = NULL;
- return 0;
- }
- OneRNCFG = malloc(sizeof(OneRoomNetCfg));
- memset(OneRNCFG, 0, sizeof(OneRoomNetCfg));
- *pOneRNCFG = OneRNCFG;
- Line = NewStrBuf();