common/Protocol.cpp
// server/client
// metodo que no sabe nada sobre el server/client
// solo sabe que ellos le pasan un metodo que recibe un size_t y devuelve un vector de chars
server/client
metodo que no sabe nada sobre el server/client
solo sabe que ellos le pasan un metodo que recibe un size_t y devuelve un vector de chars
server / client metodo que no sabe nada sobre el server / client solo sabe que ellos le pasan un metodo que recibe un size_t y devuelve un vector de chars
std::vector<unsigned char> Protocol::dispatchReceived(uint8_t codeReceived,
                                std::function<std::vector<unsigned char>(size_t)> &receiveCallback) {
    std::vector<unsigned char> msg;
    switch (codeReceived) {
        case CREATE: {
            msg = handleCreateGame(receiveCallback);
            break;
        }
        case JOIN: {
            msg = handleStringMsg(receiveCallback);
            break;
        }
        case LIST:
            break;
        case MOVE: {
            msg = handleByte(receiveCallback);
            break;
        }
        case STOP_MOVE: {
            msg = handleByte(receiveCallback);
            break;
        }
        case LOGIN_RESPONSE: {
            msg = handleLoginResponse(receiveCallback);
            break;
        }
        case POS_UPDATE: {
            msg = handleUpdatePosition(receiveCallback);
            break;
        }
        case ROTATE: {
            msg = handleRotation(receiveCallback);
            break;
        }
        case ANGLE_UPDATE: {
            msg = handleAngleUpdate(receiveCallback);
            break;
        }
        case ATTACK : {
            break;
        }
        case STOP_ATTACK : {
            break;
        }
        case ATTACK_UPDATE:{
            msg = handleByte(receiveCallback);
            break;
        }
        case HIT_UPDATE:{
            msg = handleByte(receiveCallback);
            break;
        }
        case DEAD_UPDATE:{
            msg = handleByte(receiveCallback);
            break;
        }
        case CHANGE_WEAPON: {
            msg = handleByte(receiveCallback);
            break;
        }
        case WEAPON_UPDATE: {
            msg = handleUpdateWeapon(receiveCallback);
            break;
        }
        case BUY: {
            msg = handleByte(receiveCallback);
            break;
        }
        case BUYING_UPDATE: {
            msg = handleByte(receiveCallback);
            break;
        }
        case WEAPON_DROP_UPDATE: {
            msg = handleDropUpdate(receiveCallback);
            break;
        }
        case PICKUP: {
            break;
        }
        case TEAM_UPDATE: {
            msg = handleTeamUpdate(receiveCallback);
            break;
        }
        case TIMER_UPDATE: {
            msg = handleByte(receiveCallback);
            break;
        }
        case HEALTH_UPDATE: {
            msg = handleByte(receiveCallback);
            break;
        }
        case CLIP_UPDATE: {
            msg = handleByte(receiveCallback);
            break;
        }
        case MONEY_UPDATE: {
            msg = handleShort(receiveCallback);
            break;
        }
        case RELOAD: {
            break;
        }
        case PLANT: {
            break;
        }
        case STOP_PLANT: {
            break;
        }
        case LOGIN_LIST_GAMES: {
            msg = handleStringMsg(receiveCallback);
            break;
        }
        case LIST_MAPS: {
            break;
        }
        case GAME_DONE: {
            break;
        }
        case MAP_INFO_UPDATE: {
            msg = handleStringMsg(receiveCallback);
            break;
        }
        case EARLY_START:{
            break;
        }
        case BOMB_PLANT_UPDATE: {
            msg = handleByte(receiveCallback);
            break;
        }
        case BOMB_EXPLODE_DONE: {
            break;
        }
        case TT_WIN_ROUND: {
            break;
        }
        case CT_WIN_ROUND: {
            break;
        }
        case SCORE_UPDATE: {
            msg = handleStringMsg(receiveCallback);
            break;
        }
        default:
            throw std::invalid_argument("Bad code received\n");
    }
    return msg;
}
std :: vector < unsigned char > Protocol :: dispatchReceived ( uint8_t codeReceived , std :: function < std :: vector < unsigned char > ( size_t ) > & receiveCallback ) { std :: vector < unsigned char > msg ; switch ( codeReceived ) { case CREATE : { msg = handleCreateGame ( receiveCallback ) ; break ; } case JOIN : { msg = handleStringMsg ( receiveCallback ) ; break ; } case LIST : break ; case MOVE : { msg = handleByte ( receiveCallback ) ; break ; } case STOP_MOVE : { msg = handleByte ( receiveCallback ) ; break ; } case LOGIN_RESPONSE : { msg = handleLoginResponse ( receiveCallback ) ; break ; } case POS_UPDATE : { msg = handleUpdatePosition ( receiveCallback ) ; break ; } case ROTATE : { msg = handleRotation ( receiveCallback ) ; break ; } case ANGLE_UPDATE : { msg = handleAngleUpdate ( receiveCallback ) ; break ; } case ATTACK : { break ; } case STOP_ATTACK : { break ; } case ATTACK_UPDATE : { msg = handleByte ( receiveCallback ) ; break ; } case HIT_UPDATE : { msg = handleByte ( receiveCallback ) ; break ; } case DEAD_UPDATE : { msg = handleByte ( receiveCallback ) ; break ; } case CHANGE_WEAPON : { msg = handleByte ( receiveCallback ) ; break ; } case WEAPON_UPDATE : { msg = handleUpdateWeapon ( receiveCallback ) ; break ; } case BUY : { msg = handleByte ( receiveCallback ) ; break ; } case BUYING_UPDATE : { msg = handleByte ( receiveCallback ) ; break ; } case WEAPON_DROP_UPDATE : { msg = handleDropUpdate ( receiveCallback ) ; break ; } case PICKUP : { break ; } case TEAM_UPDATE : { msg = handleTeamUpdate ( receiveCallback ) ; break ; } case TIMER_UPDATE : { msg = handleByte ( receiveCallback ) ; break ; } case HEALTH_UPDATE : { msg = handleByte ( receiveCallback ) ; break ; } case CLIP_UPDATE : { msg = handleByte ( receiveCallback ) ; break ; } case MONEY_UPDATE : { msg = handleShort ( receiveCallback ) ; break ; } case RELOAD : { break ; } case PLANT : { break ; } case STOP_PLANT : { break ; } case LOGIN_LIST_GAMES : { msg = handleStringMsg ( receiveCallback ) ; break ; } case LIST_MAPS : { break ; } case GAME_DONE : { break ; } case MAP_INFO_UPDATE : { msg = handleStringMsg ( receiveCallback ) ; break ; } case EARLY_START : { break ; } case BOMB_PLANT_UPDATE : { msg = handleByte ( receiveCallback ) ; break ; } case BOMB_EXPLODE_DONE : { break ; } case TT_WIN_ROUND : { break ; } case CT_WIN_ROUND : { break ; } case SCORE_UPDATE : { msg = handleStringMsg ( receiveCallback ) ; break ; } default : throw std :: invalid_argument ( " \n " ) ; } return msg ; }
server/client
metodo que no sabe nada sobre el server/client
solo sabe que ellos le pasan un metodo que recibe un size_t y devuelve un vector de chars
server / client metodo que no sabe nada sobre el server / client solo sabe que ellos le pasan un metodo que recibe un size_t y devuelve un vector de chars
// vacio pq el codigo es identico a STOP_MOVE // recibo la dir // err, bad code