Beispiel #1
0
int main(int argc,char** argv){
  msg r;
  init(HOST,PORT);

  if (recv_message(&r)<0){
    perror("Receive message");
    return -1;
  }

  int i = 0;
  printf("Got message: \n");
  for (; i < r.len; ++ i)
  {
    r.payload[i] = fix_char(r.payload[i]);
    if (validate(r.payload[i]))
    {
      printf("-%x-\n", r.payload[i]);
    }
    else
    {
      printf("Error: -%x- \n", r.payload[i]);
    }
  }
  printf("\nOriginal message\n");
  
  for (i = 0; i < r.len; i += 2)
  {
    char orig = get_original(r.payload[i], r.payload[i + 1]);
    printf("%c", orig);
  }
  
  
  
  return 0;
}
Beispiel #2
0
/*
 * Read an area from the map, convert it to standard map
 * characters and print them.
 */
void do_draw(int x, int y, int x__width, int y__width) {

    int i, j;
    mixed mape;

    mape = get_area_from_corner(x, y, x__width, y__width);

    for(i = 0 ; i < y__width ; i++) {
	for(j = 0 ; j < x__width ; j++)
	    write(fix_char(extract((string)(mape[j]), i*2, i*2)) + " ");
	write("\n");
    }
}
Beispiel #3
0
void 
do_guild (CHAR_DATA * ch, char *argy)
{
  
  int i;
  CHAR_DATA *mob;
  char buf[STD_LENGTH];
  char arg1[SML_LENGTH];
  DEFINE_COMMAND ("guild", do_guild, POSITION_STANDING, 0, LOG_NORMAL, "This command allows you to perform guild options at a guild house.")
    if (IS_MOB (ch))
      return;
  argy = one_argy(argy, arg1);
  if (!str_cmp (arg1, "info") || !str_cmp(arg1, "cost") || !str_cmp(arg1,
								    "costs"))
    {
      show_guild_costs(ch, "");
      return;
    }		

  for (mob = ch->in_room->more->people; mob != NULL; mob = mob->next_in_room)
    {
      if (IS_MOB (mob) && (
	   IS_SET (mob->pIndexData->act3, ACT3_TINKER)
	   || IS_SET (mob->pIndexData->act3, ACT3_WARRIOR)
	   || IS_SET (mob->pIndexData->act3, ACT3_HEALER)
	   || IS_SET (mob->pIndexData->act3, ACT3_WIZARD)
	   || IS_SET (mob->pIndexData->act3, ACT3_THIEFG)
	   || IS_SET (mob->pIndexData->act3, ACT3_RANGER)
	   || IS_SET (mob->pIndexData->act3, ACT3_ROGUE)
	   || IS_SET (mob->pIndexData->act3, ACT3_MYSTIC)
	   || IS_SET (mob->pIndexData->act3, ACT3_CONJURER)
	   || IS_SET (mob->pIndexData->act3, ACT3_BATTLEMASTER)
	   || IS_SET (mob->pIndexData->act3, ACT3_NECROMANCER)
	   || IS_SET (mob->pIndexData->act3, ACT3_MONK)
	   )
	  )
	break;
    }
  if (mob == NULL)
    {
      send_to_char ("There is no guildmaster present here!\n\r", ch);
      return;
    }
  if (arg1[0] == '\0')
    {
      send_to_char ("\n\rOptions:\n\r---> Guild leave\n\r---> Guild info\n\r---> Guild join\n\r---> Guild status\n\r", ch);
      return;
    }
  
  /*end of GUILD INFO */
  if (!str_cmp (arg1, "status"))
    {
      if (!IS_SET (ch->pcdata->guilds, (mob->pIndexData->act3)))
	{
	  send_to_char ("You are not a member of our guild!\n\r", ch);
	  return;
	}
      send_to_char ("You are an highly respected member of the guild.\n\r", ch);
      return;
    }				/*end of GUILD STATUS */
  
  
  if (!str_cmp (arg1, "leave"))
    {
      
      if (!is_member (ch, (mob->pIndexData->act3)))
	{
	  send_to_char ("You aren't even a member!!\n\r", ch);
	  return;
	}
      for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++)
	{
	  if (IS_SET(mob->pIndexData->act3, guild_data[i].mob_guildmaster_bit))
	    {
	      ch->pcdata->stat[guild_data[i].stat_modified]--;
	      REMOVE_BIT(ch->pcdata->guilds, guild_data[i].player_guild_bit);
	      send_to_char("You are no longer a member of the guild.", ch);
	      player_preset(ch, "Zlughlkheyn");
              do_remove(ch, "all");
	      break;
	    }
	}
    }
  /*end of GUILD LEAVE */
  if (!str_cmp(arg1, "replace"))
    {
      char arg2[STD_LENGTH];
      char arg3[STD_LENGTH];
      int oldnum = -1;
      int newnum = -1;
      
      argy = one_argy(argy, arg2);
      argy = one_argy(argy, arg3);
      if (arg2[0] == '\0' || arg3[0] == '\0')
	{
	  send_to_char("Syntax: Guild Replace <old_guild> <new_guild>\n\r", ch);
	  return;
	}
      for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++)
	{
	  if (!str_cmp(guild_data[i].what_you_type, arg2))
	    {
	      oldnum = guild_data[i].mob_guildmaster_bit;
	      break;
	    }
	}
      for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++)
	{
	  if (!str_cmp(guild_data[i].what_you_type, arg3))
	    {
	      newnum = guild_data[i].mob_guildmaster_bit;
	      break;
	    }
	}
      if (oldnum == -1 || newnum == -1)
	{
	  send_to_char("You need to check those names again. I don't know which guilds you are talking about.\n\r", ch);
	  return;
	}
      if (!IS_SET(ch->pcdata->guilds, oldnum))
	{
	  send_to_char("You don't have that guild so how do you expect to replace it?\n\r", ch);
	  return;
	}
      if (newnum == oldnum)
	{
	  send_to_char("You are not changing anything!! Get a clue.\n\r", ch);
	  return;
	}
      if (!IS_SET(mob->pIndexData->act3, newnum))
	{
	  send_to_char("This guildmaster cannot add you. You must find the proper guildmaster for the guild you wish to join.\n\r", ch);
	  return;
	}
      if (is_member(ch, newnum))
	{
	  send_to_char("You are already a member of that guild!\n\r", ch);
	  return; 
	}
      if (ch->pcdata->bank < 60000)
	{
	  send_to_char("You need 60000 coins in the bank for this to be done.\n\r", ch);
	  return;
	}
      if(ch->pcdata->warpoints < 100)
	{
	  send_to_char("You need 100 warpoints for this to be done.\n\r", ch);
	  return;
	}
      ch->pcdata->bank -= 60000;
      ch->pcdata->warpoints -= 100;
      for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++)
	{
	  if (IS_SET(oldnum, guild_data[i].mob_guildmaster_bit))
	    {
	      ch->pcdata->stat[guild_data[i].stat_modified]--;
	      REMOVE_BIT(ch->pcdata->guilds, guild_data[i].player_guild_bit);
	      break;
	    }
	}
      for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++)
	{
	  if (IS_SET(newnum, guild_data[i].mob_guildmaster_bit))
	    {
	      ch->pcdata->stat[guild_data[i].stat_modified]++;
	      SET_BIT(ch->pcdata->guilds, guild_data[i].player_guild_bit);
	      break;
	    }
	}
      sprintf(buf, "Congratulations! You are now a member of the %s!\n\r", guild_data[i].what_you_see);
      send_to_char(buf, ch);
      sprintf (buf, "Welcome to our guild, %s!", NAME (ch));
      do_say (mob, buf); 
      player_preset(ch, "Zlughlkheyn");
      fix_char(ch);
      send_to_char("Ok, the guilds have been switched.\n\r", ch);
      return;
    }
  if (!str_cmp (arg1, "join"))
    {
      int num = get_num_guilds(ch);
      int remorts = pow.guild_info[num][0];
      int lvl = pow.guild_info[num][1];
      int cst = (pow.guild_info[num][2] * 100);
      int wps = pow.guild_info[num][3];
      int kps = pow.guild_info[num][4];
      bool can_join = TRUE;
      if (IS_SET (ch->pcdata->guilds, mob->pIndexData->act3 ))
	{
	  send_to_char ("You are already a member of our guild!\n\r", ch);
	  return;
	}
      if (ch->pcdata->remort_times < remorts)
	{
	  sprintf (buf, "You need to have at least %d remorts to join this guild!\n\r", remorts);
	  send_to_char (buf, ch);
	  can_join = FALSE;
	}
      // Commented out because i replaced it with the code below.
        /* if (LEVEL (ch) < lvl)
	{
	  sprintf (buf, "You need to be level %d to join the guild!\n\r", lvl);
	  send_to_char (buf, ch);
	  can_join = FALSE;
	}*/
      //Added so if the player has a remort that they can join even if they don't meet the level req.
      //Sabelis 1-18-2006
      if ((LEVEL (ch) >lvl) || (ch->pcdata->remort_times>0))
          {
          can_join = TRUE;
          }
      else if (LEVEL (ch) < lvl)
        {
          sprintf (buf, "You need to be level %d to join the guild!\n\r", lvl);
          send_to_char (buf, ch);
          can_join = FALSE;
        }

      if (tally_coins (ch) < cst)
	{
	  sprintf (buf, "We need a payment of %d coins before we can let you join.\n\r", cst);
	  send_to_char (buf, ch);
	  can_join = FALSE;
	}
      if (ch->pcdata->warpoints < wps)
	{
	  sprintf (buf, "You need to have at least %d warpoints to join this guild!\n\r", wps);
	  send_to_char (buf, ch);
	  can_join = FALSE;
	}
      if (ch->pcdata->killpoints < kps)
	{
	  sprintf (buf, "You need to have at least %d killpoints to join this guild!\n\r", kps);
	  send_to_char (buf, ch);
	  can_join = FALSE;
	}
      if (!can_join)
	return;
      
      ch->pcdata->warpoints -= wps;
      ch->pcdata->killpoints -= kps;
      sub_coins (cst, ch);
      for (i = 0; str_cmp(guild_data[i].what_you_type, "end_of_list"); i++)
	{
	  if (IS_SET(mob->pIndexData->act3, guild_data[i].mob_guildmaster_bit))
	    {
	      ch->pcdata->stat[guild_data[i].stat_modified]++;
	      SET_BIT(ch->pcdata->guilds, guild_data[i].player_guild_bit);
	      break;
	    }
	}
      sprintf(buf, "Congratulations! You are now a member of the %s!\n\r", guild_data[i].what_you_see);
      send_to_char(buf, ch);
      sprintf (buf, "Welcome to our guild, %s!", NAME (ch));
      do_say (mob, buf);
    }
  return;
}
Beispiel #4
0
int fs_emu_font_render(fs_emu_font *font, const char *text, float x, float y,
        float r, float g, float b, float alpha) {
    if (font == NULL || font->image == NULL) {
        return 0;
    }
    if (text == NULL || *text == '\0') {
        return 0 ;
    }
    if (!g_initialized) {
        initialize();
    }

    // find cached text entry, if any
    GList* list = g_cache;
    while (list) {
        cache_item *item = (cache_item *) list->data;
        if (item->font == font && strcmp(item->text, text) == 0) {
            break;
        }
        list = list->next;
    }
    if (list) {
        cache_item *item = (cache_item *) list->data;
        g_cache = g_list_delete_link(g_cache, list);
        sanity_check();
        fs_gl_blending(1);
        fs_gl_texturing(1);
        //fs_emu_ortho();
        //fs_emu_set_texture(NULL);
        fs_gl_bind_texture(g_text_texture);
        //glColor4f(1.0, 1.0, 1.0, alpha);
        //printf("rendering %f %f %f %f...\n", item->x1, item->x2, item->y1, item->y2);
        fs_gl_color4f(r, g, b, alpha);
        //glColor4f(r * alpha, g * alpha, b * alpha, alpha);

#ifdef USE_GLES
        GLfloat tex[] = {
            item->x1, item->y2,
            item->x2, item->y2,
            item->x2, item->y1,
            item->x1, item->y1
        };
        GLfloat vert[] = {
            x, y,
            x + item->width, y,
            x + item->width, y + item->height,
            x, y + item->height
        };

        glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);

        glVertexPointer(2, GL_FLOAT, 0, vert);
        glTexCoordPointer(2, GL_FLOAT, 0, tex);
        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

        glDisableClientState(GL_VERTEX_ARRAY);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#else
        glBegin(GL_QUADS);
        glTexCoord2f(item->x1, item->y2);
        glVertex2f(x, y);
        glTexCoord2f(item->x2, item->y2);
        glVertex2f(x + item->width, y);
        glTexCoord2f(item->x2, item->y1);
        glVertex2f(x + item->width, y + item->height);
        glTexCoord2f(item->x1, item->y1);
        glVertex2f(x, y + item->height);
        glEnd();
#endif

        g_cache = g_list_prepend(g_cache, item);
        sanity_check();
        return item->width;
    }

    // calculate size of text

    //printf(":: %s\n", text);

    int num_chars = 0;
    int required_width = 0;
    int required_height = font->h;

    //char *base_text = fs_utf8_strup(text, -1);
    const char *base_text = text;

    unsigned const char *c = (unsigned const char*) base_text;
    int continuations = 0;
    int cp = 0;
    while(*c) {
        //if ((*c & 0b10000000) == 0b00000000) {
        if ((*c & 0x80) == 0x0) {
            continuations = 0;
            //cp = *c & 0b01111111;
            cp = *c & 0x7f;
        }
        //else if ((*c & 0b11000000) == 0b10000000) {
        else if ((*c & 0xc0) == 0x80) {
            continuations--;
            cp = cp << 6;
            //cp = cp | (*c & 0b00111111);
            cp = cp | (*c & 0x3f);
        }
        //else if ((*c & 0b11111110) == 0b11111100) { // 1111110x
        else if ((*c & 0xfe) == 0xfc) { // 1111110x
            continuations = 5;
            //cp = *c & 0b00000001;
            cp = *c & 0x1;
        }
        //else if ((*c & 0b11111100) == 0b11111000) { // 111110xx
        else if ((*c & 0xfc) == 0xf8) { // 111110xx
            continuations = 4;
            //cp = *c & 0b00000011;
            cp = *c & 0x3;
        }
        //else if ((*c & 0b11111000) == 0b11110000) { // 11110xxx
        else if ((*c & 0xf8) == 0xf0) { // 11110xxx
            continuations = 3;
            //cp = *c & 0b00000111;
            cp = *c & 0x7;
        }
        //else if ((*c & 0b11110000) == 0b11100000) { // 1110xxxx
        else if ((*c & 0xf0) == 0xe0) { // 1110xxxx
            continuations = 2;
            //cp = *c & 0b00001111;
            cp = *c & 0xf;
        }
        //else if ((*c & 0b11100000) == 0b11000000) { // 110xxxxx
        else if ((*c & 0xe0) == 0xc0) { // 110xxxxx
            continuations = 1;
            //cp = *c & 0b00011111;
            cp = *c & 0x1f;
        }

        ++c;
        if (continuations) {
            continue;
        }

        cp = fix_char(font, cp);
        //printf("%d\n", cp);
        if (required_width + font->w[cp] > g_texture_width) {
            break;
        }
        required_width += font->w[cp];
        num_chars++;
    }

    int dx = 0;
    int dy = 0;
    c = (unsigned const char*) base_text;
    //printf("base_text: %s\n", c);
    continuations = 0;
    cp = 0;
    int k = 0;
    while(*c) {
        //printf("%d\n", *c);
        //if ((*c & 0b10000000) == 0b00000000) {
        if ((*c & 0x80) == 0x0) {
            continuations = 0;
            //cp = *c & 0b01111111;
            cp = *c & 0x7f;
        }
        //else if ((*c & 0b11000000) == 0b10000000) {
        else if ((*c & 0xc0) == 0x80) {
            continuations--;
            cp = cp << 6;
            //cp = cp | (*c & 0b00111111);
            cp = cp | (*c & 0x3f);
        }
        //else if ((*c & 0b11111110) == 0b11111100) { // 1111110x
        else if ((*c & 0xfe) == 0xfc) { // 1111110x
            continuations = 5;
            //cp = *c & 0b00000001;
            cp = *c & 0x1;
        }
        //else if ((*c & 0b11111100) == 0b11111000) { // 111110xx
        else if ((*c & 0xfc) == 0xf8) { // 111110xx
            continuations = 4;
            //cp = *c & 0b00000011;
            cp = *c & 0x3;
        }
        //else if ((*c & 0b11111000) == 0b11110000) { // 11110xxx
        else if ((*c & 0xf8) == 0xf0) { // 11110xxx
            continuations = 3;
            //cp = *c & 0b00000111;
            cp = *c & 0x7;
        }
        //else if ((*c & 0b11110000) == 0b11100000) { // 1110xxxx
        else if ((*c & 0xf0) == 0xe0) { // 1110xxxx
            continuations = 2;
            //cp = *c & 0b00001111;
            cp = *c & 0xf;
        }
        //else if ((*c & 0b11100000) == 0b11000000) { // 110xxxxx
        else if ((*c & 0xe0) == 0xc0) { // 110xxxxx
            continuations = 1;
            //cp = *c & 0b00011111;
            cp = *c & 0x1f;
        }

        ++c;
        if (continuations) {
            continue;
        }

        if (++k > num_chars) {
            // there may be more chars left in the original string,
            // but there is no room for the next char in the texture
            break;
        }

        cp = fix_char(font, cp);

        int sx = font->x[cp];
        int sy = font->y[cp];
        int sw = font->w[cp];
        int sh = font->h;

        //if (c > 256) {
        //    printf("%d %d %d %d %d\n", c, sx, sy, sw, sh);
        //}

        // draw character
        //printf("-----------> %d\n", cp);

        int *sl = ((int *) font->image->data) + font->image->width * sy + sx;
        int ss = font->image->width; // source stride
        //int *sl = sp;
        int *dl = ((int *) g_buffer) + g_texture_width * dy + dx;
        int ds = g_texture_width; // destination stride
        //int *dl = dp;

        for (int y = 0; y < sh; y++) {
            //printf("%d\n", y);
            int *sp = sl;
            int *dp = dl;
            for (int x = 0; x < sw; x++) {
                //printf("%d %d\n", x, y);
                //*dp++ = 0xff0000ff;
                //*dp++ = *sp++;
                int a = *sp;
                sp++;
                *dp = a;
                dp++;
                //int a = *sp++;
            }
            sl += ss;
            dl += ds;
        }

        dx += sw;
    }
    //free(utext);
    //free(base_text);

    GList *last = g_list_last(g_cache);
    cache_item *last_item = (cache_item *) last->data;
    int position = last_item->position;

    fs_gl_bind_texture(g_text_texture);
    int gl_buffer_format = GL_RGBA;
    if (fs_emu_get_video_format() == FS_EMU_VIDEO_FORMAT_BGRA) {
        gl_buffer_format = GL_BGRA;
    }
