Exemplo n.º 1
0
void list_characters_in_chan(int connection, int chan){

    /** public function - see header */

    char text_out[1024]="";

    sprintf(text_out, "%cListing for channel [%i]: %s", c_blue1+127, chan, channel[chan].channel_name);
    send_raw_text(connection, CHAT_SERVER, text_out);

    sprintf(text_out, "%cDescription: %s", c_blue1+127, channel[chan].description);
    send_raw_text(connection, CHAT_SERVER, text_out);

    sprintf(text_out, "%cCharacters in channel...", c_blue1+127);
    send_raw_text(connection, CHAT_SERVER, text_out);

    int i=0;

    for(i=0; i<MAX_CLIENTS; i++){

        if(clients.client[i].client_status==LOGGED_IN){

            if(is_player_in_chan(i, chan)!=NOT_FOUND){

                sprintf(text_out, "%c%s ", c_blue1+127, clients.client[i].char_name);
                send_raw_text(connection, CHAT_SERVER, text_out);
            }
        }
    }
}
Exemplo n.º 2
0
void check_new_character(int connection, unsigned char *packet){

    int packet_length=packet[1] + (packet[2] * 256) + 2;

    //create a union so we can convert the packet array into easily accessible individual data elements
    union {

        unsigned char buf[packet_length];

        struct {
            unsigned char protocol;
            unsigned char lsb;
            unsigned char msb;
            char name_and_password[packet_length-10];
            unsigned char skin;
            unsigned char hair;
            unsigned char shirt;
            unsigned char pants;
            unsigned char boots;
            unsigned char type;
            unsigned char head;
        }output;

    }convert;

    //copy the packet into the union
    memcpy(convert.buf, packet, packet_length);

    //extract the character name from the union
    char char_name[80]="";
    get_str_island(convert.output.name_and_password, char_name, 1);

    //check if the character name already exists
    if(get_db_char_data(char_name)==FOUND){

        //if the char name exists, abort character creation and send warning to client
        char text_out[1024]="";
        sprintf(text_out, "%cSorry, but that character name already exists", c_red1+127);
        send_raw_text(connection, CHAT_SERVER, text_out);

        send_create_char_not_ok(connection);

        log_event(EVENT_SESSION, "Attempt to create new char with existing char name [%s]", char_name);

        return;
    }
    else {

        //if char name does not exist, tell idle buffer to create a new character with that name
        db_push_buffer("", connection, IDLE_BUFFER_PROCESS_ADD_NEWCHAR, packet);
    }
}
Exemplo n.º 3
0
void send_pm(int connection, char *target_name, char *message) {

    char text_out[1024]="";

    // echo message back to sender
    sprintf(text_out, "%c[PM to %s: %s]", c_orange1+127, target_name, message);
    send_raw_text(connection, CHAT_PERSONAL, text_out);

    //check if message recipient is in game
    int target_connection=char_in_game(target_name);

    if(target_connection==NOT_FOUND){

         log_text(EVENT_CHAT, "target character not logged in");

        return;
    }

    sprintf(text_out, "%c[PM from %s: %s]", c_orange1+127, target_name, message);
    send_raw_text(target_connection, CHAT_PERSONAL, text_out);

    return;
}
Exemplo n.º 4
0
int join_channel(int connection, int chan){

    /** public function - see header */

    char text_out[1024]="";

    // check for valid channel number
    if(chan<0 || chan>=MAX_CHANNELS){

        sprintf(text_out, "%cyou tried to join an invalid channel", c_red3+127);
        send_raw_text(connection, CHAT_SERVER, text_out);

        return CHANNEL_NOT_JOINED;
    }

    //stop players from joining system channels
    else if(channel[chan].chan_type==CHAN_SYSTEM){

        sprintf(text_out, "%cchannel is reserved for system use", c_red3+127);
        send_raw_text(connection, CHAT_SERVER, text_out);

        return CHANNEL_NOT_JOINED;
    }

    //stop players from joining vacant channels
    else if(channel[chan].chan_type==CHAN_VACANT){

        sprintf(text_out, "%cThat channel is not open", c_red3+127);
        send_raw_text(connection, CHAT_SERVER, text_out);

        return CHANNEL_NOT_JOINED;
    }

    //stop players from joining guild channels
    else if(channel[chan].chan_type==CHAN_GUILD){

        sprintf(text_out, "%cThat channel is for a guild", c_red3+127);
        send_raw_text(connection, CHAT_SERVER, text_out);

        return CHANNEL_NOT_JOINED;
    }

    //check if player is already in chan
    if(is_player_in_chan(connection, chan)!=NOT_FOUND){

        sprintf(text_out, "%cYou have already joined that chan", c_red3+127);
        send_raw_text(connection, CHAT_SERVER, text_out);

        return CHANNEL_NOT_JOINED;
    }

    //check if client has a free chan slot
    int i=0;

    for(i=0; i<MAX_CHAN_SLOTS; i++){

        //found free slot
        if(clients.client[connection].chan[i]==0) {

            sprintf(text_out, "%c%s has joined channel %s", c_yellow2+127, clients.client[connection].char_name, channel[chan].channel_name);
            broadcast_channel_event(chan, connection, text_out);

            clients.client[connection].chan[i]=chan;

            char sql[MAX_SQL_LEN]="";
            snprintf(sql, MAX_SQL_LEN, "UPDATE CHARACTER_TABLE SET CHAN_%i=%i WHERE CHAR_ID=%i;", i, chan, clients.client[connection].character_id);
            db_push_buffer(sql, 0, IDLE_BUFFER_PROCESS_SQL, NULL);

            clients.client[connection].active_chan=i+31;
            send_get_active_channels(connection);

            snprintf(sql, MAX_SQL_LEN, "UPDATE CHARACTER_TABLE SET ACTIVE_CHAN=%i WHERE CHAR_ID=%i;", clients.client[connection].active_chan, clients.client[connection].character_id);
            db_push_buffer(sql, 0, IDLE_BUFFER_PROCESS_SQL, NULL);

            //echo back to player which channel was just joined and its description etc
            sprintf(text_out, "%cYou joined channel %s", c_green3+127, channel[chan].channel_name);
            send_raw_text(connection, CHAT_SERVER, text_out);

            sprintf(text_out, "%cDescription : %s", c_green2+127, channel[chan].description);
            send_raw_text(connection, CHAT_SERVER, text_out);

            sprintf(text_out, "%cIn channel :", c_green1+127);
            send_raw_text(connection, CHAT_SERVER, text_out);

            list_characters_in_chan(connection, chan);

            //tell other in chan that player has joined
            sprintf(text_out, "%c%s has joined channel %s", c_yellow2+127, clients.client[connection].char_name, channel[chan].channel_name);
            broadcast_channel_event(chan, connection, text_out);

            return CHANNEL_JOINED;
        }
    }

    //free chan slot not found
    sprintf(text_out, "%cyou have no free channel slots left", c_red3+127);
    send_raw_text(connection, CHAT_SERVER, text_out);

    return CHANNEL_NOT_JOINED;
}
Exemplo n.º 5
0
int leave_channel(int connection, int chan){

    /** public function - see header */

    char text_out[80]="";
    char sql[MAX_SQL_LEN]="";

    int slot=is_player_in_chan(connection, chan);

    if(slot==NOT_FOUND){

            sprintf(text_out, "%cyou are not in this channel", c_red3+127);
            send_raw_text(connection, CHAT_SERVER, text_out);

            return CHANNEL_NOT_LEFT;
    }

    //echo back to player which channel was just left
    sprintf(text_out, "%c%s has left channel %s", c_yellow2+127, clients.client[connection].char_name, channel[chan].channel_name);
    broadcast_channel_event(chan, connection, text_out);

    //null the channel slot
    clients.client[connection].chan[slot]=0;

    snprintf(sql, MAX_SQL_LEN,"UPDATE CHARACTER_TABLE SET CHAN_%i=%i WHERE CHAR_ID=%i;", slot, chan, clients.client[connection].character_id);
    db_push_buffer(sql, 0, IDLE_BUFFER_PROCESS_SQL, NULL);

    // need to echo back to player which channel was just joined and its description etc
    sprintf(text_out, "%cyou left channel %s", c_green3+127, channel[chan].channel_name);
    send_raw_text(connection, CHAT_SERVER, text_out);

    //tell others in chan that player has left
    sprintf(text_out, "%c%s has left channel %s", c_yellow2+127, clients.client[connection].char_name, channel[chan].channel_name);
    broadcast_channel_event(chan, connection, text_out);

    //set active channel to next used channel slot or 0
    clients.client[connection].active_chan=0;

    int i=0;
    for(i=0; i<MAX_CHAN_SLOTS; i++){

        if(clients.client[connection].chan[i]>0){

            clients.client[connection].active_chan=i+31;
            break;
        }
    }

    send_get_active_channels(connection);

    sprintf(sql, "UPDATE CHARACTER_TABLE SET ACTIVE_CHAN=%i WHERE CHAR_ID=%i;", clients.client[connection].active_chan, clients.client[connection].character_id);
    db_push_buffer(sql, 0, IDLE_BUFFER_PROCESS_SQL, NULL);

    if(clients.client[connection].active_chan==0){

        sprintf(text_out, "%cyou have no channels", c_red3+127);
        send_raw_text(connection, CHAT_SERVER, text_out);
    }

    return CHANNEL_LEFT;
}
Exemplo n.º 6
0
void add_new_character(int connection, unsigned char *packet){

    int packet_length=packet[1] + (packet[2] * 256) + 2;

    //create a union so we can convert the packet array into easily accessible individual data elements
    union {

        unsigned char buf[packet_length];

        struct {
            unsigned char protocol;
            unsigned char lsb;
            unsigned char msb;
            char name_and_password[packet_length-10];
            unsigned char skin;
            unsigned char hair;
            unsigned char shirt;
            unsigned char pants;
            unsigned char boots;
            unsigned char type;
            unsigned char head;
        }output;

    }convert;

    //copy the packet into the union
    memcpy(convert.buf, packet, packet_length);

    //We pass character data to the database via the character struct, so lets clear it first
    memset(&character, 0, sizeof(character));

    //extract character data from the union and place in the character struct
    get_str_island(convert.output.name_and_password, character.char_name, 1);
    get_str_island(convert.output.name_and_password, character.password, 2);
    character.skin_type=convert.output.skin;
    character.hair_type=convert.output.hair;
    character.shirt_type=convert.output.shirt;
    character.pants_type=convert.output.pants;
    character.boots_type=convert.output.boots;
    character.char_type=convert.output.type;
    character.head_type=convert.output.head;

    //set the char to stand
    character.frame=frame_stand;

    //set the char creation time
    character.char_created=time(NULL);

    //set starting channels
    int i=0, j=0;
    for(i=0; i<MAX_CHANNELS; i++){

        if(channel[i].new_chars==1){

            if(j<MAX_CHAN_SLOTS){

                if(j==0) character.active_chan=i-CHAT_CHANNEL0;
                character.chan[j]=i;
            }
        }
    }

    //set starting map and tile
    character.map_id=game_data.beam_map_id;
    character.map_tile=game_data.beam_map_tile;

    //we use the add_db_char_data function to add character to the database. This function returns
    //an integer corresponding to the character_table id for the new record which, we'll need to
    //link to corresponding entries for the character in the inventory table
    clients.client[connection].character_id=add_db_char_data(character);

    //add initial items to inventory
    //int slot=0;
    //add_item_to_inventory(connection, 612, 1, &slot);
    //add_item_to_inventory(connection, 613, 1, &slot);
    //add_item_to_inventory(connection, 216, 1, &slot);
    //add_item_to_inventory(connection, 217, 1, &slot);

    //update game data
    race[character.char_type].char_count++;
    game_data.char_count++;
    strcpy(game_data.name_last_char_created, character.char_name);
    game_data.date_last_char_created=character.char_created;

    //notify client that character has been created
    char text_out[160]="";
    sprintf(text_out, "%cCongratulations. You've created your new game character.", c_green3+127);
    send_raw_text(connection, CHAT_SERVER, text_out);
    send_create_char_ok(connection);

    //log character creation event
    log_event(EVENT_NEW_CHAR, "[%s] password [%s]\n", character.char_name, character.password);
}
Exemplo n.º 7
0
void handle_command(char *user, char *command, char *args)
{
	int privilege;
	 
	if (!strcasecmp(user, cfg.admin)) {
		privilege = 5;
	} else {
		privilege = get_privilege_for_user(user);
	}

	// Handle trade commands
	if (command[0] != '#') {          
		handle_trade_command(user, command, args);
		return;
	}

	if (privilege < 1) {
		return;
	}
	
	// Level 1 commands
	
	
	if (privilege < 2) {
		return;
	}
	
	// Level 2 commands
	
	if (!strcasecmp(command, "#reload")) {
		load_config();
		send_pm("%s %s", user, "OK");
		return;
	}
	
	if (privilege < 3) {
		return;
	}
	
	// Level 3 commands
	
	if (privilege < 4) {
		return;
	}
	
	// Level 4 commands
	
	if (!strcasecmp(command, "#get_credits")) {
		int credits = get_credits_for_user(args);
		send_pm("%s %s has %d gold coin(s) in credit", user, args, credits);
		return;
	}
	
	if (!strcasecmp(command, "#get_priv")) {
		int priv = get_privilege_for_user(args);
		send_pm("%s %s's privilege level is %d", user, args, priv);
		return;
	}
	
	if (privilege < 5) {
		return;
	}
	
	// Level 5 commands
	
	if (!strcasecmp(command, "#set_credits") && args) {
		char *ptr = strchr(args, ' ');
		int credits;
		
		if (!ptr || ptr[1] < '0' || ptr[1] > '9') { return; }
		*ptr++ = 0;
		credits = atoi(ptr);
		
		set_credits_for_user(args, credits);
		
		send_pm("%s %s now has %d gold coin(s) in credit", user, args, credits);
		return;
	}
	
	if (!strcasecmp(command, "#add_credits") && args) {
		char *ptr = strchr(args, ' ');
		int credits;
		
		if (!ptr || ptr[1] < '0' || ptr[1] > '9') { return; }
		*ptr++ = 0;
		credits = atoi(ptr);
		
		add_credits_to_user(args, credits);
		
		send_pm("%s %s now has %d gold coin(s) in credit", user,
			args, get_credits_for_user(args));
		return;
	}
	
	if (!strcasecmp(command, "#rem_credits") && args) {
		char *ptr = strchr(args, ' ');
		int credits;
		
		if (!ptr || ptr[1] < '0' || ptr[1] > '9') { return; }
		*ptr++ = 0;
		credits = atoi(ptr);
		
		remove_credits_from_user(args, credits);
		
		send_pm("%s %s now has %d gold coin(s) in credit", user,
			args, get_credits_for_user(args));
		return;
	}
	
	if (!strcasecmp(command, "#set_priv") && args) {
		char *ptr = strchr(args, ' ');
		int priv;
		
		if (!ptr || ptr[1] < '0' || ptr[1] > '9') { return; }
		*ptr++ = 0;
		priv = atoi(ptr);
		
		set_privilege_for_user(args, priv);
		
		send_pm("%s %s's privilege level is now %d", user, args, priv);
		return;
	}
	
	if (!strcasecmp(command, "#say") && args) {
		send_raw_text(args);
		return;
	}
}
Exemplo n.º 8
0
void start_char_move(int connection, int destination){

    /** public function - see header */

    char text_out[1024]="";

    int map_id=clients.client[connection].map_id;
    int current_tile=clients.client[connection].map_tile;

/*
    //if char is harvesting then stop
    if(clients.client[connection].harvest_flag==TRUE){

        stop_harvesting2(connection, loop);
        return;
    }
*/

    //if char is sitting then stand before moving
    if(clients.client[connection].frame==frame_sit){

        clients.client[connection].frame=frame_stand;
        broadcast_actor_packet(connection, actor_cmd_stand_up, clients.client[connection].map_tile);

        char sql[MAX_SQL_LEN]="";
        snprintf(sql, MAX_SQL_LEN, "UPDATE CHARACTER_TABLE SET FRAME=%i WHERE CHAR_ID=%i", clients.client[connection].frame, clients.client[connection].character_id);
        db_push_buffer(sql, 0, IDLE_BUFFER_PROCESS_SQL, NULL);
    }

    //check if the destination is walkable
    if(maps.map[map_id].height_map[destination]<MIN_TRAVERSABLE_VALUE){

        sprintf(text_out, "%cThe tile you clicked on can't be walked on", c_red3+127);
        send_raw_text(connection, CHAT_SERVER, text_out);

        return;
    }

    //check for zero length path
    if(current_tile==destination){

        #if DEBUG_MOVEMENT==1
        printf("current tile = destination (ignored)\n");
        #endif

        return;
    }

    //get path
    if(get_astar_path(connection, current_tile, destination)==NOT_FOUND){

        log_event(EVENT_ERROR, "path not found in function %s: module %s: line %i", __func__, __FILE__, __LINE__);
    }

/*
    //if standing on a bag, close the bag grid
    if(clients.client[connection].bag_open==TRUE){

        clients.client[connection].bag_open=FALSE;
        send_s_close_bag(connection);
    }
*/

    #if DEBUG_MOVEMENT==1
    printf("character [%s] got a new path...\n", clients.client[connection].char_name);

    int i=0;
    for(i=0; i<clients.client[connection].path_count; i++){
        printf("%i %i\n", i, clients.client[connection].path[i]);
    }
    #endif

    //reset time of last move to zero so the movement is processed without delay
    clients.client[connection].time_of_last_move=0;
}