core/GameDataFetcher.h
author David Anderson <dvander@alliedmods.net>
Wed Feb 25 20:07:12 2009 -0500 (2009-02-25)
changeset 2607 f3b8bbe17f85
parent 2477 b51cbb84d3f0
permissions -rw-r--r--
Backed out changeset fa286305bd3f
pred@2142
     1
/**
dvander@2476
     2
 * vim: set ts=4 :
dvander@2476
     3
 * =============================================================================
dvander@2476
     4
 * SourceMod
dvander@2476
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
dvander@2476
     6
 * =============================================================================
dvander@2476
     7
 *
dvander@2476
     8
 * This program is free software; you can redistribute it and/or modify it under
dvander@2476
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
dvander@2476
    10
 * Free Software Foundation.
dvander@2476
    11
 * 
dvander@2476
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
dvander@2476
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
dvander@2476
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
dvander@2476
    15
 * details.
dvander@2476
    16
 *
dvander@2476
    17
 * You should have received a copy of the GNU General Public License along with
dvander@2476
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@2476
    19
 *
dvander@2476
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
dvander@2476
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
dvander@2476
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
dvander@2476
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
dvander@2476
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
dvander@2476
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
dvander@2476
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
dvander@2476
    27
 * or <http://www.sourcemod.net/license.php>.
dvander@2476
    28
 *
dvander@2476
    29
 * Version: $Id$
dvander@2476
    30
 */
pred@2142
    31
pred@2142
    32
#ifndef _INCLUDE_SOURCEMOD_GAMEDATAFETCHER_H_
pred@2142
    33
#define _INCLUDE_SOURCEMOD_GAMEDATAFETCHER_H_
pred@2142
    34
pred@2142
    35
#include "sourcemod.h"
pred@2142
    36
#include "TextParsers.h"
pred@2142
    37
#include "IThreader.h"
pred@2142
    38
#include "Logger.h"
pred@2142
    39
#include "LibrarySys.h"
pred@2142
    40
#include "ThreadSupport.h"
pred@2142
    41
#include "sm_memtable.h"
dvander@2475
    42
#include <sh_string.h>
dvander@2475
    43
#include <sh_list.h>
pred@2142
    44
pred@2142
    45
enum UpdateStatus
pred@2142
    46
{ 
pred@2142
    47
	Update_Unknown = 0,				/* Version wasn't recognised or version querying is unsupported */
pred@2142
    48
	Update_Current = 1,				/* Server is running latest version */
pred@2142
    49
	Update_NewBuild = 2,			/* Server is on a svn release and a newer version is available */
pred@2142
    50
	Update_MinorAvailable = 3,		/* Server is on a release and a minor release has superceeded it */
pred@2142
    51
	Update_MajorAvailable = 4,		/* Server is on a release and a major release has superceeded it */
pred@2142
    52
	Update_CriticalAvailable = 5,	/* A critical update has been released (security fixes etc) */
pred@2142
    53
};
pred@2142
    54
dvander@2474
    55
class MD5;
dvander@2474
    56
pred@2142
    57
class BuildMD5ableBuffer : public ITextListener_SMC
pred@2142
    58
{
pred@2142
    59
public:
dvander@2474
    60
	BuildMD5ableBuffer();
dvander@2474
    61
	~BuildMD5ableBuffer();
dvander@2474
    62
	void ReadSMC_ParseStart();
dvander@2474
    63
	SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
dvander@2474
    64
	SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
dvander@2474
    65
	void ReadSMC_ParseEnd(bool halted, bool failed);
dvander@2474
    66
public:
dvander@2474
    67
	MD5 *checksum;
pred@2142
    68
private:
pred@2142
    69
	BaseStringTable *stringTable;
pred@2142
    70
};
pred@2142
    71
pred@2142
    72
struct FileData
pred@2142
    73
{
pred@2142
    74
	SourceHook::String *filename;
dvander@2474
    75
	char checksum[33];
pred@2142
    76
};
pred@2142
    77
pred@2142
    78
class FetcherThread : public IThread
pred@2142
    79
{
pred@2142
    80
public:
dvander@2474
    81
	FetcherThread();
dvander@2474
    82
	~FetcherThread();
dvander@2474
    83
public:
pred@2142
    84
	void RunThread(IThreadHandle *pHandle);
pred@2142
    85
	void OnTerminate(IThreadHandle *pHandle, bool cancel);
pred@2142
    86
private:
pred@2142
    87
	int BuildGameDataQuery(char *buffer, int maxlen);
pred@2142
    88
	void ProcessGameDataQuery(int SocketDescriptor);
pred@2367
    89
	int RecvData(int socketDescriptor, char *buffer, int len);
pred@2367
    90
	int SendData(int socketDescriptor, char *buffer, int len);
pred@2142
    91
	int ConnectSocket();
pred@2142
    92
	void HandleUpdateStatus(UpdateStatus status, short version[4]);
pred@2142
    93
public:
pred@2142
    94
	SourceHook::CVector<FileData *> filenames;
dvander@2476
    95
	bool needsRestart;
dvander@2475
    96
	bool wasSuccess;
dvander@2476
    97
private:
dvander@2475
    98
	UpdateStatus updateStatus;
pred@2142
    99
	BaseMemTable *memtable;
dvander@2475
   100
	short build[4];
pred@2142
   101
};
pred@2142
   102
pred@2142
   103
extern bool g_blockGameDataLoad;
pred@2142
   104
pred@2142
   105
#endif // _INCLUDE_SOURCEMOD_GAMEDATAFETCHER_H_
dvander@2474
   106