#ifdef USE_GLES
    /* GLES does not support unpack padding of buffer. we have to update line-wise (or create a new one) */
    uint8_t *buf = g_buffer;
    for(int y=0;y<required_height;y++) {
        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, position * 32 + y, required_width,
                1, gl_buffer_format, GL_UNSIGNED_BYTE, buf);
        buf += g_texture_width * 4;
    }
#else
    fs_gl_unpack_row_length(g_texture_width);
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, position * 32, required_width,
            required_height, gl_buffer_format, GL_UNSIGNED_BYTE, g_buffer);
#endif

    cache_item *item = malloc(sizeof(cache_item));
    item->font = font;
    item->text = g_strdup(text);
    item->width = required_width;
    item->height = required_height;
    item->position = position;

    item->x1 = 0;
    item->x2 = required_width / (1.0 * g_texture_width);
    item->y1 = (item->position * 32) / (1.0 * g_texture_height);
    item->y2 = (item->position * 32 + required_height) /
            (1.0 * g_texture_height);
    //item->texture = render_texture;
    g_cache = g_list_prepend(g_cache, item);
    sanity_check();

    if (last_item->text) {
        free(last_item->text);
    }
    /*
    if (last_item->texture) {
        glDeleteTextures(1, &last_item->texture);
    }
    */
    free(last_item);

    g_cache = g_list_delete_link(g_cache, last);
    sanity_check();

    // now the text is in the cache, so call function again
    return fs_emu_font_render(font, text, x, y, r, g, b, alpha);
}
Beispiel #5
0
static void siginfo_handler(int signum) {

  static unsigned table[] = {
    0x0400,
    0x0480,
    0x0500,
    0x0580,
    0x0600,
    0x0680,
    0x0700,
    0x0780,
    0x0428,
    0x04A8,
    0x0528,
    0x05A8,
    0x0628,
    0x06A8,
    0x0728,
    0x07A8,
    0x0450,
    0x04D0,
    0x0550,
    0x05D0,
    0x0650,
    0x06D0,
    0x0750,
    0x07D0,
  };

  extern int g_cur_a2_stat;
  extern int get_byte_at_address(int addr);


  if (g_cur_a2_stat & ALL_STAT_SUPER_HIRES) return; // not text...

  int st80 = g_cur_a2_stat & ALL_STAT_VID80 /* ALL_STAT_ST80 */;

  //if (!(g_cur_a2_stat & ALL_STAT_TEXT)) return; // text is not enabled.

  char buffer[80+1];

  for (int row = 0; row < 24; ++row) {
    unsigned address = table[row];
    int column = 0;

    memset(buffer, ' ', sizeof(buffer));

    for(int j = 0; j < 40; ++j, ++address) {

      unsigned char c;

      if (st80) {
        c  = get_byte_at_address(0xe10000 + address);
        c = fix_char(c);
        buffer[column++] = c;
      }

      c  = get_byte_at_address(0xe00000 + address);
      c = fix_char(c);
      buffer[column++] = c;

    }
    if (st80) {
      buffer[80] = '\n';
      write(1, buffer, 81);
    } else {
      buffer[40] = '\n';
      write(1, buffer, 41);
    }
  }
  write(1, "\n\n", 2);
}