Пример #1
0
void game_sv_GameState::CheckPlayerName(xrClientData* CL)
{
	R_ASSERT	(CL && CL->ps);
	R_ASSERT	(!CL->ps->m_account.is_online());

	char const *	current_name = NULL;
	if (CL->ps->m_account.name().size())	//in case of logging from gamespy login page
	{
		current_name = CL->ps->getName();
	} else
	{
		current_name = CL->name.c_str();
		CL->ps->m_account.set_player_name(current_name);
	}
	u32				current_name_length = xr_strlen(current_name);


	u32				new_name_dest_size = current_name_length + 16;
	char *			new_name_dest = static_cast<char*>(
		_alloca(new_name_dest_size));

	while (FindPlayerName(current_name, CL))
	{
		GenerateNewName(current_name, new_name_dest, new_name_dest_size);
		CL->ps->m_account.set_player_name(new_name_dest);
		current_name = new_name_dest;
	}
}
Пример #2
0
bool game_sv_GameState::CheckNewPlayer(xrClientData* CL)
{
	xrGameSpyServer*		gs_server = smart_cast<xrGameSpyServer*>(m_server);
	R_ASSERT				(gs_server);
	
	char const *			error_msg = NULL;
	ClientID				tmp_client_id(CL->ID);
	
	if (gs_server->IsPublicServer())
	{
		if (!CL->ps->m_account.is_online())
		{
			error_msg = "mp_please_login";
		} else
		{
			if (FindPlayerName(CL->ps->getName(), CL))
			{
				error_msg = "mp_already_logged_in";
			}
		}
	} else
	{
		if (CL->ps->m_account.is_online())
		{
			error_msg = "mp_use_offline_mode";
		} else
		{
			CheckPlayerName(CL);
		}
	}

	if (error_msg)
	{
		m_server->SendProfileCreationError(CL, error_msg);
		if (CL != m_server->GetServerClient()) //CL can be NULL
			CleanDelayedEventFor(tmp_client_id);
		return false;
	}
	return true;
}
Пример #3
0
void
GameEvent(CORE_DATA *cd)
{
	switch (cd->event) {
	case EVENT_START:
		RegisterPlugin(OPENCORE_VERSION, "rabbit", "cycad", "1.0", __DATE__, __TIME__, "A rabbit bot", sizeof(USER_DATA), 0);

		/* set rabbit pid to nobody */
		ud(cd)->rabbit_pid = PID_NONE;

		/* register rabbit command */
		RegisterCommand(COMMAND_RABBIT, "!rabbit", "Rabbit", 2, CMD_PRIVATE, "<name>:<bounty>[:<special>]", "Start the rabbit game", NULL); break;
	case EVENT_LOGIN:
		/* set the bot's location to center */
		SetPosition(16 * 512, 16 * 512, 0, 0);
		break;
	case EVENT_COMMAND:
		switch (cd->cmd_id) {
		case COMMAND_RABBIT: {
			int show_usage = 0;

			PLAYER_ID rpid = ud(cd)->rabbit_pid;

			if (rpid == PID_NONE) {	/* rabbit game is not runnig */
				if (cd->cmd_argc <= 1) {
					show_usage = 1;
				} else {
					char *cmd = cd->cmd_argr[1];
					int nargs = ArgCount(cmd, ':');

					if (nargs != 2 && nargs != 3) {
						show_usage = 1;
					} else {	/* args to command are valid */
						/* copy name out of command */
						char rname[20];
						DelimArgs(rname, sizeof(rname), cmd, 0, ':', 0);

						/* copy bounty out of command */
						int bty = AtoiArg(cmd, 1, ':');

						/* copy special out of command if it was specified */
						int special = 0;
						if (nargs == 3)
							special = AtoiArg(cmd, 2, ':');

						/* find the player specified on the command line */
						PLAYER *rabbit = FindPlayerName(rname, MATCH_HERE | MATCH_PREFIX);
						if (rabbit) {
							/* player found, start the game */
							start_rabbit_game(cd, rabbit, bty, special);
						} else {
							RmtMessageFmt(cd->cmd_name, "Player not found: %s", rname);
						}
					}
				}
			} else {
				/* rabbit game is already running */
				PLAYER *p = FindPlayerPid(rpid, MATCH_HERE);

				RmtMessageFmt(cd->cmd_name, "Rabbit is already running (%s is the rabbit)",
				    p ? p->name : "**UNKNOWN**");
			}

			/* display usage if necessary */
			if (show_usage) RmtMessageFmt(cd->cmd_name, "Usage: %s <name>:<bounty>[:<special>]", cd->cmd_argv[0]);
		}
		default: break;
		}
		break;
	case EVENT_UPDATE:
		if (ud(cd)->rabbit_pid == cd->p1->pid) {	/* if the update is for the rabbit */
			if (cd->p1->status & STATUS_SAFE) {	/* check if the rabbit is in safe */
				/* the rabbit entered safe, end the game */
				ArenaMessageFmt("%s has lost the rabbit game by entering safe!", cd->p1->name);
				ud(cd)->rabbit_pid = PID_NONE;
			}
		}
		break;
	case EVENT_TIMER:
		if (ud(cd)->rabbit_pid != PID_NONE) {	/* if the rabbit game is running */
			/* find the rabbit */
			PLAYER *p = FindPlayerPid(ud(cd)->rabbit_pid, MATCH_HERE);
			if (p) {
				if (ud(cd)->where_timer == cd->timer_id) {
					/* a *where timer expired, send the next one and look for response */
					PrivMessage(p, "*where");
					ud(cd)->expecting_where = 1;
				} else if (ud(cd)->gameover_timer == cd->timer_id) {
					/* the game over timer expired, the rabbit didnt die and he won */
					ArenaMessageFmt("%s wins the rabbit game by staying alive!", p->name);
					ud(cd)->rabbit_pid = PID_NONE;
				}
			} else {
				/* rabbit not found, this should never happen! */
			}
		}
	case EVENT_MESSAGE:
		/*
		 * Only look for a response of the game is running, the bot is expecting *where,
		 * and the message type is an arena message.
		 */
		if (ud(cd)->rabbit_pid != PID_NONE && ud(cd)->expecting_where && 
		    cd->msg_type == MSG_ARENA) {
			/* message is a possible *where response */

			/* find the rabbit */
			PLAYER *p = FindPlayerPid(ud(cd)->rabbit_pid, MATCH_HERE);
			if (p) {
				char where_prefix[32];
				snprintf(where_prefix, 32, "%s: ", p->name);
				where_prefix[32 - 1] = '\0';

				/*
				 * Verify that this is *where output by looking for "rabbit: " at the
				 * beginning of the string.
				 */
				if (strncasecmp(where_prefix, cd->msg, strlen(where_prefix)) == 0) {
					/* this must be a *where response, process it */
					char loc[4];
					snprintf(loc, 4, "%s", &cd->msg[strlen(where_prefix)]);
					loc[4 - 1] = '\0';

					/* announce the rabbits location */
					ArenaMessageFmt(">>> Rabbit %s is at %-3s <<<", p->name, loc);

					/* set the next *where timer */
					ud(cd)->where_timer = SetTimer(30 * 1000, 0, 0);

					/*
					 * The bot wont be looking for *where responses until the
					 * next time it sends the command, so turn parsing off
					 * for now.
					 */
					ud(cd)->expecting_where = 0;
				}
			}
		}
		break;
	case EVENT_KILL:
		if (cd->p1->pid == ud(cd)->rabbit_pid) {
			/* the rabbit died */
			ArenaMessageFmt("%s wins the rabbit game by killing Rabbit %s!", cd->p2->name, cd->p1->name);
			ud(cd)->rabbit_pid = PID_NONE;
		}
		break;
	case EVENT_LEAVE:
		if (ud(cd)->rabbit_pid == cd->p1->pid) {
			/* the rabbit left */
			ArenaMessageFmt("%s has lost the rabbit game by leaving the arena!", cd->p1->name);
			ud(cd)->rabbit_pid = PID_NONE;
		}
		break;
	case EVENT_CHANGE:
		if (ud(cd)->rabbit_pid == cd->p1->pid) {
			/* the rabbit changed ship */
			ArenaMessageFmt("%s has lost the rabbit game by changing ship/freq!", cd->p1->name);
			ud(cd)->rabbit_pid = PID_NONE;
		}
		break;
	}
}