
/* AMX Mod script.
*
* Redirection Plugin for AMX by sonic (sonic@codet.de)
*
* (c) Copyright 2002, sonic
* This file is provided as is (no warranties).
*
*/

/*  put in server.cfg:
*
*	amx_re_pwfield < _amx_noredirect >  // - setinfo pwfield name
*  amx_re_adminpw < password >         // - bypass the redirection with this password
*  amx_re_maxppl < 19 >                // - begin redirection when more the x ppl connected ( 0 = redirect all players )
*  amx_re_server < IP >                // - redirect to this server
*  amx_re_serverport < PORT >          // - redirect server port
*  amx_re_serverpw < password >        // - password for the amx_re_server
*
*  default adminpw is "dont"  - setinfo "_amx_noredirect" "dont" on client config.cfg
*
*  to disable this plugin use the ppause plugin, or set amx_re_maxppl to 33
*/

#include <amxmod>

public plugin_init() {
	register_plugin("Redirect","0.9.3a","sonic@codet.de")
	register_cvar("amx_re_pwfield","_amx_noredirect")
	register_cvar("amx_re_adminpw","dont")
	register_cvar("amx_re_maxppl","0")

	register_cvar("amx_re_server","")
	register_cvar("amx_re_serverport","")
	register_cvar("amx_re_serverpw","")

	return PLUGIN_CONTINUE
}

public client_connect(id){
	new rr_maxppl = get_cvar_num("amx_re_maxppl")
	new rr_serverport = get_cvar_num("amx_re_serverport")
	new rr_server[64], rr_serverpw[32], rr_pwfield[32], rr_adminpw[32], pInfoPW[32]
	get_cvar_string("amx_re_server",rr_server,63)
	get_cvar_string("amx_re_serverpw",rr_serverpw,31)
	get_cvar_string("amx_re_pwfield",rr_pwfield,31)
	get_cvar_string("amx_re_adminpw",rr_adminpw,31)
	get_user_info(id,rr_pwfield,pInfoPW,31)
	if ( get_playersnum() >= rr_maxppl && !equal(rr_adminpw,pInfoPW) ) {
		if ( !equal(rr_serverpw,"") )
			client_cmd(id,"echo ^"Set Password to %s^";password %s",rr_serverpw,rr_serverpw)
		client_cmd(id,"echo ^"Redirecting to %s:%d^";connect %s:%d",rr_server,rr_serverport,rr_server,rr_serverport)
	}
	return PLUGIN_CONTINUE
}
