~muirrum/cmud

9dcb63c5cd8c0254f3fb01b01e119fdf8b25a98e — Cara Salter 7 months ago bdded4f master
Make it clearer how big buffers are in login process
1 files changed, 10 insertions(+), 1 deletions(-)

M src/login.c
M src/login.c => src/login.c +10 -1
@@ 65,16 65,19 @@ int step_login(playerc_t *player, int conn_fd) {
                     "Awww :(. Oh well, hope to see you again soon!\n");
          return 4;
        }
        free(buf);
        break;
      } else {
        load_player_from_xml(playername, player);
        player->state = EnterPassword;
        free(buf);
        break;
      }
    case EnterPassword: ;
      char* buf = (char*) malloc(sizeof(char)*32);
      asprintf(&buf, "Welcome back %s! Please enter your password, so we can confirm it.\n", player->plr.name);
      send_to_fd(player->conn, buf);
      memset(buf, '\0', 1 << 9);
      memset(buf, '\0', sizeof(char)*32);
      recv(player->conn, buf, sizeof(buf), 0); 
      char* pw = trimwhitespace(buf);
      int res = argon2i_verify(player->plr.pw_hash, pw, strlen(pw));  


@@ 85,10 88,13 @@ int step_login(playerc_t *player, int conn_fd) {
      } else {
          // Password is incorrect
          send_to_fd(player->conn, "Password incorrect, please try again\n");
          free(buf);
          break;
      }
      free(buf);
      break;
    case WantMakeAccount:
      char* buf = (char*) malloc(sizeof(char)*32);
      asprintf(&buf, "Welcome aboard %s! Why don't you start us off by giving me a password.\n", player->plr.name);
      send_to_fd(player->conn, buf);
      memset(buf, '\0', 1 << 9);


@@ 110,6 116,7 @@ int step_login(playerc_t *player, int conn_fd) {
            if (err != ARGON2_OK) {
                send_to_fd(player->conn, "Uhhh, something happened. Try again."); 
                player->state = LoggedOut;
                free(buf);
                break;
            } else {
                send_to_fd(player->conn, "Sounds good! let's drop you into a world!");


@@ 124,6 131,8 @@ int step_login(playerc_t *player, int conn_fd) {
                player->state = Complete; 
            }
        }
        free(buf);
        break;
    case Complete: ;
        return 0;
    }