1.1 --- a/core/GameDataFetcher.h Fri Jul 11 06:51:21 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,185 +0,0 @@
1.4 -/**
1.5 -* vim: set ts=4 :
1.6 -* =============================================================================
1.7 -* SourceMod
1.8 -* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
1.9 -* =============================================================================
1.10 -*
1.11 -* This program is free software; you can redistribute it and/or modify it under
1.12 -* the terms of the GNU General Public License, version 3.0, as published by the
1.13 -* Free Software Foundation.
1.14 -*
1.15 -* This program is distributed in the hope that it will be useful, but WITHOUT
1.16 -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.17 -* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.18 -* details.
1.19 -*
1.20 -* You should have received a copy of the GNU General Public License along with
1.21 -* this program. If not, see <http://www.gnu.org/licenses/>.
1.22 -*
1.23 -* As a special exception, AlliedModders LLC gives you permission to link the
1.24 -* code of this program (as well as its derivative works) to "Half-Life 2," the
1.25 -* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.26 -* by the Valve Corporation. You must obey the GNU General Public License in
1.27 -* all respects for all other code used. Additionally, AlliedModders LLC grants
1.28 -* this exception to all derivative works. AlliedModders LLC defines further
1.29 -* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.30 -* or <http://www.sourcemod.net/license.php>.
1.31 -*
1.32 -* Version: $Id$
1.33 -*/
1.34 -
1.35 -#ifndef _INCLUDE_SOURCEMOD_GAMEDATAFETCHER_H_
1.36 -#define _INCLUDE_SOURCEMOD_GAMEDATAFETCHER_H_
1.37 -
1.38 -#include "sourcemod.h"
1.39 -#include "TextParsers.h"
1.40 -#include "IThreader.h"
1.41 -#include "Logger.h"
1.42 -#include "LibrarySys.h"
1.43 -#include "ThreadSupport.h"
1.44 -#include "md5.h"
1.45 -#include "sm_memtable.h"
1.46 -
1.47 -enum UpdateStatus
1.48 -{
1.49 - Update_Unknown = 0, /* Version wasn't recognised or version querying is unsupported */
1.50 - Update_Current = 1, /* Server is running latest version */
1.51 - Update_NewBuild = 2, /* Server is on a svn release and a newer version is available */
1.52 - Update_MinorAvailable = 3, /* Server is on a release and a minor release has superceeded it */
1.53 - Update_MajorAvailable = 4, /* Server is on a release and a major release has superceeded it */
1.54 - Update_CriticalAvailable = 5, /* A critical update has been released (security fixes etc) */
1.55 -};
1.56 -
1.57 -class BuildMD5ableBuffer : public ITextListener_SMC
1.58 -{
1.59 -public:
1.60 -
1.61 - BuildMD5ableBuffer()
1.62 - {
1.63 - stringTable = new BaseStringTable(2048);
1.64 - md5[0] = 0;
1.65 - md5String[0] = 0;
1.66 - }
1.67 -
1.68 - ~BuildMD5ableBuffer()
1.69 - {
1.70 - delete stringTable;
1.71 - }
1.72 -
1.73 - void ReadSMC_ParseStart()
1.74 - {
1.75 - checksum = MD5();
1.76 - }
1.77 -
1.78 - SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value)
1.79 - {
1.80 - stringTable->AddString(key);
1.81 - stringTable->AddString(value);
1.82 -
1.83 - return SMCResult_Continue;
1.84 - }
1.85 -
1.86 - SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name)
1.87 - {
1.88 - stringTable->AddString(name);
1.89 -
1.90 - return SMCResult_Continue;
1.91 - }
1.92 -
1.93 - void ReadSMC_ParseEnd(bool halted, bool failed)
1.94 - {
1.95 - if (halted || failed)
1.96 - {
1.97 - return;
1.98 - }
1.99 -
1.100 - void *data = stringTable->GetMemTable()->GetAddress(0);
1.101 -
1.102 - if (data != NULL)
1.103 - {
1.104 - checksum.update((unsigned char *)data, stringTable->GetMemTable()->GetActualMemUsed());
1.105 - }
1.106 -
1.107 - checksum.finalize();
1.108 -
1.109 - checksum.hex_digest(md5String);
1.110 - checksum.raw_digest(md5);
1.111 -
1.112 - stringTable->Reset();
1.113 - }
1.114 -
1.115 - unsigned char * GetMD5()
1.116 - {
1.117 - return md5;
1.118 - }
1.119 -
1.120 - unsigned char * GetMD5String()
1.121 - {
1.122 - return (unsigned char *)&md5String[0];
1.123 - }
1.124 -
1.125 -private:
1.126 - MD5 checksum;
1.127 - unsigned char md5[16];
1.128 - char md5String[33];
1.129 - BaseStringTable *stringTable;
1.130 -};
1.131 -
1.132 -struct FileData
1.133 -{
1.134 - SourceHook::String *filename;
1.135 - unsigned char checksum[33];
1.136 -};
1.137 -
1.138 -
1.139 -class FetcherThread : public IThread
1.140 -{
1.141 -public:
1.142 - FetcherThread()
1.143 - {
1.144 - //filenames = new BaseStringTable(200);
1.145 - memtable = new BaseMemTable(4096);
1.146 - }
1.147 -
1.148 - ~FetcherThread()
1.149 - {
1.150 - //delete filenames;
1.151 - SourceHook::CVector<FileData *>::iterator iter = filenames.begin();
1.152 -
1.153 - FileData *curData;
1.154 -
1.155 - while (iter != filenames.end())
1.156 - {
1.157 - curData = (*iter);
1.158 - delete curData->filename;
1.159 - delete curData;
1.160 - iter = filenames.erase(iter);
1.161 - }
1.162 - }
1.163 -
1.164 - void RunThread(IThreadHandle *pHandle);
1.165 - void OnTerminate(IThreadHandle *pHandle, bool cancel);
1.166 -
1.167 -private:
1.168 - int BuildGameDataQuery(char *buffer, int maxlen);
1.169 - void ProcessGameDataQuery(int SocketDescriptor);
1.170 -
1.171 - /* These names are a lie. It's really NoMoreBlockingThan10Seconds */
1.172 - int NonBlockingRecv(int socketDescriptor, char *buffer, int len);
1.173 - int NonBlockingSend(int socketDescriptor, char *buffer, int len);
1.174 -
1.175 - int ConnectSocket();
1.176 -
1.177 - void HandleUpdateStatus(UpdateStatus status, short version[4]);
1.178 -
1.179 -public:
1.180 - SourceHook::CVector<FileData *> filenames;
1.181 -private:
1.182 - BaseMemTable *memtable;
1.183 -};
1.184 -
1.185 -extern BuildMD5ableBuffer g_MD5Builder;
1.186 -extern bool g_blockGameDataLoad;
1.187 -
1.188 -#endif // _INCLUDE_SOURCEMOD_GAMEDATAFETCHER_H_