// 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()); } } }
//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 ServerImpl::onEventArrived( CL_NetGameConnection *p_conn, const CL_NetGameEvent &p_event ) { cl_log_event(LOG_EVENT, "event %1 arrived", p_event.to_string()); 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); } // 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 Server::on_event_received(CL_NetGameConnection *connection, const CL_NetGameEvent &e) { cl_log_event("system", "Client sent event: %1", e.to_string()); ServerPlayer *player = ServerPlayer::get_player(connection); handle_event(player, e); }
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 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 GameEvents::on_event_game_has_started(const CL_NetGameEvent &e) { if (client->get_game_model()->get_map()->validate()) { client->get_game_view()->start_game(); } else { // TODO: Show an error to user cl_log_event("error", "Unable to start game: Map is invalid", e.to_string()); } }
//Evento Server: Recibido void Cliente::on_evento_recibido(const CL_NetGameEvent &e) { cl_log_event("eventos", "Servidor envio evento: %1", e.to_string()); bool evento_manejado = false; if(!logged_in) { // Usuario no se ha logeado, enrutar a eventos del despachador de login evento_manejado = eventos_login.dispatch(e); } else { // Usuario logiado, enrutar a eventos del despachador del juego evento_manejado = eventos_juego.dispatch(e); } if(! evento_manejado) { //Evento no manejado cl_log_event("eventos", "Evento no manejado: %1", e.to_string()); } }
// An event was received from server void Client::on_event_received(const CL_NetGameEvent &e) { cl_log_event("events", "Server sent event: %1", e.to_string()); bool handled_event = false; if(!logged_in) { // We haven't logged in, so route events to login dispatcher handled_event = login_events.dispatch(e); } else { // We have logged in, so route events to game dispatcher handled_event = game_events.dispatch(e); } if(!handled_event) { // We received an event which we didn't hook up cl_log_event("events", "Unhandled event: %1", e.to_string()); } }
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()); }
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()); }
// TODO: This method should not be public, but it needs to currently to make it possible // for AI player to directly send an event to server void Server::handle_event(ServerPlayer *player, const CL_NetGameEvent &e) { bool handled_event = false; if (player->id == 0) { handled_event = login_events->get_dispatcher().dispatch(e, player); } else { if (player->lobby_player) handled_event = lobby_events->get_dispatcher().dispatch(e, player->lobby_player); if (player->game_player) if(player->game_player->current_game) handled_event |= game_events->get_dispatcher().dispatch(e, player->game_player->current_game, player->game_player); } if (!handled_event) cl_log_event("system", "Unhandled event: %1", e.to_string()); }
void ServerImpl::onEventArrived(CL_NetGameConnection *p_conn, const CL_NetGameEvent &p_event) { cl_log_event(LOG_EVENT, "event %1 arrived", p_event.to_string()); m_parent->handleEvent(p_conn, p_event); }