core/GameDataFetcher.cpp
author David Anderson <dvander@alliedmods.net>
Sun Nov 16 16:06:18 2008 -0800 (2008-11-16)
changeset 2411 8dfaa3d730b5
parent 2371 323fbf1ab608
child 2400 76b7b4575e21
child 2474 1f4345fb0f75
permissions -rw-r--r--
Removed pointless "systems" folder from core.
     1 /**
     2 * vim: set ts=4 :
     3 * =============================================================================
     4 * SourceMod
     5 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6 * =============================================================================
     7 *
     8 * This program is free software; you can redistribute it and/or modify it under
     9 * the terms of the GNU General Public License, version 3.0, as published by the
    10 * Free Software Foundation.
    11 * 
    12 * This program is distributed in the hope that it will be useful, but WITHOUT
    13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15 * details.
    16 *
    17 * You should have received a copy of the GNU General Public License along with
    18 * this program.  If not, see <http://www.gnu.org/licenses/>.
    19 *
    20 * As a special exception, AlliedModders LLC gives you permission to link the
    21 * code of this program (as well as its derivative works) to "Half-Life 2," the
    22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23 * by the Valve Corporation.  You must obey the GNU General Public License in
    24 * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25 * this exception to all derivative works.  AlliedModders LLC defines further
    26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27 * or <http://www.sourcemod.net/license.php>.
    28 *
    29 * Version: $Id$
    30 */
    31 
    32 #include "GameDataFetcher.h"
    33 #include "bitbuf.h"
    34 
    35 #ifdef PLATFORM_WINDOWS
    36 #include <winsock2.h>
    37 #else
    38 #include <unistd.h>
    39 #include <sys/types.h>
    40 #include <sys/socket.h>
    41 #include <netinet/in.h>
    42 #include <netdb.h>
    43 #include <arpa/inet.h>
    44 
    45 #define INVALID_SOCKET -1
    46 #define closesocket close
    47 #endif
    48 
    49 #include "sh_vector.h"
    50 #include "sh_string.h"
    51 #include "sm_version.h"
    52 
    53 #ifdef ORANGEBOX_BUILD
    54 #include "convar_sm_ob.h"
    55 #else
    56 #include "convar_sm.h"
    57 #endif
    58 
    59 #include "sourcemm_api.h"
    60 #include "time.h"
    61 #include "TimerSys.h"
    62 #include "compat_wrappers.h"
    63 #include "sm_stringutil.h"
    64 
    65 #define QUERY_MAX_LENGTH 1024
    66 
    67 BuildMD5ableBuffer g_MD5Builder;
    68 FetcherThread g_FetchThread;
    69 
    70 FILE *logfile = NULL;
    71 
    72 bool g_disableGameDataUpdate = false;
    73 bool g_restartAfterUpdate = false;
    74 
    75 int g_serverPort = 6500;
    76 char g_serverAddress[100] = "hayate.alliedmods.net";
    77 
    78 void FetcherThread::RunThread( IThreadHandle *pHandle )
    79 {
    80 	char lock_path[PLATFORM_MAX_PATH];
    81 	g_SourceMod.BuildPath(Path_SM, lock_path, sizeof(lock_path), "data/temp");
    82 	g_LibSys.CreateFolder(lock_path);
    83 
    84 	g_SourceMod.BuildPath(Path_SM, lock_path, sizeof(lock_path), "data/temp/gamedata.lock");
    85 
    86 	g_Logger.LogMessage("Starting Gamedata update fetcher... please report problems to bugs.alliedmods.net");
    87 
    88 	char log_path[PLATFORM_MAX_PATH];
    89 	g_SourceMod.BuildPath(Path_SM, log_path, sizeof(log_path), "logs/gamedata");
    90 
    91 	g_LibSys.CreateFolder(log_path);
    92 
    93 	time_t t;
    94 	GetAdjustedTime(&t);
    95 	tm *curtime = localtime(&t);
    96 
    97 	g_SourceMod.BuildPath(Path_SM, log_path, sizeof(log_path), "logs/gamedata/L%02d%02d.log", curtime->tm_mon + 1, curtime->tm_mday);
    98 
    99 	logfile = fopen(log_path, "a");
   100 
   101 	if (!logfile)
   102 	{
   103 		g_Logger.LogError("Failed to create GameData log file");
   104 		return;
   105 	}
   106 
   107 	//Create a blank lock file
   108 	FILE *fp = fopen(lock_path, "w");
   109 	if (fp)
   110 	{
   111 		fclose(fp);
   112 	}
   113 
   114 	char query[QUERY_MAX_LENGTH];
   115 
   116 	/* Check for updated gamedata files */
   117 	int len = BuildGameDataQuery(query, QUERY_MAX_LENGTH);
   118 
   119 	if (len == 0)
   120 	{
   121 		g_Logger.LogToOpenFile(logfile, "Query Writing failed");
   122 
   123 		fclose(logfile);
   124 		unlink(lock_path);
   125 		return;
   126 	}
   127 
   128 	if (g_disableGameDataUpdate)
   129 	{
   130 #ifdef DEBUG
   131 		g_Logger.LogMessage("Skipping GameData Query due to DisableAutoUpdate being set to true");
   132 #endif
   133 
   134 		fclose(logfile);
   135 		unlink(lock_path);
   136 		return;
   137 	}
   138 
   139 	/* Create a new socket for this connection */
   140 	int socketDescriptor = ConnectSocket();
   141 
   142 	if (socketDescriptor == INVALID_SOCKET)
   143 	{
   144 		fclose(logfile);
   145 		unlink(lock_path);
   146 		return;
   147 	}
   148 
   149 	int sent = SendData(socketDescriptor, query, len);
   150 
   151 #ifdef DEBUG
   152 	g_Logger.LogToOpenFile(logfile, "Sent Query!");
   153 #endif
   154 
   155 	if (sent == 0)
   156 	{
   157 		g_Logger.LogToOpenFile(logfile, "Failed to send gamedata query data to remote host");
   158 
   159 		closesocket(socketDescriptor);
   160 		fclose(logfile);
   161 		unlink(lock_path);
   162 		return;
   163 	}
   164 
   165 	ProcessGameDataQuery(socketDescriptor);
   166 
   167 	/* And we're done! */
   168 	closesocket(socketDescriptor);
   169 	fclose(logfile);
   170 	unlink(lock_path);
   171 }
   172 
   173 void FetcherThread::OnTerminate( IThreadHandle *pHandle, bool cancel )
   174 {
   175 	g_blockGameDataLoad = false;
   176 }
   177 
   178 int FetcherThread::BuildGameDataQuery( char *buffer, int maxlen )
   179 {
   180 	char gamedata_path[PLATFORM_MAX_PATH];
   181 	g_SourceMod.BuildPath(Path_SM, gamedata_path, sizeof(gamedata_path), "gamedata");
   182 
   183 	IDirectory *dir = g_LibSys.OpenDirectory(gamedata_path);
   184 
   185 	if (dir == NULL)
   186 	{
   187 		return 0;
   188 	}
   189 
   190 	bf_write Writer = bf_write("GameDataQuery", buffer, maxlen);
   191 
   192 	Writer.WriteByte('A'); //Generic Header char
   193 	Writer.WriteByte('G'); //G for gamedata query, or green, like my hat.
   194 
   195 	short build[4] = { SVN_FILE_VERSION };
   196 
   197 	Writer.WriteBytes(&build[0], 8);
   198 
   199 	Writer.WriteByte(0); // Initialize the file counter - Index 10
   200 
   201 	while (dir->MoreFiles())
   202 	{
   203 		if (dir->IsEntryFile())
   204 		{
   205 			const char *name = dir->GetEntryName();
   206 			size_t len = strlen(name);
   207 			if (len >= 4
   208 				&& strcmp(&name[len-4], ".txt") == 0)
   209 			{
   210 				char file[PLATFORM_MAX_PATH];
   211 
   212 				g_LibSys.PathFormat(file, sizeof(file), "%s/%s", gamedata_path, name);
   213 
   214 				SMCStates states;
   215 				if (g_TextParser.ParseFile_SMC(file, &g_MD5Builder, &states) == SMCError_Okay)
   216 				{
   217 					unsigned char *md5 = g_MD5Builder.GetMD5();
   218 					if (md5 != NULL)
   219 					{
   220 						(uint8_t)buffer[10]++; //Increment the file counter
   221 						Writer.WriteBytes(md5, 16);
   222 
   223 						g_Logger.LogToOpenFile(logfile, "%s - \"%s\"", file, g_MD5Builder.GetMD5String());
   224 
   225 						FileData *data = new FileData();
   226 						data->filename = new SourceHook::String(file);
   227 						memcpy(data->checksum, g_MD5Builder.GetMD5String(), 33);
   228 						filenames.push_back(data);
   229 					}
   230 					else
   231 					{
   232 #ifdef DEBUG
   233 						g_Logger.LogToOpenFile(logfile, "%s no md5?", file);
   234 #endif
   235 					}
   236 				}
   237 				else
   238 				{
   239 #ifdef DEBUG
   240 					g_Logger.LogToOpenFile(logfile, "%s failed!", file);
   241 #endif
   242 				}
   243 			}
   244 		}
   245 
   246 		dir->NextEntry();
   247 	}
   248 
   249 	return Writer.GetNumBytesWritten();
   250 }
   251 
   252 int FetcherThread::ConnectSocket()
   253 {
   254 	struct protoent *ptrp;
   255 	ptrp = getprotobyname("tcp");
   256 
   257 #ifdef WIN32
   258 	WSADATA wsaData;
   259 	WSAStartup(0x0101, &wsaData);
   260 #endif
   261 
   262 	if (ptrp == NULL) 
   263 	{
   264 		g_Logger.LogToOpenFile(logfile, "Failed to find TCP");
   265 		return INVALID_SOCKET;
   266 	}
   267 
   268 	int socketDescriptor = socket(AF_INET, SOCK_STREAM, ptrp->p_proto);
   269 
   270 	if (socketDescriptor == INVALID_SOCKET)
   271 	{
   272 		//bugger aye?
   273 #ifdef WIN32
   274 		g_Logger.LogToOpenFile(logfile, "Failed to create a new socket - Error %i", WSAGetLastError());
   275 #else
   276 		g_Logger.LogToOpenFile(logfile, "Failed to create a new socket - Error %i", errno);
   277 #endif
   278 		closesocket(socketDescriptor);
   279 		return INVALID_SOCKET;
   280 	}
   281 
   282 	struct hostent *he;
   283 	struct sockaddr_in local_addr;
   284 
   285 	local_addr.sin_family = AF_INET;
   286 	local_addr.sin_port = htons((u_short)g_serverPort);
   287 
   288 	he = gethostbyname(g_serverAddress);
   289 
   290 	if (!he)
   291 	{
   292 		if ((local_addr.sin_addr.s_addr = inet_addr(g_serverAddress)) == INADDR_NONE)
   293 		{
   294 			g_Logger.LogToOpenFile(logfile, "Couldn't locate address");
   295 			closesocket(socketDescriptor);
   296 			return INVALID_SOCKET;
   297 		}
   298 	} 
   299 	else 
   300 	{
   301 		memcpy(&local_addr.sin_addr, (struct in_addr *)he->h_addr, he->h_length);
   302 	}
   303 
   304 	if (connect(socketDescriptor, (struct sockaddr *) &local_addr, sizeof(local_addr)) < 0)
   305 	{
   306 #ifdef WIN32
   307 		g_Logger.LogToOpenFile(logfile, "Couldn't connect - Error %i", WSAGetLastError());
   308 #else
   309 		g_Logger.LogToOpenFile(logfile, "Couldn't connect - Error %i", errno);
   310 #endif
   311 		closesocket(socketDescriptor);
   312 		return INVALID_SOCKET;
   313 	}
   314 
   315 	return socketDescriptor;
   316 }
   317 
   318 void FetcherThread::ProcessGameDataQuery(int socketDescriptor)
   319 {
   320 	char buffer[50];
   321 #ifdef DEBUG
   322 	g_Logger.LogToOpenFile(logfile, "Waiting for reply!");
   323 #endif
   324 
   325 	//Read in the header bytes
   326 	int returnLen = RecvData(socketDescriptor, buffer, 12);
   327 
   328 #ifdef DEBUG
   329 	g_Logger.LogToOpenFile(logfile, "Recv Completed");
   330 #endif
   331 
   332 	if (returnLen == 0)
   333 	{
   334 #ifdef DEBUG
   335 		g_Logger.LogToOpenFile(logfile, ",but it failed.");
   336 #endif
   337 		/* Timeout or fail? */
   338 		return;
   339 	}
   340 
   341 #ifdef DEBUG
   342 	g_Logger.LogToOpenFile(logfile, "Received Header!");
   343 #endif
   344 
   345 	bf_read Reader = bf_read("GameDataQuery", buffer, 12);
   346 
   347 	if (Reader.ReadByte() != 'A' || Reader.ReadByte() != 'G')
   348 	{
   349 		g_Logger.LogToOpenFile(logfile, "Unknown Query Response");
   350 		return;
   351 	}
   352 
   353 	UpdateStatus updateStatus = (UpdateStatus)Reader.ReadByte();
   354 
   355 	short build[4] = {0,0,0,0};
   356 
   357 	build[0] = Reader.ReadShort();
   358 	build[1] = Reader.ReadShort();
   359 	build[2] = Reader.ReadShort();
   360 	build[3] = Reader.ReadShort();
   361 
   362 #ifdef DEBUG
   363 	g_Logger.LogToOpenFile(logfile, "Update Status: %i - Latest %i.%i.%i.%i", updateStatus, build[0], build[1], build[2], build[3]);
   364 #endif
   365 
   366 	HandleUpdateStatus(updateStatus, build);
   367 
   368 	int changedFiles = Reader.ReadByte();
   369 
   370 #ifdef DEBUG
   371 	g_Logger.LogToOpenFile(logfile, "Files to download: %i", changedFiles);
   372 #endif
   373 
   374 	for (int i=0; i<changedFiles; i++)
   375 	{
   376 		//Read in the file index and byte count
   377 		returnLen = RecvData(socketDescriptor, buffer, 5);
   378 
   379 		if (returnLen == 0)
   380 		{
   381 			/* Timeout or fail? */
   382 			return;
   383 		}
   384 
   385 		Reader.StartReading(buffer, 5);
   386 
   387 		int index = Reader.ReadByte();
   388 		int tempLen = Reader.ReadUBitLong(32);
   389 
   390 #ifdef DEBUG
   391 		g_Logger.LogToOpenFile(logfile, "File index %i and length %i", index, tempLen);
   392 #endif
   393 
   394 		void *memPtr;
   395 		memtable->CreateMem(tempLen+1, &memPtr);
   396 
   397 		//Read the contents of our file into the memtable
   398 		returnLen = RecvData(socketDescriptor, (char *)memPtr, tempLen);
   399 
   400 #ifdef DEBUG
   401 		g_Logger.LogToOpenFile(logfile, "Recieved %i bytes", returnLen);
   402 #endif
   403 
   404 		if (returnLen == 0)
   405 		{
   406 			/* Timeout or fail? */
   407 			return;
   408 		}
   409 
   410 		((unsigned char *)memPtr)[tempLen] = '\0';
   411 
   412 		FileData *data = filenames.at(index);
   413 		const char* filename;
   414 		if (data != NULL)
   415 		{
   416 			filename = data->filename->c_str();
   417 
   418 			FILE *fp = fopen(filename, "w");
   419 
   420 			if (fp)
   421 			{
   422 				fprintf(fp, (const char *)memPtr);
   423 				fclose(fp);
   424 			}
   425 			else
   426 			{
   427 				g_Logger.LogToOpenFile(logfile, "Failed to open file \"%s\"", filename);
   428 			}
   429 		}
   430 		else
   431 		{
   432 			filename = "";
   433 		}
   434 
   435 		memtable->Reset();
   436 
   437 #ifdef DEBUG
   438 		g_Logger.LogToOpenFile(logfile, "Updated File %s", filename);
   439 #endif
   440 	}
   441 
   442 #ifdef DEBUG
   443 	g_Logger.LogToOpenFile(logfile, "File Downloads Completed!");
   444 #endif
   445 
   446 	bool needsRestart = false;
   447 
   448 	if (changedFiles > 0)
   449 	{
   450 		needsRestart = true;
   451 		g_Logger.LogMessage("New GameData Files have been downloaded to your gamedata directory. Please restart your server for these to take effect");
   452 	}
   453 
   454 	//Read changed file count
   455 	returnLen = RecvData(socketDescriptor, buffer, 1);
   456 
   457 	if (returnLen == 0)
   458 	{
   459 		/* Timeout or fail? */
   460 		g_Logger.LogToOpenFile(logfile, "Failed to receive unknown count");
   461 		return;
   462 	}
   463 
   464 	Reader.StartReading(buffer, 1);
   465 
   466 	changedFiles = Reader.ReadByte();
   467 
   468 	if (changedFiles == 0)
   469 	{
   470 #ifdef DEBUG
   471 		g_Logger.LogToOpenFile(logfile, "No unknown files. We're all done");
   472 #endif
   473 		return;
   474 	}
   475 
   476 	char *changedFileIndexes = new char[changedFiles];
   477 
   478 #ifdef DEBUG
   479 	g_Logger.LogToOpenFile(logfile, "%i Files were unknown", changedFiles);
   480 #endif
   481 
   482 	returnLen = RecvData(socketDescriptor, changedFileIndexes, changedFiles);
   483 
   484 	if (returnLen == 0)
   485 	{
   486 		/* Timeout or fail? */
   487 #ifdef DEBUG
   488 		g_Logger.LogToOpenFile(logfile, "Failed to receive unknown list");
   489 #endif
   490 		return;
   491 	}
   492 
   493 	Reader.StartReading(changedFileIndexes, changedFiles);
   494 
   495 	for (int i=0; i<changedFiles; i++)
   496 	{
   497 		int index = Reader.ReadByte();
   498 		char fileName[30];
   499 
   500 		FileData *data = filenames.at(index);
   501 		const char* pathname;
   502 		if (data != NULL)
   503 		{
   504 			pathname = data->filename->c_str();
   505 		}
   506 		else
   507 		{
   508 			pathname = "";
   509 		}
   510 
   511 		g_LibSys.GetFileFromPath(fileName, sizeof(fileName), pathname);
   512 #ifdef DEBUG
   513 		g_Logger.LogToOpenFile(logfile, "Unknown File %i : %s", index, fileName);
   514 #endif
   515 	}
   516 
   517 	delete [] changedFileIndexes;
   518 
   519 	if (needsRestart && g_restartAfterUpdate)
   520 	{
   521 		g_Logger.LogMessage("Automatically restarting server after a successful gamedata update!");
   522 		engine->ServerCommand("quit\n");
   523 	}
   524 }
   525 
   526 int FetcherThread::RecvData( int socketDescriptor, char *buffer, int len )
   527 {
   528 	fd_set fds;
   529 	struct timeval tv;
   530 
   531 	/* Create a 10 Second Timeout */
   532 	tv.tv_sec = 10;
   533 	tv.tv_usec = 0;
   534 
   535 	int bytesReceivedTotal = 0;
   536 
   537 	while (bytesReceivedTotal < len)
   538 	{
   539 		/* Add our socket to a socket set */
   540 		FD_ZERO(&fds);
   541 		FD_SET(socketDescriptor, &fds);
   542 
   543 		/* Wait max of 10 seconds for recv to become available */
   544 		select(socketDescriptor+1, &fds, NULL, NULL, &tv);
   545 
   546 		int bytesReceived = 0;
   547 
   548 		/* Is there a limit on how much we can receive? Some site said 1024 bytes, which will be well short of a file */
   549 		if (FD_ISSET(socketDescriptor, &fds))
   550 		{
   551 			bytesReceived = recv(socketDescriptor, buffer+bytesReceivedTotal, len-bytesReceivedTotal, 0);
   552 		}
   553 
   554 		if (bytesReceived == 0 || bytesReceived == -1)
   555 		{
   556 			return 0;
   557 		}
   558 
   559 		bytesReceivedTotal += bytesReceived;
   560 	}
   561 
   562 	return bytesReceivedTotal;	
   563 }
   564 
   565 int FetcherThread::SendData( int socketDescriptor, char *buffer, int len )
   566 {
   567 	fd_set fds;
   568 	struct timeval tv;
   569 
   570 	tv.tv_sec = 10;
   571 	tv.tv_usec = 0;
   572 
   573 	int sentBytesTotal = 0;
   574 
   575 	while (sentBytesTotal < len)
   576 	{
   577 		FD_ZERO(&fds);
   578 		FD_SET(socketDescriptor, &fds);
   579 
   580 		select(socketDescriptor+1, NULL, &fds, NULL, &tv);
   581 
   582 		int sentBytes = 0;
   583 
   584 		if (FD_ISSET(socketDescriptor, &fds))
   585 		{
   586 			sentBytes = send(socketDescriptor, buffer+sentBytesTotal, len-sentBytesTotal, 0);
   587 		}
   588 
   589 		if (sentBytes == 0 || sentBytes == -1)
   590 		{
   591 			return 0;
   592 		}		
   593 
   594 		sentBytesTotal += sentBytes;
   595 	}
   596 
   597 	return sentBytesTotal;
   598 }
   599 
   600 void FetcherThread::HandleUpdateStatus( UpdateStatus status, short version[4] )
   601 {
   602 	switch (status)
   603 	{
   604 		case Update_Unknown:
   605 		case Update_Current:
   606 		{
   607 			break;
   608 		}
   609 
   610 		case Update_NewBuild:
   611 		{
   612 			g_Logger.LogMessage("SourceMod Update: A new Mercurial build is available from sourcemod.net");
   613 			g_Logger.LogMessage("Current Version: %i.%i.%i.%i Available: %i.%i.%i.%i", version[0], version[1], version[2], version[3], version[0], version[1], version[2], version[3]);
   614 			break;
   615 		}
   616 
   617 		case Update_MinorAvailable:
   618 		{
   619 			g_Logger.LogMessage("SourceMod Update: An incremental minor release of SourceMod is now available from sourcemod.net");
   620 			g_Logger.LogMessage("Current Version: %i.%i.%i Available: %i.%i.%i", version[0], version[1], version[2], version[0], version[1], version[2]);
   621 			break;
   622 		}
   623 
   624 		case Update_MajorAvailable:
   625 		{
   626 			g_Logger.LogMessage("SourceMod Update: An major release of SourceMod is now available from sourcemod.net");
   627 			g_Logger.LogMessage("Current Version: %i.%i.%i Available: %i.%i.%i", version[0], version[1], version[2], version[0], version[1], version[2]);
   628 			break;
   629 		}
   630 
   631 		case Update_CriticalAvailable:
   632 		{
   633 			g_Logger.LogError("SourceMod Update: A new critical release of SourceMod is now available from sourcemod.net. It is strongly recommended that you update");
   634 			g_Logger.LogMessage("Current Version: %i.%i.%i.%i Available: %i.%i.%i.%i", version[0], version[1], version[2], version[3], version[0], version[1], version[2], version[3]);
   635 			break;
   636 		}
   637 	}
   638 }
   639 
   640 bool g_blockGameDataLoad = false;
   641 
   642 class InitFetch : public SMGlobalClass
   643 {
   644 public:
   645 	void OnSourceModAllInitialized_Post()
   646 	{
   647 		char lock_path[PLATFORM_MAX_PATH];
   648 		g_SourceMod.BuildPath(Path_SM, lock_path, sizeof(lock_path), "data/temp/gamedata.lock");
   649 
   650 		if (g_LibSys.IsPathFile(lock_path) && g_LibSys.PathExists(lock_path))
   651 		{
   652 			g_Logger.LogError("sourcemod/data/temp/gamedata.lock file detected. This is most likely due to a crash during GameData updating - Blocking GameData loading");
   653 			g_Logger.LogError("If this error persists delete the file manually");
   654 			g_blockGameDataLoad = true;
   655 		}
   656 
   657 		ThreadParams fetchThreadParams = ThreadParams();
   658 		fetchThreadParams.prio = ThreadPrio_Low;
   659 		g_pThreader->MakeThread(&g_FetchThread, &fetchThreadParams);
   660 	}
   661 
   662 	ConfigResult OnSourceModConfigChanged(const char *key, 
   663 		const char *value, 
   664 		ConfigSource source,
   665 		char *error, 
   666 		size_t maxlength)
   667 	{
   668 		if (strcmp(key, "DisableAutoUpdate") == 0)
   669 		{
   670 			if (strcmp(value, "yes") == 0)
   671 			{
   672 				g_disableGameDataUpdate = true;
   673 				return ConfigResult_Accept;
   674 			}
   675 			else if (strcmp(value, "no") == 0)
   676 			{
   677 				g_disableGameDataUpdate = false;
   678 				return ConfigResult_Accept;
   679 			}
   680 
   681 			return ConfigResult_Reject;
   682 		}
   683 
   684 		if (strcmp(key, "ForceRestartAfterUpdate") == 0)
   685 		{
   686 			if (strcmp(value, "yes") == 0)
   687 			{
   688 				g_restartAfterUpdate = true;
   689 				return ConfigResult_Accept;
   690 			}
   691 			else if (strcmp(value, "no") == 0)
   692 			{
   693 				g_restartAfterUpdate = false;
   694 				return ConfigResult_Accept;
   695 			}
   696 
   697 			return ConfigResult_Reject;
   698 		}
   699 
   700 		if (strcmp(key, "AutoUpdateServer") == 0)
   701 		{
   702 			UTIL_Format(g_serverAddress, sizeof(g_serverAddress), "%s", value);
   703 
   704 			return ConfigResult_Accept;
   705 		}
   706 
   707 		if (strcmp(key, "AutoUpdatePort") == 0)
   708 		{
   709 			int port = atoi(value);
   710 
   711 			if (!port)
   712 			{
   713 				return ConfigResult_Reject;
   714 			}
   715 
   716 			g_serverPort = port;
   717 
   718 			return ConfigResult_Accept;
   719 		}
   720 
   721 		return ConfigResult_Ignore;
   722 	}
   723 } g_InitFetch;
   724 
   725 CON_COMMAND(sm_gamedata_md5, "Checks the MD5 sum for a given gamedata file")
   726 {
   727 #if !defined ORANGEBOX_BUILD
   728 	CCommand args;
   729 #endif
   730 
   731 	if (args.ArgC() < 2)
   732 	{
   733 		g_SMAPI->ConPrint("Usage: sm_gamedata_md5 <file>\n");
   734 		return;
   735 	}
   736 
   737 	const char *file = args.Arg(1);
   738 	if (!file || file[0] == '\0')
   739 	{
   740 		g_SMAPI->ConPrint("Usage: sm_gamedata_md5 <file>\n");
   741 		return;
   742 	}
   743 
   744 	SourceHook::CVector<FileData *>::iterator iter = g_FetchThread.filenames.begin();
   745 
   746 	FileData *curData;
   747 
   748 	while (iter != g_FetchThread.filenames.end())
   749 	{
   750 		curData = (*iter);
   751 
   752 		char fileName[30];
   753 
   754 		g_LibSys.GetFileFromPath(fileName, sizeof(fileName), curData->filename->c_str());
   755 
   756 		if (strcmpi(fileName, file) == 0)
   757 		{
   758 			g_SMAPI->ConPrintf("MD5 Sum: %s\n", curData->checksum);
   759 			return;
   760 		}
   761 
   762 		iter++;
   763 	}
   764 
   765 	g_SMAPI->ConPrint("File not found!\n");
   766 }