void Cliente::on_evento_juego_otorga_powerup(const CL_NetGameEvent &e) { int id_tanque = e.get_argument(0); int id_power = e.get_argument(1); mundo->otorgaPowerup(id_tanque, id_power); }
void GameEvents::on_event_game_over(const CL_NetGameEvent &e) { CL_String title = e.get_argument(0); CL_String message = e.get_argument(1); client->get_game_view()->game_over(title, message); }
// An event was received from a client void Server::on_event_received(CL_NetGameConnection *connection, const CL_NetGameEvent &e) { cl_log_event("events", "Client sent event: %1", e.to_string()); ServerUser *user = ServerUser::get_user(connection); if(user) { bool handled_event = false; if (user->id == 0) // User has not logged in, so route events to login dispatcher { // Route login events handled_event = login_events.dispatch(e, user); } else { // Route game events handled_event = game_events.dispatch(e, user); } if (!handled_event) { // We received an event which we didn't hook up cl_log_event("events", "Unhandled event: %1", e.to_string()); } } }
void ServerGameEvents::on_event_attack_area(const CL_NetGameEvent &e, ServerGame *game, ServerGamePlayer *game_player) { int map_area_from_id = e.get_argument(0); int map_area_to_id = e.get_argument(1); game->attack_area(game_player, map_area_from_id, map_area_to_id); }
void Cliente::on_evento_juego_actualizar_SubID(const CL_NetGameEvent &e) { cl_log_event("eventos", "Actualiza SubID"); int contSubID = e.get_argument(0); int tanqueid = e.get_argument(1); mundo->setSubID(contSubID); mundo->getTanqueID(tanqueid)->disparar(); }
// "Game-LoadMap" event was received void Client::on_event_game_loadmap(const CL_NetGameEvent &e) { CL_String map_name = e.get_argument(0); int max_players = e.get_argument(1); CustomType position = e.get_argument(2); cl_log_event("events", "Loading map: %1 with %2 players, Position %3,%4,%5", map_name, max_players, position.get_x(), position.get_y(), position.get_z()); }
//Evento Login: Recibido void Servidor::on_evento_login(const CL_NetGameEvent &e, UsuarioServidor *usuario) { cl_log_event("eventos", "Cliente solicita login"); int numusuarios = Usuarios.size(); /* if(numusuarios < (numjugadores -1) ) { CL_String idlogin = e.get_argument(0); CL_String password = e.get_argument(1); CL_String nombre_usuario = e.get_argument(2); CL_SqliteConnection bd_conexion("bdjuego.sql3"); CL_DBCommand consulta_login = bd_conexion.create_command("SELECT password FROM Usuarios WHERE id=?1"); consulta_login.set_input_parameter_string(1,idlogin); CL_DBReader reader = bd_conexion.execute_reader(consulta_login); CL_String pas_bd; if(reader.retrieve_row()) { pas_bd = reader.get_column_string(0); if(password.compare(pas_bd)==0) //Password Correcto { usuario->nombre_usuario= nombre_usuario; usuario->id = siguiente_usuario_id++; Usuarios.push_back(usuario); usuario->enviar_evento(CL_NetGameEvent("Login-Completado")); } else //Clave Incorrecta { usuario->enviar_evento(CL_NetGameEvent("Login-Fallado", "Clave Incorrecta")); } } else { usuario->enviar_evento(CL_NetGameEvent("Login-Fallado", "ID No encontrado")); //ID Incorrecto } reader.close(); } else { usuario->enviar_evento(CL_NetGameEvent("Login-ServidorLleno")); } */ CL_String idlogin = e.get_argument(0); CL_String password = e.get_argument(1); CL_String nombre_usuario = e.get_argument(2); usuario->nombre_usuario= nombre_usuario; usuario->id = siguiente_usuario_id++; Usuarios.push_back(usuario); usuario->enviar_evento(CL_NetGameEvent("Login-Completado")); }
void Cliente::on_evento_juego_agrega_powerup(const CL_NetGameEvent &e) { int i = e.get_argument(0); float x = e.get_argument(1); float y = e.get_argument(2); PowerupTipo tipos[4] = {MEDIKIT,ESCUDO,RAPIDEZ_TANQUE,DISPARO_360}; mundo->agregarPowerup(tipos[i], CL_Vec2f(x, y)); }
void LobbyEvents::on_event_player_logged_in(const CL_NetGameEvent &e) { int player_id = e.get_argument(0); CL_String player_name = e.get_argument(1); LobbyPlayer *player = player_collection->create_player(player_id, player_name); if (client->get_lobby_view()) client->get_lobby_view()->player_logged_in(player); }
void LobbyEvents::on_event_player_message(const CL_NetGameEvent &e) { int player_id = e.get_argument(0); CL_String message = e.get_argument(1); LobbyPlayer *player = player_collection->get_player(player_id); if(client->get_lobby_view() && player) client->get_lobby_view()->add_chat_message(player, message); }
void RankingClientImpl::parseEvent(const CL_NetGameEvent &p_event) { const CL_String eventName = p_event.get_name(); if (eventName == EVENT_RANKING_ENTRIES) { parseEntriesEvent(p_event); } else { cl_log_event(LOG_ERROR, "event remains unhandled: %1", p_event.to_string()); } }
void Cliente::on_evento_juego_matar_tanque(const CL_NetGameEvent &e) { cl_log_event("eventos", "Matar Tanque"); int idtanque = e.get_argument(0); int tiempofin = e.get_argument(1); mundo->getTanqueID(idtanque)->Matar(CL_System::get_time(), tiempofin); }
void GameEvents::on_event_game_player_message(const CL_NetGameEvent &e) { int player_id = e.get_argument(0); CL_String message = e.get_argument(1); GamePlayer *player = client->get_game_model()->get_players()->get_player(player_id); if(player) { client->get_game_view()->add_player_message(player, message); } }
void RaceStart::parseEvent(const CL_NetGameEvent &p_event) { assert(p_event.get_name() == EVENT_RACE_START); int i = 0; m_carPosition.x = static_cast<float> (p_event.get_argument(i++)); m_carPosition.y = static_cast<float> (p_event.get_argument(i++)); m_carRotation.set_radians(static_cast<float> (p_event.get_argument(i++))); }
void GameEvents::on_event_set_maparea_army_strength(const CL_NetGameEvent &e) { int map_area_id = e.get_argument(0); int army_strength = e.get_argument(1); MapArea *map_area = client->get_game_model()->get_map()->get_area_by_id(map_area_id); if(map_area != 0 && army_strength >= 1 && army_strength <= 8) map_area->army_strength = army_strength; else cl_log_event("error", "Invalid event: %1", e.to_string()); }
void GameEvents::on_event_player_joined_game(const CL_NetGameEvent &e) { int player_id = e.get_argument(0); CL_String player_name = e.get_argument(1); int visual_id = e.get_argument(2); GamePlayer *player = client->get_game_model()->get_players()->create_player(player_name, player_id, visual_id); if(player) client->get_game_view()->player_joined_game(player); else cl_log_event("error", "Invalid event: %1", e.to_string()); }
void Cliente::on_evento_juego_agrega_tanque(const CL_NetGameEvent &e) { cl_log_event("eventos", "Agrega Tanque"); float x = e.get_argument(0); //Obtiene posicion float y = e.get_argument(1); int mi_id = e.get_argument(2); CL_String nombre = e.get_argument(3); int contSubID = e.get_argument(4); CL_Vec2f postanque = CL_Vec2f(x,y); mundo->quitarTanque(0); //Se quita y se agrega el jugador mundo->agregarTanque(mi_id,DEFAULT,nombre,true,false,postanque,0.0f,0.0f); mundo->setSubID(contSubID); }
void CarState::parseEvent(const CL_NetGameEvent &p_event) { assert(p_event.get_name() == EVENT_CAR_STATE); m_name = p_event.get_argument(0); m_serialData = CL_NetGameEvent(""); const int argCount = static_cast<signed>(p_event.get_argument_count()); for (int i = 1; i < argCount; ++i) { m_serialData.add_argument(p_event.get_argument(i)); } }
void GameEvents::on_event_player_left_game(const CL_NetGameEvent &e) { int player_id = e.get_argument(0); GamePlayer *player = client->get_game_model()->get_players()->get_player(player_id); if(player) { client->get_game_view()->player_left_game(player); client->get_game_model()->get_players()->remove_player(player); } else cl_log_event("error", "Invalid event: %1", e.to_string()); }
//Evento Juego: Solicitud de comenzar void Servidor::on_evento_juego_solicitudcomenzar(const CL_NetGameEvent &e, UsuarioServidor *usuario) { CL_String nombre = e.get_argument(0); cl_log_event("eventos", "Cliente solicito comenzar juego"); CL_String mensaje= "Se conecto " + usuario->nombre_usuario; mundo->AgregarCadenaChat(mensaje); int id_nuevo = mundo->tanques.size(); enviaratodosEx(CL_NetGameEvent("Juego-Msj",mensaje),id_nuevo); //Enviar a todos que se conecto alquien CL_Vec2f pospawn = mundo->agregarTanque(id_nuevo,DEFAULT,nombre,false,false); //agrega el usuario //Devuelve el id_actual usuario->enviar_evento(CL_NetGameEvent("Juego-Comenzar",pospawn.x,pospawn.y,id_nuevo, nombre, mundo->getActualSubID())); //envia el SpawnPoint al usuario //enviaratodosEx(CL_NetGameEvent("Juego-AgregarTanque",pospawn.x,pospawn.y,id_nuevo, nombre), id_nuevo); //envia el SpawnPoint al usuario //Envia los tanques creados std::list<Tanque *>::iterator it; for(it=mundo->tanques.begin(); it != mundo->tanques.end(); ++it) { CL_NetGameEvent evento("Juego-JugadorConectado",(*it)->getID(),(*it)->getPos().x,(*it)->getPos().y //Envia al usuario todos los tanques ,(*it)->getanguloCuerpo(),(*it)->getAnguloTorreta()); evento.add_argument((*it)->getNombre()); //usuario->enviar_evento(evento); //actuales enviaratodos(evento); } mundo->quitarTodosPowerup(); //enviaratodosEx(CL_NetGameEvent("Juego-JugadorConectado",usuario->id,pospawn.x,pospawn.y,(*final)->getanguloCuerpo() //Envia a todos el nuevo tanque // ,(*final)->getAnguloTorreta()),usuario->id); }
void Cliente::on_evento_juego_actualizar_tiempo(const CL_NetGameEvent &e) { int min = e.get_argument(0); int seg = e.get_argument(1); mundo->setReloj(min, seg, false); }
void Cliente::on_evento_juego_mensajechat(const CL_NetGameEvent &e) { cl_log_event("eventos", "Mensaje recibido"); CL_String mensaje = e.get_argument(0); mundo->AgregarCadenaChat(mensaje); //Agrega mensaje recibido }
void LoginEvents::on_event_login_failed(const CL_NetGameEvent &e) { CL_String fail_reason = e.get_argument(0); // TODO: Handle failed login more gracefully throw CL_Exception("Login failed: " + fail_reason); }
//Evento Cliente: Recibido void Servidor::on_evento_recibido(CL_NetGameConnection *conexion, const CL_NetGameEvent &e) { UsuarioServidor *usuario = UsuarioServidor::get_usuario(conexion); if(usuario) { bool evento_manejado = false; if (usuario->id == 0) // Usuario no se ha logeado, enrutar a eventos del despachador de login { //Despachador de eventos de login evento_manejado = eventos_login.dispatch(e, usuario); } else { //Despachador de eventos del juego evento_manejado = eventos_juego.dispatch(e, usuario); } if (!evento_manejado) { //Evento no manejado cl_log_event("eventos", "Evento no manejado: %1", e.to_string()); } } }
void LobbyEvents::on_event_error_message(const CL_NetGameEvent &e) { CL_String message = e.get_argument(0); if(client->get_lobby_view()) client->get_lobby_view()->add_info_message(message); }
void LobbyEvents::on_event_player_left_game(const CL_NetGameEvent &e) { int player_id = e.get_argument(0); int game_id = e.get_argument(1); LobbyPlayer *player = player_collection->get_player(player_id); LobbyGame *game = game_collection->get_game(game_id); if(game && player) { game->remove_player(player); if (client->get_lobby_view()) client->get_lobby_view()->player_left_game(game, player); } }
void GameEvents::on_event_set_maparea_ownership(const CL_NetGameEvent &e) { int map_area_id = e.get_argument(0); int player_id = e.get_argument(1); MapArea *map_area = client->get_game_model()->get_map()->get_area_by_id(map_area_id); GamePlayer *player = client->get_game_model()->get_players()->get_player(player_id); if(map_area != 0 && player != 0) { map_area->player_id = player->id; client->get_game_view()->update_map(); } else cl_log_event("error", "Invalid event: %1", e.to_string()); }
void ServerImpl::handleEvent(CL_NetGameConnection *p_conn, const CL_NetGameEvent &p_event) { try { bool unhandled = false; const CL_String eventName = p_event.get_name(); // connection initialize events if (eventName == EVENT_CLIENT_INFO) { onClientInfo(p_conn, p_event); } // master server events if (eventName == EVENT_INFO_REQUEST) { onServerInfoRequest(p_conn, p_event); } // race events else if (eventName == EVENT_CAR_STATE) { onCarState(p_conn, p_event); } else if (eventName == EVENT_VOTE_START) { onVoteStart(p_conn, p_event); } else if (eventName == EVENT_VOTE_TICK) { onVoteTick(p_conn, p_event); } // unknown events remains unhandled else { unhandled = true; } if (unhandled) { cl_log_event( LOG_EVENT, "event %1 remains unhandled", p_event.to_string() ); } } catch (CL_Exception e) { cl_log_event(LOG_ERROR, e.message); } }
void LobbyEvents::on_event_game_created(const CL_NetGameEvent &e) { int game_id = e.get_argument(0); CL_String game_name = e.get_argument(1); CL_String map_name = e.get_argument(2); int max_players = e.get_argument(3); LobbyGame *game = game_collection->create_game(game_id, game_name, map_name, max_players, LobbyGame::lobby); if(game) { if (client->get_lobby_view()) { client->get_lobby_view()->add_game(game); client->get_lobby_view()->create_game(game); } } }
void Cliente::on_evento_juego_saludyscore(const CL_NetGameEvent &e) { int idtanque = e.get_argument(0); int vida = e.get_argument(1); int armadura = e.get_argument(2); int score = e.get_argument(3); Tanque *tank = mundo->getTanqueID(idtanque); if(tank != NULL) { tank->setVida(vida); tank->setArmadura(armadura); tank->setScore(score); } }