コード例 #1
0
/** 
\fn void ParticipantManager::checkAnswers( Vect3D objPos, int radius )
\brief Checks which players answered correctly
\param objPos Position of the tile with the correct answer
\param radius Sphere collision boundary. If the player is within this radius of the tile position, detect as correct.

Checks which players answered correctly and tells the player whether they are right or wrong. 
Increments their score accordingly.
*/
void ParticipantManager::checkAnswers( Vect3D objPos, int radius )
{
	std::string scoremsg;
	for ( unsigned int i = 0; i < quizUsers.size(); i++ )
	{
		if ( quizUsers.at(i)->checkCollision( objPos, radius ) )
		{
			quizUsers.at(i)->addScore(); 

			if ( quizUsers.at(i)->getScore() > topScore )
			{
				topScore = quizUsers.at(i)->getScore();
			}

			scoremsg = "You got it right! ";
			
		}
		else
		{
			scoremsg = "Wrong answer, boo. ";
		}
	
		scoremsg += "Your score is: ";
		char scorestr [2];
		_itoa_s(quizUsers.at(i)->getScore(), scorestr, 10);
		scoremsg += scorestr;
	
		whisper( quizUsers.at(i)->getSessionID(), scoremsg.c_str(), 100, 0, 100, 0, 0 );
	}
}
コード例 #2
0
void *clnt_connection(void *arg) {
    int clnt_sock = (int) arg;
    int str_len = 0;
    char message[BUFSIZE];
    int i;

    while ((str_len = read(clnt_sock, message, sizeof(message))) != 0) {
        if (message[0] == '@' && message[1] == '@' && message[2] == 'j' && message[3] == 'o' && message[4] == 'i' && message[5] == 'n') {
            addUser(clnt_sock, message);
        } else if (message[0] == '@' && message[1] == '@' && message[2] == 'm' && message[3] == 'e' && message[4] == 'm' && message[5] == 'b' && message[6] == 'e' && message[7] == 'r') {
            showUserInfo(clnt_sock);
        } else if(message[0] == '@' && message[1] == '@' && message[2] == 't' && message[3] == 'a' && message[4] == 'l' && message[5] == 'k') {
            whisper(message);
        } else {
            send_message(message, str_len);
        }

        memset(message, 0, sizeof(char) * BUFSIZE);
    }

    pthread_mutex_lock(&mutx);
    for (i = 0; i < clnt_number; i++) {   /* 클라이언트 연결 종료 시 */
        if (clnt_sock == clnt_socks[i]) {
            for (; i < clnt_number - 1; i++)
                clnt_socks[i] = clnt_socks[i + 1];
            break;
        }
    }
    clnt_number--;
    pthread_mutex_unlock(&mutx);

    close(clnt_sock);
    return 0;
}
コード例 #3
0
ファイル: m_cprivmsg.c プロジェクト: Compy/Undernet-IRCU
/*
 * m_cprivmsg - generic message handler
 *
 * parv[0] = sender prefix
 * parv[1] = nick
 * parv[2] = #channel
 * parv[3] = Private message text
 */
