コード例 #1
0
ファイル: chatserv.c プロジェクト: catskillmarina/eBBS
int chat_query_chatid( int unum, char *msg )
{
  USERDATA udata;
  int recunum;
  char *recipient = nextword(&msg);
  send_to_unum(unum, "***\n", -1);
  if (*recipient == '\0') {
    /* map all chatids to userids */
    return (chat_map_chatids(unum));
  }
  recunum = fuzzy_chatid_to_indx(recipient);
  if (recunum < 0) {  
    /* no such user, or ambiguous */
    if (recunum == -1) sprintf(genbuf, "*** No such chatid '%s'\n", recipient);
    else sprintf(genbuf, "*** '%s' is ambiguous: try more letters", recipient);
    send_to_unum(unum, genbuf, -1);
    return 0;
  }    
  if (utable_get_record(users[recunum].utent, &udata) != S_OK ||
      strcmp(users[recunum].userid, udata.u.userid) ||
      udata.u.mode != M_CHAT) {
    sprintf(genbuf, "*** '%s' is apparently no longer here\n", 
	    users[recunum].userid);
    send_to_unum(unum, genbuf, -1);
    exit_room(recunum, EXIT_LOSTCONN, (char *)NULL);
    logout_user(recunum);        
    return 0;
  }
  sprintf(genbuf, "*** %s is %s (%s)\n", users[recunum].chatid,
          udata.u.userid, udata.u.username);
  send_to_unum(unum, genbuf, -1);
  sprintf(genbuf, "*** Logged in from %s\n", udata.u.fromhost);          
  send_to_unum(unum, genbuf, -1);
  return 0;
}
コード例 #2
0
ファイル: chatserv.c プロジェクト: catskillmarina/eBBS
int chat_kick( int unum, char *msg )
{
  char *twit = nextword(&msg);
  int rnum = users[unum].room;
  int recunum;
  if (!OPERATOR(unum) && !MANAGER(unum)) {
    send_to_unum(unum, "*** You're not operator\n", -1);
    return 0;
  }
  if ((recunum = chatid_to_indx(twit)) == -1) {
    /* no such user */
    sprintf(genbuf, "*** No such chatid '%s'\n", twit);
    send_to_unum(unum, genbuf, -1);
    return 0;
  }    
  if (rnum != users[recunum].room) {
    sprintf(genbuf, "*** '%s' is not in this room\n", users[recunum].chatid);
    send_to_unum(unum, genbuf, -1);
    return 0;
  }
  exit_room(recunum, EXIT_KICK, msg);

  if (rnum == 0) logout_user(recunum);        
  else enter_room(recunum, mainroom, (char *)NULL);    

  return 0;  
}  
コード例 #3
0
ファイル: services.c プロジェクト: junbinxu/ChineseChess
void on_exit_room (int fd, struct message *msg)
{
	printf ("on_exit_room\n");
	int index ;
	sscanf (msg->buff, "%d", &index);

	send_to_opp (fd, msg);
	exit_room (fd, msg);

	msg->type = UPDATE_ROOM;
	memcpy (msg->buff, &rooms[index], sizeof (rooms[index]));
	send_to_online_user (msg);
}
コード例 #4
0
ファイル: seg000.c プロジェクト: diddledan/SDLPoP
// seg000:08EB
void __pascal far play_frame() {
	do_mobs();
	process_trobs();
	check_skel();
	check_can_guard_see_kid();
	// if level is restarted, return immediately
	if (play_kid_frame()) return;
	play_guard_frame();
	if (0 == resurrect_time) {
		check_sword_hurting();
		check_sword_hurt();
	}
	check_sword_vs_sword();
	do_delta_hp();
	exit_room();
	check_the_end();
	check_guard_fallout();
	if (current_level == 0) {
		// Special event: level 0 running exit
		if (Kid.room == 24) {
			draw_rect(&screen_rect, 0);
			start_level = 0;
			need_quotes = 1;
			start_game();
		}
	} else if(current_level == 6) {
		// Special event: level 6 falling exit
		if (roomleave_result == -2) {
			Kid.y = -1;
			stop_sounds();
			++next_level;
		}
	} else if(current_level == 12) {
		// Special event: level 12 running exit
		if (Kid.room == 23) {
			++next_level;
// Sounds must be stopped, because play_level_2() checks next_level only if there are no sounds playing. 
			stop_sounds();
			seamless = 1;
		}
	}
	show_time();
	// expiring doesn't count on Jaffar/princess level
	if (current_level < 13 && rem_min == 0) {
		expired();
	}
}
コード例 #5
0
ファイル: chatserv.c プロジェクト: catskillmarina/eBBS
int enter_room( int unum, char *room, char *msg )
{
  int rnum = roomid_to_indx(room);
  int op = 0;
  register int i;
  if (rnum == -1) {
    /* new room */
    for (i=1; i<bbs_max_users; i++) {
      if (rooms[i].occupants == 0) {
        rnum = i;
        if (rooms[rnum].invites == NULL) {
          rooms[rnum].invites = (char *)malloc(bbs_max_users);
          if (rooms[rnum].invites == NULL) {
            send_to_unum(unum, "*** Not enough memory\n", -1);
            return 0;
          }
        }
        memset(rooms[rnum].invites, 0, bbs_max_users);
        strncpy(rooms[rnum].name, room, NAMELEN);
        rooms[rnum].name[NAMELEN] = '\0';
        rooms[rnum].flags = 0;
        op++;
        break;
      }
    }
    if (rnum == -1) {
      send_to_unum(unum, "*** No more rooms available\n", -1);
      return 0;
    }
  }
  if (!MANAGER(unum))
    if (LOCKED(rnum) && rooms[rnum].invites[unum] == 0) {
      send_to_unum(unum, "*** Cannot enter locked room without a key\n", -1);
      return 0;
    }

  exit_room(unum, EXIT_LOGOUT, msg);
  users[unum].room = rnum;
  if (op) users[unum].flags |= FLG_CHATOP;
  rooms[rnum].occupants++;
  rooms[rnum].invites[unum] = 0;
  sprintf(genbuf, "*** %s has entered room '%s'\n", 
          users[unum].chatid, rooms[rnum].name);
  send_to_room(rnum, genbuf, unum);
  return 0;
}
コード例 #6
0
ファイル: chatserv.c プロジェクト: catskillmarina/eBBS
int process_chat_command(int unum)
{
  register int i;
  int sd, rc, ibufsize;
  CHATLINE recbuf;
  
  sd = users[unum].sockfd;
#ifdef DEBUG
  printf("Incoming on fd %d: ", sd);
#endif
  if ((rc = recv(sd, recbuf, sizeof recbuf, 0)) <= 0) {
    /* disconnected */
    exit_room(unum, EXIT_LOSTCONN, (char *)NULL);
    return -1;
  }
  ibufsize = users[unum].ibufsize;
  for (i=0; i<rc; i++) {
    /* if newline is two characters, throw out the first */
    if (recbuf[i] == '\r') continue;

    /* carriage return signals end of line */
    else if (recbuf[i] == '\n') {
      users[unum].ibuf[ibufsize] = '\0';
      if (command_execute(unum) == -1) return -1;
      ibufsize = 0;
    }

    /* add other chars to input buffer unless size limit exceeded */
    else {
      if (ibufsize < CHATLINE_TEXT_MAX)
        users[unum].ibuf[ibufsize++] = recbuf[i];
    }
  }
  users[unum].ibufsize = ibufsize;
  return 0;
}
コード例 #7
0
ファイル: chatserv.c プロジェクト: catskillmarina/eBBS
int login_user( int unum, char *msg )
{
  int i, utent, fd = users[unum].sockfd;
  char accessbytes[MAX_CLNTCMDS];
  char *utentstr = nextword(&msg);
  char *chatid = nextword(&msg);
  USERDATA udata;
  PATH ignorefile;
      
  utent = atoi(utentstr);
  if (utable_get_record(utent, &udata) != S_OK || udata.u.mode != M_CHAT) {
    send_to_unum(unum, CHAT_LOGIN_BOGUS, -1);
    return -1;
  }
  for (i=0; i<bbs_max_users; i++) {
    if (users[i].sockfd != -1 && users[i].utent == utent) {
      /* Either a "ghost" or a hacker */
      if (kill(users[i].client_pid, 0) == 0) {
        send_to_unum(unum, CHAT_LOGIN_BOGUS, -1);
        return -1;
      }
      else {
        exit_room(i, EXIT_LOSTCONN, (char *)NULL);
        logout_user(i);
      }
    }
  }
  if (strlen(chatid) > CHATID_MAX) chatid[CHATID_MAX] = '\0';
  if (!is_valid_chatid(chatid)) {
    send_to_unum(unum, CHAT_LOGIN_INVALID, -1);
    return 0; /* TODO change to -1 when possible */
  }
  if (chatid_to_indx(chatid) != -1) {
    /* userid in use */
    send_to_unum(unum, CHAT_LOGIN_EXISTS, -1);
    return 0; /* TODO: change to -1 when possible */
  }    

  /* Login is ok. Set flags and fill in user record. */
  utable_get_record(utent, &udata);
  if (udata.u.flags & FLG_CLOAK) {
    udata.u.flags &= ~FLG_CLOAK;
    users[unum].flags |= FLG_RESTORECLOAK;
  }  
  utable_set_record(utent, &udata);

  if (is_in_namelist(manager_list, udata.u.userid))
    users[unum].flags |= FLG_CHATMGR;    
  else if (is_in_namelist(restricted_list, udata.u.userid))
    users[unum].flags |= FLG_CHATGUEST;

  users[unum].utent = utent;
  users[unum].client_pid = udata.u.pid;
  strncpy(users[unum].userid, udata.u.userid, NAMELEN);
  if (!RESTRICTED(unum)) {
    chat_get_ignore_file(users[unum].userid, ignorefile);  
    read_namelist(ignorefile, &users[unum].ignorelist);
  }
  users[unum].ignoring = NULL;
  for (i = 0; i < bbs_max_users; i++) {
    if (users[i].sockfd == -1) continue;
    if (is_in_namelist(users[i].ignorelist, udata.u.userid)) {
      if (users[unum].ignoring == NULL)
        users[unum].ignoring = (char *)calloc(bbs_max_users, sizeof(char));
      if (users[unum].ignoring != NULL)
        users[unum].ignoring[i] = 1;
    }
    if (is_in_namelist(users[unum].ignorelist, users[i].userid)) {
      if (users[i].ignoring == NULL)
        users[i].ignoring = (char *)calloc(bbs_max_users, sizeof(char));
      if (users[i].ignoring != NULL)
        users[i].ignoring[unum] = 1;
    }
  }
  strcpy(users[unum].chatid, chatid);
  send_to_unum(unum, CHAT_LOGIN_OK, -1);
  sprintf(genbuf, "*** Welcome to Chat, %s\n", users[unum].chatid);
  send_to_unum(unum, genbuf, -1);
  display_motd(unum);
  print_user_counts(unum);
  enter_room(unum, mainroom, (char *)NULL);
  return 0;  
}  
コード例 #8
0
ファイル: chatserv.c プロジェクト: catskillmarina/eBBS
int chat_goodbye( int unum, char *msg )
{
  exit_room(unum, EXIT_LOGOUT, msg);
  return 0;  
}  
コード例 #9
0
ファイル: main.c プロジェクト: kitling/undertale_techdemo
// Main part of the coding, where everything works (or not)
int main(void) {
    init();

    // Main loop
    while (aptMainLoop()) {

        // Verify button presses
        hidScanInput();

        // Unsigned variables for different types of button presses
        u32 kDown = hidKeysDown();
        u32 kHeld = hidKeysHeld();
        // u32 kUp = hidKeysUp();

        // Exit homebrew
        if (kDown & KEY_START) {
            break;
        }

        // Activate first easter egg
        else if (kDown & KEY_SELECT) {
            easterEgg = !easterEgg;
        }

        // Change pages for the easterEgg/debug menu.
        else if (kDown & KEY_R) {
            if (++easterPage > MAX_PAGE) easterPage = 0;
        }
        else if (kDown & KEY_L) {
            if (--easterPage < 0) easterPage = MAX_PAGE;
        }


        timerStep();

        // If no movement, set the sprite timer to 0
        if (kDown & KEY_UP || kDown & KEY_DOWN || kDown & KEY_LEFT || kDown & KEY_RIGHT) {
            sprTimer = 0;
        }

        // Reset horizontal and vertical speeds
        vsp = 0;
        hsp = 0;

        // Player movement (pretty easy to understand)
        // TODO: Would it be possible to make this less... iffy?
        if (kHeld & KEY_UP) {
            if (!(kHeld & KEY_DOWN)) {
                vsp = -.5; // Vertical speed to negative .5
                playerDir = BACK; // Player direction = back
            }
        }

        if (kHeld & KEY_DOWN) {
            vsp = .5; // Vertical speed to .5
            playerDir = FORWARD; // Player direction = up
        }

        if (kHeld & KEY_LEFT) {
            if (!(kHeld & KEY_RIGHT)) {
                hsp = -.5; // Vertical speed to negative .5
                playerDir = LEFT; // Player direction = left
            }
        }

        if (kHeld & KEY_RIGHT) {
            hsp = .5; // Vertical speed to .5
            playerDir = RIGHT; // Player direction = right
        }

        // Diagonal movement speed fix
        if (vsp != 0) {
            if (hsp != 0) {
                vsp *= .8;
                hsp *= .8;
            }
        }

        // Movement calculation... AND proper room colision.
        // TODO: Consider a function for translating and/or clamping coordinates directly?
        player_pos.x = fclamp(player_pos.x + hsp * dt,
                              rooms[room].collision[0].x,
                              rooms[room].collision[1].x);

        player_pos.y = fclamp(player_pos.y + vsp * dt,
                              rooms[room].collision[0].y,
                              rooms[room].collision[1].y);

        // Scrolling calculation.
        // TODO: Make these constants better/customizable.
        if (player_pos.x - camera_pos.x >= 300) {
            camera_pos.x = player_pos.x - 300;
        }
        else if (player_pos.x - camera_pos.x <= 100) {
            camera_pos.x = player_pos.x - 100;
        }
        camera_pos.x = fclamp(camera_pos.x, 0, rooms[room].scroll_max.x);

        if (player_pos.y - camera_pos.y >= 200) {
            camera_pos.y = player_pos.y - 200;
        }
        else if (player_pos.y - camera_pos.y <= 50) {
            camera_pos.y = player_pos.y - 50;
        }
        camera_pos.y = fclamp(camera_pos.y, 0, rooms[room].scroll_max.y);

        // Player sprites
        if (hsp == 0 && vsp == 0) curr_tex = tex_arr_friskWalk[playerDir][0];

        else curr_tex = tex_arr_friskWalk[playerDir][(int)floor(sprTimer)];

        // Sprite animation timer
        // TODO: Why .15 * .03 * actual time?
        sprTimer += (.03 * dt);

        while (sprTimer >= 4) {
            sprTimer -= 4;
        }

        if (!next_exit){
            if (roomTimer < 255) {
                roomTimer = fmin(roomTimer + (4 * dt), 255);
            }
            next_exit = exit_room(room, &player_pos);
        }
        else {
            roomTimer -= 4 * dt;
            if (roomTimer <= 0) {
                room = next_exit->room_id;
                player_pos = next_exit->entrance;
                next_exit = NULL;
                roomTimer = 0;
            }
        }

        render();

        // Swap sf2d framebuffers and wait for VBlank
        sf2d_swapbuffers();
    }

    // Free images/textures/fonts from memory

    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 4; ++j) {
            sf2d_free_texture(tex_arr_friskWalk[i][j]);
        }
    }

    for (int i = 0; i < 3; ++i) {
        sf2d_free_texture(rooms[i].bg.tex);
    }

    sftd_free_font(font);

    // Exit services
    sf2d_fini();
    sftd_fini();
    sound_stop(home);
    audio_stop();
    hidExit();
    aptExit();
    srvExit();

    return 0;
}