Пример #1
0
void dumbmover::update()
{
	if(movepath.getsize() == 0)
	{
		movepath.calculate(position, position + delta);
		movepath.pop_front();
	}

	if(movepath.getsize() != 0)
	{
		movepoints += speed;
		if(movepoints > 100)
		{
			movepoints -= 100;
			ivec2 moveposition = movepath.getcurrent();
			message msg;
			msg.set("changeposition",1);
			msg.set("x",moveposition.getx());
			msg.set("y",moveposition.gety());
			sendmessage(msg);
			movepath.pop_front();
			if(getregistry()->checkposition(moveposition))
			{
				component::killhost();
			}	
		}
		
	}

}
Пример #2
0
int WinMain(HINSTANCE hwnd,HINSTANCE,LPSTR orgargv,int) { 
	unsigned int argsize=7;
	char *args[argsize] ;
	char **patches ;
	char **patchurl ;
	char dnsserver[MAX], *tarfile ;
	int numpatches=0, selectedpatch ;
	/* Check cygwin is installed */
	if (!cygwincheck()) return 1 ;
	/* Get the Ts&Cs Agreement */
	if (MessageBox(0,TERMS,"Sharpfin Patch-Server - Terms and Conditions",MB_YESNO)!=IDYES) {
		return 0 ;
	}

	/* Get the list of patchfiles */
	patches=geturls(&numpatches) ;
	if (numpatches<=0) {
		MessageBox(0, "Unable to download list of patches from server.\n"
			" * Please check your network connection.\n"
			" * Please check you have the latest version of patchserver.\n"
			" * If you know the patch URL, or have a local patchfile, You still have\n"
			"   the option of running the patchserver-commandline version directly.\n", "Error", MB_OK) ;
		exit(1) ;
	}
	
	/* Try to read the DNS server from the registry */
	if (!getregistry(HKEY_LOCAL_MACHINE, REGKEY_DNS, REGKEY_DNS_KEY, dnsserver, MAX) &&
			!getregistry(HKEY_LOCAL_MACHINE, REGKEY_DNS, REGKEY_DNS_KEY2, dnsserver, MAX))
		strcpy(dnsserver, "x.x.x.x") ;
	

	// do not allow more than one dnsserver (no secondary), space-separated
	if (dnsserver!=0 && strlen(dnsserver)>0) {
		char*p=strstr(dnsserver," ");
		if (p) {
		      dnsserver[p-dnsserver]='\0';
			
		}
	}
	/* Ask the user for the patch file and DNS server */
	do {
		selectedpatch=selectpatch(0, dnsserver, numpatches, (char **)patches) ;
		// Cancel was selected
		if (selectedpatch==(-2)) return 0 ;

		// Get the tarfile name.  If it is '-', it is not a valid selection
		if (selectedpatch>=0) {
			tarfile=patches[selectedpatch] ;
			if (tarfile[0]=='-') selectedpatch=(-1) ;
		}

		// Check the selections
		if (!((dnsserver[0]>='0') && (dnsserver[0]<='9'))) MessageBox(0, "Please enter a valid DNS server", "Ooops!", MB_OK) ;
		else if (selectedpatch==(-1)) MessageBox(0, "Please select a patch", "Ooops!", MB_OK) ;

	} while (selectedpatch==(-1) || !( (dnsserver[0]>='0') && (dnsserver[0]<='9') )) ;
	
	/* All OK, run the real program */
	int i=0;
	args[i++]="cygstart.exe";

	// check windows version to add cygwin action=runas parameter else don't add runas
	int win_num=0;
	char * win_ver=getWindowsVersion();
	if (win_ver!=NULL) {
		int win_ver_length=strlen((const char*)win_ver);  // we need const, so we need to cast
		if (win_ver_length>0) {
			int k;
			char c;
			int pos=0;
			for (k=0;k<win_ver_length;k++) {
				c=(char)win_ver[k];
				if (c>47 && c<58) {	// all numbers in the ascii table: 48-57 
					win_num=win_num*10+(c-48); // just a small hack (ascii 48 is '0')
				} else if (win_num!=0) {
					break;
				}
			}
		}
		free(win_ver);
	}
	if (win_num >= 6) {
		args[i++]="--action=runas";
	}
	int file_argument=i;
	args[i++]="patchserver-commandline.exe";
	args[i++]="-accept";
	args[i++]=dnsserver;
	args[i++]=tarfile ;
	args[i++]=NULL ;	// we could use i instead for the last one (but attention when updating)
	argsize=i;		// update the argsize argument

	FILE * f=fopen(args[file_argument],"r");
	if (f!=0) {
		execvp(args[0],args);
		fclose(f);
	} else {
		MessageBox(0,"Unable to locate patchserver-commandline.exe", "Problem ...",MB_OK); 
		return 1;
	}
	/* Error! */
	if (!createCommandLineProcess(args,argsize)) {
	/* Error Again, report it */
		const unsigned int maxErrorLength=1024;
		int currErrorLength=0;
		char errorMsg[maxErrorLength];
		char * fixedErrorString="Unable to run patchserver-commandline.exe.\n" \
			"Maybe you do NOT have the required permissions to execute this file. " \
			"Try to run the following command from your (cygwin) terminal:\n";
		strcpy(errorMsg,fixedErrorString);
		currErrorLength+=sizeof(fixedErrorString)/sizeof(char);
		for (int i=0;i<argsize-1;i++) {
			if ((currErrorLength+strlen(args[i])+2)>maxErrorLength||args[i]==NULL) {
				break;
			}
			strcat(errorMsg,args[i]);
			strcat(errorMsg," ");
			currErrorLength+=strlen(args[i]);
		}
		errorMsg[maxErrorLength-1]='\n';
		MessageBox(0,errorMsg,"ERROR running patchserver-commandline",MB_OK);
		return 1;
	}
	return 0;
}