int m_cprivmsg(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
{
  assert(0 != cptr);
  assert(cptr == sptr);

  if (parc < 4 || EmptyString(parv[3]))
    return need_more_params(sptr, "CPRIVMSG");

  return whisper(sptr, parv[1], parv[2], parv[3], 0);
}
コード例 #4
0
ファイル: m_cprivmsg.c プロジェクト: Compy/Undernet-IRCU
/*
 * m_cnotice - generic message handler
 *
 * parv[0] = sender prefix
 * parv[1] = nick
 * parv[2] = #channel
 * parv[3] = Private message text
 */
int m_cnotice(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
{
  assert(0 != cptr);
  assert(cptr == sptr);

  if (parc < 4 || EmptyString(parv[3]))
    return need_more_params(sptr, "CNOTICE");

  return whisper(sptr, parv[1], parv[2], parv[3], 1);
}
コード例 #5
0
ファイル: gossiper.c プロジェクト: jshumway/gossip
// Run the gossip protocol.
void gossip(int sockfd)
{
   fd_set readfds;
   int rv, shutdown = 0;
   struct timeval timeout;
   time_t last_whisper = 0;
   time_t diff;

   while (!shutdown) {
      FD_ZERO(&readfds);
      FD_SET(sockfd, &readfds);
      FD_SET(STDIN_FILENO, &readfds);

      diff = time(NULL) - last_whisper;
      if (diff >= WHISPER_DELAY_SEC) {
         // Timeout instantly. Or just whisper now...
         timeout.tv_sec = 0;
         timeout.tv_usec = 0;
      } else {
         timeout.tv_sec = diff > WHISPER_DELAY_SEC - diff;
         timeout.tv_sec = 3;
         timeout.tv_usec = 0;
      }

      rv = select(sockfd + 1, &readfds, NULL, NULL, &timeout);

      if (rv == -1)
         perror("select");
      else if (rv == 0) {
         whisper(sockfd);
         last_whisper = time(NULL);
      }

      if (FD_ISSET(sockfd, &readfds))
         hear_whisper(sockfd);
      if (FD_ISSET(STDIN_FILENO, &readfds))
         shutdown = 1;
   }
}
コード例 #6
0
ファイル: lab4.c プロジェクト: AstoniaDev/Astonia-3.5
void lab4_gnalb_driver(int cn, int ret, int lastact)
{
        struct lab4_gnalb_driver_data *dat;
        struct msg *msg,*next;
        int co,cc,in;
        char *str;

        // get data
        dat=set_data(cn,DRD_LAB4_GNALB,sizeof(struct lab4_gnalb_driver_data));
	if (!dat) return;	// oops...

        // loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                if (msg->type==NT_CREATE) {
                        lab4_gnalb_driver_parse(cn,dat);
                        lab4_gnalb_driver_init(cn,dat);
                }

                if (msg->type==NT_GIVE) {

                        co=msg->dat1;
                        if (!(in=ch[cn].citem)) { remove_message(cn,msg); continue; } // ??? i saw something like this at DBs source

                        // destroy everything we get
                        destroy_item(ch[cn].citem);
                        ch[cn].citem=0;
                }

                if (msg->type==NT_TEXT) {
                        co=msg->dat3;
                        str=(char *)msg->dat2;
                        tabunga(cn,co,str);
                        if (co==cn) { remove_message(cn,msg); continue; }
                }

                if (msg->type==NT_SEEHIT && dat->type==2) {

                        cc=msg->dat1;
                        co=msg->dat2;
                        if (!cc || !co) { remove_message(cn,msg); continue; }

                        // is the victim our friend? then help
                        if (co!=cn && ch[co].group==ch[cn].group) {
                                if (!is_valid_enemy(cn,cc,-1)) { remove_message(cn,msg); continue; }
                                if (char_dist(cn,cc)>10) { remove_message(cn,msg); continue; }
                                fight_driver_add_enemy(cn,cc,1,1);
                                remove_message(cn,msg);
                                continue;
                        }

                        // is the attacker our friend? then help
                        if (cc!=cn && ch[cc].group==ch[cn].group) {
                                if (!is_valid_enemy(cn,co,-1)) { remove_message(cn,msg); continue; }
                                if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }
                                fight_driver_add_enemy(cn,co,0,1);
                                remove_message(cn,msg);
                                continue;
                        }
                        remove_message(cn,msg);
                        continue;
                }

                standard_message_driver(cn,msg,dat->aggressive,dat->helper);
                remove_message(cn,msg);
	}

        // fighting
        fight_driver_update(cn);
        if (fight_driver_attack_visible(cn,0)) return;
        if (fight_driver_follow_invisible(cn)) return;

        // rest of standard action
	if (regenerate_driver(cn)) return;
	if (spell_self_driver(cn)) return;

        // gnalb guards patroling
        if (dat->type==1 && dat->path) {

                fight_driver_set_home(cn,ch[cn].x,ch[cn].y);

                if (swap_move_driver(cn,gnalb_path[dat->path].x,gnalb_path[dat->path].y,1)) return;
                if (map_dist(ch[cn].x,ch[cn].y,gnalb_path[dat->path].x,gnalb_path[dat->path].y)<4) {
                        int p;

                        do p=RANDOM(4); while(gnalb_path[dat->path].next[p]==0 || (gnalb_path[dat->path].next[1]!=0 && gnalb_path[dat->path].next[p]==dat->lastpath));
                        dat->lastpath=dat->path;
                        dat->path=gnalb_path[dat->path].next[p];
                }
                else do_idle(cn,TICKS/2);

                return;
        }

        // crazy gnalb talking
        if (dat->type==3) {

                switch (RANDOM(50)) {
                        case 0: whisper(cn,"Me saw right in Fire."); break;
                        case 1: whisper(cn,"Me not crazy. In me house me saw in fire."); break;
                        case 2: whisper(cn,"Me will get it out."); break;
                        case 3: whisper(cn,"Fire hot, but me not crazy."); break;
                        case 4: whisper(cn,"Tell mage me saw in fire, me not crazy."); break;
                        case 10: case 11: case 12: case 13: case 14: if (do_use(cn,DX_RIGHT,0)) return;
                }

                if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_RIGHT,ret,lastact)) return;
                // nothing left to do
                do_idle(cn,TICKS/2);
                return;
        }

        if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_DOWN,ret,lastact)) return;

        // nothing left to do
        do_idle(cn,TICKS/2);
}
コード例 #7
0
ファイル: command_executor.cpp プロジェクト: aquileia/wesnoth
bool command_executor::execute_command(const hotkey_command&  cmd, int /*index*/, bool press)
{
	// hotkey release handling
	if (!press) {
		switch(cmd.id) {
			// release a scroll key, un-apply scrolling in the given direction
			case HOTKEY_SCROLL_UP:
				scroll_up(false);
				break;
			case HOTKEY_SCROLL_DOWN:
				scroll_down(false);
				break;
			case HOTKEY_SCROLL_LEFT:
				scroll_left(false);
				break;
			case HOTKEY_SCROLL_RIGHT:
				scroll_right(false);
				break;
			default:
				return false; // nothing else handles a hotkey release
		}

		return true;
	}

	// hotkey press handling
	switch(cmd.id) {
		case HOTKEY_SCROLL_UP:
			scroll_up(true);
			break;
		case HOTKEY_SCROLL_DOWN:
			scroll_down(true);
			break;
		case HOTKEY_SCROLL_LEFT:
			scroll_left(true);
			break;
		case HOTKEY_SCROLL_RIGHT:
			scroll_right(true);
			break;
		case HOTKEY_CYCLE_UNITS:
			cycle_units();
			break;
		case HOTKEY_CYCLE_BACK_UNITS:
			cycle_back_units();
			break;
		case HOTKEY_ENDTURN:
			end_turn();
			break;
		case HOTKEY_UNIT_HOLD_POSITION:
			unit_hold_position();
			break;
		case HOTKEY_END_UNIT_TURN:
			end_unit_turn();
			break;
		case HOTKEY_LEADER:
			goto_leader();
			break;
		case HOTKEY_UNDO:
			undo();
			break;
		case HOTKEY_REDO:
			redo();
			break;
		case HOTKEY_TERRAIN_DESCRIPTION:
			terrain_description();
			break;
		case HOTKEY_UNIT_DESCRIPTION:
			unit_description();
			break;
		case HOTKEY_RENAME_UNIT:
			rename_unit();
			break;
		case HOTKEY_SAVE_GAME:
			save_game();
			break;
		case HOTKEY_SAVE_REPLAY:
			save_replay();
			break;
		case HOTKEY_SAVE_MAP:
			save_map();
			break;
		case HOTKEY_LOAD_GAME:
			load_game();
			break;
		case HOTKEY_TOGGLE_ELLIPSES:
			toggle_ellipses();
			break;
		case HOTKEY_TOGGLE_GRID:
			toggle_grid();
			break;
		case HOTKEY_STATUS_TABLE:
			status_table();
			break;
		case HOTKEY_RECALL:
			recall();
			break;
		case HOTKEY_LABEL_SETTINGS:
			label_settings();
			break;
		case HOTKEY_RECRUIT:
			recruit();
			break;
		case hotkey::HOTKEY_REPEAT_RECRUIT:
			repeat_recruit();
			break;
		case HOTKEY_SPEAK:
			speak();
			break;
		case HOTKEY_SPEAK_ALLY:
			whisper();
			break;
		case HOTKEY_SPEAK_ALL:
			shout();
			break;
		case HOTKEY_CREATE_UNIT:
			create_unit();
			break;
		case HOTKEY_CHANGE_SIDE:
			change_side();
			break;
		case HOTKEY_KILL_UNIT:
			kill_unit();
			break;
		case HOTKEY_PREFERENCES:
			preferences();
			break;
		case HOTKEY_OBJECTIVES:
			objectives();
			break;
		case HOTKEY_UNIT_LIST:
			unit_list();
			break;
		case HOTKEY_STATISTICS:
			show_statistics();
			break;
		case HOTKEY_STOP_NETWORK:
			stop_network();
			break;
		case HOTKEY_START_NETWORK:
			start_network();
			break;
		case HOTKEY_LABEL_TEAM_TERRAIN:
			label_terrain(true);
			break;
		case HOTKEY_LABEL_TERRAIN:
			label_terrain(false);
			break;
		case HOTKEY_CLEAR_LABELS:
			clear_labels();
			break;
		case HOTKEY_SHOW_ENEMY_MOVES:
			show_enemy_moves(false);
			break;
		case HOTKEY_BEST_ENEMY_MOVES:
			show_enemy_moves(true);
			break;
		case HOTKEY_DELAY_SHROUD:
			toggle_shroud_updates();
			break;
		case HOTKEY_UPDATE_SHROUD:
			update_shroud_now();
			break;
		case HOTKEY_CONTINUE_MOVE:
			continue_move();
			break;
		case HOTKEY_SEARCH:
			search();
			break;
		case HOTKEY_HELP:
			show_help();
			break;
		case HOTKEY_CHAT_LOG:
			show_chat_log();
			break;
		case HOTKEY_USER_CMD:
			user_command();
			break;
		case HOTKEY_CUSTOM_CMD:
			custom_command();
			break;
		case HOTKEY_AI_FORMULA:
			ai_formula();
			break;
		case HOTKEY_CLEAR_MSG:
			clear_messages();
			break;
		case HOTKEY_LANGUAGE:
			change_language();
			break;
		case HOTKEY_REPLAY_PLAY:
			play_replay();
			break;
		case HOTKEY_REPLAY_RESET:
			reset_replay();
			break;
		case HOTKEY_REPLAY_STOP:
			stop_replay();
			break;
		case HOTKEY_REPLAY_NEXT_TURN:
			replay_next_turn();
			break;
		case HOTKEY_REPLAY_NEXT_SIDE:
			replay_next_side();
			break;
		case HOTKEY_REPLAY_NEXT_MOVE:
			replay_next_move();
			break;
		case HOTKEY_REPLAY_SHOW_EVERYTHING:
			replay_show_everything();
			break;
		case HOTKEY_REPLAY_SHOW_EACH:
			replay_show_each();
			break;
		case HOTKEY_REPLAY_SHOW_TEAM1:
			replay_show_team1();
			break;
		case HOTKEY_REPLAY_SKIP_ANIMATION:
			replay_skip_animation();
			break;
		case HOTKEY_REPLAY_EXIT:
			replay_exit();
			break;
		case HOTKEY_WB_TOGGLE:
			whiteboard_toggle();
			break;
		case HOTKEY_WB_EXECUTE_ACTION:
			whiteboard_execute_action();
			break;
		case HOTKEY_WB_EXECUTE_ALL_ACTIONS:
			whiteboard_execute_all_actions();
			break;
		case HOTKEY_WB_DELETE_ACTION:
			whiteboard_delete_action();
			break;
		case HOTKEY_WB_BUMP_UP_ACTION:
			whiteboard_bump_up_action();
			break;
		case HOTKEY_WB_BUMP_DOWN_ACTION:
			whiteboard_bump_down_action();
			break;
		case HOTKEY_WB_SUPPOSE_DEAD:
			whiteboard_suppose_dead();
			break;
		case HOTKEY_SELECT_HEX:
			select_hex();
			break;
		case HOTKEY_DESELECT_HEX:
			deselect_hex();
			break;
		case HOTKEY_MOVE_ACTION:
			move_action();
			break;
		case HOTKEY_SELECT_AND_ACTION:
			select_and_action();
			break;
		case HOTKEY_ACCELERATED:
			toggle_accelerated_speed();
			break;
		case LUA_CONSOLE:
			lua_console();
			break;
		case HOTKEY_ZOOM_IN:
			zoom_in();
			break;
		case HOTKEY_ZOOM_OUT:
			zoom_out();
			break;
		case HOTKEY_ZOOM_DEFAULT:
			zoom_default();
			break;
		case HOTKEY_MAP_SCREENSHOT:
			map_screenshot();
			break;
		case HOTKEY_QUIT_TO_DESKTOP:
			quit_confirmation::quit_to_desktop();
			break;
		case HOTKEY_QUIT_GAME:
			quit_confirmation::quit_to_title();
			break;
		default:
			return false;
	}
	return true;
}
コード例 #8
0
ファイル: saltmine.c プロジェクト: AstoniaDev/Astonia-3.5
void monk_gatama_driver(int cn, int ret, int lastact)
{
        static struct talk_data talkbuf;   // we only have one, so there is no need to use the memory system (?)
        struct talk_data *talkdat=&talkbuf;
        struct saltmine_ppd *ppd;
        struct msg *msg,*next;
        int co;
        int talkdir=0,didsay=0,noturn=0;
        char *str;

        // loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                if (msg->type==NT_CREATE) {
                        fight_driver_set_dist(cn,20,0,30);
                }

                if (msg->type==NT_GIVE) {
                        if (!ch[cn].citem) { remove_message(cn,msg); continue; } // ??? i saw something like this at DBs source
                        co=msg->dat1;

                        // destroy everything we get
                        destroy_item(ch[cn].citem);
                        ch[cn].citem=0;
                }

                if (msg->type==NT_CHAR) {

                        co=msg->dat1;

                        // dont talk
                        if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }             // dont talk to other NPCs
                        if (ch[co].driver==CDR_LOSTCON) { remove_message(cn,msg); continue; }            // dont talk to players without connection
                        if (ticker<talkdat->lasttalk+5*TICKS) { remove_message(cn,msg); continue; }      // only talk when the old sentence is read
                        if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }       // dont talk to someone we cant see, and dont talk to ourself

                        // get ppd
                        if (!(ppd=get_saltmine_ppd(co))) { remove_message(cn,msg); continue; }

                        if (char_dist(cn,co)>7) { ppd->gatamastate=0; remove_message(cn,msg); continue; } // dont talk to someone far away

                        // remove cv
                        if (talkdat->cv_co) {
                                if (!ch[talkdat->cv_co].flags || ch[talkdat->cv_co].serial!=talkdat->cv_serial || char_dist(cn,talkdat->cv_co)>7 || !char_see_char(cn,talkdat->cv_co)) {
                                        talkdat->cv_co=0;
                                }
                        }

                        // only talk to cv
                        if (talkdat->cv_co && talkdat->cv_co!=co) { remove_message(cn,msg); continue; }

                        // set new cv
                        if (!talkdat->cv_co) {
                                talkdat->cv_co=co;
                                talkdat->cv_serial=ch[co].serial;
                        }

                        switch(ppd->gatamastate) {
                                case 0: if (ppd->salt) ppd->gatamastate=50; else ppd->gatamastate=10;
                                        break;

                                // Intro
                                case 10: say(cn,"Welcome %s. The Monastery of Kir Laka needs thine help. We live from the salt we get from the saltmine thou can find to the west. But now many golems appeared in the mine and we had to run for our lives, and all the salt we had already mined is lost there.",ch[co].name); didsay=1; ppd->gatamastate++; break;
                                case 11: say(cn,"Thou might want to know more °c4details°c0 of what thee can do for the monastery. After this, thou might °c4begin°c0 helping us, or not."); didsay=1; ppd->gatamastate++; break;
                                case 12: talkdat->cv_co=0; break;

                                // Details
                                case 20: say(cn,"Thou will have to lead group of monks safely to certain ladders in the saltmine. Once reached, thou \"use\" the ladder, and one of the monks will get the salt out of that place. Every ladder can be used only once every 12 astonian days, and every monk can only carry one bag of salt."); didsay=1; ppd->gatamastate++; break;
                                case 21: say(cn,"The monks will follow thee, and help thee against the golems. Once left, thou canst return to the monastery any time you like, the monks will then deposit their salt, if they have any, and will rest then. Thou can give some commands to the monks by simply speaking to them. Those commands are:");
                                         say(cn,"wait - and they will wait a short while.");
                                         say(cn,"come - and they will come to thee.");
                                         say(cn,"salt - and they will show thee if they carry salt, or not.");
                                         didsay=1; ppd->gatamastate++; break;
                                case 22: say(cn,"Hopefully thou now decide to °c4begin°c0 helping us."); didsay=1; ppd->gatamastate++; break;
                                case 23: talkdat->cv_co=0; break;

                                // Begin (check)
                                case 30: if (monksout(co,ppd)) ppd->gatamastate=40; else ppd->gatamastate++; break;
                                case 31: say(cn,"Come here, Monks. The mighty %s offers %s help. I want to see and hear quick feet now!",ch[co].name,hisname(co)); didsay=1; ppd->gatamastate++;
                                         create_worker(co,ppd);
                                         create_worker(co,ppd);
                                         create_worker(co,ppd);
                                         break;
                                case 32: say(cn,"Lead them wise and carfully, %s. Mayest thou all return safe.",ch[co].name); didsay=1; ppd->gatamastate++;
                                case 33: talkdat->cv_co=0; break;

                                // ...
                                case 40: say(cn,"Let us wait until all thine Monks are resting. Either in the rest room, or in peace."); didsay=1; ppd->gatamastate++;
                                case 41: talkdat->cv_co=0; break;

                                // Reward
                                case 50: say(cn,"Thanks thee %s for thine help. Thou canst use the saltbag in the store room, to take thee thine reward. I trust thee, that thou wilt take the right amount.",ch[co].name); ppd->gatamastate++;
                                case 51: talkdat->cv_co=0; break;
                        }

                        if (didsay) {
                                talkdat->lasttalk=ticker;
                                talkdir=offset2dx(ch[cn].x,ch[cn].y,ch[co].x,ch[co].y);
                        }

		}

                if (msg->type==NT_TEXT) {

                        co=msg->dat3;
                        str=(char *)msg->dat2;

                        tabunga(cn,co,(char*)msg->dat2);

                        if (co==cn) { remove_message(cn,msg); continue; }
			if (!(ch[co].flags&CF_PLAYER)) { remove_message(cn,msg); continue; }
			if (!char_see_char(cn,co)) { remove_message(cn,msg); continue; }
                        if (char_dist(cn,co)>7) { remove_message(cn,msg); continue; }

                        // get ppd
                        if (!(ppd=get_saltmine_ppd(co))) { remove_message(cn,msg); continue; }

                        if (strcasestr(str,"REPEAT")) { say(cn,"I will repeat, %s",ch[co].name); ppd->gatamastate=0; }
                        else if (strcasestr(str,"DETAILS")) { ppd->gatamastate=20; }
                        else if (strcasestr(str,"BEGIN")) { ppd->gatamastate=30; }
                }

                standard_message_driver(cn,msg,1,1);
                remove_message(cn,msg);
	}

        if (talkdir) turn(cn,talkdir);

        // fighting
        fight_driver_update(cn);
        if (fight_driver_attack_visible(cn,0)) return;
	if (regenerate_driver(cn)) return;
	if (spell_self_driver(cn)) return;

        if (talkdat->lasttalk+TICKS*30<ticker || noturn) {
                if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_LEFT,ret,lastact)) return;
                if (!noturn && (ticker/TICKS)%5==0) whisper(cn,"Auaaauuuuuuummmmmmmmmmm");
        }

        do_idle(cn,TICKS);
}
コード例 #9
0
ファイル: clubmaster.c プロジェクト: AstoniaDev/v3.0-server
void clubmaster_driver(int cn,int ret,int lastact)
{
	struct clubmaster_driver_data *dat;
        int co,in,n,rank,cc,val;
        struct msg *msg,*next;
	char *ptr,tmp[80],name[80];

        dat=set_data(cn,DRD_CLUBMASTERDRIVER,sizeof(struct clubmaster_driver_data));
	if (!dat) return;	// oops...

        if (ch[cn].arg) {
                clubmaster_driver_parse(cn,dat);
		ch[cn].arg=NULL;
	}

        // loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

		// did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

			// dont talk to the same person twice
			if (mem_check_driver(cn,co,7)) { remove_message(cn,msg); continue; }

			if (!get_char_club(cn) && !get_char_clan(cn)) quiet_say(cn,"Hello %s! Would you like to found a °c4club°c0?",ch[co].name);
			mem_add_driver(cn,co,7);
		}

                // talk back
		if (msg->type==NT_TEXT) {
			analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,msg->dat3);

                        if ((msg->dat1==1 || msg->dat1==2) && (co=msg->dat3)!=cn) {	// talk, and not our talk				
                                if ((ptr=strcasestr((char*)msg->dat2,"found:"))) {
					if (!(ch[co].flags&CF_PAID)) {
						quiet_say(cn,"I'm sorry, %s, but only paying players may found clubs.",ch[co].name);
					} else if (!get_char_clan(co) && !get_char_club(co)) {
						if (ch[co].gold>=10000*100) {
							ptr+=6;
							while (isspace(*ptr)) ptr++;
							for (n=0; n<79; n++) {
								if (!(isalpha(*ptr) || *ptr==' ')) break;
								name[n]=*ptr++;
							}
							name[n]=0;
							
							if ((n=create_club(name))) {
								take_money(co,10000*100);
								ch[co].clan=n+CLUBOFFSET;
								ch[co].clan_serial=club[n].serial;
								ch[co].clan_rank=2;
								quiet_say(cn,"Congratulations, %s, you are now the leader of the club %s.",ch[co].name,club[n].name);
								dlog(co,0,"created club %d %s",n,club[n].name);
							} else quiet_say(cn,"Something's wrong with the name.");
						} else quiet_say(cn,"You cannot pay the fee of 10,000 gold.");
					} else quiet_say(cn,"You are already a member of a clan or club. You cannot found a new one.");
				}
				if ((ptr=strcasestr((char*)msg->dat2,"accept:"))) {
					if (!get_char_club(co) || ch[co].clan_rank<1) {
                                                quiet_say(cn,"You are not a club leader, %s.",ch[co].name);
					} else {
						ptr+=7;
						while (isspace(*ptr)) ptr++;
						for (n=0; n<79; n++) {
							if (!*ptr || *ptr=='"') break;
							dat->accept[n]=*ptr++;
						}
						dat->accept[n]=0;
						strcpy(dat->join,ch[co].name);
						dat->accept_clan=get_char_club(co);
						dat->accept_cn=co;

						quiet_say(cn,"To join %s's club %s, say: 'join: %s'",dat->join,dat->accept,dat->join);
					}
				}
				if ((ptr=strcasestr((char*)msg->dat2,"join:"))) {
					if (get_char_clan(co) || get_char_club(co)) {
                                                quiet_say(cn,"You are already a clan or club member, %s.",ch[co].name);
					} else {
						ptr+=5;
						while (isspace(*ptr)) ptr++;
						for (n=0; n<79; n++) {
							if (!*ptr || *ptr=='"') break;
							tmp[n]=*ptr++;
						}
						tmp[n]=0;
                                                if (strcasecmp(dat->accept,ch[co].name)) {
							quiet_say(cn,"You have not been invited, %s.",ch[co].name);
						} else if (strcasecmp(dat->join,tmp)) {
							quiet_say(cn,"%s has not invited you, %s.",tmp,ch[co].name);
						} else {
                                                        //add_member(co,dat->accept_clan,dat->join);
							ch[co].clan=dat->accept_clan+CLUBOFFSET;
							ch[co].clan_serial=club[dat->accept_clan].serial;
							ch[co].clan_rank=0;
							quiet_say(cn,"%s, you are now a member of %s's club.",ch[co].name,dat->join);
							dat->accept[0]=0;
							dat->accept_clan=0;
							dat->join[0]=0;
						}
						
					}
				}
				if ((ptr=strcasestr((char*)msg->dat2,"leave!"))) {
					if (!get_char_club(co)) {
                                                quiet_say(cn,"You are not a club member, %s.",ch[co].name);
					} else {
						remove_member(co,co);
						quiet_say(cn,"You are no longer a member of any club, %s",ch[co].name);
					}
				}
				if ((ptr=strcasestr((char*)msg->dat2,"rank:"))) {
					if (!get_char_club(co) || ch[co].clan_rank<2) {
                                                quiet_say(cn,"You are not a club founder, %s.",ch[co].name);
					} else {
						ptr+=6;
						while (isspace(*ptr)) ptr++;
						for (n=0; n<79; n++) {
							if (!*ptr || *ptr=='"' || isspace(*ptr)) break;
							tmp[n]=*ptr++;
						}
						tmp[n]=0;
						
						rank=atoi(ptr);

						if (rank<0 || rank>1) {
							quiet_say(cn,"You must use a rank between 0 and 1.");
							remove_message(cn,msg);
							continue;
						}

						for (cc=getfirst_char(); cc; cc=getnext_char(cc)) {
							if (!strcasecmp(tmp,ch[cc].name) && (ch[cc].flags&CF_PLAYER)) break;
						}
						if (cc) {
							if (!(ch[cc].flags&CF_PAID) && rank>0) {
                                                                quiet_say(cn,"%s is not a paying player, you cannot set the rank higher than 0.",ch[cc].name);
							} else if (ch[cc].clan_rank==2) {
								quiet_say(cn,"%s is the club's founder, cannot change rank.",ch[cc].name);
							} else if (get_char_club(cc)==get_char_club(co)) {
								ch[cc].clan_rank=rank;
								quiet_say(cn,"Set %s's rank to %d.",ch[cc].name,rank);
							} else quiet_say(cn,"You cannot change the rank of those not belonging to your club.");
						} else {
							int uID;

							uID=lookup_name(tmp,NULL);
							if (uID==0) continue;
							if (uID==-1) {
								quiet_say(cn,"Sorry, no player by the name %s found.",tmp);
							} else {
								task_set_clan_rank(uID,ch[co].ID,get_char_club(co)+CLUBOFFSET,rank,ch[co].name);
								quiet_say(cn,"Update scheduled (%s,%d).",tmp,rank);
							}
						}
					}
				}
				if ((ptr=strcasestr((char*)msg->dat2,"fire:"))) {
					if (!get_char_club(co) || ch[co].clan_rank<1) {
                                                quiet_say(cn,"You are not a club leader, %s.",ch[co].name);
					} else {
						ptr+=6;
						while (isspace(*ptr)) ptr++;
						for (n=0; n<79; n++) {
							if (!*ptr || *ptr=='"' || isspace(*ptr)) break;
							tmp[n]=*ptr++;
						}
						tmp[n]=0;
						
                                                for (cc=getfirst_char(); cc; cc=getnext_char(cc)) {
							if (!strcasecmp(tmp,ch[cc].name) && (ch[cc].flags&CF_PLAYER)) break;
						}
						if (cc) {
							if (get_char_club(cc)==get_char_club(co)) {
								if (ch[cc].clan_rank<2) {
									remove_member(cc,co);
									quiet_say(cn,"Fired: %s.",ch[cc].name);
								} else quiet_say(cn,"You cannot fire the founder of the club.");
							} else quiet_say(cn,"You cannot fire those not belonging to your club.");
						} else {
							int uID;

							uID=lookup_name(tmp,NULL);
							if (uID==0) continue;
							if (uID==-1) {
								quiet_say(cn,"Sorry, no player by the name %s found.",tmp);
							} else {
								task_fire_from_clan(uID,ch[co].ID,get_char_club(co)+CLUBOFFSET,ch[co].name);
								quiet_say(cn,"Update scheduled (%s).",tmp);
							}
						}
					}
				}

				if ((ptr=strcasestr((char*)msg->dat2,"deposit:"))) {
					if (!(n=get_char_club(co))) {
                                                quiet_say(cn,"You are not a club member, %s.",ch[co].name);
					} else {
						val=atoi(ptr+8)*100;

						if (val>0 && ch[co].gold>=val) {
							club[n].money+=val;
							take_money(co,val);
							quiet_say(cn,"You have deposited %dG, for a total of %dG, %s.",val/100,club[n].money/100,ch[co].name);
							dlog(co,0,"Deposited %dG into club %d, for a new total of %dG",val/100,n,club[n].money/100);
							db_update_club(n);
						} else quiet_say(cn,"You do not have that much gold, %s.",ch[co].name);
					}
				}
				if ((ptr=strcasestr((char*)msg->dat2,"withdraw:"))) {
					if (!(n=get_char_club(co)) || ch[co].clan_rank<2) {
                                                quiet_say(cn,"You are not a club founder, %s.",ch[co].name);
					} else {
						val=atoi(ptr+9)*100;

						if (val>0 && club[n].money>=val) {
							club[n].money-=val;
							give_money(co,val,"club withdrawal");
							quiet_say(cn,"You have withdrawn %dG, money left in club %dG, %s.",val/100,club[n].money/100,ch[co].name);
							dlog(co,0,"Withdrew %dG from club %d, for a new total of %dG",val/100,n,club[n].money/100);
							db_update_club(n);
						} else quiet_say(cn,"The club does not have that much gold, %s.",ch[co].name);
					}
				}
			}			
		}

		// got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;

                        if ((in=ch[cn].citem)) {	// we still have it
				// try to give it back
                                if (give_char_item(cn,co)) return;
				
				// didnt work, let it vanish, then
				destroy_item(ch[cn].citem);
				ch[cn].citem=0;
			}
		}
                remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

	if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,dat->dir,ret,lastact)) return;

        if (ticker>dat->last_talk+TICKS*60 && !RANDOM(25)) {
		switch(RANDOM(8)) {
			case 0:		murmur(cn,"My back itches."); break;
			case 1:		whisper(cn,"There's something stuck between your teeth."); break;
			case 2:		murmur(cn,"Oh yeah, those were the days."); break;
			case 3:		murmur(cn,"Now where did I put it?"); break;
			case 4:		murmur(cn,"Oh my, life is hard but unfair."); break;
                        case 5:		murmur(cn,"Beware of the fire snails!"); break;
			case 6:         murmur(cn,"I love the clicking of coins."); break;
			case 7:		murmur(cn,"Gold and Silver, Silver and Gold."); break;
			default:	break;
		}
		
		dat->last_talk=ticker;
	}

	if (ticker>dat->memcleartimer) {
		mem_erase_driver(cn,7);
		dat->memcleartimer=ticker+TICKS*60*60*12;
	}

        do_idle(cn,TICKS*2);
}
コード例 #10
0
ファイル: hotkeys.cpp プロジェクト: AG-Dev/wesnoth_ios
bool command_executor::execute_command(HOTKEY_COMMAND command, int /*index*/)
{
	switch(command) {
		case HOTKEY_CYCLE_UNITS:
			cycle_units();
			break;
		case HOTKEY_CYCLE_BACK_UNITS:
			cycle_back_units();
			break;
		case HOTKEY_ENDTURN:
			end_turn();
			break;
		case HOTKEY_UNIT_HOLD_POSITION:
			unit_hold_position();
			break;
		case HOTKEY_END_UNIT_TURN:
			end_unit_turn();
			break;
		case HOTKEY_LEADER:
			goto_leader();
			break;
		case HOTKEY_UNDO:
			undo();
			break;
		case HOTKEY_REDO:
			redo();
			break;
		case HOTKEY_UNIT_DESCRIPTION:
			unit_description();
			break;
		case HOTKEY_RENAME_UNIT:
			rename_unit();
			break;
		case HOTKEY_SAVE_GAME:
			save_game();
			break;
		case HOTKEY_SAVE_REPLAY:
			save_replay();
			break;
		case HOTKEY_SAVE_MAP:
			save_map();
			break;
		case HOTKEY_LOAD_GAME:
			load_game();
			break;
		case HOTKEY_TOGGLE_ELLIPSES:
			toggle_ellipses();
			break;
		case HOTKEY_TOGGLE_GRID:
			toggle_grid();
			break;
		case HOTKEY_STATUS_TABLE:
			status_table();
			break;
		case HOTKEY_RECALL:
			recall();
			break;
		case HOTKEY_RECRUIT:
			recruit();
			break;
		case hotkey::HOTKEY_REPEAT_RECRUIT:
			repeat_recruit();
			break;
		case HOTKEY_SPEAK:
			speak();
			break;
		case HOTKEY_SPEAK_ALLY:
			whisper();
			break;
		case HOTKEY_SPEAK_ALL:
			shout();
			break;
		case HOTKEY_CREATE_UNIT:
			create_unit();
			break;
		case HOTKEY_CHANGE_SIDE:
			change_side();
			break;
		case HOTKEY_PREFERENCES:
			preferences();
			break;
		case HOTKEY_OBJECTIVES:
			objectives();
			break;
		case HOTKEY_UNIT_LIST:
			unit_list();
			break;
		case HOTKEY_STATISTICS:
			show_statistics();
			break;
		case HOTKEY_STOP_NETWORK:
			stop_network();
			break;
		case HOTKEY_START_NETWORK:
			start_network();
			break;
		case HOTKEY_LABEL_TEAM_TERRAIN:
			label_terrain(true);
			break;
		case HOTKEY_LABEL_TERRAIN:
			label_terrain(false);
			break;
		case HOTKEY_CLEAR_LABELS:
			clear_labels();
			break;
		case HOTKEY_SHOW_ENEMY_MOVES:
			show_enemy_moves(false);
			break;
		case HOTKEY_BEST_ENEMY_MOVES:
			show_enemy_moves(true);
			break;
		case HOTKEY_DELAY_SHROUD:
			toggle_shroud_updates();
			break;
		case HOTKEY_UPDATE_SHROUD:
			update_shroud_now();
			break;
		case HOTKEY_CONTINUE_MOVE:
			continue_move();
			break;
		case HOTKEY_SEARCH:
			search();
			break;
		case HOTKEY_HELP:
			show_help();
			break;
		case HOTKEY_CHAT_LOG:
			show_chat_log();
			break;
		case HOTKEY_USER_CMD:
			user_command();
			break;
		case HOTKEY_CUSTOM_CMD:
			custom_command();
			break;
		case HOTKEY_AI_FORMULA:
			ai_formula();
			break;
		case HOTKEY_CLEAR_MSG:
			clear_messages();
			break;
		 case HOTKEY_LANGUAGE:
			change_language();
			break;
		 case HOTKEY_PLAY_REPLAY:
			play_replay();
			 break;
		 case HOTKEY_RESET_REPLAY:
			reset_replay();
			 break;
		 case HOTKEY_STOP_REPLAY:
			 stop_replay();
			 break;
		 case HOTKEY_REPLAY_NEXT_TURN:
			replay_next_turn();
			 break;
		 case HOTKEY_REPLAY_NEXT_SIDE:
			replay_next_side();
			 break;
		 case HOTKEY_REPLAY_SHOW_EVERYTHING:
			replay_show_everything();
			 break;
		 case HOTKEY_REPLAY_SHOW_EACH:
			replay_show_each();
			 break;
		 case HOTKEY_REPLAY_SHOW_TEAM1:
			replay_show_team1();
			 break;
		 case HOTKEY_REPLAY_SKIP_ANIMATION:
			replay_skip_animation();
			 break;
		 case HOTKEY_WB_TOGGLE:
			 whiteboard_toggle();
			 break;
		 case HOTKEY_WB_EXECUTE_ACTION:
			 whiteboard_execute_action();
			 break;
		 case HOTKEY_WB_EXECUTE_ALL_ACTIONS:
			 whiteboard_execute_all_actions();
			 break;
		 case HOTKEY_WB_DELETE_ACTION:
			 whiteboard_delete_action();
			 break;
		 case HOTKEY_WB_BUMP_UP_ACTION:
			 whiteboard_bump_up_action();
			 break;
		 case HOTKEY_WB_BUMP_DOWN_ACTION:
			 whiteboard_bump_down_action();
			 break;
		 case HOTKEY_WB_SUPPOSE_DEAD:
			 whiteboard_suppose_dead();
			 break;
		 case HOTKEY_LEFT_MOUSE_CLICK:
			 left_mouse_click();
			 break;
		 case HOTKEY_RIGHT_MOUSE_CLICK:
			 right_mouse_click();
			 break;
		 default:
			 return false;
	}
	return true;
}
コード例 #11
0
ファイル: merchant.c プロジェクト: AstoniaDev/v3.0-server
void merchant_driver(int cn,int ret,int lastact)
{
	struct merchant_driver_data *dat;
        int co,in,n;
	struct msg *msg,*next;

        dat=set_data(cn,DRD_MERCHANTDRIVER,sizeof(struct merchant_driver_data));
	if (!dat) return;	// oops...

        if (ch[cn].arg) {
		dat->open=6; dat->close=23;
		merchant_driver_parse(cn,dat);
		ch[cn].arg=NULL;
	}
	if (!ch[cn].store) {
		if (dat->pricemulti) create_store(cn,dat->ignore,dat->pricemulti);
		else create_store(cn,dat->ignore,400);
		if (dat->special) {
			for (n=0; n<5; n++) add_special_store(cn);
		}
	}
	
	// loop through our messages
	for (msg=ch[cn].msg; msg; msg=next) {
		next=msg->next;

                // did we see someone?
		if (msg->type==NT_CHAR) {
			
                        co=msg->dat1;

			// dont talk to someone we cant see, and dont talk to ourself
			if (!char_see_char(cn,co) || cn==co) { remove_message(cn,msg); continue; }

			// dont talk to someone far away
			if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; }

			// dont talk to the same person twice
			if (mem_check_driver(cn,co,7)) { remove_message(cn,msg); continue; }

			quiet_say(cn,"Hello %s! If you'd like to trade, say: '°c4%s, trade°c0!",ch[co].name,ch[cn].name);
			mem_add_driver(cn,co,7);
		}

                // talk back
		if (msg->type==NT_TEXT) {
			analyse_text_driver(cn,msg->dat1,(char*)msg->dat2,msg->dat3);

			if ((msg->dat1==1 || msg->dat1==2) && (co=msg->dat3)!=cn) {	// talk, and not our talk
				if (strcasestr((char*)msg->dat2,ch[cn].name) &&
				    strcasestr((char*)msg->dat2,"trade")) {
					/*if (abuser(ch[co].ID)) {
						switch(RANDOM(3)) {
                                                        case 0:		murmur(cn,"I hate cheaters."); break;
							case 1:		emote(cn,"clenches his fists and stares at %s.",ch[co].name); break;
							case 2:		murmur(cn,"I wish the cheaters would leave me alone."); break;
						}
					}*/
					ch[co].merchant=cn;
				}
			}			
		}

		// got an item?
		if (msg->type==NT_GIVE) {
			co=msg->dat1;

                        if ((in=ch[cn].citem)) {	// we still have it
				// let it vanish
				destroy_item(ch[cn].citem);
				ch[cn].citem=0;
			}
		}

                remove_message(cn,msg);
	}

        // do something. whenever possible, call do_idle with as high a tick count
	// as reasonable when doing nothing.

	if (dat->dayx) {	// we have day / night positions
		if (!opening_time(dat->open,dat->close)) {	// we're closed
                        if (dat->doorx && !is_closed(dat->doorx,dat->doory)) {	// door is still open
				if (!is_room_empty(dat->storefx,dat->storefy,dat->storetx,dat->storety)) {	// store is not empty
					quiet_say(cn,"We're closing, please leave now!");
					do_idle(cn,TICKS);
					return;
				} else {
					if (use_item_at(cn,dat->doorx,dat->doory,0)) return;
					do_idle(cn,TICKS);
					return;
				}
			}
			if (secure_move_driver(cn,dat->nightx,dat->nighty,dat->nightdir,ret,lastact)) return;
		} else {	// we're open
                        if (dat->doorx && is_closed(dat->doorx,dat->doory)) {	// door is still closed
                                if (use_item_at(cn,dat->doorx,dat->doory,0)) return;
				do_idle(cn,TICKS);
				return;			
			}

			if (secure_move_driver(cn,dat->dayx,dat->dayy,dat->daydir,ret,lastact)) return;			
		}
	} else {		// just one position
		if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,dat->dir,ret,lastact)) return;		
	}

        if (ticker>dat->last_talk+TICKS*60 && !RANDOM(25)) {
		switch(RANDOM(11)) {
			case 0:		murmur(cn,"My back itches."); break;
			case 1:		whisper(cn,"There's something stuck between your teeth."); break;
			case 2:		murmur(cn,"Oh yeah, those were the days."); break;
			case 3:		murmur(cn,"Now where did I put it?"); break;
			case 4:		murmur(cn,"Oh my, life is hard but unfair."); break;
			case 5:		murmur(cn,"Beware of the fire snails!"); break;	
			case 6:		murmur(cn,"Ishtar! Oh, what has become of us!"); break;
			case 7:		murmur(cn,"The demons will get you."); break;
			case 8:		emote(cn,"scratches %s back",hisname(cn)); break;
			case 9:		if (map[ch[cn].x+ch[cn].y*MAXMAP].flags&MF_INDOORS) emote(cn,"stares at the ceiling");
					else emote(cn,"stares at the sky");
					break;
			case 10:	emote(cn,"twiddles %s thumbs",hisname(cn)); break;

			default:	break;
		}
		
		dat->last_talk=ticker;
	}
	if (dat->special && ticker>dat->lastadd+TICKS*60*60*12) {
		add_special_store(cn);
		dat->lastadd=ticker;
	}

	if (ticker>dat->memcleartimer) {
		mem_erase_driver(cn,7);
		dat->memcleartimer=ticker+TICKS*60*60*12;
	}

        do_idle(cn,TICKS*2);
}
コード例 #12
0
ファイル: Server.cpp プロジェクト: Yann4/MultiCPP
Actions::Event Server::sendHelpText(std::string message, Client client)
{
	std::string helpText = "Welcome to the server. There are several commands that you can use.\n/Name [NewName here] changes your name\n/Quit to exit\n/Help to see this help text";
	whisper(Message(helpText, client.id));
	return Actions::Event::HELP;
}