From df314df6c510ac0f3f8d4d0687e092ded52db551 Mon Sep 17 00:00:00 2001 From: shutterbug2000 Date: Sun, 16 Feb 2025 00:21:26 +0000 Subject: [PATCH] Upload pre-migration files --- .gitignore | 20 +- Makefile | 6 +- README.md | 3 +- database/get_unique_id_by_owner_pid.go | 11 + database/init_postgres.go | 13 +- database/insert_common_data_by_owner_pid.go | 11 + globals/accounts.go | 56 ++ globals/globals.go | 8 +- globals/password_from_pid.go | 11 +- go.mod | 39 +- go.sum | 84 +- init.go | 10 +- nex-protocols-common-go/.gitignore | 30 + nex-protocols-common-go/LICENSE | 661 ++++++++++++++++ nex-protocols-common-go/README.md | 77 ++ .../datastore/change_meta.go | 81 ++ .../datastore/complete_post_object.go | 111 +++ .../datastore/complete_post_objects.go | 89 +++ .../datastore/delete_object.go | 54 ++ nex-protocols-common-go/datastore/get_meta.go | 66 ++ .../datastore/get_metas.go | 80 ++ .../datastore/get_metas_multiple_param.go | 86 +++ .../datastore/post_meta_binary.go | 74 ++ .../datastore/prepare_get_object.go | 84 ++ .../datastore/prepare_post_object.go | 112 +++ nex-protocols-common-go/datastore/protocol.go | 163 ++++ .../datastore/rate_object.go | 69 ++ .../datastore/rate_objects.go | 99 +++ .../datastore/s3_presigner.go | 51 ++ .../datastore/search_object.go | 98 +++ nex-protocols-common-go/globals/globals.go | 7 + .../globals/matchmaking_globals.go | 17 + .../globals/matchmaking_utils.go | 627 +++++++++++++++ nex-protocols-common-go/globals/utils.go | 7 + nex-protocols-common-go/go.mod | 40 + nex-protocols-common-go/go.sum | 89 +++ .../match-making-ext/end_participation.go | 115 +++ .../match-making-ext/protocol.go | 25 + .../match-making/find_by_single_id.go | 47 ++ .../match-making/get_session_urls.go | 53 ++ .../match-making/protocol.go | 45 ++ .../match-making/unregister_gathering.go | 103 +++ .../match-making/update_session_host.go | 110 +++ .../match-making/update_session_host_v1.go | 43 ++ .../match-making/update_session_url.go | 108 +++ .../auto_matchmake_postpone.go | 82 ++ .../auto_matchmake_with_param_postpone.go | 67 ++ ...matchmake_with_search_criteria_postpone.go | 74 ++ .../browse_matchmake_session.go | 67 ++ .../close_participation.go | 40 + .../create_matchmake_session.go | 66 ++ .../create_matchmake_session_with_param.go | 52 ++ .../get_simple_playing_session.go | 87 +++ .../join_matchmake_session.go | 52 ++ .../join_matchmake_session_ex.go | 52 ++ .../join_matchmake_session_with_param.go | 47 ++ .../modify_current_game_attribute.go | 46 ++ .../matchmake-extension/open_participation.go | 40 + .../matchmake-extension/protocol.go | 63 ++ .../update_application_buffer.go | 38 + .../update_progress_score.go | 44 ++ .../nat-traversal/README.md | 2 + .../nat-traversal/get_relay_signature_key.go | 50 ++ .../nat-traversal/protocol.go | 33 + .../nat-traversal/report_nat_properties.go | 40 + .../report_nat_traversal_result.go | 29 + .../report_nat_traversal_result_detail.go | 29 + .../request_probe_initiation_ext.go | 93 +++ .../ranking/get_cached_top_x_ranking.go | 69 ++ .../ranking/get_cached_top_x_rankings.go | 88 +++ .../ranking/get_common_data.go | 45 ++ .../ranking/get_ranking.go | 57 ++ nex-protocols-common-go/ranking/protocol.go | 40 + .../ranking/upload_common_data.go | 40 + .../ranking/upload_score.go | 41 + .../secure-connection/README.md | 2 + .../secure-connection/protocol.go | 30 + .../secure-connection/register.go | 115 +++ .../secure-connection/replace_url.go | 51 ++ .../secure-connection/send_report.go | 41 + .../ticket-granting/generate_ticket.go | 51 ++ .../ticket-granting/login.go | 95 +++ .../ticket-granting/login_ex.go | 93 +++ .../ticket-granting/protocol.go | 54 ++ .../ticket-granting/request_ticket.go | 62 ++ .../utility/acquire_nex_unique_id.go | 42 + nex-protocols-common-go/utility/protocol.go | 25 + nex-protocols-go/.gitignore | 30 + nex-protocols-go/.golangci.yml | 17 + nex-protocols-go/LICENSE | 661 ++++++++++++++++ nex-protocols-go/README.md | 59 ++ .../aa-user/get_application_info.go | 29 + nex-protocols-go/aa-user/protocol.go | 116 +++ .../aa-user/register_application.go | 47 ++ .../aa-user/set_application_info.go | 49 ++ .../aa-user/types/application_info.go | 127 ++++ .../aa-user/unregister_application.go | 47 ++ .../account-management/change_password.go | 47 ++ .../change_password_by_guest.go | 71 ++ .../account-management/create_account.go | 82 ++ .../create_account_with_custom_data.go | 104 +++ .../custom_create_account.go | 93 +++ .../account-management/delete_account.go | 47 ++ .../account-management/disable_account.go | 71 ++ .../disconnect_all_principals.go | 29 + .../disconnect_principal.go | 47 ++ .../account-management/find_by_name_like.go | 71 ++ .../account-management/find_by_name_regex.go | 71 ++ .../account-management/get_account_data.go | 29 + .../get_last_connection_stats.go | 47 ++ .../get_multiple_public_data.go | 48 ++ .../account-management/get_name.go | 47 ++ .../account-management/get_private_data.go | 29 + .../account-management/get_public_data.go | 47 ++ .../account-management/get_status.go | 47 ++ .../lookup_or_create_account.go | 93 +++ .../nintendo_create_account.go | 93 +++ .../account-management/protocol.go | 427 +++++++++++ .../account-management/reset_password.go | 29 + .../account-management/retrieve_account.go | 29 + .../account-management/test_capability.go | 47 ++ .../account-management/types/account_data.go | 210 +++++ .../types/account_extra_info.go | 140 ++++ .../types/basic_account_info.go | 112 +++ .../types/nintendo_create_account_data.go | 141 ++++ .../account-management/update_account.go | 82 ++ .../update_account_effective_date.go | 71 ++ .../update_account_email.go | 47 ++ .../update_account_expiry_date.go | 71 ++ .../account-management/update_account_name.go | 47 ++ .../account-management/update_custom_data.go | 60 ++ .../account-management/update_status.go | 47 ++ nex-protocols-go/datastore/change_meta.go | 47 ++ nex-protocols-go/datastore/change_meta_v1.go | 47 ++ nex-protocols-go/datastore/change_metas.go | 74 ++ nex-protocols-go/datastore/change_metas_v1.go | 74 ++ .../datastore/complete_post_object.go | 47 ++ .../datastore/complete_post_object_v1.go | 47 ++ .../datastore/complete_post_objects.go | 48 ++ .../datastore/complete_update_object.go | 47 ++ nex-protocols-go/datastore/delete_object.go | 47 ++ nex-protocols-go/datastore/delete_objects.go | 62 ++ nex-protocols-go/datastore/get_meta.go | 47 ++ nex-protocols-go/datastore/get_metas.go | 62 ++ .../datastore/get_metas_multiple_param.go | 49 ++ .../get_new_arrived_notifications.go | 47 ++ .../get_new_arrived_notifications_v1.go | 47 ++ .../datastore/get_notification_url.go | 47 ++ .../datastore/get_object_infos.go | 47 ++ .../datastore/get_password_info.go | 47 ++ .../datastore/get_password_infos.go | 48 ++ .../datastore/get_persistence_info.go | 60 ++ .../datastore/get_persistence_infos.go | 61 ++ nex-protocols-go/datastore/get_rating.go | 61 ++ .../datastore/get_rating_with_log.go | 61 ++ nex-protocols-go/datastore/get_ratings.go | 61 ++ .../datastore/get_specific_meta.go | 47 ++ .../datastore/get_specific_meta_v1.go | 47 ++ .../datastore/miitopia/protocol.go | 67 ++ .../datastore/miitopia/search_mii.go | 47 ++ .../miitopia/types/mii_tube_mii_info.go | 122 +++ .../miitopia/types/mii_tube_search_param.go | 177 +++++ .../miitopia/types/mii_tube_search_result.go | 138 ++++ .../get_meta_by_owner_id.go | 47 ++ .../nintendo-badge-arcade/protocol.go | 67 ++ .../datastore_get_meta_by_owner_id_param.go | 143 ++++ .../datastore/perpetuate_object.go | 71 ++ .../pokemon-bank/complete_post_bank_object.go | 47 ++ .../complete_update_bank_object.go | 72 ++ .../datastore/pokemon-bank/delete_pokemon.go | 47 ++ .../pokemon-bank/download_my_pokemon.go | 47 ++ .../pokemon-bank/download_other_pokemon.go | 47 ++ .../pokemon-bank/get_transaction_param.go | 47 ++ .../datastore/pokemon-bank/get_unlock_key.go | 47 ++ .../pokemon-bank/prepare_get_bank_object.go | 60 ++ .../pokemon-bank/prepare_post_bank_object.go | 60 ++ .../pokemon-bank/prepare_trade_pokemon.go | 47 ++ .../prepare_update_bank_object.go | 47 ++ .../pokemon-bank/prepare_upload_pokemon.go | 28 + .../datastore/pokemon-bank/protocol.go | 181 +++++ .../pokemon-bank/request_migration.go | 61 ++ .../pokemon-bank/rollback_bank_object.go | 72 ++ .../datastore/pokemon-bank/search_pokemon.go | 47 ++ .../datastore/pokemon-bank/trade_pokemon.go | 47 ++ .../pokemon-bank/types/bank_migration_info.go | 112 +++ .../types/bank_transaction_param.go | 154 ++++ .../types/global_trade_station_data.go | 154 ++++ ...obal_trade_station_delete_pokemon_param.go | 112 +++ ...trade_station_download_my_pokemon_param.go | 98 +++ ...rade_station_download_my_pokemon_result.go | 112 +++ ...de_station_download_other_pokemon_param.go | 98 +++ ...l_trade_station_download_pokemon_result.go | 126 +++ ...ade_station_prepare_trade_pokemon_param.go | 112 +++ ...de_station_prepare_trade_pokemon_result.go | 112 +++ .../types/global_trade_station_record_key.go | 112 +++ ...obal_trade_station_search_pokemon_param.go | 184 +++++ ...bal_trade_station_search_pokemon_result.go | 128 ++++ .../types/global_trade_station_trade_key.go | 112 +++ ...lobal_trade_station_trade_pokemon_param.go | 196 +++++ ...obal_trade_station_trade_pokemon_result.go | 112 +++ ...obal_trade_station_upload_pokemon_param.go | 154 ++++ .../datastore/pokemon-bank/upload_pokemon.go | 47 ++ .../datastore/pokemon-gen6/delete_pokemon.go | 47 ++ .../pokemon-gen6/download_my_pokemon.go | 47 ++ .../pokemon-gen6/download_other_pokemon.go | 47 ++ .../pokemon-gen6/prepare_trade_pokemon.go | 47 ++ .../pokemon-gen6/prepare_upload_pokemon.go | 28 + .../datastore/pokemon-gen6/protocol.go | 116 +++ .../datastore/pokemon-gen6/search_pokemon.go | 47 ++ .../datastore/pokemon-gen6/trade_pokemon.go | 47 ++ .../types/global_trade_station_data.go | 154 ++++ ...obal_trade_station_delete_pokemon_param.go | 112 +++ ...trade_station_download_my_pokemon_param.go | 98 +++ ...rade_station_download_my_pokemon_result.go | 112 +++ ...de_station_download_other_pokemon_param.go | 98 +++ ...l_trade_station_download_pokemon_result.go | 126 +++ ...ade_station_prepare_trade_pokemon_param.go | 112 +++ ...de_station_prepare_trade_pokemon_result.go | 112 +++ .../types/global_trade_station_record_key.go | 112 +++ ...obal_trade_station_search_pokemon_param.go | 184 +++++ ...bal_trade_station_search_pokemon_result.go | 128 ++++ .../types/global_trade_station_trade_key.go | 112 +++ ...lobal_trade_station_trade_pokemon_param.go | 196 +++++ ...obal_trade_station_trade_pokemon_result.go | 112 +++ ...obal_trade_station_upload_pokemon_param.go | 154 ++++ .../datastore/pokemon-gen6/upload_pokemon.go | 47 ++ .../post_meta_binaries_with_data_id.go | 74 ++ .../datastore/post_meta_binary.go | 47 ++ .../post_meta_binary_with_data_id.go | 61 ++ .../datastore/prepare_get_object.go | 47 ++ .../prepare_get_object_or_meta_binary.go | 47 ++ .../datastore/prepare_get_object_v1.go | 47 ++ .../datastore/prepare_post_object.go | 47 ++ .../datastore/prepare_post_object_v1.go | 47 ++ .../datastore/prepare_update_object.go | 47 ++ nex-protocols-go/datastore/protocol.go | 620 +++++++++++++++ nex-protocols-go/datastore/rate_object.go | 72 ++ .../datastore/rate_object_with_posting.go | 83 ++ nex-protocols-go/datastore/rate_objects.go | 85 +++ .../datastore/rate_objects_with_posting.go | 97 +++ nex-protocols-go/datastore/reset_rating.go | 61 ++ nex-protocols-go/datastore/reset_ratings.go | 61 ++ nex-protocols-go/datastore/search_object.go | 47 ++ .../datastore/search_object_light.go | 47 ++ .../super-mario-maker/add_to_buffer_queue.go | 61 ++ .../super-mario-maker/add_to_buffer_queues.go | 63 ++ .../best_score_rate_course_search_object.go | 62 ++ .../change_playable_platform.go | 49 ++ .../check_rate_custom_ranking_counter.go | 47 ++ .../super-mario-maker/clear_buffer_queues.go | 49 ++ .../super-mario-maker/complete_attach_file.go | 47 ++ .../complete_attach_file_v1.go | 47 ++ .../complete_post_object_with_owner_id.go | 61 ++ .../conditional_search_object.go | 73 ++ .../ctr_pick_up_course_search_object.go | 62 ++ .../super-mario-maker/custom_search_object.go | 61 ++ .../delete_application_config.go | 60 ++ .../delete_cached_ranking.go | 61 ++ .../super-mario-maker/delete_course_record.go | 47 ++ .../delete_custom_ranking.go | 48 ++ .../followings_latest_course_search_object.go | 62 ++ .../get_application_config.go | 47 ++ .../get_application_config_string.go | 47 ++ .../super-mario-maker/get_buffer_queue.go | 47 ++ .../super-mario-maker/get_buffer_queues.go | 49 ++ .../super-mario-maker/get_course_record.go | 47 ++ .../super-mario-maker/get_custom_ranking.go | 47 ++ .../get_custom_ranking_by_data_id.go | 47 ++ .../super-mario-maker/get_deletion_reason.go | 48 ++ .../super-mario-maker/get_meta_by_owner_id.go | 47 ++ .../get_metas_with_course_record.go | 63 ++ .../super-mario-maker/get_object_infos.go | 48 ++ .../latest_course_search_object.go | 62 ++ .../super-mario-maker/prepare_attach_file.go | 47 ++ ...e_post_object_with_owner_id_and_data_id.go | 72 ++ .../datastore/super-mario-maker/protocol.go | 363 +++++++++ .../super-mario-maker/rate_custom_ranking.go | 49 ++ .../recommended_course_search_object.go | 62 ++ .../super-mario-maker/report_course.go | 47 ++ .../reset_rate_custom_ranking_counter.go | 47 ++ .../score_range_cascaded_search_object.go | 62 ++ .../search_unknown_platform_objects.go | 31 + .../set_application_config.go | 71 ++ .../set_application_config_string.go | 71 ++ .../super-mario-maker/set_cached_ranking.go | 73 ++ .../super-mario-maker/set_deletion_reason.go | 61 ++ .../suggested_course_search_object.go | 62 ++ .../types/buffer_queue_param.go | 112 +++ .../types/datastore_attach_file_param.go | 127 ++++ ...atastore_change_playable_platform_param.go | 112 +++ ...tastore_custom_ranking_rating_condition.go | 164 ++++ .../types/datastore_custom_ranking_result.go | 127 ++++ .../datastore_file_server_object_info.go | 113 +++ .../datastore_get_course_record_param.go | 112 +++ .../datastore_get_course_record_result.go | 182 +++++ ...ore_get_custom_ranking_by_data_id_param.go | 128 ++++ .../datastore_get_custom_ranking_param.go | 140 ++++ .../datastore_get_meta_by_owner_id_param.go | 143 ++++ .../datastore_rate_custom_ranking_param.go | 140 ++++ .../types/datastore_report_course_param.go | 140 ++++ .../datastore_upload_course_record_param.go | 126 +++ .../super-mario-maker/upload_course_record.go | 47 ++ .../super-smash-bros-4/check_post_replay.go | 47 ++ .../complete_post_replay.go | 47 ++ .../complete_post_shared_data.go | 47 ++ .../get_application_config.go | 47 ++ .../get_fighting_power_chart.go | 47 ++ .../get_fighting_power_chart_all.go | 29 + .../super-smash-bros-4/get_next_replay.go | 29 + .../super-smash-bros-4/get_profiles.go | 48 ++ .../super-smash-bros-4/get_replay_meta.go | 47 ++ .../get_shared_data_meta.go | 31 + .../get_world_play_report.go | 29 + .../post_fighting_power_score.go | 49 ++ .../super-smash-bros-4/post_profile.go | 47 ++ .../super-smash-bros-4/prepare_get_replay.go | 47 ++ .../super-smash-bros-4/prepare_post_replay.go | 47 ++ .../prepare_post_shared_data.go | 47 ++ .../datastore/super-smash-bros-4/protocol.go | 200 +++++ .../super-smash-bros-4/report_shared_data.go | 47 ++ .../super-smash-bros-4/search_replay.go | 47 ++ .../super-smash-bros-4/search_shared_data.go | 47 ++ .../super-smash-bros-4/send_play_report.go | 48 ++ .../datastore_complete_post_replay_param.go | 127 ++++ ...tastore_complete_post_shared_data_param.go | 127 ++++ .../types/datastore_fighting_power_chart.go | 114 +++ .../types/datastore_fighting_power_score.go | 112 +++ .../datastore_file_object_server_info.go | 113 +++ .../types/datastore_get_replay_meta_param.go | 112 +++ ...tastore_post_fighting_power_score_param.go | 126 +++ .../types/datastore_post_profile_param.go | 98 +++ .../datastore_prepare_get_replay_param.go | 114 +++ .../datastore_prepare_post_replay_param.go | 256 +++++++ ...atastore_prepare_post_shared_data_param.go | 212 ++++++ .../types/datastore_profile_info.go | 112 +++ .../types/datastore_replay_meta_info.go | 213 ++++++ .../types/datastore_replay_player.go | 210 +++++ .../types/datastore_search_replay_param.go | 140 ++++ .../datastore_search_shared_data_param.go | 182 +++++ .../types/datastore_shared_data_info.go | 210 +++++ nex-protocols-go/datastore/touch_object.go | 47 ++ .../datastore_change_meta_compare_param.go | 226 ++++++ .../types/datastore_change_meta_param.go | 282 +++++++ .../types/datastore_change_meta_param_v1.go | 212 ++++++ .../types/datastore_complete_post_param.go | 112 +++ .../types/datastore_complete_post_param_v1.go | 112 +++ .../types/datastore_complete_update_param.go | 161 ++++ .../datastore/types/datastore_delete_param.go | 112 +++ .../types/datastore_get_meta_param.go | 140 ++++ ...ore_get_new_arrived_notifications_param.go | 112 +++ .../datastore_get_notification_url_param.go | 98 +++ .../datastore_get_specific_meta_param.go | 100 +++ .../datastore_get_specific_meta_param_v1.go | 100 +++ .../datastore/types/datastore_key_value.go | 112 +++ .../datastore/types/datastore_meta_info.go | 379 +++++++++ .../datastore/types/datastore_notification.go | 112 +++ .../types/datastore_notification_v1.go | 112 +++ .../types/datastore_password_info.go | 126 +++ .../datastore/types/datastore_permission.go | 114 +++ .../types/datastore_persistence_info.go | 126 +++ .../types/datastore_persistence_init_param.go | 112 +++ .../types/datastore_persistence_target.go | 112 +++ .../types/datastore_prepare_get_param.go | 168 ++++ .../types/datastore_prepare_get_param_v1.go | 112 +++ .../types/datastore_prepare_post_param.go | 282 +++++++ .../types/datastore_prepare_post_param_v1.go | 241 ++++++ .../types/datastore_prepare_update_param.go | 173 +++++ .../types/datastore_rate_object_param.go | 112 +++ .../datastore/types/datastore_rating_info.go | 126 +++ .../types/datastore_rating_info_with_slot.go | 112 +++ .../types/datastore_rating_init_param.go | 196 +++++ .../datastore_rating_init_param_with_slot.go | 112 +++ .../datastore/types/datastore_rating_log.go | 140 ++++ .../types/datastore_rating_target.go | 112 +++ .../datastore_req_get_additional_meta.go | 140 ++++ .../datastore/types/datastore_req_get_info.go | 168 ++++ .../types/datastore_req_get_info_v1.go | 142 ++++ ...datastore_req_get_notification_url_info.go | 140 ++++ .../types/datastore_req_post_info.go | 157 ++++ .../types/datastore_req_post_info_v1.go | 157 ++++ .../types/datastore_req_update_info.go | 178 +++++ .../datastore/types/datastore_search_param.go | 355 +++++++++ .../types/datastore_search_result.go | 128 ++++ .../types/datastore_specific_meta_info.go | 154 ++++ .../types/datastore_specific_meta_info_v1.go | 154 ++++ .../types/datastore_touch_object_param.go | 126 +++ .../datastore/unperpetuate_object.go | 60 ++ .../debug/disable_api_recorder.go | 29 + nex-protocols-go/debug/enable_api_recorder.go | 29 + .../debug/get_api_call_summary.go | 31 + nex-protocols-go/debug/get_api_calls.go | 72 ++ .../get_exclude_joined_matchmake_session.go | 31 + .../debug/is_api_recorder_enabled.go | 29 + nex-protocols-go/debug/protocol.go | 151 ++++ .../set_exclude_joined_matchmake_session.go | 31 + .../add_friend_by_lst_principal_id.go | 61 ++ .../friends-3ds/add_friend_by_principal_id.go | 60 ++ .../friends-3ds/get_all_friends.go | 29 + .../friends-3ds/get_friend_comment.go | 49 ++ .../friends-3ds/get_friend_mii.go | 49 ++ .../friends-3ds/get_friend_mii_list.go | 49 ++ .../friends-3ds/get_friend_persistent_info.go | 48 ++ .../friends-3ds/get_friend_picture.go | 48 ++ .../friends-3ds/get_friend_presence.go | 48 ++ .../friends-3ds/get_friend_relationships.go | 48 ++ .../get_principal_id_by_local_friend_code.go | 61 ++ .../friends-3ds/is_active_game.go | 62 ++ nex-protocols-go/friends-3ds/protocol.go | 380 ++++++++++ .../remove_friend_by_local_friend_code.go | 47 ++ .../remove_friend_by_principal_id.go | 47 ++ .../friends-3ds/send_invitation.go | 48 ++ nex-protocols-go/friends-3ds/sync_friend.go | 73 ++ .../friends-3ds/types/friend_comment.go | 141 ++++ .../friends-3ds/types/friend_info.go | 112 +++ .../friends-3ds/types/friend_mii.go | 141 ++++ .../friends-3ds/types/friend_mii_list.go | 141 ++++ .../types/friend_persistent_info.go | 253 +++++++ .../friends-3ds/types/friend_picture.go | 141 ++++ .../friends-3ds/types/friend_presence.go | 127 ++++ .../friends-3ds/types/friend_relationship.go | 141 ++++ .../friends-3ds/types/game_key.go | 127 ++++ nex-protocols-go/friends-3ds/types/mii.go | 155 ++++ .../friends-3ds/types/mii_list.go | 157 ++++ .../friends-3ds/types/my_profile.go | 211 ++++++ .../friends-3ds/types/nintendo_presence.go | 239 ++++++ .../friends-3ds/types/played_game.go | 112 +++ .../friends-3ds/update_black_list.go | 48 ++ .../friends-3ds/update_comment.go | 47 ++ .../friends-3ds/update_favorite_game_key.go | 47 ++ nex-protocols-go/friends-3ds/update_mii.go | 47 ++ .../friends-3ds/update_mii_list.go | 47 ++ .../friends-3ds/update_picture.go | 60 ++ .../friends-3ds/update_played_games.go | 49 ++ .../friends-3ds/update_preference.go | 71 ++ .../friends-3ds/update_presence.go | 61 ++ .../friends-3ds/update_profile.go | 47 ++ .../friends-wiiu/accept_friend_request.go | 47 ++ .../friends-wiiu/add_black_list.go | 47 ++ nex-protocols-go/friends-wiiu/add_friend.go | 47 ++ .../friends-wiiu/add_friend_by_name.go | 47 ++ .../friends-wiiu/add_friend_request.go | 116 +++ .../friends-wiiu/cancel_friend_request.go | 47 ++ .../friends-wiiu/check_setting_status.go | 29 + .../friends-wiiu/delete_friend_request.go | 47 ++ .../delete_persistent_notification.go | 49 ++ .../friends-wiiu/deny_friend_request.go | 47 ++ .../friends-wiiu/get_basic_info.go | 48 ++ .../get_request_block_settings.go | 48 ++ .../mark_friend_requests_as_received.go | 48 ++ nex-protocols-go/friends-wiiu/protocol.go | 308 ++++++++ .../friends-wiiu/remove_black_list.go | 47 ++ .../friends-wiiu/remove_friend.go | 47 ++ .../types/blacklisted_principal.go | 141 ++++ .../friends-wiiu/types/comment.go | 141 ++++ .../friends-wiiu/types/friend_info.go | 183 +++++ .../friends-wiiu/types/friend_request.go | 141 ++++ .../types/friend_request_message.go | 225 ++++++ .../friends-wiiu/types/game_key.go | 127 ++++ nex-protocols-go/friends-wiiu/types/mii_v2.go | 169 +++++ .../types/nintendo_presence_v2.go | 309 ++++++++ .../friends-wiiu/types/nna_info.go | 141 ++++ .../types/persistent_notification.go | 169 +++++ .../types/persistent_notification_list.go | 115 +++ .../types/principal_basic_info.go | 155 ++++ .../types/principal_preference.go | 141 ++++ .../types/principal_request_block_setting.go | 127 ++++ .../update_and_get_all_information.go | 72 ++ .../friends-wiiu/update_comment.go | 47 ++ nex-protocols-go/friends-wiiu/update_mii.go | 47 ++ .../friends-wiiu/update_preference.go | 47 ++ .../friends-wiiu/update_presence.go | 47 ++ nex-protocols-go/friends/accept_friendship.go | 47 ++ nex-protocols-go/friends/add_friend.go | 71 ++ .../friends/add_friend_by_name.go | 71 ++ .../add_friend_by_name_with_details.go | 71 ++ .../friends/add_friend_with_details.go | 71 ++ nex-protocols-go/friends/black_list.go | 60 ++ .../friends/black_list_by_name.go | 60 ++ .../friends/clear_relationship.go | 47 ++ .../friends/decline_friendship.go | 47 ++ nex-protocols-go/friends/get_detailed_list.go | 60 ++ nex-protocols-go/friends/get_list.go | 60 ++ nex-protocols-go/friends/get_relationships.go | 47 ++ nex-protocols-go/friends/protocol.go | 223 ++++++ nex-protocols-go/friends/types/friend_data.go | 154 ++++ .../friends/types/relationship_data.go | 154 ++++ nex-protocols-go/friends/update_details.go | 60 ++ nex-protocols-go/globals/logger.go | 7 + nex-protocols-go/globals/respond.go | 50 ++ nex-protocols-go/globals/respond_error.go | 66 ++ nex-protocols-go/go.mod | 27 + nex-protocols-go/go.sum | 46 ++ nex-protocols-go/health/fix_sanity_errors.go | 29 + nex-protocols-go/health/ping_daemon.go | 29 + nex-protocols-go/health/ping_database.go | 29 + nex-protocols-go/health/protocol.go | 114 +++ nex-protocols-go/health/run_sanity_check.go | 29 + nex-protocols-go/init.go | 23 + .../match-making-ext/delete_from_deletions.go | 61 ++ .../match-making-ext/end_participation.go | 60 ++ .../get_detailed_participants.go | 60 ++ .../get_gathering_relations.go | 60 ++ .../match-making-ext/get_participants.go | 60 ++ .../match-making-ext/get_participants_urls.go | 48 ++ nex-protocols-go/match-making-ext/protocol.go | 139 ++++ .../match-making/accept_invitation.go | 60 ++ .../match-making/add_participants.go | 72 ++ .../match-making/cancel_invitation.go | 72 ++ .../match-making/cancel_participation.go | 60 ++ .../match-making/decline_invitation.go | 60 ++ .../match-making/delete_from_deletions.go | 48 ++ .../match-making/delete_gathering.go | 47 ++ .../match-making/find_by_description.go | 60 ++ .../match-making/find_by_description_like.go | 60 ++ .../match-making/find_by_description_regex.go | 60 ++ nex-protocols-go/match-making/find_by_id.go | 48 ++ .../match-making/find_by_owner.go | 60 ++ .../match-making/find_by_participants.go | 48 ++ .../match-making/find_by_single_id.go | 47 ++ .../match-making/find_by_sql_query.go | 60 ++ nex-protocols-go/match-making/find_by_type.go | 60 ++ .../match-making/find_invitations.go | 47 ++ .../match-making/gathering_flags.go | 15 + .../match-making/get_details_participants.go | 47 ++ .../match-making/get_invitations_received.go | 29 + .../match-making/get_invitations_sent.go | 47 ++ .../match-making/get_participants.go | 47 ++ .../match-making/get_participants_urls.go | 47 ++ .../match-making/get_pending_deletions.go | 60 ++ .../match-making/get_session_url.go | 47 ++ .../match-making/get_session_urls.go | 47 ++ nex-protocols-go/match-making/get_state.go | 47 ++ nex-protocols-go/match-making/get_stats.go | 72 ++ nex-protocols-go/match-making/invite.go | 72 ++ .../match-making/launch_session.go | 60 ++ .../migrate_gathering_ownership.go | 72 ++ .../migrate_gathering_ownership_v1.go | 61 ++ nex-protocols-go/match-making/participate.go | 60 ++ nex-protocols-go/match-making/protocol.go | 596 +++++++++++++++ .../match-making/register_gathering.go | 47 ++ .../match-making/register_local_url.go | 60 ++ .../match-making/register_local_urls.go | 61 ++ nex-protocols-go/match-making/report_stats.go | 62 ++ nex-protocols-go/match-making/set_state.go | 60 ++ .../types/auto_matchmake_param.go | 200 +++++ .../types/create_matchmake_session_param.go | 170 +++++ .../match-making/types/deletion_entry.go | 126 +++ ..._matchmake_session_by_participant_param.go | 128 ++++ ...matchmake_session_by_participant_result.go | 112 +++ .../match-making/types/gathering.go | 224 ++++++ .../match-making/types/gathering_stats.go | 128 ++++ .../match-making/types/gathering_urls.go | 114 +++ .../match-making/types/invitation.go | 126 +++ .../types/join_matchmake_session_param.go | 252 ++++++ .../types/matchmake_block_list_param.go | 98 +++ .../match-making/types/matchmake_param.go | 101 +++ .../match-making/types/matchmake_session.go | 382 ++++++++++ .../matchmake_session_search_criteria.go | 357 +++++++++ .../match-making/types/participant_details.go | 140 ++++ .../types/persistent_gathering.go | 213 ++++++ .../match-making/types/playing_session.go | 112 +++ .../match-making/types/simple_community.go | 112 +++ .../types/simple_playing_session.go | 140 ++++ .../types/update_matchmake_session_param.go | 324 ++++++++ .../match-making/unregister_gathering.go | 47 ++ .../match-making/unregister_gatherings.go | 48 ++ .../match-making/update_gathering.go | 47 ++ .../update_gathering_ownership.go | 60 ++ .../match-making/update_session_host.go | 60 ++ .../match-making/update_session_host_v1.go | 47 ++ .../match-making/update_session_url.go | 60 ++ .../matchmake-extension/add_to_block_list.go | 48 ++ .../auto_matchmake_postpone.go | 60 ++ ...to_matchmake_with_gathering_id_postpone.go | 72 ++ .../auto_matchmake_with_param_postpone.go | 47 ++ ...matchmake_with_search_criteria_postpone.go | 73 ++ .../browse_matchmake_session.go | 61 ++ .../browse_matchmake_session_no_holder.go | 61 ++ ...hmake_session_no_holder_no_result_range.go | 47 ++ ...browse_matchmake_session_with_host_urls.go | 61 ++ ...chmake_session_with_host_urls_no_holder.go | 61 ++ ...ith_host_urls_no_holder_no_result_range.go | 47 ++ ...clear_matchmake_session_system_password.go | 47 ++ .../clear_my_block_list.go | 29 + .../close_participation.go | 47 ++ .../matchmake-extension/create_community.go | 61 ++ .../create_matchmake_session.go | 75 ++ .../create_matchmake_session_with_param.go | 47 ++ .../matchmake-extension/debug_notify_event.go | 104 +++ .../find_comminuty_by_owner.go | 31 + .../find_community_by_gathering_id.go | 48 ++ .../find_community_by_participant.go | 60 ++ .../find_matchmake_session_by_gathering_id.go | 48 ++ ...atchmake_session_by_gathering_id_detail.go | 47 ++ .../find_matchmake_session_by_owner.go | 60 ++ .../find_matchmake_session_by_participant.go | 47 ++ ...atchmake_session_by_single_gathering_id.go | 47 ++ .../find_official_community.go | 60 ++ ...erate_matchmake_session_system_password.go | 47 ++ .../get_friend_notification_data.go | 47 ++ .../get_lst_friend_notification_data.go | 48 ++ .../matchmake-extension/get_my_block_list.go | 29 + .../get_playing_session.go | 48 ++ .../get_simple_community.go | 48 ++ .../get_simple_playing_session.go | 61 ++ .../matchmake-extension/is_violation_user.go | 29 + .../matchmake-extension/join_community.go | 71 ++ .../join_matchmake_session.go | 60 ++ .../join_matchmake_session_ex.go | 85 +++ .../join_matchmake_session_with_param.go | 47 ++ .../create_simple_search_object.go | 47 ++ .../delete_simple_search_object.go | 47 ++ ...tchmake_session_with_extra_participants.go | 93 +++ .../mario-kart-8/protocol.go | 103 +++ .../search_simple_search_object.go | 47 ++ ...arch_simple_search_object_by_object_ids.go | 48 ++ .../types/simple_search_condition.go | 112 +++ .../simple_search_date_time_attribute.go | 168 ++++ .../types/simple_search_object.go | 184 +++++ .../mario-kart-8/types/simple_search_param.go | 170 +++++ .../update_simple_search_object.go | 61 ++ .../modify_current_game_attribute.go | 71 ++ .../monster-hunter-xx/add_friends.go | 48 ++ .../find_community_by_owner.go | 60 ++ .../get_friend_user_profiles.go | 48 ++ .../monster-hunter-xx/protocol.go | 96 +++ .../monster-hunter-xx/remove_friend.go | 47 ++ .../types/friend_user_info.go | 126 +++ .../types/friend_user_param.go | 98 +++ .../update_friend_user_profile.go | 47 ++ .../matchmake-extension/open_participation.go | 47 ++ .../clear_my_previously_matched_user_cache.go | 29 + .../pokemon-gen6/protocol.go | 66 ++ .../matchmake-extension/protocol.go | 716 ++++++++++++++++++ .../remove_from_block_list.go | 48 ++ .../matchmake-extension/report_violation.go | 71 ++ .../request_matchmaking.go | 47 ++ .../auto_tournament_matchmake.go | 31 + ...end_community_competition_participation.go | 31 + .../debug_join_community_competition.go | 31 + ...post_community_competition_match_result.go | 31 + .../debug_register_community_competition.go | 31 + .../debug_unregister_community_competition.go | 31 + ...end_community_competition_participation.go | 31 + ...mpetition_participation_by_gathering_id.go | 31 + ..._community_competitions_by_gathering_id.go | 31 + ...d_community_competitions_by_participant.go | 31 + .../get_community_competition_by_id.go | 31 + .../get_community_competition_ranking.go | 31 + .../get_community_competitions.go | 31 + .../super-smash-bros-4/get_tournament.go | 31 + .../get_tournament_competition.go | 31 + .../get_tournament_competitions.go | 31 + .../get_tournament_profiles.go | 31 + .../get_tournament_replay_id.go | 31 + .../get_tournament_replay_ids.go | 31 + .../get_tournament_result.go | 31 + .../join_community_competition.go | 31 + ...n_community_competition_by_gathering_id.go | 31 + .../join_or_create_matchmake_session.go | 31 + ...post_community_competition_match_result.go | 31 + .../super-smash-bros-4/protocol.go | 311 ++++++++ .../register_community_competition.go | 31 + .../register_tournament_bot.go | 31 + .../register_tournament_player_info.go | 31 + .../replace_tournament_leaf_node.go | 31 + .../report_tournament_bot_round_result.go | 31 + .../search_community_competition.go | 31 + .../select_community_competition_by_owner.go | 31 + .../set_tournament_replay_id.go | 31 + .../super-smash-bros-4/simple_find_by_i_d.go | 31 + .../super-smash-bros-4/start_tournament.go | 31 + .../unregister_community_competition.go | 31 + .../unregister_community_competition_by_id.go | 31 + .../update_application_buffer.go | 60 ++ .../matchmake-extension/update_community.go | 47 ++ .../update_matchmake_session.go | 47 ++ .../update_matchmake_session_attribute.go | 61 ++ .../update_matchmake_session_part.go | 47 ++ .../update_notification_data.go | 82 ++ .../update_privacy_setting.go | 60 ++ .../update_progress_score.go | 60 ++ .../withdraw_matchmaking.go | 47 ++ .../withdraw_matchmaking_all.go | 29 + .../matchmake-referee/create_stats.go | 47 ++ .../matchmake-referee/end_round.go | 47 ++ .../end_round_without_report.go | 47 ++ .../get_not_summarized_round.go | 29 + .../matchmake-referee/get_or_create_stats.go | 47 ++ .../matchmake-referee/get_round.go | 47 ++ .../get_round_participants.go | 47 ++ .../get_start_round_param.go | 47 ++ .../matchmake-referee/get_stats_all.go | 47 ++ .../matchmake-referee/get_stats_primaries.go | 49 ++ .../matchmake-referee/get_stats_primary.go | 47 ++ .../matchmake-referee/protocol.go | 224 ++++++ .../matchmake-referee/reset_stats.go | 29 + .../matchmake-referee/start_round.go | 47 ++ .../matchmake_referee_end_round_param.go | 129 ++++ ...matchmake_referee_personal_round_result.go | 169 +++++ .../types/matchmake_referee_round.go | 171 +++++ .../matchmake_referee_start_round_param.go | 143 ++++ .../types/matchmake_referee_stats.go | 323 ++++++++ .../matchmake_referee_stats_init_param.go | 127 ++++ .../types/matchmake_referee_stats_target.go | 127 ++++ .../message-delivery/deliver_message.go | 47 ++ nex-protocols-go/message-delivery/protocol.go | 79 ++ .../messaging/delete_all_messages.go | 47 ++ nex-protocols-go/messaging/delete_messages.go | 62 ++ nex-protocols-go/messaging/deliver_message.go | 47 ++ .../messaging/deliver_message_multi_target.go | 31 + .../messaging/get_messages_headers.go | 61 ++ .../messaging/get_number_of_messages.go | 47 ++ nex-protocols-go/messaging/protocol.go | 164 ++++ .../retrieve_all_messages_within_range.go | 61 ++ .../messaging/retrieve_messages.go | 73 ++ .../messaging/types/binary_message.go | 113 +++ .../messaging/types/message_recipient.go | 126 +++ .../messaging/types/text_message.go | 113 +++ .../messaging/types/user_message.go | 245 ++++++ .../monitoring/get_cluster_members.go | 29 + nex-protocols-go/monitoring/ping_daemon.go | 29 + nex-protocols-go/monitoring/protocol.go | 90 +++ .../nat-traversal/get_relay_signature_key.go | 29 + .../nat-traversal/initiate_probe.go | 47 ++ nex-protocols-go/nat-traversal/protocol.go | 151 ++++ .../nat-traversal/report_nat_properties.go | 71 ++ .../report_nat_traversal_result.go | 76 ++ .../report_nat_traversal_result_detail.go | 87 +++ .../nat-traversal/request_probe_initiation.go | 48 ++ .../request_probe_initiation_ext.go | 61 ++ .../notification_types.go | 55 ++ .../nintendo-notifications/protocol.go | 37 + .../types/nintendo_notification_event.go | 126 +++ .../nintendo_notification_event_general.go | 140 ++++ .../notifications/build_notification_type.go | 7 + .../notifications/notification_categories.go | 34 + .../notifications/notification_subtypes.go | 107 +++ nex-protocols-go/notifications/protocol.go | 36 + .../notifications/types/notification_event.go | 168 ++++ .../persistent-store/find_by_group.go | 47 ++ .../find_items_by_sql_query.go | 71 ++ .../persistent-store/get_custom_item.go | 60 ++ nex-protocols-go/persistent-store/get_item.go | 60 ++ .../persistent-store/insert_custom_item.go | 82 ++ .../persistent-store/insert_item.go | 82 ++ nex-protocols-go/persistent-store/protocol.go | 151 ++++ .../persistent-store/remove_item.go | 60 ++ nex-protocols-go/pokemon-pss/protocol.go | 90 +++ nex-protocols-go/pokemon-pss/unk1.go | 29 + nex-protocols-go/pokemon-pss/unk2.go | 29 + .../ranking/change_all_attributes.go | 61 ++ nex-protocols-go/ranking/change_attributes.go | 72 ++ nex-protocols-go/ranking/delete_all_scores.go | 47 ++ .../ranking/delete_common_data.go | 47 ++ nex-protocols-go/ranking/delete_score.go | 60 ++ nex-protocols-go/ranking/get_approx_order.go | 94 +++ .../ranking/get_cached_top_x_ranking.go | 61 ++ .../ranking/get_cached_top_x_rankings.go | 63 ++ nex-protocols-go/ranking/get_common_data.go | 47 ++ nex-protocols-go/ranking/get_ranking.go | 94 +++ .../ranking/get_ranking_by_pid_list.go | 95 +++ .../ranking/get_ranking_by_unique_id_list.go | 95 +++ nex-protocols-go/ranking/get_stats.go | 72 ++ .../mario-kart-8/get_competition_info.go | 47 ++ .../get_competition_ranking_score.go | 31 + .../ranking/mario-kart-8/protocol.go | 81 ++ .../types/competition_ranking_info.go | 128 ++++ .../competition_ranking_info_get_param.go | 112 +++ .../competition_ranking_upload_score_param.go | 196 +++++ .../upload_competition_ranking_score.go | 47 ++ nex-protocols-go/ranking/protocol.go | 248 ++++++ .../delete_competition_ranking_score.go | 31 + .../splatoon/get_competition_ranking_score.go | 31 + ...ompetition_ranking_score_by_period_list.go | 31 + nex-protocols-go/ranking/splatoon/protocol.go | 87 +++ .../upload_competition_ranking_score.go | 31 + .../ranking/types/ranking_cached_result.go | 141 ++++ .../types/ranking_change_attributes_param.go | 128 ++++ .../ranking/types/ranking_order_param.go | 168 ++++ .../ranking/types/ranking_rank_data.go | 222 ++++++ .../ranking/types/ranking_result.go | 128 ++++ .../ranking/types/ranking_score_data.go | 168 ++++ .../ranking/types/ranking_stats.go | 100 +++ .../ranking/upload_common_data.go | 60 ++ nex-protocols-go/ranking/upload_score.go | 61 ++ .../ranking2/delete_common_data.go | 47 ++ .../ranking2/get_category_setting.go | 47 ++ nex-protocols-go/ranking2/get_common_data.go | 71 ++ .../ranking2/get_estimate_score_rank.go | 47 ++ nex-protocols-go/ranking2/get_ranking.go | 47 ++ .../ranking2/get_ranking_by_principal_id.go | 62 ++ .../ranking2/get_ranking_chart.go | 47 ++ .../ranking2/get_ranking_charts.go | 49 ++ nex-protocols-go/ranking2/protocol.go | 188 +++++ nex-protocols-go/ranking2/put_common_data.go | 61 ++ nex-protocols-go/ranking2/put_score.go | 62 ++ .../types/ranking2_category_setting.go | 210 +++++ .../ranking2/types/ranking2_chart_info.go | 338 +++++++++ .../types/ranking2_chart_info_input.go | 112 +++ .../ranking2/types/ranking2_common_data.go | 126 +++ .../ranking2_estimate_score_rank_input.go | 126 +++ .../ranking2_estimate_score_rank_output.go | 168 ++++ .../types/ranking2_get_by_list_param.go | 168 ++++ .../ranking2/types/ranking2_get_param.go | 210 +++++ .../ranking2/types/ranking2_info.go | 142 ++++ .../ranking2/types/ranking2_rank_data.go | 168 ++++ .../ranking2/types/ranking2_score_data.go | 126 +++ nex-protocols-go/remote-log-device/log.go | 47 ++ .../remote-log-device/protocol.go | 79 ++ nex-protocols-go/screening/protocol.go | 90 +++ .../screening/report_datastore_content.go | 31 + nex-protocols-go/screening/report_user.go | 31 + .../get_maintenance_status.go | 29 + .../nintendo-badge-arcade/protocol.go | 66 ++ .../secure-connection/protocol.go | 163 ++++ .../secure-connection/register.go | 48 ++ .../secure-connection/register_ex.go | 61 ++ .../secure-connection/replace_url.go | 60 ++ .../request_connection_data.go | 60 ++ .../secure-connection/request_urls.go | 60 ++ .../secure-connection/send_report.go | 60 ++ .../secure-connection/test_connectivity.go | 29 + .../secure-connection/update_urls.go | 48 ++ nex-protocols-go/service-item/protocol.go | 57 ++ .../acquire_service_item_by_account.go | 47 ++ .../get_balance_request.go | 47 ++ .../get_balance_response.go | 47 ++ .../get_environment.go | 60 ++ .../get_law_message_request.go | 47 ++ .../get_law_message_response.go | 47 ++ .../get_prepurchase_info_request.go | 47 ++ .../get_prepurchase_info_response.go | 47 ++ .../get_purchase_history_request.go | 47 ++ .../get_purchase_history_response.go | 47 ++ .../get_service_item_right_request.go | 61 ++ .../get_service_item_right_response.go | 47 ++ .../team-kirby-clash-deluxe/get_support_id.go | 47 ++ .../http_get_request.go | 47 ++ .../http_get_response.go | 47 ++ .../list_service_item_request.go | 47 ++ .../list_service_item_response.go | 47 ++ .../post_right_binary_by_account.go | 47 ++ .../team-kirby-clash-deluxe/protocol.go | 215 ++++++ .../purchase_service_item_request.go | 47 ++ .../purchase_service_item_response.go | 47 ++ .../types/service_item_account_right.go | 128 ++++ .../service_item_account_right_consumption.go | 143 ++++ .../types/service_item_account_right_time.go | 102 +++ ...m_acquire_service_item_by_account_param.go | 210 +++++ ...vice_item_acquire_service_item_response.go | 170 +++++ .../types/service_item_amount.go | 126 +++ .../types/service_item_attribute.go | 112 +++ .../types/service_item_catalog.go | 156 ++++ .../types/service_item_eshop_response.go | 126 +++ .../types/service_item_get_balance_param.go | 131 ++++ .../service_item_get_balance_response.go | 115 +++ .../service_item_get_law_message_param.go | 131 ++++ .../service_item_get_law_message_response.go | 115 +++ .../types/service_item_get_notice_param.go | 98 +++ ...service_item_get_prepurchase_info_param.go | 154 ++++ ...vice_item_get_prepurchase_info_response.go | 115 +++ ...service_item_get_purchase_history_param.go | 154 ++++ ...vice_item_get_purchase_history_response.go | 115 +++ ...rvice_item_get_service_item_right_param.go | 159 ++++ ...ce_item_get_service_item_right_response.go | 115 +++ .../service_item_get_support_id_param.go | 112 +++ .../types/service_item_http_get_param.go | 98 +++ .../types/service_item_http_get_response.go | 98 +++ .../types/service_item_law_message.go | 112 +++ .../types/service_item_limitation.go | 112 +++ .../types/service_item_list_item.go | 170 +++++ .../service_item_list_service_item_param.go | 173 +++++ ...service_item_list_service_item_response.go | 115 +++ .../types/service_item_notice.go | 182 +++++ ...item_post_right_binary_by_account_param.go | 168 ++++ .../types/service_item_prepurchase_info.go | 224 ++++++ .../service_item_prepurchase_right_info.go | 170 +++++ .../types/service_item_purchase_history.go | 128 ++++ .../types/service_item_purchase_info.go | 140 ++++ ...ervice_item_purchase_service_item_param.go | 215 ++++++ ...ice_item_purchase_service_item_response.go | 115 +++ .../types/service_item_right_binary.go | 112 +++ .../service_item_right_consumption_info.go | 115 +++ .../types/service_item_right_info.go | 112 +++ .../types/service_item_right_infos.go | 158 ++++ .../types/service_item_right_time_info.go | 115 +++ .../types/service_item_transaction.go | 210 +++++ ..._item_use_service_item_by_account_param.go | 196 +++++ .../service_item_use_service_item_response.go | 115 +++ .../types/service_item_used_info.go | 112 +++ .../types/service_item_user_info.go | 98 +++ .../use_service_item_by_account_request.go | 47 ++ .../use_service_item_by_account_response.go | 47 ++ .../wii-sports-club/end_challenge.go | 47 ++ .../wii-sports-club/get_balance_request.go | 47 ++ .../wii-sports-club/get_balance_response.go | 47 ++ .../wii-sports-club/get_notice.go | 47 ++ .../get_prepurchase_info_request.go | 47 ++ .../get_prepurchase_info_response.go | 47 ++ .../get_purchase_history_request.go | 47 ++ .../get_purchase_history_response.go | 47 ++ .../get_service_item_right_request.go | 47 ++ .../get_service_item_right_response.go | 47 ++ .../service-item/wii-sports-club/hello.go | 47 ++ .../wii-sports-club/http_get_request.go | 47 ++ .../wii-sports-club/http_get_response.go | 47 ++ .../list_service_item_request.go | 47 ++ .../list_service_item_response.go | 47 ++ .../wii-sports-club/load_user_info.go | 29 + .../service-item/wii-sports-club/protocol.go | 215 ++++++ .../purchase_service_item_request.go | 47 ++ .../purchase_service_item_response.go | 47 ++ .../request_ticket_restoration.go | 47 ++ .../wii-sports-club/save_user_info.go | 47 ++ .../wii-sports-club/start_challenge.go | 47 ++ .../types/service_item_account_right.go | 112 +++ .../types/service_item_amount.go | 126 +++ .../types/service_item_attribute.go | 112 +++ .../types/service_item_catalog.go | 128 ++++ .../types/service_item_end_challenge_param.go | 112 +++ .../types/service_item_eshop_response.go | 126 +++ .../types/service_item_event.go | 196 +++++ .../types/service_item_get_balance_param.go | 112 +++ .../service_item_get_balance_response.go | 115 +++ .../types/service_item_get_notice_param.go | 98 +++ ...service_item_get_prepurchase_info_param.go | 126 +++ ...vice_item_get_prepurchase_info_response.go | 115 +++ ...service_item_get_purchase_history_param.go | 140 ++++ ...vice_item_get_purchase_history_response.go | 115 +++ ...rvice_item_get_service_item_right_param.go | 112 +++ ...ce_item_get_service_item_right_response.go | 115 +++ .../types/service_item_http_get_param.go | 98 +++ .../types/service_item_http_get_response.go | 98 +++ .../types/service_item_limitation.go | 112 +++ .../types/service_item_list_item.go | 170 +++++ .../service_item_list_service_item_param.go | 140 ++++ ...service_item_list_service_item_response.go | 115 +++ .../types/service_item_notice.go | 182 +++++ .../types/service_item_prepurchase_info.go | 196 +++++ .../types/service_item_purchace_info.go | 140 ++++ .../types/service_item_purchase_history.go | 128 ++++ ...ervice_item_purchase_service_item_param.go | 196 +++++ ...ice_item_purchase_service_item_response.go | 115 +++ ...e_item_request_ticket_restoration_param.go | 112 +++ .../types/service_item_right_info.go | 114 +++ .../types/service_item_right_infos.go | 100 +++ .../service_item_start_challenge_param.go | 126 +++ .../types/service_item_ticket_info.go | 112 +++ .../types/service_item_transaction.go | 210 +++++ .../types/service_item_user_info.go | 112 +++ .../update_and_get_ticket_info.go | 47 ++ .../nintendo-badge-arcade/get_riv_token.go | 60 ++ .../nintendo-badge-arcade/post_play_log.go | 47 ++ .../shop/nintendo-badge-arcade/protocol.go | 75 ++ .../types/shop_post_play_log_param.go | 128 ++++ nex-protocols-go/shop/protocol.go | 58 ++ nex-protocols-go/shop/types/shop_item.go | 140 ++++ .../shop/types/shop_item_rights.go | 126 +++ .../storage-manager/acquire_card_id.go | 29 + .../storage-manager/activate_with_card_id.go | 60 ++ nex-protocols-go/storage-manager/protocol.go | 91 +++ nex-protocols-go/subscriber/delete_content.go | 61 ++ nex-protocols-go/subscriber/follow.go | 31 + nex-protocols-go/subscriber/get_content.go | 47 ++ .../subscriber/get_content_multi.go | 49 ++ nex-protocols-go/subscriber/get_follower.go | 31 + nex-protocols-go/subscriber/get_following.go | 31 + .../subscriber/get_friend_user_statuses.go | 48 ++ .../subscriber/get_num_followers.go | 31 + nex-protocols-go/subscriber/get_timeline.go | 31 + .../subscriber/get_user_statuses.go | 62 ++ nex-protocols-go/subscriber/hello.go | 47 ++ nex-protocols-go/subscriber/post_content.go | 47 ++ nex-protocols-go/subscriber/protocol.go | 248 ++++++ .../subscriber/types/subscriber_content.go | 170 +++++ .../types/subscriber_get_content_param.go | 140 ++++ .../types/subscriber_post_content_param.go | 128 ++++ .../types/subscriber_user_status_info.go | 114 +++ nex-protocols-go/subscriber/types/unknown.go | 98 +++ nex-protocols-go/subscriber/unfollow.go | 31 + .../subscriber/unfollow_all_and_follow.go | 31 + .../subscriber/update_user_status.go | 63 ++ .../create_my_subscription_data.go | 52 ++ .../get_active_player_subscription_data.go | 29 + .../get_friend_subscription_data.go | 29 + .../subscription/get_privacy_levels.go | 29 + .../subscription/get_subscription_data.go | 48 ++ .../get_target_subscription_data.go | 29 + nex-protocols-go/subscription/protocol.go | 184 +++++ ...eplace_target_and_get_subscription_data.go | 29 + .../update_my_subscription_data.go | 52 ++ nex-protocols-go/ticket-granting/get_name.go | 47 ++ nex-protocols-go/ticket-granting/get_pid.go | 47 ++ nex-protocols-go/ticket-granting/login.go | 47 ++ nex-protocols-go/ticket-granting/login_ex.go | 60 ++ .../ticket-granting/login_with_context.go | 29 + nex-protocols-go/ticket-granting/protocol.go | 139 ++++ .../ticket-granting/request_ticket.go | 60 ++ .../types/authentication_info.go | 167 ++++ .../types/nintendo_login_data.go | 98 +++ .../utility/acquire_nex_unique_id.go | 29 + .../acquire_nex_unique_id_with_password.go | 29 + ...iate_nex_unique_id_with_my_principal_id.go | 47 ++ ...ate_nex_unique_ids_with_my_principal_id.go | 49 ++ ...ated_nex_unique_id_with_my_principal_id.go | 29 + ...ted_nex_unique_ids_with_my_principal_id.go | 29 + .../utility/get_integer_settings.go | 47 ++ .../utility/get_string_settings.go | 47 ++ nex-protocols-go/utility/protocol.go | 164 ++++ .../utility/types/unique_id_info.go | 112 +++ nex/authentication.go | 45 +- .../cleanup_search_matchmake_session.go | 14 + nex/message-delivery/deliver_message.go | 77 ++ nex/pokemon-pss/unk1.go | 52 ++ nex/pokemon-pss/unk2.go | 43 ++ ..._common_authentication_server_protocols.go | 36 +- ...register_common_secure_server_protocols.go | 55 +- nex/register_secure_server_nex_protocols.go | 43 +- nex/secure.go | 42 +- .../create_my_subscription_data.go | 32 +- .../get_active_player_subscription_data.go | 36 +- .../get_friend_subscription_data.go | 31 +- nex/subscription/get_privacy_levels.go | 26 +- nex/subscription/get_subscription_data.go | 39 +- .../get_target_subscription_data.go | 31 +- ...eplace_target_and_get_subscription_data.go | 31 +- .../update_my_subscription_data.go | 40 +- 1028 files changed, 88711 insertions(+), 229 deletions(-) create mode 100644 database/get_unique_id_by_owner_pid.go create mode 100644 database/insert_common_data_by_owner_pid.go create mode 100644 globals/accounts.go create mode 100644 nex-protocols-common-go/.gitignore create mode 100644 nex-protocols-common-go/LICENSE create mode 100644 nex-protocols-common-go/README.md create mode 100644 nex-protocols-common-go/datastore/change_meta.go create mode 100644 nex-protocols-common-go/datastore/complete_post_object.go create mode 100644 nex-protocols-common-go/datastore/complete_post_objects.go create mode 100644 nex-protocols-common-go/datastore/delete_object.go create mode 100644 nex-protocols-common-go/datastore/get_meta.go create mode 100644 nex-protocols-common-go/datastore/get_metas.go create mode 100644 nex-protocols-common-go/datastore/get_metas_multiple_param.go create mode 100644 nex-protocols-common-go/datastore/post_meta_binary.go create mode 100644 nex-protocols-common-go/datastore/prepare_get_object.go create mode 100644 nex-protocols-common-go/datastore/prepare_post_object.go create mode 100644 nex-protocols-common-go/datastore/protocol.go create mode 100644 nex-protocols-common-go/datastore/rate_object.go create mode 100644 nex-protocols-common-go/datastore/rate_objects.go create mode 100644 nex-protocols-common-go/datastore/s3_presigner.go create mode 100644 nex-protocols-common-go/datastore/search_object.go create mode 100644 nex-protocols-common-go/globals/globals.go create mode 100644 nex-protocols-common-go/globals/matchmaking_globals.go create mode 100644 nex-protocols-common-go/globals/matchmaking_utils.go create mode 100644 nex-protocols-common-go/globals/utils.go create mode 100644 nex-protocols-common-go/go.mod create mode 100644 nex-protocols-common-go/go.sum create mode 100644 nex-protocols-common-go/match-making-ext/end_participation.go create mode 100644 nex-protocols-common-go/match-making-ext/protocol.go create mode 100644 nex-protocols-common-go/match-making/find_by_single_id.go create mode 100644 nex-protocols-common-go/match-making/get_session_urls.go create mode 100644 nex-protocols-common-go/match-making/protocol.go create mode 100644 nex-protocols-common-go/match-making/unregister_gathering.go create mode 100644 nex-protocols-common-go/match-making/update_session_host.go create mode 100644 nex-protocols-common-go/match-making/update_session_host_v1.go create mode 100644 nex-protocols-common-go/match-making/update_session_url.go create mode 100644 nex-protocols-common-go/matchmake-extension/auto_matchmake_postpone.go create mode 100644 nex-protocols-common-go/matchmake-extension/auto_matchmake_with_param_postpone.go create mode 100644 nex-protocols-common-go/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go create mode 100644 nex-protocols-common-go/matchmake-extension/browse_matchmake_session.go create mode 100644 nex-protocols-common-go/matchmake-extension/close_participation.go create mode 100644 nex-protocols-common-go/matchmake-extension/create_matchmake_session.go create mode 100644 nex-protocols-common-go/matchmake-extension/create_matchmake_session_with_param.go create mode 100644 nex-protocols-common-go/matchmake-extension/get_simple_playing_session.go create mode 100644 nex-protocols-common-go/matchmake-extension/join_matchmake_session.go create mode 100644 nex-protocols-common-go/matchmake-extension/join_matchmake_session_ex.go create mode 100644 nex-protocols-common-go/matchmake-extension/join_matchmake_session_with_param.go create mode 100644 nex-protocols-common-go/matchmake-extension/modify_current_game_attribute.go create mode 100644 nex-protocols-common-go/matchmake-extension/open_participation.go create mode 100644 nex-protocols-common-go/matchmake-extension/protocol.go create mode 100644 nex-protocols-common-go/matchmake-extension/update_application_buffer.go create mode 100644 nex-protocols-common-go/matchmake-extension/update_progress_score.go create mode 100644 nex-protocols-common-go/nat-traversal/README.md create mode 100644 nex-protocols-common-go/nat-traversal/get_relay_signature_key.go create mode 100644 nex-protocols-common-go/nat-traversal/protocol.go create mode 100644 nex-protocols-common-go/nat-traversal/report_nat_properties.go create mode 100644 nex-protocols-common-go/nat-traversal/report_nat_traversal_result.go create mode 100644 nex-protocols-common-go/nat-traversal/report_nat_traversal_result_detail.go create mode 100644 nex-protocols-common-go/nat-traversal/request_probe_initiation_ext.go create mode 100644 nex-protocols-common-go/ranking/get_cached_top_x_ranking.go create mode 100644 nex-protocols-common-go/ranking/get_cached_top_x_rankings.go create mode 100644 nex-protocols-common-go/ranking/get_common_data.go create mode 100644 nex-protocols-common-go/ranking/get_ranking.go create mode 100644 nex-protocols-common-go/ranking/protocol.go create mode 100644 nex-protocols-common-go/ranking/upload_common_data.go create mode 100644 nex-protocols-common-go/ranking/upload_score.go create mode 100644 nex-protocols-common-go/secure-connection/README.md create mode 100644 nex-protocols-common-go/secure-connection/protocol.go create mode 100644 nex-protocols-common-go/secure-connection/register.go create mode 100644 nex-protocols-common-go/secure-connection/replace_url.go create mode 100644 nex-protocols-common-go/secure-connection/send_report.go create mode 100644 nex-protocols-common-go/ticket-granting/generate_ticket.go create mode 100644 nex-protocols-common-go/ticket-granting/login.go create mode 100644 nex-protocols-common-go/ticket-granting/login_ex.go create mode 100644 nex-protocols-common-go/ticket-granting/protocol.go create mode 100644 nex-protocols-common-go/ticket-granting/request_ticket.go create mode 100644 nex-protocols-common-go/utility/acquire_nex_unique_id.go create mode 100644 nex-protocols-common-go/utility/protocol.go create mode 100644 nex-protocols-go/.gitignore create mode 100644 nex-protocols-go/.golangci.yml create mode 100644 nex-protocols-go/LICENSE create mode 100644 nex-protocols-go/README.md create mode 100644 nex-protocols-go/aa-user/get_application_info.go create mode 100644 nex-protocols-go/aa-user/protocol.go create mode 100644 nex-protocols-go/aa-user/register_application.go create mode 100644 nex-protocols-go/aa-user/set_application_info.go create mode 100644 nex-protocols-go/aa-user/types/application_info.go create mode 100644 nex-protocols-go/aa-user/unregister_application.go create mode 100644 nex-protocols-go/account-management/change_password.go create mode 100644 nex-protocols-go/account-management/change_password_by_guest.go create mode 100644 nex-protocols-go/account-management/create_account.go create mode 100644 nex-protocols-go/account-management/create_account_with_custom_data.go create mode 100644 nex-protocols-go/account-management/custom_create_account.go create mode 100644 nex-protocols-go/account-management/delete_account.go create mode 100644 nex-protocols-go/account-management/disable_account.go create mode 100644 nex-protocols-go/account-management/disconnect_all_principals.go create mode 100644 nex-protocols-go/account-management/disconnect_principal.go create mode 100644 nex-protocols-go/account-management/find_by_name_like.go create mode 100644 nex-protocols-go/account-management/find_by_name_regex.go create mode 100644 nex-protocols-go/account-management/get_account_data.go create mode 100644 nex-protocols-go/account-management/get_last_connection_stats.go create mode 100644 nex-protocols-go/account-management/get_multiple_public_data.go create mode 100644 nex-protocols-go/account-management/get_name.go create mode 100644 nex-protocols-go/account-management/get_private_data.go create mode 100644 nex-protocols-go/account-management/get_public_data.go create mode 100644 nex-protocols-go/account-management/get_status.go create mode 100644 nex-protocols-go/account-management/lookup_or_create_account.go create mode 100644 nex-protocols-go/account-management/nintendo_create_account.go create mode 100644 nex-protocols-go/account-management/protocol.go create mode 100644 nex-protocols-go/account-management/reset_password.go create mode 100644 nex-protocols-go/account-management/retrieve_account.go create mode 100644 nex-protocols-go/account-management/test_capability.go create mode 100644 nex-protocols-go/account-management/types/account_data.go create mode 100644 nex-protocols-go/account-management/types/account_extra_info.go create mode 100644 nex-protocols-go/account-management/types/basic_account_info.go create mode 100644 nex-protocols-go/account-management/types/nintendo_create_account_data.go create mode 100644 nex-protocols-go/account-management/update_account.go create mode 100644 nex-protocols-go/account-management/update_account_effective_date.go create mode 100644 nex-protocols-go/account-management/update_account_email.go create mode 100644 nex-protocols-go/account-management/update_account_expiry_date.go create mode 100644 nex-protocols-go/account-management/update_account_name.go create mode 100644 nex-protocols-go/account-management/update_custom_data.go create mode 100644 nex-protocols-go/account-management/update_status.go create mode 100644 nex-protocols-go/datastore/change_meta.go create mode 100644 nex-protocols-go/datastore/change_meta_v1.go create mode 100644 nex-protocols-go/datastore/change_metas.go create mode 100644 nex-protocols-go/datastore/change_metas_v1.go create mode 100644 nex-protocols-go/datastore/complete_post_object.go create mode 100644 nex-protocols-go/datastore/complete_post_object_v1.go create mode 100644 nex-protocols-go/datastore/complete_post_objects.go create mode 100644 nex-protocols-go/datastore/complete_update_object.go create mode 100644 nex-protocols-go/datastore/delete_object.go create mode 100644 nex-protocols-go/datastore/delete_objects.go create mode 100644 nex-protocols-go/datastore/get_meta.go create mode 100644 nex-protocols-go/datastore/get_metas.go create mode 100644 nex-protocols-go/datastore/get_metas_multiple_param.go create mode 100644 nex-protocols-go/datastore/get_new_arrived_notifications.go create mode 100644 nex-protocols-go/datastore/get_new_arrived_notifications_v1.go create mode 100644 nex-protocols-go/datastore/get_notification_url.go create mode 100644 nex-protocols-go/datastore/get_object_infos.go create mode 100644 nex-protocols-go/datastore/get_password_info.go create mode 100644 nex-protocols-go/datastore/get_password_infos.go create mode 100644 nex-protocols-go/datastore/get_persistence_info.go create mode 100644 nex-protocols-go/datastore/get_persistence_infos.go create mode 100644 nex-protocols-go/datastore/get_rating.go create mode 100644 nex-protocols-go/datastore/get_rating_with_log.go create mode 100644 nex-protocols-go/datastore/get_ratings.go create mode 100644 nex-protocols-go/datastore/get_specific_meta.go create mode 100644 nex-protocols-go/datastore/get_specific_meta_v1.go create mode 100644 nex-protocols-go/datastore/miitopia/protocol.go create mode 100644 nex-protocols-go/datastore/miitopia/search_mii.go create mode 100644 nex-protocols-go/datastore/miitopia/types/mii_tube_mii_info.go create mode 100644 nex-protocols-go/datastore/miitopia/types/mii_tube_search_param.go create mode 100644 nex-protocols-go/datastore/miitopia/types/mii_tube_search_result.go create mode 100644 nex-protocols-go/datastore/nintendo-badge-arcade/get_meta_by_owner_id.go create mode 100644 nex-protocols-go/datastore/nintendo-badge-arcade/protocol.go create mode 100644 nex-protocols-go/datastore/nintendo-badge-arcade/types/datastore_get_meta_by_owner_id_param.go create mode 100644 nex-protocols-go/datastore/perpetuate_object.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/complete_post_bank_object.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/complete_update_bank_object.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/delete_pokemon.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/download_my_pokemon.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/download_other_pokemon.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/get_transaction_param.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/get_unlock_key.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/prepare_get_bank_object.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/prepare_post_bank_object.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/prepare_trade_pokemon.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/prepare_update_bank_object.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/prepare_upload_pokemon.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/protocol.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/request_migration.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/rollback_bank_object.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/search_pokemon.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/trade_pokemon.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/types/bank_migration_info.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/types/bank_transaction_param.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_data.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_delete_pokemon_param.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_download_my_pokemon_param.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_download_my_pokemon_result.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_download_other_pokemon_param.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_download_pokemon_result.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_prepare_trade_pokemon_param.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_prepare_trade_pokemon_result.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_record_key.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_search_pokemon_param.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_search_pokemon_result.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_trade_key.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_trade_pokemon_param.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_trade_pokemon_result.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_upload_pokemon_param.go create mode 100644 nex-protocols-go/datastore/pokemon-bank/upload_pokemon.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/delete_pokemon.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/download_my_pokemon.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/download_other_pokemon.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/prepare_trade_pokemon.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/prepare_upload_pokemon.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/protocol.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/search_pokemon.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/trade_pokemon.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_data.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_delete_pokemon_param.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_download_my_pokemon_param.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_download_my_pokemon_result.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_download_other_pokemon_param.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_download_pokemon_result.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_prepare_trade_pokemon_param.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_prepare_trade_pokemon_result.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_record_key.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_search_pokemon_param.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_search_pokemon_result.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_trade_key.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_trade_pokemon_param.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_trade_pokemon_result.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_upload_pokemon_param.go create mode 100644 nex-protocols-go/datastore/pokemon-gen6/upload_pokemon.go create mode 100644 nex-protocols-go/datastore/post_meta_binaries_with_data_id.go create mode 100644 nex-protocols-go/datastore/post_meta_binary.go create mode 100644 nex-protocols-go/datastore/post_meta_binary_with_data_id.go create mode 100644 nex-protocols-go/datastore/prepare_get_object.go create mode 100644 nex-protocols-go/datastore/prepare_get_object_or_meta_binary.go create mode 100644 nex-protocols-go/datastore/prepare_get_object_v1.go create mode 100644 nex-protocols-go/datastore/prepare_post_object.go create mode 100644 nex-protocols-go/datastore/prepare_post_object_v1.go create mode 100644 nex-protocols-go/datastore/prepare_update_object.go create mode 100644 nex-protocols-go/datastore/protocol.go create mode 100644 nex-protocols-go/datastore/rate_object.go create mode 100644 nex-protocols-go/datastore/rate_object_with_posting.go create mode 100644 nex-protocols-go/datastore/rate_objects.go create mode 100644 nex-protocols-go/datastore/rate_objects_with_posting.go create mode 100644 nex-protocols-go/datastore/reset_rating.go create mode 100644 nex-protocols-go/datastore/reset_ratings.go create mode 100644 nex-protocols-go/datastore/search_object.go create mode 100644 nex-protocols-go/datastore/search_object_light.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/add_to_buffer_queue.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/add_to_buffer_queues.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/best_score_rate_course_search_object.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/change_playable_platform.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/check_rate_custom_ranking_counter.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/clear_buffer_queues.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/complete_attach_file.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/complete_attach_file_v1.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/complete_post_object_with_owner_id.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/conditional_search_object.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/ctr_pick_up_course_search_object.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/custom_search_object.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/delete_application_config.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/delete_cached_ranking.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/delete_course_record.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/delete_custom_ranking.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/followings_latest_course_search_object.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/get_application_config.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/get_application_config_string.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/get_buffer_queue.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/get_buffer_queues.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/get_course_record.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/get_custom_ranking.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/get_custom_ranking_by_data_id.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/get_deletion_reason.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/get_meta_by_owner_id.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/get_metas_with_course_record.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/get_object_infos.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/latest_course_search_object.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/prepare_attach_file.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/prepare_post_object_with_owner_id_and_data_id.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/protocol.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/rate_custom_ranking.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/recommended_course_search_object.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/report_course.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/reset_rate_custom_ranking_counter.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/score_range_cascaded_search_object.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/search_unknown_platform_objects.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/set_application_config.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/set_application_config_string.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/set_cached_ranking.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/set_deletion_reason.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/suggested_course_search_object.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/types/buffer_queue_param.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/types/datastore_attach_file_param.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/types/datastore_change_playable_platform_param.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/types/datastore_custom_ranking_rating_condition.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/types/datastore_custom_ranking_result.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/types/datastore_file_server_object_info.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/types/datastore_get_course_record_param.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/types/datastore_get_course_record_result.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/types/datastore_get_custom_ranking_by_data_id_param.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/types/datastore_get_custom_ranking_param.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/types/datastore_get_meta_by_owner_id_param.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/types/datastore_rate_custom_ranking_param.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/types/datastore_report_course_param.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/types/datastore_upload_course_record_param.go create mode 100644 nex-protocols-go/datastore/super-mario-maker/upload_course_record.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/check_post_replay.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/complete_post_replay.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/complete_post_shared_data.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/get_application_config.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/get_fighting_power_chart.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/get_fighting_power_chart_all.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/get_next_replay.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/get_profiles.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/get_replay_meta.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/get_shared_data_meta.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/get_world_play_report.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/post_fighting_power_score.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/post_profile.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/prepare_get_replay.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/prepare_post_replay.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/prepare_post_shared_data.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/protocol.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/report_shared_data.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/search_replay.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/search_shared_data.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/send_play_report.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/types/datastore_complete_post_replay_param.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/types/datastore_complete_post_shared_data_param.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/types/datastore_fighting_power_chart.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/types/datastore_fighting_power_score.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/types/datastore_file_object_server_info.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/types/datastore_get_replay_meta_param.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/types/datastore_post_fighting_power_score_param.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/types/datastore_post_profile_param.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/types/datastore_prepare_get_replay_param.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/types/datastore_prepare_post_replay_param.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/types/datastore_prepare_post_shared_data_param.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/types/datastore_profile_info.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/types/datastore_replay_meta_info.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/types/datastore_replay_player.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/types/datastore_search_replay_param.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/types/datastore_search_shared_data_param.go create mode 100644 nex-protocols-go/datastore/super-smash-bros-4/types/datastore_shared_data_info.go create mode 100644 nex-protocols-go/datastore/touch_object.go create mode 100644 nex-protocols-go/datastore/types/datastore_change_meta_compare_param.go create mode 100644 nex-protocols-go/datastore/types/datastore_change_meta_param.go create mode 100644 nex-protocols-go/datastore/types/datastore_change_meta_param_v1.go create mode 100644 nex-protocols-go/datastore/types/datastore_complete_post_param.go create mode 100644 nex-protocols-go/datastore/types/datastore_complete_post_param_v1.go create mode 100644 nex-protocols-go/datastore/types/datastore_complete_update_param.go create mode 100644 nex-protocols-go/datastore/types/datastore_delete_param.go create mode 100644 nex-protocols-go/datastore/types/datastore_get_meta_param.go create mode 100644 nex-protocols-go/datastore/types/datastore_get_new_arrived_notifications_param.go create mode 100644 nex-protocols-go/datastore/types/datastore_get_notification_url_param.go create mode 100644 nex-protocols-go/datastore/types/datastore_get_specific_meta_param.go create mode 100644 nex-protocols-go/datastore/types/datastore_get_specific_meta_param_v1.go create mode 100644 nex-protocols-go/datastore/types/datastore_key_value.go create mode 100644 nex-protocols-go/datastore/types/datastore_meta_info.go create mode 100644 nex-protocols-go/datastore/types/datastore_notification.go create mode 100644 nex-protocols-go/datastore/types/datastore_notification_v1.go create mode 100644 nex-protocols-go/datastore/types/datastore_password_info.go create mode 100644 nex-protocols-go/datastore/types/datastore_permission.go create mode 100644 nex-protocols-go/datastore/types/datastore_persistence_info.go create mode 100644 nex-protocols-go/datastore/types/datastore_persistence_init_param.go create mode 100644 nex-protocols-go/datastore/types/datastore_persistence_target.go create mode 100644 nex-protocols-go/datastore/types/datastore_prepare_get_param.go create mode 100644 nex-protocols-go/datastore/types/datastore_prepare_get_param_v1.go create mode 100644 nex-protocols-go/datastore/types/datastore_prepare_post_param.go create mode 100644 nex-protocols-go/datastore/types/datastore_prepare_post_param_v1.go create mode 100644 nex-protocols-go/datastore/types/datastore_prepare_update_param.go create mode 100644 nex-protocols-go/datastore/types/datastore_rate_object_param.go create mode 100644 nex-protocols-go/datastore/types/datastore_rating_info.go create mode 100644 nex-protocols-go/datastore/types/datastore_rating_info_with_slot.go create mode 100644 nex-protocols-go/datastore/types/datastore_rating_init_param.go create mode 100644 nex-protocols-go/datastore/types/datastore_rating_init_param_with_slot.go create mode 100644 nex-protocols-go/datastore/types/datastore_rating_log.go create mode 100644 nex-protocols-go/datastore/types/datastore_rating_target.go create mode 100644 nex-protocols-go/datastore/types/datastore_req_get_additional_meta.go create mode 100644 nex-protocols-go/datastore/types/datastore_req_get_info.go create mode 100644 nex-protocols-go/datastore/types/datastore_req_get_info_v1.go create mode 100644 nex-protocols-go/datastore/types/datastore_req_get_notification_url_info.go create mode 100644 nex-protocols-go/datastore/types/datastore_req_post_info.go create mode 100644 nex-protocols-go/datastore/types/datastore_req_post_info_v1.go create mode 100644 nex-protocols-go/datastore/types/datastore_req_update_info.go create mode 100644 nex-protocols-go/datastore/types/datastore_search_param.go create mode 100644 nex-protocols-go/datastore/types/datastore_search_result.go create mode 100644 nex-protocols-go/datastore/types/datastore_specific_meta_info.go create mode 100644 nex-protocols-go/datastore/types/datastore_specific_meta_info_v1.go create mode 100644 nex-protocols-go/datastore/types/datastore_touch_object_param.go create mode 100644 nex-protocols-go/datastore/unperpetuate_object.go create mode 100644 nex-protocols-go/debug/disable_api_recorder.go create mode 100644 nex-protocols-go/debug/enable_api_recorder.go create mode 100644 nex-protocols-go/debug/get_api_call_summary.go create mode 100644 nex-protocols-go/debug/get_api_calls.go create mode 100644 nex-protocols-go/debug/get_exclude_joined_matchmake_session.go create mode 100644 nex-protocols-go/debug/is_api_recorder_enabled.go create mode 100644 nex-protocols-go/debug/protocol.go create mode 100644 nex-protocols-go/debug/set_exclude_joined_matchmake_session.go create mode 100644 nex-protocols-go/friends-3ds/add_friend_by_lst_principal_id.go create mode 100644 nex-protocols-go/friends-3ds/add_friend_by_principal_id.go create mode 100644 nex-protocols-go/friends-3ds/get_all_friends.go create mode 100644 nex-protocols-go/friends-3ds/get_friend_comment.go create mode 100644 nex-protocols-go/friends-3ds/get_friend_mii.go create mode 100644 nex-protocols-go/friends-3ds/get_friend_mii_list.go create mode 100644 nex-protocols-go/friends-3ds/get_friend_persistent_info.go create mode 100644 nex-protocols-go/friends-3ds/get_friend_picture.go create mode 100644 nex-protocols-go/friends-3ds/get_friend_presence.go create mode 100644 nex-protocols-go/friends-3ds/get_friend_relationships.go create mode 100644 nex-protocols-go/friends-3ds/get_principal_id_by_local_friend_code.go create mode 100644 nex-protocols-go/friends-3ds/is_active_game.go create mode 100644 nex-protocols-go/friends-3ds/protocol.go create mode 100644 nex-protocols-go/friends-3ds/remove_friend_by_local_friend_code.go create mode 100644 nex-protocols-go/friends-3ds/remove_friend_by_principal_id.go create mode 100644 nex-protocols-go/friends-3ds/send_invitation.go create mode 100644 nex-protocols-go/friends-3ds/sync_friend.go create mode 100644 nex-protocols-go/friends-3ds/types/friend_comment.go create mode 100644 nex-protocols-go/friends-3ds/types/friend_info.go create mode 100644 nex-protocols-go/friends-3ds/types/friend_mii.go create mode 100644 nex-protocols-go/friends-3ds/types/friend_mii_list.go create mode 100644 nex-protocols-go/friends-3ds/types/friend_persistent_info.go create mode 100644 nex-protocols-go/friends-3ds/types/friend_picture.go create mode 100644 nex-protocols-go/friends-3ds/types/friend_presence.go create mode 100644 nex-protocols-go/friends-3ds/types/friend_relationship.go create mode 100644 nex-protocols-go/friends-3ds/types/game_key.go create mode 100644 nex-protocols-go/friends-3ds/types/mii.go create mode 100644 nex-protocols-go/friends-3ds/types/mii_list.go create mode 100644 nex-protocols-go/friends-3ds/types/my_profile.go create mode 100644 nex-protocols-go/friends-3ds/types/nintendo_presence.go create mode 100644 nex-protocols-go/friends-3ds/types/played_game.go create mode 100644 nex-protocols-go/friends-3ds/update_black_list.go create mode 100644 nex-protocols-go/friends-3ds/update_comment.go create mode 100644 nex-protocols-go/friends-3ds/update_favorite_game_key.go create mode 100644 nex-protocols-go/friends-3ds/update_mii.go create mode 100644 nex-protocols-go/friends-3ds/update_mii_list.go create mode 100644 nex-protocols-go/friends-3ds/update_picture.go create mode 100644 nex-protocols-go/friends-3ds/update_played_games.go create mode 100644 nex-protocols-go/friends-3ds/update_preference.go create mode 100644 nex-protocols-go/friends-3ds/update_presence.go create mode 100644 nex-protocols-go/friends-3ds/update_profile.go create mode 100644 nex-protocols-go/friends-wiiu/accept_friend_request.go create mode 100644 nex-protocols-go/friends-wiiu/add_black_list.go create mode 100644 nex-protocols-go/friends-wiiu/add_friend.go create mode 100644 nex-protocols-go/friends-wiiu/add_friend_by_name.go create mode 100644 nex-protocols-go/friends-wiiu/add_friend_request.go create mode 100644 nex-protocols-go/friends-wiiu/cancel_friend_request.go create mode 100644 nex-protocols-go/friends-wiiu/check_setting_status.go create mode 100644 nex-protocols-go/friends-wiiu/delete_friend_request.go create mode 100644 nex-protocols-go/friends-wiiu/delete_persistent_notification.go create mode 100644 nex-protocols-go/friends-wiiu/deny_friend_request.go create mode 100644 nex-protocols-go/friends-wiiu/get_basic_info.go create mode 100644 nex-protocols-go/friends-wiiu/get_request_block_settings.go create mode 100644 nex-protocols-go/friends-wiiu/mark_friend_requests_as_received.go create mode 100644 nex-protocols-go/friends-wiiu/protocol.go create mode 100644 nex-protocols-go/friends-wiiu/remove_black_list.go create mode 100644 nex-protocols-go/friends-wiiu/remove_friend.go create mode 100644 nex-protocols-go/friends-wiiu/types/blacklisted_principal.go create mode 100644 nex-protocols-go/friends-wiiu/types/comment.go create mode 100644 nex-protocols-go/friends-wiiu/types/friend_info.go create mode 100644 nex-protocols-go/friends-wiiu/types/friend_request.go create mode 100644 nex-protocols-go/friends-wiiu/types/friend_request_message.go create mode 100644 nex-protocols-go/friends-wiiu/types/game_key.go create mode 100644 nex-protocols-go/friends-wiiu/types/mii_v2.go create mode 100644 nex-protocols-go/friends-wiiu/types/nintendo_presence_v2.go create mode 100644 nex-protocols-go/friends-wiiu/types/nna_info.go create mode 100644 nex-protocols-go/friends-wiiu/types/persistent_notification.go create mode 100644 nex-protocols-go/friends-wiiu/types/persistent_notification_list.go create mode 100644 nex-protocols-go/friends-wiiu/types/principal_basic_info.go create mode 100644 nex-protocols-go/friends-wiiu/types/principal_preference.go create mode 100644 nex-protocols-go/friends-wiiu/types/principal_request_block_setting.go create mode 100644 nex-protocols-go/friends-wiiu/update_and_get_all_information.go create mode 100644 nex-protocols-go/friends-wiiu/update_comment.go create mode 100644 nex-protocols-go/friends-wiiu/update_mii.go create mode 100644 nex-protocols-go/friends-wiiu/update_preference.go create mode 100644 nex-protocols-go/friends-wiiu/update_presence.go create mode 100644 nex-protocols-go/friends/accept_friendship.go create mode 100644 nex-protocols-go/friends/add_friend.go create mode 100644 nex-protocols-go/friends/add_friend_by_name.go create mode 100644 nex-protocols-go/friends/add_friend_by_name_with_details.go create mode 100644 nex-protocols-go/friends/add_friend_with_details.go create mode 100644 nex-protocols-go/friends/black_list.go create mode 100644 nex-protocols-go/friends/black_list_by_name.go create mode 100644 nex-protocols-go/friends/clear_relationship.go create mode 100644 nex-protocols-go/friends/decline_friendship.go create mode 100644 nex-protocols-go/friends/get_detailed_list.go create mode 100644 nex-protocols-go/friends/get_list.go create mode 100644 nex-protocols-go/friends/get_relationships.go create mode 100644 nex-protocols-go/friends/protocol.go create mode 100644 nex-protocols-go/friends/types/friend_data.go create mode 100644 nex-protocols-go/friends/types/relationship_data.go create mode 100644 nex-protocols-go/friends/update_details.go create mode 100644 nex-protocols-go/globals/logger.go create mode 100644 nex-protocols-go/globals/respond.go create mode 100644 nex-protocols-go/globals/respond_error.go create mode 100644 nex-protocols-go/go.mod create mode 100644 nex-protocols-go/go.sum create mode 100644 nex-protocols-go/health/fix_sanity_errors.go create mode 100644 nex-protocols-go/health/ping_daemon.go create mode 100644 nex-protocols-go/health/ping_database.go create mode 100644 nex-protocols-go/health/protocol.go create mode 100644 nex-protocols-go/health/run_sanity_check.go create mode 100644 nex-protocols-go/init.go create mode 100644 nex-protocols-go/match-making-ext/delete_from_deletions.go create mode 100644 nex-protocols-go/match-making-ext/end_participation.go create mode 100644 nex-protocols-go/match-making-ext/get_detailed_participants.go create mode 100644 nex-protocols-go/match-making-ext/get_gathering_relations.go create mode 100644 nex-protocols-go/match-making-ext/get_participants.go create mode 100644 nex-protocols-go/match-making-ext/get_participants_urls.go create mode 100644 nex-protocols-go/match-making-ext/protocol.go create mode 100644 nex-protocols-go/match-making/accept_invitation.go create mode 100644 nex-protocols-go/match-making/add_participants.go create mode 100644 nex-protocols-go/match-making/cancel_invitation.go create mode 100644 nex-protocols-go/match-making/cancel_participation.go create mode 100644 nex-protocols-go/match-making/decline_invitation.go create mode 100644 nex-protocols-go/match-making/delete_from_deletions.go create mode 100644 nex-protocols-go/match-making/delete_gathering.go create mode 100644 nex-protocols-go/match-making/find_by_description.go create mode 100644 nex-protocols-go/match-making/find_by_description_like.go create mode 100644 nex-protocols-go/match-making/find_by_description_regex.go create mode 100644 nex-protocols-go/match-making/find_by_id.go create mode 100644 nex-protocols-go/match-making/find_by_owner.go create mode 100644 nex-protocols-go/match-making/find_by_participants.go create mode 100644 nex-protocols-go/match-making/find_by_single_id.go create mode 100644 nex-protocols-go/match-making/find_by_sql_query.go create mode 100644 nex-protocols-go/match-making/find_by_type.go create mode 100644 nex-protocols-go/match-making/find_invitations.go create mode 100644 nex-protocols-go/match-making/gathering_flags.go create mode 100644 nex-protocols-go/match-making/get_details_participants.go create mode 100644 nex-protocols-go/match-making/get_invitations_received.go create mode 100644 nex-protocols-go/match-making/get_invitations_sent.go create mode 100644 nex-protocols-go/match-making/get_participants.go create mode 100644 nex-protocols-go/match-making/get_participants_urls.go create mode 100644 nex-protocols-go/match-making/get_pending_deletions.go create mode 100644 nex-protocols-go/match-making/get_session_url.go create mode 100644 nex-protocols-go/match-making/get_session_urls.go create mode 100644 nex-protocols-go/match-making/get_state.go create mode 100644 nex-protocols-go/match-making/get_stats.go create mode 100644 nex-protocols-go/match-making/invite.go create mode 100644 nex-protocols-go/match-making/launch_session.go create mode 100644 nex-protocols-go/match-making/migrate_gathering_ownership.go create mode 100644 nex-protocols-go/match-making/migrate_gathering_ownership_v1.go create mode 100644 nex-protocols-go/match-making/participate.go create mode 100644 nex-protocols-go/match-making/protocol.go create mode 100644 nex-protocols-go/match-making/register_gathering.go create mode 100644 nex-protocols-go/match-making/register_local_url.go create mode 100644 nex-protocols-go/match-making/register_local_urls.go create mode 100644 nex-protocols-go/match-making/report_stats.go create mode 100644 nex-protocols-go/match-making/set_state.go create mode 100644 nex-protocols-go/match-making/types/auto_matchmake_param.go create mode 100644 nex-protocols-go/match-making/types/create_matchmake_session_param.go create mode 100644 nex-protocols-go/match-making/types/deletion_entry.go create mode 100644 nex-protocols-go/match-making/types/find_matchmake_session_by_participant_param.go create mode 100644 nex-protocols-go/match-making/types/find_matchmake_session_by_participant_result.go create mode 100644 nex-protocols-go/match-making/types/gathering.go create mode 100644 nex-protocols-go/match-making/types/gathering_stats.go create mode 100644 nex-protocols-go/match-making/types/gathering_urls.go create mode 100644 nex-protocols-go/match-making/types/invitation.go create mode 100644 nex-protocols-go/match-making/types/join_matchmake_session_param.go create mode 100644 nex-protocols-go/match-making/types/matchmake_block_list_param.go create mode 100644 nex-protocols-go/match-making/types/matchmake_param.go create mode 100644 nex-protocols-go/match-making/types/matchmake_session.go create mode 100644 nex-protocols-go/match-making/types/matchmake_session_search_criteria.go create mode 100644 nex-protocols-go/match-making/types/participant_details.go create mode 100644 nex-protocols-go/match-making/types/persistent_gathering.go create mode 100644 nex-protocols-go/match-making/types/playing_session.go create mode 100644 nex-protocols-go/match-making/types/simple_community.go create mode 100644 nex-protocols-go/match-making/types/simple_playing_session.go create mode 100644 nex-protocols-go/match-making/types/update_matchmake_session_param.go create mode 100644 nex-protocols-go/match-making/unregister_gathering.go create mode 100644 nex-protocols-go/match-making/unregister_gatherings.go create mode 100644 nex-protocols-go/match-making/update_gathering.go create mode 100644 nex-protocols-go/match-making/update_gathering_ownership.go create mode 100644 nex-protocols-go/match-making/update_session_host.go create mode 100644 nex-protocols-go/match-making/update_session_host_v1.go create mode 100644 nex-protocols-go/match-making/update_session_url.go create mode 100644 nex-protocols-go/matchmake-extension/add_to_block_list.go create mode 100644 nex-protocols-go/matchmake-extension/auto_matchmake_postpone.go create mode 100644 nex-protocols-go/matchmake-extension/auto_matchmake_with_gathering_id_postpone.go create mode 100644 nex-protocols-go/matchmake-extension/auto_matchmake_with_param_postpone.go create mode 100644 nex-protocols-go/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go create mode 100644 nex-protocols-go/matchmake-extension/browse_matchmake_session.go create mode 100644 nex-protocols-go/matchmake-extension/browse_matchmake_session_no_holder.go create mode 100644 nex-protocols-go/matchmake-extension/browse_matchmake_session_no_holder_no_result_range.go create mode 100644 nex-protocols-go/matchmake-extension/browse_matchmake_session_with_host_urls.go create mode 100644 nex-protocols-go/matchmake-extension/browse_matchmake_session_with_host_urls_no_holder.go create mode 100644 nex-protocols-go/matchmake-extension/browse_matchmake_session_with_host_urls_no_holder_no_result_range.go create mode 100644 nex-protocols-go/matchmake-extension/clear_matchmake_session_system_password.go create mode 100644 nex-protocols-go/matchmake-extension/clear_my_block_list.go create mode 100644 nex-protocols-go/matchmake-extension/close_participation.go create mode 100644 nex-protocols-go/matchmake-extension/create_community.go create mode 100644 nex-protocols-go/matchmake-extension/create_matchmake_session.go create mode 100644 nex-protocols-go/matchmake-extension/create_matchmake_session_with_param.go create mode 100644 nex-protocols-go/matchmake-extension/debug_notify_event.go create mode 100644 nex-protocols-go/matchmake-extension/find_comminuty_by_owner.go create mode 100644 nex-protocols-go/matchmake-extension/find_community_by_gathering_id.go create mode 100644 nex-protocols-go/matchmake-extension/find_community_by_participant.go create mode 100644 nex-protocols-go/matchmake-extension/find_matchmake_session_by_gathering_id.go create mode 100644 nex-protocols-go/matchmake-extension/find_matchmake_session_by_gathering_id_detail.go create mode 100644 nex-protocols-go/matchmake-extension/find_matchmake_session_by_owner.go create mode 100644 nex-protocols-go/matchmake-extension/find_matchmake_session_by_participant.go create mode 100644 nex-protocols-go/matchmake-extension/find_matchmake_session_by_single_gathering_id.go create mode 100644 nex-protocols-go/matchmake-extension/find_official_community.go create mode 100644 nex-protocols-go/matchmake-extension/generate_matchmake_session_system_password.go create mode 100644 nex-protocols-go/matchmake-extension/get_friend_notification_data.go create mode 100644 nex-protocols-go/matchmake-extension/get_lst_friend_notification_data.go create mode 100644 nex-protocols-go/matchmake-extension/get_my_block_list.go create mode 100644 nex-protocols-go/matchmake-extension/get_playing_session.go create mode 100644 nex-protocols-go/matchmake-extension/get_simple_community.go create mode 100644 nex-protocols-go/matchmake-extension/get_simple_playing_session.go create mode 100644 nex-protocols-go/matchmake-extension/is_violation_user.go create mode 100644 nex-protocols-go/matchmake-extension/join_community.go create mode 100644 nex-protocols-go/matchmake-extension/join_matchmake_session.go create mode 100644 nex-protocols-go/matchmake-extension/join_matchmake_session_ex.go create mode 100644 nex-protocols-go/matchmake-extension/join_matchmake_session_with_param.go create mode 100644 nex-protocols-go/matchmake-extension/mario-kart-8/create_simple_search_object.go create mode 100644 nex-protocols-go/matchmake-extension/mario-kart-8/delete_simple_search_object.go create mode 100644 nex-protocols-go/matchmake-extension/mario-kart-8/join_matchmake_session_with_extra_participants.go create mode 100644 nex-protocols-go/matchmake-extension/mario-kart-8/protocol.go create mode 100644 nex-protocols-go/matchmake-extension/mario-kart-8/search_simple_search_object.go create mode 100644 nex-protocols-go/matchmake-extension/mario-kart-8/search_simple_search_object_by_object_ids.go create mode 100644 nex-protocols-go/matchmake-extension/mario-kart-8/types/simple_search_condition.go create mode 100644 nex-protocols-go/matchmake-extension/mario-kart-8/types/simple_search_date_time_attribute.go create mode 100644 nex-protocols-go/matchmake-extension/mario-kart-8/types/simple_search_object.go create mode 100644 nex-protocols-go/matchmake-extension/mario-kart-8/types/simple_search_param.go create mode 100644 nex-protocols-go/matchmake-extension/mario-kart-8/update_simple_search_object.go create mode 100644 nex-protocols-go/matchmake-extension/modify_current_game_attribute.go create mode 100644 nex-protocols-go/matchmake-extension/monster-hunter-xx/add_friends.go create mode 100644 nex-protocols-go/matchmake-extension/monster-hunter-xx/find_community_by_owner.go create mode 100644 nex-protocols-go/matchmake-extension/monster-hunter-xx/get_friend_user_profiles.go create mode 100644 nex-protocols-go/matchmake-extension/monster-hunter-xx/protocol.go create mode 100644 nex-protocols-go/matchmake-extension/monster-hunter-xx/remove_friend.go create mode 100644 nex-protocols-go/matchmake-extension/monster-hunter-xx/types/friend_user_info.go create mode 100644 nex-protocols-go/matchmake-extension/monster-hunter-xx/types/friend_user_param.go create mode 100644 nex-protocols-go/matchmake-extension/monster-hunter-xx/update_friend_user_profile.go create mode 100644 nex-protocols-go/matchmake-extension/open_participation.go create mode 100644 nex-protocols-go/matchmake-extension/pokemon-gen6/clear_my_previously_matched_user_cache.go create mode 100644 nex-protocols-go/matchmake-extension/pokemon-gen6/protocol.go create mode 100644 nex-protocols-go/matchmake-extension/protocol.go create mode 100644 nex-protocols-go/matchmake-extension/remove_from_block_list.go create mode 100644 nex-protocols-go/matchmake-extension/report_violation.go create mode 100644 nex-protocols-go/matchmake-extension/request_matchmaking.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/auto_tournament_matchmake.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_end_community_competition_participation.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_join_community_competition.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_post_community_competition_match_result.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_register_community_competition.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_unregister_community_competition.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/end_community_competition_participation.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/end_community_competition_participation_by_gathering_id.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/find_community_competitions_by_gathering_id.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/find_community_competitions_by_participant.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/get_community_competition_by_id.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/get_community_competition_ranking.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/get_community_competitions.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_competition.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_competitions.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_profiles.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_replay_id.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_replay_ids.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_result.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/join_community_competition.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/join_community_competition_by_gathering_id.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/join_or_create_matchmake_session.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/post_community_competition_match_result.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/protocol.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/register_community_competition.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/register_tournament_bot.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/register_tournament_player_info.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/replace_tournament_leaf_node.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/report_tournament_bot_round_result.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/search_community_competition.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/select_community_competition_by_owner.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/set_tournament_replay_id.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/simple_find_by_i_d.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/start_tournament.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/unregister_community_competition.go create mode 100644 nex-protocols-go/matchmake-extension/super-smash-bros-4/unregister_community_competition_by_id.go create mode 100644 nex-protocols-go/matchmake-extension/update_application_buffer.go create mode 100644 nex-protocols-go/matchmake-extension/update_community.go create mode 100644 nex-protocols-go/matchmake-extension/update_matchmake_session.go create mode 100644 nex-protocols-go/matchmake-extension/update_matchmake_session_attribute.go create mode 100644 nex-protocols-go/matchmake-extension/update_matchmake_session_part.go create mode 100644 nex-protocols-go/matchmake-extension/update_notification_data.go create mode 100644 nex-protocols-go/matchmake-extension/update_privacy_setting.go create mode 100644 nex-protocols-go/matchmake-extension/update_progress_score.go create mode 100644 nex-protocols-go/matchmake-extension/withdraw_matchmaking.go create mode 100644 nex-protocols-go/matchmake-extension/withdraw_matchmaking_all.go create mode 100644 nex-protocols-go/matchmake-referee/create_stats.go create mode 100644 nex-protocols-go/matchmake-referee/end_round.go create mode 100644 nex-protocols-go/matchmake-referee/end_round_without_report.go create mode 100644 nex-protocols-go/matchmake-referee/get_not_summarized_round.go create mode 100644 nex-protocols-go/matchmake-referee/get_or_create_stats.go create mode 100644 nex-protocols-go/matchmake-referee/get_round.go create mode 100644 nex-protocols-go/matchmake-referee/get_round_participants.go create mode 100644 nex-protocols-go/matchmake-referee/get_start_round_param.go create mode 100644 nex-protocols-go/matchmake-referee/get_stats_all.go create mode 100644 nex-protocols-go/matchmake-referee/get_stats_primaries.go create mode 100644 nex-protocols-go/matchmake-referee/get_stats_primary.go create mode 100644 nex-protocols-go/matchmake-referee/protocol.go create mode 100644 nex-protocols-go/matchmake-referee/reset_stats.go create mode 100644 nex-protocols-go/matchmake-referee/start_round.go create mode 100644 nex-protocols-go/matchmake-referee/types/matchmake_referee_end_round_param.go create mode 100644 nex-protocols-go/matchmake-referee/types/matchmake_referee_personal_round_result.go create mode 100644 nex-protocols-go/matchmake-referee/types/matchmake_referee_round.go create mode 100644 nex-protocols-go/matchmake-referee/types/matchmake_referee_start_round_param.go create mode 100644 nex-protocols-go/matchmake-referee/types/matchmake_referee_stats.go create mode 100644 nex-protocols-go/matchmake-referee/types/matchmake_referee_stats_init_param.go create mode 100644 nex-protocols-go/matchmake-referee/types/matchmake_referee_stats_target.go create mode 100644 nex-protocols-go/message-delivery/deliver_message.go create mode 100644 nex-protocols-go/message-delivery/protocol.go create mode 100644 nex-protocols-go/messaging/delete_all_messages.go create mode 100644 nex-protocols-go/messaging/delete_messages.go create mode 100644 nex-protocols-go/messaging/deliver_message.go create mode 100644 nex-protocols-go/messaging/deliver_message_multi_target.go create mode 100644 nex-protocols-go/messaging/get_messages_headers.go create mode 100644 nex-protocols-go/messaging/get_number_of_messages.go create mode 100644 nex-protocols-go/messaging/protocol.go create mode 100644 nex-protocols-go/messaging/retrieve_all_messages_within_range.go create mode 100644 nex-protocols-go/messaging/retrieve_messages.go create mode 100644 nex-protocols-go/messaging/types/binary_message.go create mode 100644 nex-protocols-go/messaging/types/message_recipient.go create mode 100644 nex-protocols-go/messaging/types/text_message.go create mode 100644 nex-protocols-go/messaging/types/user_message.go create mode 100644 nex-protocols-go/monitoring/get_cluster_members.go create mode 100644 nex-protocols-go/monitoring/ping_daemon.go create mode 100644 nex-protocols-go/monitoring/protocol.go create mode 100644 nex-protocols-go/nat-traversal/get_relay_signature_key.go create mode 100644 nex-protocols-go/nat-traversal/initiate_probe.go create mode 100644 nex-protocols-go/nat-traversal/protocol.go create mode 100644 nex-protocols-go/nat-traversal/report_nat_properties.go create mode 100644 nex-protocols-go/nat-traversal/report_nat_traversal_result.go create mode 100644 nex-protocols-go/nat-traversal/report_nat_traversal_result_detail.go create mode 100644 nex-protocols-go/nat-traversal/request_probe_initiation.go create mode 100644 nex-protocols-go/nat-traversal/request_probe_initiation_ext.go create mode 100644 nex-protocols-go/nintendo-notifications/notification_types.go create mode 100644 nex-protocols-go/nintendo-notifications/protocol.go create mode 100644 nex-protocols-go/nintendo-notifications/types/nintendo_notification_event.go create mode 100644 nex-protocols-go/nintendo-notifications/types/nintendo_notification_event_general.go create mode 100644 nex-protocols-go/notifications/build_notification_type.go create mode 100644 nex-protocols-go/notifications/notification_categories.go create mode 100644 nex-protocols-go/notifications/notification_subtypes.go create mode 100644 nex-protocols-go/notifications/protocol.go create mode 100644 nex-protocols-go/notifications/types/notification_event.go create mode 100644 nex-protocols-go/persistent-store/find_by_group.go create mode 100644 nex-protocols-go/persistent-store/find_items_by_sql_query.go create mode 100644 nex-protocols-go/persistent-store/get_custom_item.go create mode 100644 nex-protocols-go/persistent-store/get_item.go create mode 100644 nex-protocols-go/persistent-store/insert_custom_item.go create mode 100644 nex-protocols-go/persistent-store/insert_item.go create mode 100644 nex-protocols-go/persistent-store/protocol.go create mode 100644 nex-protocols-go/persistent-store/remove_item.go create mode 100644 nex-protocols-go/pokemon-pss/protocol.go create mode 100644 nex-protocols-go/pokemon-pss/unk1.go create mode 100644 nex-protocols-go/pokemon-pss/unk2.go create mode 100644 nex-protocols-go/ranking/change_all_attributes.go create mode 100644 nex-protocols-go/ranking/change_attributes.go create mode 100644 nex-protocols-go/ranking/delete_all_scores.go create mode 100644 nex-protocols-go/ranking/delete_common_data.go create mode 100644 nex-protocols-go/ranking/delete_score.go create mode 100644 nex-protocols-go/ranking/get_approx_order.go create mode 100644 nex-protocols-go/ranking/get_cached_top_x_ranking.go create mode 100644 nex-protocols-go/ranking/get_cached_top_x_rankings.go create mode 100644 nex-protocols-go/ranking/get_common_data.go create mode 100644 nex-protocols-go/ranking/get_ranking.go create mode 100644 nex-protocols-go/ranking/get_ranking_by_pid_list.go create mode 100644 nex-protocols-go/ranking/get_ranking_by_unique_id_list.go create mode 100644 nex-protocols-go/ranking/get_stats.go create mode 100644 nex-protocols-go/ranking/mario-kart-8/get_competition_info.go create mode 100644 nex-protocols-go/ranking/mario-kart-8/get_competition_ranking_score.go create mode 100644 nex-protocols-go/ranking/mario-kart-8/protocol.go create mode 100644 nex-protocols-go/ranking/mario-kart-8/types/competition_ranking_info.go create mode 100644 nex-protocols-go/ranking/mario-kart-8/types/competition_ranking_info_get_param.go create mode 100644 nex-protocols-go/ranking/mario-kart-8/types/competition_ranking_upload_score_param.go create mode 100644 nex-protocols-go/ranking/mario-kart-8/upload_competition_ranking_score.go create mode 100644 nex-protocols-go/ranking/protocol.go create mode 100644 nex-protocols-go/ranking/splatoon/delete_competition_ranking_score.go create mode 100644 nex-protocols-go/ranking/splatoon/get_competition_ranking_score.go create mode 100644 nex-protocols-go/ranking/splatoon/getcompetition_ranking_score_by_period_list.go create mode 100644 nex-protocols-go/ranking/splatoon/protocol.go create mode 100644 nex-protocols-go/ranking/splatoon/upload_competition_ranking_score.go create mode 100644 nex-protocols-go/ranking/types/ranking_cached_result.go create mode 100644 nex-protocols-go/ranking/types/ranking_change_attributes_param.go create mode 100644 nex-protocols-go/ranking/types/ranking_order_param.go create mode 100644 nex-protocols-go/ranking/types/ranking_rank_data.go create mode 100644 nex-protocols-go/ranking/types/ranking_result.go create mode 100644 nex-protocols-go/ranking/types/ranking_score_data.go create mode 100644 nex-protocols-go/ranking/types/ranking_stats.go create mode 100644 nex-protocols-go/ranking/upload_common_data.go create mode 100644 nex-protocols-go/ranking/upload_score.go create mode 100644 nex-protocols-go/ranking2/delete_common_data.go create mode 100644 nex-protocols-go/ranking2/get_category_setting.go create mode 100644 nex-protocols-go/ranking2/get_common_data.go create mode 100644 nex-protocols-go/ranking2/get_estimate_score_rank.go create mode 100644 nex-protocols-go/ranking2/get_ranking.go create mode 100644 nex-protocols-go/ranking2/get_ranking_by_principal_id.go create mode 100644 nex-protocols-go/ranking2/get_ranking_chart.go create mode 100644 nex-protocols-go/ranking2/get_ranking_charts.go create mode 100644 nex-protocols-go/ranking2/protocol.go create mode 100644 nex-protocols-go/ranking2/put_common_data.go create mode 100644 nex-protocols-go/ranking2/put_score.go create mode 100644 nex-protocols-go/ranking2/types/ranking2_category_setting.go create mode 100644 nex-protocols-go/ranking2/types/ranking2_chart_info.go create mode 100644 nex-protocols-go/ranking2/types/ranking2_chart_info_input.go create mode 100644 nex-protocols-go/ranking2/types/ranking2_common_data.go create mode 100644 nex-protocols-go/ranking2/types/ranking2_estimate_score_rank_input.go create mode 100644 nex-protocols-go/ranking2/types/ranking2_estimate_score_rank_output.go create mode 100644 nex-protocols-go/ranking2/types/ranking2_get_by_list_param.go create mode 100644 nex-protocols-go/ranking2/types/ranking2_get_param.go create mode 100644 nex-protocols-go/ranking2/types/ranking2_info.go create mode 100644 nex-protocols-go/ranking2/types/ranking2_rank_data.go create mode 100644 nex-protocols-go/ranking2/types/ranking2_score_data.go create mode 100644 nex-protocols-go/remote-log-device/log.go create mode 100644 nex-protocols-go/remote-log-device/protocol.go create mode 100644 nex-protocols-go/screening/protocol.go create mode 100644 nex-protocols-go/screening/report_datastore_content.go create mode 100644 nex-protocols-go/screening/report_user.go create mode 100644 nex-protocols-go/secure-connection/nintendo-badge-arcade/get_maintenance_status.go create mode 100644 nex-protocols-go/secure-connection/nintendo-badge-arcade/protocol.go create mode 100644 nex-protocols-go/secure-connection/protocol.go create mode 100644 nex-protocols-go/secure-connection/register.go create mode 100644 nex-protocols-go/secure-connection/register_ex.go create mode 100644 nex-protocols-go/secure-connection/replace_url.go create mode 100644 nex-protocols-go/secure-connection/request_connection_data.go create mode 100644 nex-protocols-go/secure-connection/request_urls.go create mode 100644 nex-protocols-go/secure-connection/send_report.go create mode 100644 nex-protocols-go/secure-connection/test_connectivity.go create mode 100644 nex-protocols-go/secure-connection/update_urls.go create mode 100644 nex-protocols-go/service-item/protocol.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/acquire_service_item_by_account.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/get_balance_request.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/get_balance_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/get_environment.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/get_law_message_request.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/get_law_message_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/get_prepurchase_info_request.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/get_prepurchase_info_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/get_purchase_history_request.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/get_purchase_history_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/get_service_item_right_request.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/get_service_item_right_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/get_support_id.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/http_get_request.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/http_get_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/list_service_item_request.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/list_service_item_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/post_right_binary_by_account.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/protocol.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/purchase_service_item_request.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/purchase_service_item_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_account_right.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_account_right_consumption.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_account_right_time.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_acquire_service_item_by_account_param.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_acquire_service_item_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_amount.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_attribute.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_catalog.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_eshop_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_balance_param.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_balance_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_law_message_param.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_law_message_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_notice_param.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_prepurchase_info_param.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_prepurchase_info_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_purchase_history_param.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_purchase_history_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_service_item_right_param.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_service_item_right_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_support_id_param.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_http_get_param.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_http_get_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_law_message.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_limitation.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_list_item.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_list_service_item_param.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_list_service_item_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_notice.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_post_right_binary_by_account_param.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_prepurchase_info.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_prepurchase_right_info.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_purchase_history.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_purchase_info.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_purchase_service_item_param.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_purchase_service_item_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_binary.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_consumption_info.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_info.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_infos.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_time_info.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_transaction.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_use_service_item_by_account_param.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_use_service_item_response.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_used_info.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_user_info.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/use_service_item_by_account_request.go create mode 100644 nex-protocols-go/service-item/team-kirby-clash-deluxe/use_service_item_by_account_response.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/end_challenge.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/get_balance_request.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/get_balance_response.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/get_notice.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/get_prepurchase_info_request.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/get_prepurchase_info_response.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/get_purchase_history_request.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/get_purchase_history_response.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/get_service_item_right_request.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/get_service_item_right_response.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/hello.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/http_get_request.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/http_get_response.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/list_service_item_request.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/list_service_item_response.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/load_user_info.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/protocol.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/purchase_service_item_request.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/purchase_service_item_response.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/request_ticket_restoration.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/save_user_info.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/start_challenge.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_account_right.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_amount.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_attribute.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_catalog.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_end_challenge_param.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_eshop_response.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_event.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_get_balance_param.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_get_balance_response.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_get_notice_param.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_get_prepurchase_info_param.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_get_prepurchase_info_response.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_get_purchase_history_param.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_get_purchase_history_response.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_get_service_item_right_param.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_get_service_item_right_response.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_http_get_param.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_http_get_response.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_limitation.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_list_item.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_list_service_item_param.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_list_service_item_response.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_notice.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_prepurchase_info.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_purchace_info.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_purchase_history.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_purchase_service_item_param.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_purchase_service_item_response.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_request_ticket_restoration_param.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_right_info.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_right_infos.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_start_challenge_param.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_ticket_info.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_transaction.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/types/service_item_user_info.go create mode 100644 nex-protocols-go/service-item/wii-sports-club/update_and_get_ticket_info.go create mode 100644 nex-protocols-go/shop/nintendo-badge-arcade/get_riv_token.go create mode 100644 nex-protocols-go/shop/nintendo-badge-arcade/post_play_log.go create mode 100644 nex-protocols-go/shop/nintendo-badge-arcade/protocol.go create mode 100644 nex-protocols-go/shop/nintendo-badge-arcade/types/shop_post_play_log_param.go create mode 100644 nex-protocols-go/shop/protocol.go create mode 100644 nex-protocols-go/shop/types/shop_item.go create mode 100644 nex-protocols-go/shop/types/shop_item_rights.go create mode 100644 nex-protocols-go/storage-manager/acquire_card_id.go create mode 100644 nex-protocols-go/storage-manager/activate_with_card_id.go create mode 100644 nex-protocols-go/storage-manager/protocol.go create mode 100644 nex-protocols-go/subscriber/delete_content.go create mode 100644 nex-protocols-go/subscriber/follow.go create mode 100644 nex-protocols-go/subscriber/get_content.go create mode 100644 nex-protocols-go/subscriber/get_content_multi.go create mode 100644 nex-protocols-go/subscriber/get_follower.go create mode 100644 nex-protocols-go/subscriber/get_following.go create mode 100644 nex-protocols-go/subscriber/get_friend_user_statuses.go create mode 100644 nex-protocols-go/subscriber/get_num_followers.go create mode 100644 nex-protocols-go/subscriber/get_timeline.go create mode 100644 nex-protocols-go/subscriber/get_user_statuses.go create mode 100644 nex-protocols-go/subscriber/hello.go create mode 100644 nex-protocols-go/subscriber/post_content.go create mode 100644 nex-protocols-go/subscriber/protocol.go create mode 100644 nex-protocols-go/subscriber/types/subscriber_content.go create mode 100644 nex-protocols-go/subscriber/types/subscriber_get_content_param.go create mode 100644 nex-protocols-go/subscriber/types/subscriber_post_content_param.go create mode 100644 nex-protocols-go/subscriber/types/subscriber_user_status_info.go create mode 100644 nex-protocols-go/subscriber/types/unknown.go create mode 100644 nex-protocols-go/subscriber/unfollow.go create mode 100644 nex-protocols-go/subscriber/unfollow_all_and_follow.go create mode 100644 nex-protocols-go/subscriber/update_user_status.go create mode 100644 nex-protocols-go/subscription/create_my_subscription_data.go create mode 100644 nex-protocols-go/subscription/get_active_player_subscription_data.go create mode 100644 nex-protocols-go/subscription/get_friend_subscription_data.go create mode 100644 nex-protocols-go/subscription/get_privacy_levels.go create mode 100644 nex-protocols-go/subscription/get_subscription_data.go create mode 100644 nex-protocols-go/subscription/get_target_subscription_data.go create mode 100644 nex-protocols-go/subscription/protocol.go create mode 100644 nex-protocols-go/subscription/replace_target_and_get_subscription_data.go create mode 100644 nex-protocols-go/subscription/update_my_subscription_data.go create mode 100644 nex-protocols-go/ticket-granting/get_name.go create mode 100644 nex-protocols-go/ticket-granting/get_pid.go create mode 100644 nex-protocols-go/ticket-granting/login.go create mode 100644 nex-protocols-go/ticket-granting/login_ex.go create mode 100644 nex-protocols-go/ticket-granting/login_with_context.go create mode 100644 nex-protocols-go/ticket-granting/protocol.go create mode 100644 nex-protocols-go/ticket-granting/request_ticket.go create mode 100644 nex-protocols-go/ticket-granting/types/authentication_info.go create mode 100644 nex-protocols-go/ticket-granting/types/nintendo_login_data.go create mode 100644 nex-protocols-go/utility/acquire_nex_unique_id.go create mode 100644 nex-protocols-go/utility/acquire_nex_unique_id_with_password.go create mode 100644 nex-protocols-go/utility/associate_nex_unique_id_with_my_principal_id.go create mode 100644 nex-protocols-go/utility/associate_nex_unique_ids_with_my_principal_id.go create mode 100644 nex-protocols-go/utility/get_associated_nex_unique_id_with_my_principal_id.go create mode 100644 nex-protocols-go/utility/get_associated_nex_unique_ids_with_my_principal_id.go create mode 100644 nex-protocols-go/utility/get_integer_settings.go create mode 100644 nex-protocols-go/utility/get_string_settings.go create mode 100644 nex-protocols-go/utility/protocol.go create mode 100644 nex-protocols-go/utility/types/unique_id_info.go create mode 100644 nex/matchmake-extension/common/cleanup_search_matchmake_session.go create mode 100644 nex/message-delivery/deliver_message.go create mode 100644 nex/pokemon-pss/unk1.go create mode 100644 nex/pokemon-pss/unk2.go diff --git a/.gitignore b/.gitignore index c42ec53..70d854d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -# If you prefer the allow list template instead of the deny list, see community template: -# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore -# # Binaries for programs and plugins *.exe *.exe~ @@ -8,23 +5,20 @@ *.so *.dylib -# Test binary, built with `go test -c` +# Test binary, build with `go test -c` *.test # Output of the go coverage tool, specifically when used with LiteIDE *.out -# Dependency directories (remove the comment below to include it) -# vendor/ - -# Go workspace file +# custom +.env +*.key go.work go.work.sum -# custom -.vscode -.env +# built server build + +# logs log -*.pem -*.key \ No newline at end of file diff --git a/Makefile b/Makefile index 97c162d..d85769e 100644 --- a/Makefile +++ b/Makefile @@ -44,17 +44,17 @@ SERVER_BUILD := $(BRANCH):$(REMOTE_PATH)@$(HASH) else # * .git folder not present, assume downloaded from zip file and just use folder name $(info "$(CYAN)git repository not found. Building server build string from folder name$(RESET)") -SERVER_BUILD := $(notdir $(CURDIR)) +SERVER_BUILD := pokemon-gen6 endif # * Final build string DATE_TIME := $(shell date --iso=seconds) BUILD_STRING := $(SERVER_BUILD), $(DATE_TIME) -all: +default: ifeq ($(wildcard .env),) $(warning "$(YELLOW).env file not found, environment variables may not be populated correctly$(RESET)") endif go get -u go mod tidy - go build -ldflags "-X 'main.serverBuildString=$(BUILD_STRING)'" -o ./build/$(notdir $(CURDIR)) \ No newline at end of file + go build -ldflags "-X 'main.serverBuildString=$(BUILD_STRING)'" -o ./build/pokemon-gen6 diff --git a/README.md b/README.md index 15c2d1c..2e3ea35 100644 --- a/README.md +++ b/README.md @@ -51,4 +51,5 @@ All configuration options are handled via environment variables | `PN_POKEGEN6_SECURE_SERVER_PORT` | Port for the secure server | Yes | | `PN_POKEGEN6_ACCOUNT_GRPC_HOST` | Host name for your account server gRPC service | Yes | | `PN_POKEGEN6_ACCOUNT_GRPC_PORT` | Port for your account server gRPC service | Yes | -| `PN_POKEGEN6_ACCOUNT_GRPC_API_KEY` | API key for your account server gRPC service | No (Assumed to be an open gRPC API) | \ No newline at end of file +| `PN_POKEGEN6_ACCOUNT_GRPC_API_KEY` | API key for your account server gRPC service | No (Assumed to be an open gRPC API) | + diff --git a/database/get_unique_id_by_owner_pid.go b/database/get_unique_id_by_owner_pid.go new file mode 100644 index 0000000..8250723 --- /dev/null +++ b/database/get_unique_id_by_owner_pid.go @@ -0,0 +1,11 @@ +package database + +func GetUniqueIDByOwnerPID(pid uint32) (uint32, error) { + var uniqueID uint32 + err := Postgres.QueryRow(`SELECT unique_id FROM common_data WHERE owner_pid=$1`, pid).Scan(&uniqueID) + if err != nil { + return 0, err + } + + return uniqueID, nil +} diff --git a/database/init_postgres.go b/database/init_postgres.go index 9e02ab4..d6b8934 100644 --- a/database/init_postgres.go +++ b/database/init_postgres.go @@ -5,17 +5,10 @@ import "github.com/PretendoNetwork/pokemon-gen6/globals" func initPostgres() { var err error - _, err = Postgres.Exec(`CREATE TABLE IF NOT EXISTS rankings ( - id bigserial PRIMARY KEY, + _, err = Postgres.Exec(`CREATE TABLE IF NOT EXISTS common_data ( + unique_id serial PRIMARY KEY, owner_pid integer, - category integer, - score integer, - order_by integer, - update_mode integer, - groups integer[], - param bigint, - common_data bytea, - created_at bigint + common_data bytea )`) if err != nil { globals.Logger.Critical(err.Error()) diff --git a/database/insert_common_data_by_owner_pid.go b/database/insert_common_data_by_owner_pid.go new file mode 100644 index 0000000..38da88a --- /dev/null +++ b/database/insert_common_data_by_owner_pid.go @@ -0,0 +1,11 @@ +package database + +func InsertCommonDataByOwnerPID(pid uint32) (uint32, error) { + var uniqueID uint32 + err := Postgres.QueryRow(`INSERT INTO common_data (owner_pid) VALUES ($1) RETURNING unique_id`, pid).Scan(&uniqueID) + if err != nil { + return 0, err + } + + return uniqueID, nil +} diff --git a/globals/accounts.go b/globals/accounts.go new file mode 100644 index 0000000..40ecadc --- /dev/null +++ b/globals/accounts.go @@ -0,0 +1,56 @@ +package globals + +import ( + "strconv" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" +) + +var AuthenticationServerAccount *nex.Account +var SecureServerAccount *nex.Account + +func AccountDetailsByPID(pid *types.PID) (*nex.Account, *nex.Error) { + if pid.Equals(AuthenticationServerAccount.PID) { + return AuthenticationServerAccount, nil + } + + if pid.Equals(SecureServerAccount.PID) { + return SecureServerAccount, nil + } + + password, errorCode := PasswordFromPID(pid) + if errorCode != 0 { + return nil, nex.NewError(errorCode, "Failed to get password from PID") + } + + account := nex.NewAccount(pid, strconv.Itoa(int(pid.LegacyValue())), password) + + return account, nil +} + +func AccountDetailsByUsername(username string) (*nex.Account, *nex.Error) { + if username == AuthenticationServerAccount.Username { + return AuthenticationServerAccount, nil + } + + if username == SecureServerAccount.Username { + return SecureServerAccount, nil + } + + pidInt, err := strconv.Atoi(username) + if err != nil { + return nil, nex.NewError(nex.ResultCodes.RendezVous.InvalidUsername, "Invalid username") + } + + pid := types.NewPID(uint64(pidInt)) + + password, errorCode := PasswordFromPID(pid) + if errorCode != 0 { + return nil, nex.NewError(errorCode, "Failed to get password from PID") + } + + account := nex.NewAccount(pid, username, password) + + return account, nil +} diff --git a/globals/globals.go b/globals/globals.go index 61546bd..60e931f 100644 --- a/globals/globals.go +++ b/globals/globals.go @@ -2,7 +2,7 @@ package globals import ( pb "github.com/PretendoNetwork/grpc-go/account" - "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-go/v2" "github.com/PretendoNetwork/plogger-go" "google.golang.org/grpc" "google.golang.org/grpc/metadata" @@ -10,8 +10,10 @@ import ( var Logger *plogger.Logger var KerberosPassword = "password" // * Default password -var AuthenticationServer *nex.Server -var SecureServer *nex.Server +var AuthenticationServer *nex.PRUDPServer +var AuthenticationEndpoint *nex.PRUDPEndPoint +var SecureServer *nex.PRUDPServer +var SecureEndpoint *nex.PRUDPEndPoint var GRPCAccountClientConnection *grpc.ClientConn var GRPCAccountClient pb.AccountClient var GRPCAccountCommonMetadata metadata.MD diff --git a/globals/password_from_pid.go b/globals/password_from_pid.go index f59823c..7cf14d6 100644 --- a/globals/password_from_pid.go +++ b/globals/password_from_pid.go @@ -4,18 +4,19 @@ import ( "context" pb "github.com/PretendoNetwork/grpc-go/account" - "github.com/PretendoNetwork/nex-go" - "github.com/PretendoNetwork/nex-protocols-go/globals" + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" "google.golang.org/grpc/metadata" ) -func PasswordFromPID(pid uint32) (string, uint32) { +func PasswordFromPID(pid *types.PID) (string, uint32) { ctx := metadata.NewOutgoingContext(context.Background(), GRPCAccountCommonMetadata) - response, err := GRPCAccountClient.GetNEXPassword(ctx, &pb.GetNEXPasswordRequest{Pid: pid}) + response, err := GRPCAccountClient.GetNEXPassword(ctx, &pb.GetNEXPasswordRequest{Pid: pid.LegacyValue()}) if err != nil { globals.Logger.Error(err.Error()) - return "", nex.Errors.RendezVous.InvalidUsername + return "", nex.ResultCodes.RendezVous.InvalidUsername } return response.Password, 0 diff --git a/go.mod b/go.mod index f42d867..f4e91ad 100644 --- a/go.mod +++ b/go.mod @@ -1,31 +1,38 @@ module github.com/PretendoNetwork/pokemon-gen6 -go 1.19 +go 1.21 + +replace github.com/PretendoNetwork/nex-protocols-go/v2 => ./nex-protocols-go +replace github.com/PretendoNetwork/nex-protocols-common-go/v2 => ./nex-protocols-common-go require ( github.com/PretendoNetwork/grpc-go v1.0.2 - github.com/PretendoNetwork/nex-go v1.0.41 - github.com/PretendoNetwork/nex-protocols-common-go v1.0.28 - github.com/PretendoNetwork/nex-protocols-go v1.0.53 + github.com/PretendoNetwork/nex-go/v2 v2.0.1 + github.com/PretendoNetwork/nex-protocols-common-go/v2 v2.0.2 + github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.1 github.com/PretendoNetwork/plogger-go v1.0.4 github.com/joho/godotenv v1.5.1 github.com/lib/pq v1.10.9 - google.golang.org/grpc v1.58.2 + google.golang.org/grpc v1.63.0 ) require ( - github.com/fatih/color v1.15.0 // indirect - github.com/golang/protobuf v1.5.3 // indirect + github.com/dolthub/maphash v0.1.0 // indirect + github.com/fatih/color v1.16.0 // indirect + github.com/golang/protobuf v1.5.4 // indirect github.com/jwalton/go-supportscolor v1.2.0 // indirect + github.com/klauspost/compress v1.17.7 // indirect + github.com/lxzan/gws v1.8.1 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e // indirect github.com/superwhiskers/crunch/v3 v3.5.7 // indirect - golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect - golang.org/x/mod v0.12.0 // indirect - golang.org/x/net v0.15.0 // indirect - golang.org/x/sys v0.12.0 // indirect - golang.org/x/term v0.12.0 // indirect - golang.org/x/text v0.13.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect - google.golang.org/protobuf v1.31.0 // indirect + golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect + golang.org/x/mod v0.17.0 // indirect + golang.org/x/net v0.24.0 // indirect + golang.org/x/sys v0.19.0 // indirect + golang.org/x/term v0.19.0 // indirect + golang.org/x/text v0.14.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect + google.golang.org/protobuf v1.33.0 // indirect ) diff --git a/go.sum b/go.sum index 376bc18..68f815f 100644 --- a/go.sum +++ b/go.sum @@ -1,56 +1,68 @@ github.com/PretendoNetwork/grpc-go v1.0.2 h1:9TvKmX7dCOANyoHEra1MMYqS1N/RGav66TRG4SHInvo= github.com/PretendoNetwork/grpc-go v1.0.2/go.mod h1:XZjEsij9lL7HJBNkH6JPbBIkUSq/1rjflvjGdv+DAj0= -github.com/PretendoNetwork/nex-go v1.0.41 h1:TcBb1Bpe2KAB+AXaGX1K9NVQBRtZJIoy4yCvRde2xbI= -github.com/PretendoNetwork/nex-go v1.0.41/go.mod h1:QwHEa165DeVd0xIuthrgc3j6NWXT8lyPSG6t5kC/Shk= -github.com/PretendoNetwork/nex-protocols-common-go v1.0.28 h1:ErkWga7Uzn4WoDU8Q/Sy+geHy0fF0G/5wFnL5i6hngI= -github.com/PretendoNetwork/nex-protocols-common-go v1.0.28/go.mod h1:4jYhLg+Cb2qhJHyyA+f2OwCrmc98zuTO3JPWK22mIKw= -github.com/PretendoNetwork/nex-protocols-go v1.0.53 h1:o56sr8D2Mx//pGEFF/pzDTwOWusI0aQVehoyRYqSqVo= -github.com/PretendoNetwork/nex-protocols-go v1.0.53/go.mod h1:9r4KbNELVZj01TY8p+FGYDb9+e4mHLiWKo5NL1fPqD8= +github.com/PretendoNetwork/nex-go/v2 v2.0.1 h1:7UEwulBtWD+HIbwB0uaRjBK1EXFLfSnv0t5+WyQYV0s= +github.com/PretendoNetwork/nex-go/v2 v2.0.1/go.mod h1:EZNyRVr0WpPLHZQqZZvarQ8/tXsEyVqLr6zy/hKCAV4= +github.com/PretendoNetwork/nex-protocols-common-go/v2 v2.0.2 h1:ZCSEA+jXE2eHF/uD/rrtugR0tlpdzmM6IVG8THlC4as= +github.com/PretendoNetwork/nex-protocols-common-go/v2 v2.0.2/go.mod h1:YEnnM1XDVGf34885MdHcRwZR/g9Qvjn3qkXlGlgiGPk= +github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.1 h1:BqrHYF2JeYfB/JUmhU3pWR1qUJEEqUDM4pigXzi95Ik= +github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.1/go.mod h1:TAzlc/gOu6E5Ct2NoTpN+Ea9Gpjh38dTsGqfs0pfZ4w= github.com/PretendoNetwork/plogger-go v1.0.4 h1:PF7xHw9eDRHH+RsAP9tmAE7fG0N0p6H4iPwHKnsoXwc= github.com/PretendoNetwork/plogger-go v1.0.4/go.mod h1:7kD6M4vPq1JL4LTuPg6kuB1OvUBOwQOtAvTaUwMbwvU= -github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= -github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dolthub/maphash v0.1.0 h1:bsQ7JsF4FkkWyrP3oCnFJgrCUAFbFf3kOl4L/QxPDyQ= +github.com/dolthub/maphash v0.1.0/go.mod h1:gkg4Ch4CdCDu5h6PMriVLawB7koZ+5ijb9puGMV50a4= +github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= +github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/jwalton/go-supportscolor v1.2.0 h1:g6Ha4u7Vm3LIsQ5wmeBpS4gazu0UP1DRDE8y6bre4H8= github.com/jwalton/go-supportscolor v1.2.0/go.mod h1:hFVUAZV2cWg+WFFC4v8pT2X/S2qUUBYMioBD9AINXGs= +github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg= +github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/lxzan/gws v1.8.1 h1:+Oc2f8U0YUE7mkBKUYUABvszUB9pfTfPQl7C26PW+LE= +github.com/lxzan/gws v1.8.1/go.mod h1:FcGeRMB7HwGuTvMLR24ku0Zx0p6RXqeKASeMc4VYgi4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e h1:dCWirM5F3wMY+cmRda/B1BiPsFtmzXqV9b0hLWtVBMs= +github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e/go.mod h1:9leZcVcItj6m9/CfHY5Em/iBrCz7js8LcRQGTKEEv2M= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/superwhiskers/crunch/v3 v3.5.7 h1:N9RLxaR65C36i26BUIpzPXGy2f6pQ7wisu2bawbKNqg= github.com/superwhiskers/crunch/v3 v3.5.7/go.mod h1:4ub2EKgF1MAhTjoOCTU4b9uLMsAweHEa89aRrfAypXA= -golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= -golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 h1:985EYyeCOxTpcgOTJpflJUwOeEz0CQOdPt73OzpE9F8= +golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= +golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU= -golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 h1:6GQBEOdGkX6MMTLT9V+TjtIRZCw9VPD5Z+yHY9wMgS0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97/go.mod h1:v7nGkzlmW8P3n/bKmWBn2WpBjpOEx8Q6gMueudAmKfY= -google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= -google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= +golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda h1:LI5DOvAxUPMv/50agcLLoo+AdWc1irS9Rzz4vPuD1V4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= +google.golang.org/grpc v1.63.0 h1:WjKe+dnvABXyPJMD7KDNLxtoGk5tgk+YFWN6cBWjZE8= +google.golang.org/grpc v1.63.0/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/init.go b/init.go index 1164d43..7a9e68a 100644 --- a/init.go +++ b/init.go @@ -6,14 +6,17 @@ import ( "strconv" "strings" + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" pb "github.com/PretendoNetwork/grpc-go/account" - "github.com/PretendoNetwork/pokemon-gen6/database" - "github.com/PretendoNetwork/pokemon-gen6/globals" "github.com/PretendoNetwork/plogger-go" "github.com/joho/godotenv" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/metadata" + + "github.com/PretendoNetwork/pokemon-gen6/database" + "github.com/PretendoNetwork/pokemon-gen6/globals" ) func init() { @@ -46,6 +49,9 @@ func init() { globals.KerberosPassword = kerberosPassword } + globals.AuthenticationServerAccount = nex.NewAccount(types.NewPID(1), "Quazal Authentication", globals.KerberosPassword) + globals.SecureServerAccount = nex.NewAccount(types.NewPID(2), "Quazal Rendez-Vous", globals.KerberosPassword) + if strings.TrimSpace(authenticationServerPort) == "" { globals.Logger.Error("PN_POKEGEN6_AUTHENTICATION_SERVER_PORT environment variable not set") os.Exit(0) diff --git a/nex-protocols-common-go/.gitignore b/nex-protocols-common-go/.gitignore new file mode 100644 index 0000000..c42ec53 --- /dev/null +++ b/nex-protocols-common-go/.gitignore @@ -0,0 +1,30 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work +go.work.sum + +# custom +.vscode +.env +build +log +*.pem +*.key \ No newline at end of file diff --git a/nex-protocols-common-go/LICENSE b/nex-protocols-common-go/LICENSE new file mode 100644 index 0000000..0ad25db --- /dev/null +++ b/nex-protocols-common-go/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/nex-protocols-common-go/README.md b/nex-protocols-common-go/README.md new file mode 100644 index 0000000..ccbfd40 --- /dev/null +++ b/nex-protocols-common-go/README.md @@ -0,0 +1,77 @@ +# NEX Protocols Common Go +## NEX protocols used by many games with premade handlers and a high level API + +[![GoDoc](https://godoc.org/github.com/PretendoNetwork/nex-protocols-common-go/v2?status.svg)](https://godoc.org/github.com/PretendoNetwork/nex-protocols-common-go/v2) + +### Other NEX libraries +[nex-go](https://github.com/PretendoNetwork/nex-go) - Barebones NEX/PRUDP server implementation + +[nex-protocols-go](https://github.com/PretendoNetwork/nex-protocols-go) - NEX protocol definitions + +### Install + +`go get github.com/PretendoNetwork/nex-protocols-common-go/v2` + +### Usage + +`nex-protocols-common-go` provides a higher level API than the [NEX Protocols Go module](https://github.com/PretendoNetwork/nex-protocols-go). This module handles many of the more common protcols and methods used shared by many servers. Instead of working directly with the NEX server, this module exposes an API for defining helper functions to provide the module with the data it needs to run + +### Example, friends (Wii U) authentication server +### For a complete example, see the complete [Friends Server](https://github.com/PretendoNetwork/friends), and other game servers + +```go +package main + +import ( + "fmt" + "os" + + "github.com/PretendoNetwork/nex-go/v2" + ticket_granting "github.com/PretendoNetwork/nex-protocols-go/v2/ticket-granting" + common_ticket_granting "github.com/PretendoNetwork/nex-protocols-common-go/v2/ticket-granting" +) + +var nexServer *nex.PRUDPServer + +func main() { + nexServer := nex.NewPRUDPServer() + + endpoint := nex.NewPRUDPEndPoint(1) + endpoint.ServerAccount = nex.NewAccount(types.NewPID(1), "Quazal Authentication", "password")) + endpoint.AccountDetailsByPID = accountDetailsByPID + endpoint.AccountDetailsByUsername = accountDetailsByUsername + + endpoint.OnData(func(packet nex.PacketInterface) { + request := packet.RMCMessage() + + fmt.Println("==Friends - Auth==") + fmt.Printf("Protocol ID: %#v\n", request.ProtocolID) + fmt.Printf("Method ID: %#v\n", request.MethodID) + fmt.Println("==================") + }) + + nexServer.SetFragmentSize(962) + nexServer.LibraryVersions.SetDefault(nex.NewLibraryVersion(1, 1, 0)) + nexServer.SessionKeyLength = 16 + nexServer.AccessKey = "ridfebb9" + + ticketGrantingProtocol := ticket_granting.NewProtocol(endpoint) + endpoint.RegisterServiceProtocol(ticketGrantingProtocol) + commonTicketGrantingProtocol := common_ticket_granting.NewCommonProtocol(ticketGrantingProtocol) + + secureStationURL := nex.NewStationURL("") + secureStationURL.Scheme = "prudps" + secureStationURL.Fields.Set("address", os.Getenv("SECURE_SERVER_LOCATION")) + secureStationURL.Fields.Set("port", os.Getenv("SECURE_SERVER_PORT")) + secureStationURL.Fields.Set("CID", "1") + secureStationURL.Fields.Set("PID", "2") + secureStationURL.Fields.Set("sid", "1") + secureStationURL.Fields.Set("stream", "10") + secureStationURL.Fields.Set("type", "2") + + commonTicketGrantingProtocol.SecureStationURL = secureStationURL + commonTicketGrantingProtocol.BuildName = "Pretendo Friends Auth" + + nexServer.Listen(60000) +} +``` diff --git a/nex-protocols-common-go/datastore/change_meta.go b/nex-protocols-common-go/datastore/change_meta.go new file mode 100644 index 0000000..002e65d --- /dev/null +++ b/nex-protocols-common-go/datastore/change_meta.go @@ -0,0 +1,81 @@ +package datastore + +import ( + "github.com/PretendoNetwork/nex-go/v2" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +func (commonProtocol *CommonProtocol) changeMeta(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreChangeMetaParam) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.GetObjectInfoByDataID == nil { + common_globals.Logger.Warning("GetObjectInfoByDataID not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.UpdateObjectPeriodByDataIDWithPassword == nil { + common_globals.Logger.Warning("UpdateObjectPeriodByDataIDWithPassword not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.UpdateObjectMetaBinaryByDataIDWithPassword == nil { + common_globals.Logger.Warning("UpdateObjectMetaBinaryByDataIDWithPassword not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.UpdateObjectDataTypeByDataIDWithPassword == nil { + common_globals.Logger.Warning("UpdateObjectDataTypeByDataIDWithPassword not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + metaInfo, errCode := commonProtocol.GetObjectInfoByDataID(param.DataID) + if errCode != nil { + return nil, errCode + } + + // TODO - Is this the right permission? + errCode = commonProtocol.VerifyObjectPermission(metaInfo.OwnerID, connection.PID(), metaInfo.DelPermission) + if errCode != nil { + return nil, errCode + } + + if param.ModifiesFlag.PAND(0x08) != 0 { + errCode = commonProtocol.UpdateObjectPeriodByDataIDWithPassword(param.DataID, param.Period, param.UpdatePassword) + if errCode != nil { + return nil, errCode + } + } + + if param.ModifiesFlag.PAND(0x10) != 0 { + errCode = commonProtocol.UpdateObjectMetaBinaryByDataIDWithPassword(param.DataID, param.MetaBinary, param.UpdatePassword) + if errCode != nil { + return nil, errCode + } + } + + if param.ModifiesFlag.PAND(0x80) != 0 { + errCode = commonProtocol.UpdateObjectDataTypeByDataIDWithPassword(param.DataID, param.DataType, param.UpdatePassword) + if errCode != nil { + return nil, errCode + } + } + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = datastore.ProtocolID + rmcResponse.MethodID = datastore.MethodChangeMeta + rmcResponse.CallID = callID + + if commonProtocol.OnAfterChangeMeta != nil { + go commonProtocol.OnAfterChangeMeta(packet, param) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/datastore/complete_post_object.go b/nex-protocols-common-go/datastore/complete_post_object.go new file mode 100644 index 0000000..0c0bfe6 --- /dev/null +++ b/nex-protocols-common-go/datastore/complete_post_object.go @@ -0,0 +1,111 @@ +package datastore + +import ( + "fmt" + + "github.com/PretendoNetwork/nex-go/v2" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +func (commonProtocol *CommonProtocol) completePostObject(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreCompletePostParam) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.minIOClient == nil { + common_globals.Logger.Warning("MinIOClient not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.GetObjectInfoByDataID == nil { + common_globals.Logger.Warning("GetObjectInfoByDataID not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.GetObjectOwnerByDataID == nil { + common_globals.Logger.Warning("GetObjectOwnerByDataID not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.GetObjectSizeByDataID == nil { + common_globals.Logger.Warning("GetObjectSizeByDataID not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.UpdateObjectUploadCompletedByDataID == nil { + common_globals.Logger.Warning("UpdateObjectUploadCompletedByDataID not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.DeleteObjectByDataID == nil { + common_globals.Logger.Warning("DeleteObjectByDataID not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + // * If GetObjectInfoByDataID returns data then that means + // * the object has already been marked as uploaded. So do + // * nothing + objectInfo, _ := commonProtocol.GetObjectInfoByDataID(param.DataID) + if objectInfo != nil { + return nil, nex.NewError(nex.ResultCodes.DataStore.PermissionDenied, "change_error") + } + + // * Only allow an objects owner to make this request + ownerPID, errCode := commonProtocol.GetObjectOwnerByDataID(param.DataID) + if errCode != nil { + return nil, errCode + } + + if ownerPID != connection.PID().LegacyValue() { + return nil, nex.NewError(nex.ResultCodes.DataStore.PermissionDenied, "change_error") + } + + bucket := commonProtocol.S3Bucket + key := fmt.Sprintf("%s/%d.bin", commonProtocol.s3DataKeyBase, param.DataID) + + if param.IsSuccess.Value { + objectSizeS3, err := commonProtocol.S3ObjectSize(bucket, key) + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.DataStore.NotFound, "change_error") + } + + objectSizeDB, errCode := commonProtocol.GetObjectSizeByDataID(param.DataID) + if errCode != nil { + return nil, errCode + } + + if objectSizeS3 != uint64(objectSizeDB) { + common_globals.Logger.Errorf("Object with DataID %d did not upload correctly! Mismatched sizes", param.DataID) + // TODO - Is this a good error? + return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error") + } + + errCode = commonProtocol.UpdateObjectUploadCompletedByDataID(param.DataID, true) + if errCode != nil { + return nil, errCode + } + } else { + errCode := commonProtocol.DeleteObjectByDataID(param.DataID) + if errCode != nil { + return nil, errCode + } + } + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = datastore.ProtocolID + rmcResponse.MethodID = datastore.MethodCompletePostObject + rmcResponse.CallID = callID + + if commonProtocol.OnAfterCompletePostObject != nil { + go commonProtocol.OnAfterCompletePostObject(packet, param) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/datastore/complete_post_objects.go b/nex-protocols-common-go/datastore/complete_post_objects.go new file mode 100644 index 0000000..e1b4d61 --- /dev/null +++ b/nex-protocols-common-go/datastore/complete_post_objects.go @@ -0,0 +1,89 @@ +package datastore + +import ( + "fmt" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" +) + +func (commonProtocol *CommonProtocol) completePostObjects(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.minIOClient == nil { + common_globals.Logger.Warning("MinIOClient not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.GetObjectSizeByDataID == nil { + common_globals.Logger.Warning("GetObjectSizeByDataID not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.UpdateObjectUploadCompletedByDataID == nil { + common_globals.Logger.Warning("UpdateObjectUploadCompletedByDataID not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + var errorCode *nex.Error + + dataIDs.Each(func(_ int, dataID *types.PrimitiveU64) bool { + bucket := commonProtocol.S3Bucket + key := fmt.Sprintf("%s/%d.bin", commonProtocol.s3DataKeyBase, dataID) + + objectSizeS3, err := commonProtocol.S3ObjectSize(bucket, key) + if err != nil { + common_globals.Logger.Error(err.Error()) + errorCode = nex.NewError(nex.ResultCodes.DataStore.NotFound, "change_error") + + return true + } + + objectSizeDB, errCode := commonProtocol.GetObjectSizeByDataID(dataID) + if errCode != nil { + errorCode = errCode + + return true + } + + if objectSizeS3 != uint64(objectSizeDB) { + common_globals.Logger.Errorf("Object with DataID %d did not upload correctly! Mismatched sizes", dataID) + // TODO - Is this a good error? + errorCode = nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error") + + return true + } + + errCode = commonProtocol.UpdateObjectUploadCompletedByDataID(dataID, true) + if errCode != nil { + errorCode = errCode + + return true + } + + return false + }) + + if errorCode != nil { + return nil, errorCode + } + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = datastore.ProtocolID + rmcResponse.MethodID = datastore.MethodCompletePostObjects + rmcResponse.CallID = callID + + if commonProtocol.OnAfterCompletePostObjects != nil { + go commonProtocol.OnAfterCompletePostObjects(packet, dataIDs) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/datastore/delete_object.go b/nex-protocols-common-go/datastore/delete_object.go new file mode 100644 index 0000000..8decd2f --- /dev/null +++ b/nex-protocols-common-go/datastore/delete_object.go @@ -0,0 +1,54 @@ +package datastore + +import ( + "github.com/PretendoNetwork/nex-go/v2" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +func (commonProtocol *CommonProtocol) deleteObject(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreDeleteParam) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.GetObjectInfoByDataID == nil { + common_globals.Logger.Warning("GetObjectInfoByDataID not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.DeleteObjectByDataIDWithPassword == nil { + common_globals.Logger.Warning("DeleteObjectByDataIDWithPassword not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + metaInfo, errCode := commonProtocol.GetObjectInfoByDataID(param.DataID) + if errCode != nil { + return nil, errCode + } + + errCode = commonProtocol.VerifyObjectPermission(metaInfo.OwnerID, connection.PID(), metaInfo.DelPermission) + if errCode != nil { + return nil, errCode + } + + errCode = commonProtocol.DeleteObjectByDataIDWithPassword(param.DataID, param.UpdatePassword) + if errCode != nil { + return nil, errCode + } + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = datastore.ProtocolID + rmcResponse.MethodID = datastore.MethodDeleteObject + rmcResponse.CallID = callID + + if commonProtocol.OnAfterDeleteObject != nil { + go commonProtocol.OnAfterDeleteObject(packet, param) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/datastore/get_meta.go b/nex-protocols-common-go/datastore/get_meta.go new file mode 100644 index 0000000..f99b1b4 --- /dev/null +++ b/nex-protocols-common-go/datastore/get_meta.go @@ -0,0 +1,66 @@ +package datastore + +import ( + "github.com/PretendoNetwork/nex-go/v2" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +func (commonProtocol *CommonProtocol) getMeta(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.GetObjectInfoByPersistenceTargetWithPassword == nil { + common_globals.Logger.Warning("GetObjectInfoByPersistenceTargetWithPassword not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.GetObjectInfoByDataIDWithPassword == nil { + common_globals.Logger.Warning("GetObjectInfoByDataIDWithPassword not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + var pMetaInfo *datastore_types.DataStoreMetaInfo + var errCode *nex.Error + + // * Real server ignores PersistenceTarget if DataID is set + if param.DataID.Value == 0 { + pMetaInfo, errCode = commonProtocol.GetObjectInfoByPersistenceTargetWithPassword(param.PersistenceTarget, param.AccessPassword) + } else { + pMetaInfo, errCode = commonProtocol.GetObjectInfoByDataIDWithPassword(param.DataID, param.AccessPassword) + } + + if errCode != nil { + return nil, errCode + } + + errCode = commonProtocol.VerifyObjectPermission(pMetaInfo.OwnerID, connection.PID(), pMetaInfo.Permission) + if errCode != nil { + return nil, errCode + } + + pMetaInfo.FilterPropertiesByResultOption(param.ResultOption) + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pMetaInfo.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = datastore.ProtocolID + rmcResponse.MethodID = datastore.MethodGetMeta + rmcResponse.CallID = callID + + if commonProtocol.OnAfterGetMeta != nil { + go commonProtocol.OnAfterGetMeta(packet, param) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/datastore/get_metas.go b/nex-protocols-common-go/datastore/get_metas.go new file mode 100644 index 0000000..54b8c3c --- /dev/null +++ b/nex-protocols-common-go/datastore/get_metas.go @@ -0,0 +1,80 @@ +package datastore + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +func (commonProtocol *CommonProtocol) getMetas(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], param *datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.GetObjectInfoByDataID == nil { + common_globals.Logger.Warning("GetObjectInfoByDataID not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + // TODO - Verify if param.PersistenceTarget is respected? It wouldn't make sense here but who knows + + pMetaInfo := types.NewList[*datastore_types.DataStoreMetaInfo]() + pResults := types.NewList[*types.QResult]() + + pMetaInfo.Type = datastore_types.NewDataStoreMetaInfo() + pResults.Type = types.NewQResult(0) + + // * param has an AccessPassword, but it goes unchecked here. + // * The password would need to be the same for every object + // * in the input array, which doesn't make any sense. Assuming + // * it's unused until proven otherwise + + dataIDs.Each(func(_ int, dataID *types.PrimitiveU64) bool { + objectInfo, errCode := commonProtocol.GetObjectInfoByDataID(dataID) + + if errCode != nil { + objectInfo = datastore_types.NewDataStoreMetaInfo() + + pResults.Append(types.NewQResultError(errCode.ResultCode)) + } else { + errCode = commonProtocol.VerifyObjectPermission(objectInfo.OwnerID, connection.PID(), objectInfo.Permission) + if errCode != nil { + objectInfo = datastore_types.NewDataStoreMetaInfo() + + pResults.Append(types.NewQResultError(errCode.ResultCode)) + } else { + pResults.Append(types.NewQResultSuccess(nex.ResultCodes.DataStore.Unknown)) + } + + objectInfo.FilterPropertiesByResultOption(param.ResultOption) + } + + pMetaInfo.Append(objectInfo) + + return false + }) + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pMetaInfo.WriteTo(rmcResponseStream) + pResults.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = datastore.ProtocolID + rmcResponse.MethodID = datastore.MethodGetMetas + rmcResponse.CallID = callID + + if commonProtocol.OnAfterGetMetas != nil { + go commonProtocol.OnAfterGetMetas(packet, dataIDs, param) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/datastore/get_metas_multiple_param.go b/nex-protocols-common-go/datastore/get_metas_multiple_param.go new file mode 100644 index 0000000..c7c1eb1 --- /dev/null +++ b/nex-protocols-common-go/datastore/get_metas_multiple_param.go @@ -0,0 +1,86 @@ +package datastore + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +func (commonProtocol *CommonProtocol) getMetasMultipleParam(err error, packet nex.PacketInterface, callID uint32, params *types.List[*datastore_types.DataStoreGetMetaParam]) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.GetObjectInfoByPersistenceTargetWithPassword == nil { + common_globals.Logger.Warning("GetObjectInfoByPersistenceTargetWithPassword not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.GetObjectInfoByDataIDWithPassword == nil { + common_globals.Logger.Warning("GetObjectInfoByDataIDWithPassword not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + pMetaInfo := types.NewList[*datastore_types.DataStoreMetaInfo]() + pResults := types.NewList[*types.QResult]() + + pMetaInfo.Type = datastore_types.NewDataStoreMetaInfo() + pResults.Type = types.NewQResult(0) + + params.Each(func(_ int, param *datastore_types.DataStoreGetMetaParam) bool { + var objectInfo *datastore_types.DataStoreMetaInfo + var errCode *nex.Error + + // * Real server ignores PersistenceTarget if DataID is set + if param.DataID.Value == 0 { + objectInfo, errCode = commonProtocol.GetObjectInfoByPersistenceTargetWithPassword(param.PersistenceTarget, param.AccessPassword) + } else { + objectInfo, errCode = commonProtocol.GetObjectInfoByDataIDWithPassword(param.DataID, param.AccessPassword) + } + + if errCode != nil { + objectInfo = datastore_types.NewDataStoreMetaInfo() + + pResults.Append(types.NewQResultError(errCode.ResultCode)) + } else { + errCode = commonProtocol.VerifyObjectPermission(objectInfo.OwnerID, connection.PID(), objectInfo.Permission) + if errCode != nil { + objectInfo = datastore_types.NewDataStoreMetaInfo() + + pResults.Append(types.NewQResultError(errCode.ResultCode)) + } else { + pResults.Append(types.NewQResultSuccess(nex.ResultCodes.DataStore.Unknown)) + } + + objectInfo.FilterPropertiesByResultOption(param.ResultOption) + } + + pMetaInfo.Append(objectInfo) + + return false + }) + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pMetaInfo.WriteTo(rmcResponseStream) + pResults.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = datastore.ProtocolID + rmcResponse.MethodID = datastore.MethodGetMetasMultipleParam + rmcResponse.CallID = callID + + if commonProtocol.OnAfterGetMetasMultipleParam != nil { + go commonProtocol.OnAfterGetMetasMultipleParam(packet, params) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/datastore/post_meta_binary.go b/nex-protocols-common-go/datastore/post_meta_binary.go new file mode 100644 index 0000000..3ab4ffd --- /dev/null +++ b/nex-protocols-common-go/datastore/post_meta_binary.go @@ -0,0 +1,74 @@ +package datastore + +import ( + "github.com/PretendoNetwork/nex-go/v2" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +func (commonProtocol *CommonProtocol) postMetaBinary(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error) { + // * This method looks to function identically to DataStore::PreparePostObject, + // * except the only difference being it doesn't return an S3 upload URL. This + // * needs to be verified though, as there are other methods in the family such + // * as DataStore::PostMetaBinaryWithDataID which make less sense in this context, + // * unless those are just used to *update* a meta binary? Or maybe the DataID in + // * those methods is a pre-allocated DataID from the server? Needs more testing + + if commonProtocol.InitializeObjectByPreparePostParam == nil { + common_globals.Logger.Warning("InitializeObjectByPreparePostParam not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.InitializeObjectRatingWithSlot == nil { + common_globals.Logger.Warning("InitializeObjectRatingWithSlot not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + // TODO - Need to verify what param.PersistenceInitParam.DeleteLastObject really means. It's often set to true even when it wouldn't make sense + dataID, errCode := commonProtocol.InitializeObjectByPreparePostParam(connection.PID(), param) + if errCode != nil { + common_globals.Logger.Errorf("Error code on object init: %s", errCode.Error()) + return nil, errCode + } + + // TODO - Should this be moved to InitializeObjectByPreparePostParam? + param.RatingInitParams.Each(func(_ int, ratingInitParamWithSlot *datastore_types.DataStoreRatingInitParamWithSlot) bool { + errCode = commonProtocol.InitializeObjectRatingWithSlot(dataID, ratingInitParamWithSlot) + if errCode != nil { + common_globals.Logger.Errorf("Error code on rating init: %s", errCode.Error()) + return true + } + + return false + }) + + if errCode != nil { + return nil, errCode + } + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + rmcResponseStream.WritePrimitiveUInt64LE(dataID) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = datastore.ProtocolID + rmcResponse.MethodID = datastore.MethodPostMetaBinary + rmcResponse.CallID = callID + + if commonProtocol.OnAfterPostMetaBinary != nil { + go commonProtocol.OnAfterPostMetaBinary(packet, param) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/datastore/prepare_get_object.go b/nex-protocols-common-go/datastore/prepare_get_object.go new file mode 100644 index 0000000..1ab9254 --- /dev/null +++ b/nex-protocols-common-go/datastore/prepare_get_object.go @@ -0,0 +1,84 @@ +package datastore + +import ( + "fmt" + "time" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +func (commonProtocol *CommonProtocol) prepareGetObject(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePrepareGetParam) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.GetObjectInfoByDataID == nil { + common_globals.Logger.Warning("GetObjectInfoByDataID not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.S3Presigner == nil { + common_globals.Logger.Warning("S3Presigner not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.Unknown, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + bucket := commonProtocol.S3Bucket + key := fmt.Sprintf("%s/%d.bin", commonProtocol.s3DataKeyBase, param.DataID) + + objectInfo, errCode := commonProtocol.GetObjectInfoByDataID(param.DataID) + if errCode != nil { + return nil, errCode + } + + errCode = commonProtocol.VerifyObjectPermission(objectInfo.OwnerID, connection.PID(), objectInfo.Permission) + if errCode != nil { + return nil, errCode + } + + url, err := commonProtocol.S3Presigner.GetObject(bucket, key, time.Minute*15) + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.DataStore.OperationNotAllowed, "change_error") + } + + requestHeaders, errCode := commonProtocol.S3GetRequestHeaders() + if errCode != nil { + return nil, errCode + } + + pReqGetInfo := datastore_types.NewDataStoreReqGetInfo() + + pReqGetInfo.URL = types.NewString(url.String()) + pReqGetInfo.RequestHeaders = types.NewList[*datastore_types.DataStoreKeyValue]() + pReqGetInfo.Size = objectInfo.Size.Copy().(*types.PrimitiveU32) + pReqGetInfo.RootCACert = types.NewBuffer(commonProtocol.RootCACert) + pReqGetInfo.DataID = param.DataID + + pReqGetInfo.RequestHeaders.Type = datastore_types.NewDataStoreKeyValue() + pReqGetInfo.RequestHeaders.SetFromData(requestHeaders) + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pReqGetInfo.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = datastore.ProtocolID + rmcResponse.MethodID = datastore.MethodPrepareGetObject + rmcResponse.CallID = callID + + if commonProtocol.OnAfterPrepareGetObject != nil { + go commonProtocol.OnAfterPrepareGetObject(packet, param) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/datastore/prepare_post_object.go b/nex-protocols-common-go/datastore/prepare_post_object.go new file mode 100644 index 0000000..9e4f7f5 --- /dev/null +++ b/nex-protocols-common-go/datastore/prepare_post_object.go @@ -0,0 +1,112 @@ +package datastore + +import ( + "fmt" + "time" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +func (commonProtocol *CommonProtocol) preparePostObject(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.InitializeObjectByPreparePostParam == nil { + common_globals.Logger.Warning("InitializeObjectByPreparePostParam not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.InitializeObjectRatingWithSlot == nil { + common_globals.Logger.Warning("InitializeObjectRatingWithSlot not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.S3Presigner == nil { + common_globals.Logger.Warning("S3Presigner not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + // TODO - Need to verify what param.PersistenceInitParam.DeleteLastObject really means. It's often set to true even when it wouldn't make sense + dataID, errCode := commonProtocol.InitializeObjectByPreparePostParam(connection.PID(), param) + if errCode != nil { + common_globals.Logger.Errorf("Error on object init: %s", errCode.Error()) + return nil, errCode + } + + // TODO - Should this be moved to InitializeObjectByPreparePostParam? + param.RatingInitParams.Each(func(_ int, ratingInitParamWithSlot *datastore_types.DataStoreRatingInitParamWithSlot) bool { + errCode = commonProtocol.InitializeObjectRatingWithSlot(dataID, ratingInitParamWithSlot) + if errCode != nil { + common_globals.Logger.Errorf("Error on rating init: %s", errCode.Error()) + + return true + } + + return false + }) + + if errCode != nil { + return nil, errCode + } + + bucket := commonProtocol.S3Bucket + key := fmt.Sprintf("%s/%d.bin", commonProtocol.s3DataKeyBase, dataID) + + URL, formData, err := commonProtocol.S3Presigner.PostObject(bucket, key, time.Minute*15) + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.DataStore.OperationNotAllowed, "change_error") + } + + requestHeaders, errCode := commonProtocol.S3PostRequestHeaders() + if errCode != nil { + return nil, errCode + } + + pReqPostInfo := datastore_types.NewDataStoreReqPostInfo() + + pReqPostInfo.DataID = types.NewPrimitiveU64(dataID) + pReqPostInfo.URL = types.NewString(URL.String()) + pReqPostInfo.RequestHeaders = types.NewList[*datastore_types.DataStoreKeyValue]() + pReqPostInfo.FormFields = types.NewList[*datastore_types.DataStoreKeyValue]() + pReqPostInfo.RootCACert = types.NewBuffer(commonProtocol.RootCACert) + + pReqPostInfo.RequestHeaders.Type = datastore_types.NewDataStoreKeyValue() + pReqPostInfo.RequestHeaders.SetFromData(requestHeaders) + + pReqPostInfo.FormFields.Type = datastore_types.NewDataStoreKeyValue() + + for key, value := range formData { + field := datastore_types.NewDataStoreKeyValue() + field.Key = types.NewString(key) + field.Value = types.NewString(value) + + pReqPostInfo.FormFields.Append(field) + } + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pReqPostInfo.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = datastore.ProtocolID + rmcResponse.MethodID = datastore.MethodPreparePostObject + rmcResponse.CallID = callID + + if commonProtocol.OnAfterPreparePostObject != nil { + go commonProtocol.OnAfterPreparePostObject(packet, param) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/datastore/protocol.go b/nex-protocols-common-go/datastore/protocol.go new file mode 100644 index 0000000..6b2bcab --- /dev/null +++ b/nex-protocols-common-go/datastore/protocol.go @@ -0,0 +1,163 @@ +package datastore + +import ( + "context" + "slices" + "strings" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/minio/minio-go/v7" +) + +type CommonProtocol struct { + endpoint nex.EndpointInterface + protocol datastore.Interface + S3Bucket string + s3DataKeyBase string + s3NotifyKeyBase string + RootCACert []byte + minIOClient *minio.Client + S3Presigner S3PresignerInterface + GetUserFriendPIDs func(pid uint32) []uint32 + GetObjectInfoByDataID func(dataID *types.PrimitiveU64) (*datastore_types.DataStoreMetaInfo, *nex.Error) + UpdateObjectPeriodByDataIDWithPassword func(dataID *types.PrimitiveU64, dataType *types.PrimitiveU16, password *types.PrimitiveU64) *nex.Error + UpdateObjectMetaBinaryByDataIDWithPassword func(dataID *types.PrimitiveU64, metaBinary *types.QBuffer, password *types.PrimitiveU64) *nex.Error + UpdateObjectDataTypeByDataIDWithPassword func(dataID *types.PrimitiveU64, period *types.PrimitiveU16, password *types.PrimitiveU64) *nex.Error + GetObjectSizeByDataID func(dataID *types.PrimitiveU64) (uint32, *nex.Error) + UpdateObjectUploadCompletedByDataID func(dataID *types.PrimitiveU64, uploadCompleted bool) *nex.Error + GetObjectInfoByPersistenceTargetWithPassword func(persistenceTarget *datastore_types.DataStorePersistenceTarget, password *types.PrimitiveU64) (*datastore_types.DataStoreMetaInfo, *nex.Error) + GetObjectInfoByDataIDWithPassword func(dataID *types.PrimitiveU64, password *types.PrimitiveU64) (*datastore_types.DataStoreMetaInfo, *nex.Error) + S3GetRequestHeaders func() ([]*datastore_types.DataStoreKeyValue, *nex.Error) + S3PostRequestHeaders func() ([]*datastore_types.DataStoreKeyValue, *nex.Error) + InitializeObjectByPreparePostParam func(ownerPID *types.PID, param *datastore_types.DataStorePreparePostParam) (uint64, *nex.Error) + InitializeObjectRatingWithSlot func(dataID uint64, param *datastore_types.DataStoreRatingInitParamWithSlot) *nex.Error + RateObjectWithPassword func(dataID *types.PrimitiveU64, slot *types.PrimitiveU8, ratingValue *types.PrimitiveS32, accessPassword *types.PrimitiveU64) (*datastore_types.DataStoreRatingInfo, *nex.Error) + DeleteObjectByDataIDWithPassword func(dataID *types.PrimitiveU64, password *types.PrimitiveU64) *nex.Error + DeleteObjectByDataID func(dataID *types.PrimitiveU64) *nex.Error + GetObjectInfosByDataStoreSearchParam func(param *datastore_types.DataStoreSearchParam) ([]*datastore_types.DataStoreMetaInfo, uint32, *nex.Error) + GetObjectOwnerByDataID func(dataID *types.PrimitiveU64) (uint32, *nex.Error) + OnAfterDeleteObject func(packet nex.PacketInterface, param *datastore_types.DataStoreDeleteParam) + OnAfterGetMeta func(packet nex.PacketInterface, param *datastore_types.DataStoreGetMetaParam) + OnAfterGetMetas func(packet nex.PacketInterface, dataIDs *types.List[*types.PrimitiveU64], param *datastore_types.DataStoreGetMetaParam) + OnAfterSearchObject func(packet nex.PacketInterface, param *datastore_types.DataStoreSearchParam) + OnAfterRateObject func(packet nex.PacketInterface, target *datastore_types.DataStoreRatingTarget, param *datastore_types.DataStoreRateObjectParam, fetchRatings *types.PrimitiveBool) + OnAfterPostMetaBinary func(packet nex.PacketInterface, param *datastore_types.DataStorePreparePostParam) + OnAfterPreparePostObject func(packet nex.PacketInterface, param *datastore_types.DataStorePreparePostParam) + OnAfterPrepareGetObject func(packet nex.PacketInterface, param *datastore_types.DataStorePrepareGetParam) + OnAfterCompletePostObject func(packet nex.PacketInterface, param *datastore_types.DataStoreCompletePostParam) + OnAfterGetMetasMultipleParam func(packet nex.PacketInterface, params *types.List[*datastore_types.DataStoreGetMetaParam]) + OnAfterCompletePostObjects func(packet nex.PacketInterface, dataIDs *types.List[*types.PrimitiveU64]) + OnAfterChangeMeta func(packet nex.PacketInterface, param *datastore_types.DataStoreChangeMetaParam) + OnAfterRateObjects func(packet nex.PacketInterface, targets *types.List[*datastore_types.DataStoreRatingTarget], params *types.List[*datastore_types.DataStoreRateObjectParam], transactional *types.PrimitiveBool, fetchRatings *types.PrimitiveBool) +} + +func (c *CommonProtocol) S3StatObject(bucket, key string) (minio.ObjectInfo, error) { + return c.minIOClient.StatObject(context.TODO(), bucket, key, minio.StatObjectOptions{}) +} + +func (c *CommonProtocol) S3ObjectSize(bucket, key string) (uint64, error) { + info, err := c.S3StatObject(bucket, key) + if err != nil { + return 0, err + } + + return uint64(info.Size), nil +} + +func (c *CommonProtocol) VerifyObjectPermission(ownerPID, accessorPID *types.PID, permission *datastore_types.DataStorePermission) *nex.Error { + if permission.Permission.Value > 3 { + return nex.NewError(nex.ResultCodes.DataStore.InvalidArgument, "change_error") + } + + // * Owner can always access their own objects + if ownerPID.Equals(accessorPID) { + return nil + } + + // * Allow anyone + if permission.Permission.Value == 0 { + return nil + } + + // * Allow only friends of the owner + if permission.Permission.Value == 1 { + // TODO - This assumes a legacy client. Will not work on the Switch + friendsList := c.GetUserFriendPIDs(ownerPID.LegacyValue()) + + if !slices.Contains(friendsList, accessorPID.LegacyValue()) { + return nex.NewError(nex.ResultCodes.DataStore.PermissionDenied, "change_error") + } + } + + // * Allow only users whose PIDs are defined in permission.RecipientIDs + if permission.Permission.Value == 2 { + if !permission.RecipientIDs.Contains(accessorPID) { + return nex.NewError(nex.ResultCodes.DataStore.PermissionDenied, "change_error") + } + } + + // * Allow only the owner + if permission.Permission.Value == 3 { + if !ownerPID.Equals(accessorPID) { + return nex.NewError(nex.ResultCodes.DataStore.PermissionDenied, "change_error") + } + } + + return nil +} + +// SetDataKeyBase sets the base for the key to be used when uploading standard DataStore objects +func (c *CommonProtocol) SetDataKeyBase(base string) { + // * Just in case someone passes a badly formatted key + base = strings.TrimPrefix(base, "/") + base = strings.TrimSuffix(base, "/") + c.s3DataKeyBase = base +} + +// SetNotifyKeyBase sets the base for the key to be used when uploading DataStore notification data +func (c *CommonProtocol) SetNotifyKeyBase(base string) { + // * Just in case someone passes a badly formatted key + base = strings.TrimPrefix(base, "/") + base = strings.TrimSuffix(base, "/") + c.s3NotifyKeyBase = base +} + +// SetMinIOClient sets the MinIO S3 client +func (c *CommonProtocol) SetMinIOClient(client *minio.Client) { + c.minIOClient = client + c.S3Presigner = NewS3Presigner(c.minIOClient) +} + +// NewCommonProtocol returns a new CommonProtocol +func NewCommonProtocol(protocol datastore.Interface) *CommonProtocol { + commonProtocol := &CommonProtocol{ + endpoint: protocol.Endpoint(), + protocol: protocol, + RootCACert: []byte{}, + S3GetRequestHeaders: func() ([]*datastore_types.DataStoreKeyValue, *nex.Error) { + return []*datastore_types.DataStoreKeyValue{}, nil + }, + S3PostRequestHeaders: func() ([]*datastore_types.DataStoreKeyValue, *nex.Error) { + return []*datastore_types.DataStoreKeyValue{}, nil + }, + } + + protocol.SetHandlerDeleteObject(commonProtocol.deleteObject) + protocol.SetHandlerGetMeta(commonProtocol.getMeta) + protocol.SetHandlerGetMetas(commonProtocol.getMetas) + protocol.SetHandlerSearchObject(commonProtocol.searchObject) + protocol.SetHandlerRateObject(commonProtocol.rateObject) + protocol.SetHandlerPostMetaBinary(commonProtocol.postMetaBinary) + protocol.SetHandlerPreparePostObject(commonProtocol.preparePostObject) + protocol.SetHandlerPrepareGetObject(commonProtocol.prepareGetObject) + protocol.SetHandlerCompletePostObject(commonProtocol.completePostObject) + protocol.SetHandlerGetMetasMultipleParam(commonProtocol.getMetasMultipleParam) + protocol.SetHandlerCompletePostObjects(commonProtocol.completePostObjects) + protocol.SetHandlerChangeMeta(commonProtocol.changeMeta) + protocol.SetHandlerRateObjects(commonProtocol.rateObjects) + + return commonProtocol +} diff --git a/nex-protocols-common-go/datastore/rate_object.go b/nex-protocols-common-go/datastore/rate_object.go new file mode 100644 index 0000000..b146a80 --- /dev/null +++ b/nex-protocols-common-go/datastore/rate_object.go @@ -0,0 +1,69 @@ +package datastore + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +func (commonProtocol *CommonProtocol) rateObject(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, param *datastore_types.DataStoreRateObjectParam, fetchRatings *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.GetObjectInfoByDataIDWithPassword == nil { + common_globals.Logger.Warning("GetObjectInfoByDataIDWithPassword not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.RateObjectWithPassword == nil { + common_globals.Logger.Warning("RateObjectWithPassword not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + objectInfo, errCode := commonProtocol.GetObjectInfoByDataIDWithPassword(target.DataID, param.AccessPassword) + if errCode != nil { + return nil, errCode + } + + errCode = commonProtocol.VerifyObjectPermission(objectInfo.OwnerID, connection.PID(), objectInfo.Permission) + if errCode != nil { + return nil, errCode + } + + pRating, errCode := commonProtocol.RateObjectWithPassword(target.DataID, target.Slot, param.RatingValue, param.AccessPassword) + if errCode != nil { + return nil, errCode + } + + // * This is kinda backwards. Server returns + // * the rating by default, so we check if + // * the client DOESN'T want it and then just + // * zero it out + if !fetchRatings.Value { + pRating = datastore_types.NewDataStoreRatingInfo() + } + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pRating.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = datastore.ProtocolID + rmcResponse.MethodID = datastore.MethodRateObject + rmcResponse.CallID = callID + + if commonProtocol.OnAfterRateObject != nil { + go commonProtocol.OnAfterRateObject(packet, target, param, fetchRatings) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/datastore/rate_objects.go b/nex-protocols-common-go/datastore/rate_objects.go new file mode 100644 index 0000000..d077d7a --- /dev/null +++ b/nex-protocols-common-go/datastore/rate_objects.go @@ -0,0 +1,99 @@ +package datastore + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +func (commonProtocol *CommonProtocol) rateObjects(err error, packet nex.PacketInterface, callID uint32, targets *types.List[*datastore_types.DataStoreRatingTarget], params *types.List[*datastore_types.DataStoreRateObjectParam], transactional *types.PrimitiveBool, fetchRatings *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.GetObjectInfoByDataIDWithPassword == nil { + common_globals.Logger.Warning("GetObjectInfoByDataIDWithPassword not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if commonProtocol.RateObjectWithPassword == nil { + common_globals.Logger.Warning("RateObjectWithPassword not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + pRatings := types.NewList[*datastore_types.DataStoreRatingInfo]() + pResults := types.NewList[*types.QResult]() + + pRatings.Type = datastore_types.NewDataStoreRatingInfo() + pResults.Type = types.NewQResult(0) + + // * Real DataStore does not actually check this. + // * I just didn't feel like working out the + // * logic for differing sized lists. So force + // * them to always be the same + if targets.Length() != params.Length() { + return nil, nex.NewError(nex.ResultCodes.DataStore.InvalidArgument, "change_error") + } + + var errorCode *nex.Error + + targets.Each(func(i int, target *datastore_types.DataStoreRatingTarget) bool { + param, err := params.Get(i) + if err != nil { + errorCode = nex.NewError(nex.ResultCodes.DataStore.InvalidArgument, "change_error") + return true + } + + objectInfo, errCode := commonProtocol.GetObjectInfoByDataIDWithPassword(target.DataID, param.AccessPassword) + if errCode != nil { + errorCode = errCode + return true + } + + errCode = commonProtocol.VerifyObjectPermission(objectInfo.OwnerID, connection.PID(), objectInfo.Permission) + if errCode != nil { + errorCode = errCode + return true + } + + rating, errCode := commonProtocol.RateObjectWithPassword(target.DataID, target.Slot, param.RatingValue, param.AccessPassword) + if errCode != nil { + errorCode = errCode + return true + } + + if fetchRatings.Value { + pRatings.Append(rating) + } + + return false + }) + + if errorCode != nil { + return nil, errorCode + } + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pRatings.WriteTo(rmcResponseStream) + pResults.WriteTo(rmcResponseStream) // * pResults is ALWAYS empty in SMM? + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = datastore.ProtocolID + rmcResponse.MethodID = datastore.MethodRateObjects + rmcResponse.CallID = callID + + if commonProtocol.OnAfterRateObjects != nil { + go commonProtocol.OnAfterRateObjects(packet, targets, params, transactional, fetchRatings) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/datastore/s3_presigner.go b/nex-protocols-common-go/datastore/s3_presigner.go new file mode 100644 index 0000000..e2e84f6 --- /dev/null +++ b/nex-protocols-common-go/datastore/s3_presigner.go @@ -0,0 +1,51 @@ +package datastore + +import ( + "context" + "net/url" + "time" + + "github.com/minio/minio-go/v7" +) + +type S3PresignerInterface interface { + GetObject(bucket, key string, lifetime time.Duration) (*url.URL, error) + PostObject(bucket, key string, lifetime time.Duration) (*url.URL, map[string]string, error) +} + +type S3Presigner struct { + minio *minio.Client +} + +func (p *S3Presigner) GetObject(bucket, key string, lifetime time.Duration) (*url.URL, error) { + reqParams := make(url.Values) + + return p.minio.PresignedGetObject(context.Background(), bucket, key, lifetime, reqParams) +} + +func (p *S3Presigner) PostObject(bucket, key string, lifetime time.Duration) (*url.URL, map[string]string, error) { + policy := minio.NewPostPolicy() + + err := policy.SetBucket(bucket) + if err != nil { + return nil, nil, err + } + + err = policy.SetKey(key) + if err != nil { + return nil, nil, err + } + + err = policy.SetExpires(time.Now().UTC().Add(lifetime).UTC()) + if err != nil { + return nil, nil, err + } + + return p.minio.PresignedPostPolicy(context.Background(), policy) +} + +func NewS3Presigner(minioClient *minio.Client) *S3Presigner { + return &S3Presigner{ + minio: minioClient, + } +} diff --git a/nex-protocols-common-go/datastore/search_object.go b/nex-protocols-common-go/datastore/search_object.go new file mode 100644 index 0000000..0d22eb9 --- /dev/null +++ b/nex-protocols-common-go/datastore/search_object.go @@ -0,0 +1,98 @@ +package datastore + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +func (commonProtocol *CommonProtocol) searchObject(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.GetObjectInfosByDataStoreSearchParam == nil { + common_globals.Logger.Warning("GetObjectInfosByDataStoreSearchParam not defined") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.DataStore.Unknown, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + // * This is likely game-specific. Also developer note: + // * Please keep in mind that no results is allowed. errCode + // * should NEVER be DataStore::NotFound! + // * + // * DataStoreSearchParam contains a ResultRange to limit the + // * returned results. TotalCount is the total matching objects + // * in the database, whereas objects is the limited results + objects, totalCount, errCode := commonProtocol.GetObjectInfosByDataStoreSearchParam(param) + if errCode != nil { + return nil, errCode + } + + pSearchResult := datastore_types.NewDataStoreSearchResult() + + pSearchResult.Result = types.NewList[*datastore_types.DataStoreMetaInfo]() + pSearchResult.Result.Type = datastore_types.NewDataStoreMetaInfo() + + for _, object := range objects { + errCode = commonProtocol.VerifyObjectPermission(object.OwnerID, connection.PID(), object.Permission) + if errCode != nil { + // * Since we don't error here, should we also + // * "hide" these results by also decrementing + // * totalCount? + continue + } + + object.FilterPropertiesByResultOption(param.ResultOption) + + pSearchResult.Result.Append(object) + } + + var totalCountType uint8 + + // * Doing this here since the object + // * the permissions checks in the + // * previous loop will mutate the data + // * returned from the database + if totalCount == uint32(pSearchResult.Result.Length()) { + totalCountType = 0 // * Has no more data. All possible results were returned + } else { + totalCountType = 1 // * Has more data. Not all possible results were returned + } + + // * Disables the TotalCount + // * + // * Only seen in struct revision 3 or + // * NEX 4.0+ + if param.StructureVersion >= 3 || endpoint.LibraryVersions().DataStore.GreaterOrEqual("4.0.0") { + if !param.TotalCountEnabled.Value { + totalCount = 0 + totalCountType = 3 + } + } + + pSearchResult.TotalCount = types.NewPrimitiveU32(totalCount) + pSearchResult.TotalCountType = types.NewPrimitiveU8(totalCountType) + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pSearchResult.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = datastore.ProtocolID + rmcResponse.MethodID = datastore.MethodSearchObject + rmcResponse.CallID = callID + + if commonProtocol.OnAfterSearchObject != nil { + go commonProtocol.OnAfterSearchObject(packet, param) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/globals/globals.go b/nex-protocols-common-go/globals/globals.go new file mode 100644 index 0000000..fd843d3 --- /dev/null +++ b/nex-protocols-common-go/globals/globals.go @@ -0,0 +1,7 @@ +package common_globals + +import ( + "github.com/PretendoNetwork/plogger-go" +) + +var Logger = plogger.NewLogger() diff --git a/nex-protocols-common-go/globals/matchmaking_globals.go b/nex-protocols-common-go/globals/matchmaking_globals.go new file mode 100644 index 0000000..135f91f --- /dev/null +++ b/nex-protocols-common-go/globals/matchmaking_globals.go @@ -0,0 +1,17 @@ +package common_globals + +import ( + "github.com/PretendoNetwork/nex-go/v2" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +type CommonMatchmakeSession struct { + GameMatchmakeSession *match_making_types.MatchmakeSession // * Used by the game, contains the current state of the MatchmakeSession + SearchMatchmakeSession *match_making_types.MatchmakeSession // * Used by the server when searching for matches, contains the state of the MatchmakeSession during the search process for easy compares + ConnectionIDs *nex.MutexSlice[uint32] // * Players in the room, referenced by their connection IDs. This is used instead of the PID in order to ensure we're talking to the correct client (in case of e.g. multiple logins) +} + +var Sessions map[uint32]*CommonMatchmakeSession +var GetUserFriendPIDsHandler func(pid uint32) []uint32 +var CurrentGatheringID = nex.NewCounter[uint32](0) +var CurrentMatchmakingCallID = nex.NewCounter[uint32](0) diff --git a/nex-protocols-common-go/globals/matchmaking_utils.go b/nex-protocols-common-go/globals/matchmaking_utils.go new file mode 100644 index 0000000..6335d53 --- /dev/null +++ b/nex-protocols-common-go/globals/matchmaking_utils.go @@ -0,0 +1,627 @@ +package common_globals + +import ( + "crypto/rand" + "fmt" + "strconv" + "strings" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/constants" + "github.com/PretendoNetwork/nex-go/v2/types" + match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" + notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications" + notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types" + "golang.org/x/exp/slices" +) + +// GetAvailableGatheringID returns a gathering ID which doesn't belong to any session +// Returns 0 if no IDs are available (math.MaxUint32 has been reached) +func GetAvailableGatheringID() uint32 { + return CurrentGatheringID.Next() +} + +// FindOtherConnectionID searches a connection ID on the session that isn't the given one +// Returns 0 if no connection ID could be found +func FindOtherConnectionID(excludedConnectionID uint32, gatheringID uint32) uint32 { + var otherConnectionID uint32 = 0 + if session, ok := Sessions[gatheringID]; ok { + session.ConnectionIDs.Each(func(_ int, connectionID uint32) bool { + if connectionID != excludedConnectionID { + otherConnectionID = connectionID + return true + } + + return false + }) + } + + return otherConnectionID +} + +// RemoveConnectionIDFromSession removes a PRUDP connection from the session +func RemoveConnectionIDFromSession(id uint32, gathering uint32) { + Sessions[gathering].ConnectionIDs.DeleteAll(id) + + if Sessions[gathering].ConnectionIDs.Size() == 0 { + delete(Sessions, gathering) + } else { + // Update the participation count with the new connection ID count + Sessions[gathering].GameMatchmakeSession.ParticipationCount.Value = uint32(Sessions[gathering].ConnectionIDs.Size()) + } +} + +// FindConnectionSession searches for session the given connection ID is connected to +func FindConnectionSession(id uint32) uint32 { + for gatheringID := range Sessions { + if Sessions[gatheringID].ConnectionIDs.Has(id) { + return gatheringID + } + } + + return 0 +} + +// RemoveConnectionFromAllSessions removes a connection from every session +func RemoveConnectionFromAllSessions(connection *nex.PRUDPConnection) { + // * Keep checking until no session is found + for gid := FindConnectionSession(connection.ID); gid != 0; { + session := Sessions[gid] + lenParticipants := session.ConnectionIDs.Size() + + RemoveConnectionIDFromSession(connection.ID, gid) + + if lenParticipants <= 1 { + gid = FindConnectionSession(connection.ID) + continue + } + + ownerPID := session.GameMatchmakeSession.Gathering.OwnerPID + + if ownerPID.Equals(connection.PID()) { + // * This flag tells the server to change the matchmake session owner if they disconnect + // * If the flag is not set, delete the session + // * More info: https://nintendo-wiki.pretendo.network/docs/nex/protocols/match-making/types#flags + if session.GameMatchmakeSession.Gathering.Flags.PAND(match_making.GatheringFlags.DisconnectChangeOwner) == 0 { + delete(Sessions, gid) + } else { + ChangeSessionOwner(connection, gid, true) + } + } else { + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + server := endpoint.Server + + category := notifications.NotificationCategories.Participation + subtype := notifications.NotificationSubTypes.Participation.Disconnected + + oEvent := notifications_types.NewNotificationEvent() + oEvent.PIDSource = connection.PID() + oEvent.Type = types.NewPrimitiveU32(notifications.BuildNotificationType(category, subtype)) + oEvent.Param1 = types.NewPrimitiveU32(gid) + oEvent.Param2 = types.NewPrimitiveU32(connection.PID().LegacyValue()) // TODO - This assumes a legacy client. This won't work on the Switch + + stream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + oEvent.WriteTo(stream) + + rmcRequest := nex.NewRMCRequest(endpoint) + rmcRequest.ProtocolID = notifications.ProtocolID + rmcRequest.CallID = CurrentMatchmakingCallID.Next() + rmcRequest.MethodID = notifications.MethodProcessNotificationEvent + rmcRequest.Parameters = stream.Bytes() + + rmcRequestBytes := rmcRequest.Bytes() + + target := endpoint.FindConnectionByPID(ownerPID.Value()) + if target == nil { + Logger.Warning("Target connection not found") + gid = FindConnectionSession(connection.ID) + continue + } + + var messagePacket nex.PRUDPPacketInterface + + if connection.DefaultPRUDPVersion == 0 { + messagePacket, _ = nex.NewPRUDPPacketV0(server, target, nil) + } else { + messagePacket, _ = nex.NewPRUDPPacketV1(server, target, nil) + } + + messagePacket.SetType(constants.DataPacket) + messagePacket.AddFlag(constants.PacketFlagNeedsAck) + messagePacket.AddFlag(constants.PacketFlagReliable) + messagePacket.SetSourceVirtualPortStreamType(connection.StreamType) + messagePacket.SetSourceVirtualPortStreamID(endpoint.StreamID) + messagePacket.SetDestinationVirtualPortStreamType(connection.StreamType) + messagePacket.SetDestinationVirtualPortStreamID(connection.StreamID) + messagePacket.SetPayload(rmcRequestBytes) + + server.Send(messagePacket) + } + + gid = FindConnectionSession(connection.ID) + } +} + +// CreateSessionByMatchmakeSession creates a gathering from a MatchmakeSession +func CreateSessionByMatchmakeSession(matchmakeSession *match_making_types.MatchmakeSession, searchMatchmakeSession *match_making_types.MatchmakeSession, hostPID *types.PID) (*CommonMatchmakeSession, *nex.Error) { + sessionIndex := GetAvailableGatheringID() + if sessionIndex == 0 { + sessionIndex = GetAvailableGatheringID() // * Skip to index 1 + } + + session := CommonMatchmakeSession{ + SearchMatchmakeSession: searchMatchmakeSession, + GameMatchmakeSession: matchmakeSession, + ConnectionIDs: nex.NewMutexSlice[uint32](), + } + + session.GameMatchmakeSession.Gathering.ID = types.NewPrimitiveU32(sessionIndex) + session.GameMatchmakeSession.Gathering.OwnerPID = hostPID + session.GameMatchmakeSession.Gathering.HostPID = hostPID + + session.GameMatchmakeSession.StartedTime = types.NewDateTime(0).Now() + session.GameMatchmakeSession.SessionKey = types.NewBuffer(make([]byte, 32)) + + rand.Read(session.GameMatchmakeSession.SessionKey.Value) + + SR := types.NewVariant() + SR.TypeID = types.NewPrimitiveU8(3) + SR.Type = types.NewPrimitiveBool(true) + + GIR := types.NewVariant() + GIR.TypeID = types.NewPrimitiveU8(1) + GIR.Type = types.NewPrimitiveS64(3) + + session.GameMatchmakeSession.MatchmakeParam.Params.Set(types.NewString("@SR"), SR) + session.GameMatchmakeSession.MatchmakeParam.Params.Set(types.NewString("@GIR"), GIR) + + Sessions[sessionIndex] = &session + + return Sessions[sessionIndex], nil +} + +// FindSessionByMatchmakeSession finds a gathering that matches with a MatchmakeSession +func FindSessionByMatchmakeSession(pid *types.PID, searchMatchmakeSession *match_making_types.MatchmakeSession) uint32 { + // * This portion finds any sessions that match the search session + // * It does not care about anything beyond that, such as if the match is already full + // * This is handled below + candidateSessionIndexes := make([]uint32, 0, len(Sessions)) + for index, session := range Sessions { + if session.SearchMatchmakeSession.Equals(searchMatchmakeSession) { + candidateSessionIndexes = append(candidateSessionIndexes, index) + } + } + + // TODO - This whole section assumes legacy clients. None of it will work on the Switch + var friendList []uint32 + for _, sessionIndex := range candidateSessionIndexes { + sessionToCheck := Sessions[sessionIndex] + if sessionToCheck.ConnectionIDs.Size() >= int(sessionToCheck.GameMatchmakeSession.MaximumParticipants.Value) { + continue + } + + if !sessionToCheck.GameMatchmakeSession.OpenParticipation.Value { + continue + } + + // * If the session only allows friends, check if the owner is in the friend list of the PID + // TODO - Is this a flag or a constant? + if sessionToCheck.GameMatchmakeSession.ParticipationPolicy.Value == 98 { + if GetUserFriendPIDsHandler == nil { + Logger.Warning("Missing GetUserFriendPIDsHandler!") + continue + } + + if len(friendList) == 0 { + friendList = GetUserFriendPIDsHandler(pid.LegacyValue()) // TODO - This grpc method needs to support the Switch + } + + if !slices.Contains(friendList, sessionToCheck.GameMatchmakeSession.OwnerPID.LegacyValue()) { + continue + } + } + + return sessionIndex // * Found a match + } + + return 0 +} + +// FindSessionsByMatchmakeSessionSearchCriterias finds a gathering that matches with the given search criteria +func FindSessionsByMatchmakeSessionSearchCriterias(pid *types.PID, searchCriterias []*match_making_types.MatchmakeSessionSearchCriteria, gameSpecificChecks func(searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, matchmakeSession *match_making_types.MatchmakeSession) bool) []*CommonMatchmakeSession { + candidateSessions := make([]*CommonMatchmakeSession, 0, len(Sessions)) + + // TODO - This whole section assumes legacy clients. None of it will work on the Switch + var friendList []uint32 + for _, session := range Sessions { + for _, criteria := range searchCriterias { + // * Check things like game specific attributes + if gameSpecificChecks != nil { + if !gameSpecificChecks(criteria, session.GameMatchmakeSession) { + continue + } + } else { + if !compareAttributesSearchCriteria(session.GameMatchmakeSession.Attributes.Slice(), criteria.Attribs.Slice()) { + continue + } + } + + if !compareSearchCriteria(session.GameMatchmakeSession.MaximumParticipants.Value, criteria.MaxParticipants.Value) { + continue + } + + if !compareSearchCriteria(session.GameMatchmakeSession.MinimumParticipants.Value, criteria.MinParticipants.Value) { + continue + } + + if !compareSearchCriteria(session.GameMatchmakeSession.MatchmakeSystemType.Value, criteria.MatchmakeSystemType.Value) { + continue + } + + if !compareSearchCriteria(session.GameMatchmakeSession.GameMode.Value, criteria.GameMode.Value) { + continue + } + + if session.ConnectionIDs.Size() >= int(session.GameMatchmakeSession.MaximumParticipants.Value) { + continue + } + + if !session.GameMatchmakeSession.OpenParticipation.Value { + continue + } + + // * If the session only allows friends, check if the owner is in the friend list of the PID + // TODO - Is this a flag or a constant? + if session.GameMatchmakeSession.ParticipationPolicy.Value == 98 { + if GetUserFriendPIDsHandler == nil { + Logger.Warning("Missing GetUserFriendPIDsHandler!") + continue + } + + if len(friendList) == 0 { + friendList = GetUserFriendPIDsHandler(pid.LegacyValue()) // TODO - Support the Switch + } + + if !slices.Contains(friendList, session.GameMatchmakeSession.OwnerPID.LegacyValue()) { + continue + } + } + + candidateSessions = append(candidateSessions, session) + + // We don't have to compare with other search criterias + break + } + } + + return candidateSessions +} + +func compareAttributesSearchCriteria(original []*types.PrimitiveU32, search []*types.String) bool { + if len(original) != len(search) { + return false + } + + for index, originalAttribute := range original { + searchAttribute := search[index] + + if !compareSearchCriteria(originalAttribute.Value, searchAttribute.Value) { + return false + } + } + + return true +} + +func compareSearchCriteria[T ~uint16 | ~uint32](original T, search string) bool { + if search == "" { // * Accept any value + return true + } + + before, after, found := strings.Cut(search, ",") + if found { + min, err := strconv.ParseUint(before, 10, 64) + if err != nil { + return false + } + + max, err := strconv.ParseUint(after, 10, 64) + if err != nil { + return false + } + + return min <= uint64(original) && max >= uint64(original) + } else { + searchNum, err := strconv.ParseUint(before, 10, 64) + if err != nil { + return false + } + + return searchNum == uint64(original) + } +} + +// AddPlayersToSession updates the given sessions state to include the provided connection IDs +// Returns a NEX error code if failed +func AddPlayersToSession(session *CommonMatchmakeSession, connectionIDs []uint32, initiatingConnection *nex.PRUDPConnection, joinMessage string) *nex.Error { + if (session.ConnectionIDs.Size() + len(connectionIDs)) > int(session.GameMatchmakeSession.Gathering.MaximumParticipants.Value) { + return nex.NewError(nex.ResultCodes.RendezVous.SessionFull, fmt.Sprintf("Gathering %d is full", session.GameMatchmakeSession.Gathering.ID)) + } + + for _, connectedID := range connectionIDs { + if session.ConnectionIDs.Has(connectedID) { + return nex.NewError(nex.ResultCodes.RendezVous.AlreadyParticipatedGathering, fmt.Sprintf("Connection ID %d is already in gathering %d", connectedID, session.GameMatchmakeSession.Gathering.ID)) + } + + session.ConnectionIDs.Add(connectedID) + + // Update the participation count with the new connection ID count + session.GameMatchmakeSession.ParticipationCount.Value = uint32(session.ConnectionIDs.Size()) + } + + endpoint := initiatingConnection.Endpoint().(*nex.PRUDPEndPoint) + server := endpoint.Server + + //session.ConnectionIDs.Each(func(_ int, connectionID uint32) bool { + target := endpoint.FindConnectionByPID(session.GameMatchmakeSession.OwnerPID.Value()) + if target == nil { + // TODO - Error here? + Logger.Warning("Player not found") + return nil + } + + notificationCategory := notifications.NotificationCategories.Participation + notificationSubtype := notifications.NotificationSubTypes.Participation.NewParticipant + + oEvent := notifications_types.NewNotificationEvent() + oEvent.PIDSource = initiatingConnection.PID() + oEvent.Type = types.NewPrimitiveU32(notifications.BuildNotificationType(notificationCategory, notificationSubtype)) + oEvent.Param1 = session.GameMatchmakeSession.ID.Copy().(*types.PrimitiveU32) + oEvent.Param2 = types.NewPrimitiveU32(initiatingConnection.PID().LegacyValue()) // TODO - This assumes a legacy client. Will not work on the Switch + oEvent.StrParam = types.NewString(joinMessage) + //oEvent.Param3 = types.NewPrimitiveU32(uint32(len(connectionIDs))) + + notificationStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + oEvent.WriteTo(notificationStream) + + notificationRequest := nex.NewRMCRequest(endpoint) + notificationRequest.ProtocolID = notifications.ProtocolID + notificationRequest.CallID = CurrentMatchmakingCallID.Next() + notificationRequest.MethodID = notifications.MethodProcessNotificationEvent + notificationRequest.Parameters = notificationStream.Bytes() + + notificationRequestBytes := notificationRequest.Bytes() + + var messagePacket nex.PRUDPPacketInterface + + if target.DefaultPRUDPVersion == 0 { + messagePacket, _ = nex.NewPRUDPPacketV0(server, target, nil) + } else { + messagePacket, _ = nex.NewPRUDPPacketV1(server, target, nil) + } + + messagePacket.SetType(constants.DataPacket) + messagePacket.AddFlag(constants.PacketFlagNeedsAck) + messagePacket.AddFlag(constants.PacketFlagReliable) + messagePacket.SetSourceVirtualPortStreamType(target.StreamType) + messagePacket.SetSourceVirtualPortStreamID(endpoint.StreamID) + messagePacket.SetDestinationVirtualPortStreamType(target.StreamType) + messagePacket.SetDestinationVirtualPortStreamID(target.StreamID) + messagePacket.SetPayload(notificationRequestBytes) + + server.Send(messagePacket) + + //return false + //}) + + // * This appears to be correct. Tri-Force Heroes uses 3.9.0, + // * and has issues if these notifications are sent. + // * Minecraft, however, requires these to be sent + // TODO - Check other games both pre and post 3.10.0 and validate + /*if server.LibraryVersions.MatchMaking.GreaterOrEqual("3.10.0")* / { + session.ConnectionIDs.Each(func(_ int, connectionID uint32) bool { + target := endpoint.FindConnectionByID(connectionID) + if target == nil { + // TODO - Error here? + Logger.Warning("Player not found") + return false + } + + notificationCategory := notifications.NotificationCategories.Participation + notificationSubtype := notifications.NotificationSubTypes.Participation.NewParticipant + + oEvent := notifications_types.NewNotificationEvent() + oEvent.PIDSource = initiatingConnection.PID() + oEvent.Type = types.NewPrimitiveU32(notifications.BuildNotificationType(notificationCategory, notificationSubtype)) + oEvent.Param1 = session.GameMatchmakeSession.ID.Copy().(*types.PrimitiveU32) + oEvent.Param2 = types.NewPrimitiveU32(target.PID().LegacyValue()) // TODO - This assumes a legacy client. Will not work on the Switch + oEvent.StrParam = types.NewString(joinMessage) + oEvent.Param3 = types.NewPrimitiveU32(uint32(len(connectionIDs))) + + notificationStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + oEvent.WriteTo(notificationStream) + + notificationRequest := nex.NewRMCRequest(endpoint) + notificationRequest.ProtocolID = notifications.ProtocolID + notificationRequest.CallID = CurrentMatchmakingCallID.Next() + notificationRequest.MethodID = notifications.MethodProcessNotificationEvent + notificationRequest.Parameters = notificationStream.Bytes() + + notificationRequestBytes := notificationRequest.Bytes() + + var messagePacket nex.PRUDPPacketInterface + + if target.DefaultPRUDPVersion == 0 { + messagePacket, _ = nex.NewPRUDPPacketV0(server, initiatingConnection, nil) + } else { + messagePacket, _ = nex.NewPRUDPPacketV1(server, initiatingConnection, nil) + } + + messagePacket.SetType(constants.DataPacket) + messagePacket.AddFlag(constants.PacketFlagNeedsAck) + messagePacket.AddFlag(constants.PacketFlagReliable) + messagePacket.SetSourceVirtualPortStreamType(target.StreamType) + messagePacket.SetSourceVirtualPortStreamID(endpoint.StreamID) + messagePacket.SetDestinationVirtualPortStreamType(target.StreamType) + messagePacket.SetDestinationVirtualPortStreamID(target.StreamID) + messagePacket.SetPayload(notificationRequestBytes) + + server.Send(messagePacket) + + return false + }) + + notificationCategory := notifications.NotificationCategories.Participation + notificationSubtype := notifications.NotificationSubTypes.Participation.NewParticipant + + oEvent := notifications_types.NewNotificationEvent() + oEvent.PIDSource = initiatingConnection.PID() + oEvent.Type = types.NewPrimitiveU32(notifications.BuildNotificationType(notificationCategory, notificationSubtype)) + oEvent.Param1 = session.GameMatchmakeSession.ID + oEvent.Param2 = types.NewPrimitiveU32(initiatingConnection.PID().LegacyValue()) // TODO - This assumes a legacy client. Will not work on the Switch + oEvent.StrParam = types.NewString(joinMessage) + oEvent.Param3 = types.NewPrimitiveU32(uint32(len(connectionIDs))) + + notificationStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + oEvent.WriteTo(notificationStream) + + notificationRequest := nex.NewRMCRequest(endpoint) + notificationRequest.ProtocolID = notifications.ProtocolID + notificationRequest.CallID = CurrentMatchmakingCallID.Next() + notificationRequest.MethodID = notifications.MethodProcessNotificationEvent + notificationRequest.Parameters = notificationStream.Bytes() + + notificationRequestBytes := notificationRequest.Bytes() + + var messagePacket nex.PRUDPPacketInterface + + if initiatingConnection.DefaultPRUDPVersion == 0 { + messagePacket, _ = nex.NewPRUDPPacketV0(server, initiatingConnection, nil) + } else { + messagePacket, _ = nex.NewPRUDPPacketV1(server, initiatingConnection, nil) + } + + messagePacket.SetType(constants.DataPacket) + messagePacket.AddFlag(constants.PacketFlagNeedsAck) + messagePacket.AddFlag(constants.PacketFlagReliable) + messagePacket.SetSourceVirtualPortStreamType(initiatingConnection.StreamType) + messagePacket.SetSourceVirtualPortStreamID(endpoint.StreamID) + messagePacket.SetDestinationVirtualPortStreamType(initiatingConnection.StreamType) + messagePacket.SetDestinationVirtualPortStreamID(initiatingConnection.StreamID) + messagePacket.SetPayload(notificationRequestBytes) + + server.Send(messagePacket) + + target := endpoint.FindConnectionByPID(session.GameMatchmakeSession.Gathering.OwnerPID.Value()) + if target == nil { + // TODO - Error here? + Logger.Warning("Player not found") + return nil + } + + if target.DefaultPRUDPVersion == 0 { + messagePacket, _ = nex.NewPRUDPPacketV0(server, target, nil) + } else { + messagePacket, _ = nex.NewPRUDPPacketV1(server, target, nil) + } + + messagePacket.SetType(constants.DataPacket) + messagePacket.AddFlag(constants.PacketFlagNeedsAck) + messagePacket.AddFlag(constants.PacketFlagReliable) + messagePacket.SetSourceVirtualPortStreamType(target.StreamType) + messagePacket.SetSourceVirtualPortStreamID(endpoint.StreamID) + messagePacket.SetDestinationVirtualPortStreamType(target.StreamType) + messagePacket.SetDestinationVirtualPortStreamID(target.StreamID) + messagePacket.SetPayload(notificationRequestBytes) + + server.Send(messagePacket) + }*/ + + return nil +} + +// ChangeSessionOwner changes the session owner to a different connection +func ChangeSessionOwner(currentOwner *nex.PRUDPConnection, gathering uint32, isLeaving bool) { + endpoint := currentOwner.Endpoint().(*nex.PRUDPEndPoint) + server := endpoint.Server + session := Sessions[gathering] + + var newOwner *nex.PRUDPConnection + + newOwnerConnectionID := FindOtherConnectionID(currentOwner.ID, gathering) + if newOwnerConnectionID != 0 { + newOwner = endpoint.FindConnectionByID(newOwnerConnectionID) + if newOwner == nil { + Logger.Warning("Other connection not found") + return + } + + // If the current owner is the host and they are leaving, change it by the new owner + if session.GameMatchmakeSession.Gathering.HostPID.Equals(currentOwner.PID()) && isLeaving { + session.GameMatchmakeSession.Gathering.HostPID = newOwner.PID() + } + session.GameMatchmakeSession.Gathering.OwnerPID = newOwner.PID() + } else { + return + } + + category := notifications.NotificationCategories.OwnershipChanged + subtype := notifications.NotificationSubTypes.OwnershipChanged.None + + oEvent := notifications_types.NewNotificationEvent() + oEvent.PIDSource = currentOwner.PID() + oEvent.Type = types.NewPrimitiveU32(notifications.BuildNotificationType(category, subtype)) + oEvent.Param1 = types.NewPrimitiveU32(gathering) + oEvent.Param2 = types.NewPrimitiveU32(newOwner.PID().LegacyValue()) // TODO - This assumes a legacy client. Will not work on the Switch + + // TODO - StrParam doesn't have this value on some servers + // * https://github.com/kinnay/NintendoClients/issues/101 + // * unixTime := time.Now() + // * oEvent.StrParam = strconv.FormatInt(unixTime.UnixMicro(), 10) + + stream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + oEvent.WriteTo(stream) + + rmcRequest := nex.NewRMCRequest(endpoint) + rmcRequest.ProtocolID = notifications.ProtocolID + rmcRequest.CallID = CurrentMatchmakingCallID.Next() + rmcRequest.MethodID = notifications.MethodProcessNotificationEvent + rmcRequest.Parameters = stream.Bytes() + + rmcRequestBytes := rmcRequest.Bytes() + + session.ConnectionIDs.Each(func(_ int, connectionID uint32) bool { + target := endpoint.FindConnectionByID(connectionID) + if target == nil { + Logger.Warning("Connection not found") + return false + } + + var messagePacket nex.PRUDPPacketInterface + + if target.DefaultPRUDPVersion == 0 { + messagePacket, _ = nex.NewPRUDPPacketV0(server, target, nil) + } else { + messagePacket, _ = nex.NewPRUDPPacketV1(server, target, nil) + } + + messagePacket.SetType(constants.DataPacket) + messagePacket.AddFlag(constants.PacketFlagNeedsAck) + messagePacket.AddFlag(constants.PacketFlagReliable) + messagePacket.SetSourceVirtualPortStreamType(target.StreamType) + messagePacket.SetSourceVirtualPortStreamID(endpoint.StreamID) + messagePacket.SetDestinationVirtualPortStreamType(target.StreamType) + messagePacket.SetDestinationVirtualPortStreamID(target.StreamID) + messagePacket.SetPayload(rmcRequestBytes) + + server.Send(messagePacket) + + return false + }) +} diff --git a/nex-protocols-common-go/globals/utils.go b/nex-protocols-common-go/globals/utils.go new file mode 100644 index 0000000..93f8528 --- /dev/null +++ b/nex-protocols-common-go/globals/utils.go @@ -0,0 +1,7 @@ +package common_globals + +// DeleteIndex removes a value from a slice with the given index +func DeleteIndex(s []uint32, index int) []uint32 { + s[index] = s[len(s)-1] + return s[:len(s)-1] +} diff --git a/nex-protocols-common-go/go.mod b/nex-protocols-common-go/go.mod new file mode 100644 index 0000000..cb1e7e7 --- /dev/null +++ b/nex-protocols-common-go/go.mod @@ -0,0 +1,40 @@ +module github.com/PretendoNetwork/nex-protocols-common-go/v2 + +go 1.21 + +require ( + github.com/PretendoNetwork/nex-go/v2 v2.0.1 + github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.1 + github.com/PretendoNetwork/plogger-go v1.0.4 + github.com/minio/minio-go/v7 v7.0.63 + golang.org/x/exp v0.0.0-20231006140011-7918f672742d +) + +require ( + github.com/dolthub/maphash v0.1.0 // indirect + github.com/dustin/go-humanize v1.0.1 // indirect + github.com/fatih/color v1.15.0 // indirect + github.com/google/uuid v1.4.0 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/jwalton/go-supportscolor v1.2.0 // indirect + github.com/klauspost/compress v1.17.5 // indirect + github.com/klauspost/cpuid/v2 v2.2.5 // indirect + github.com/lxzan/gws v1.8.0 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/minio/md5-simd v1.1.2 // indirect + github.com/minio/sha256-simd v1.0.1 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e // indirect + github.com/rs/xid v1.5.0 // indirect + github.com/sirupsen/logrus v1.9.3 // indirect + github.com/superwhiskers/crunch/v3 v3.5.7 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/mod v0.13.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/term v0.15.0 // indirect + golang.org/x/text v0.13.0 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect +) diff --git a/nex-protocols-common-go/go.sum b/nex-protocols-common-go/go.sum new file mode 100644 index 0000000..9bc05f3 --- /dev/null +++ b/nex-protocols-common-go/go.sum @@ -0,0 +1,89 @@ +github.com/PretendoNetwork/nex-go/v2 v2.0.1 h1:7UEwulBtWD+HIbwB0uaRjBK1EXFLfSnv0t5+WyQYV0s= +github.com/PretendoNetwork/nex-go/v2 v2.0.1/go.mod h1:EZNyRVr0WpPLHZQqZZvarQ8/tXsEyVqLr6zy/hKCAV4= +github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.1 h1:BqrHYF2JeYfB/JUmhU3pWR1qUJEEqUDM4pigXzi95Ik= +github.com/PretendoNetwork/nex-protocols-go/v2 v2.0.1/go.mod h1:TAzlc/gOu6E5Ct2NoTpN+Ea9Gpjh38dTsGqfs0pfZ4w= +github.com/PretendoNetwork/plogger-go v1.0.4 h1:PF7xHw9eDRHH+RsAP9tmAE7fG0N0p6H4iPwHKnsoXwc= +github.com/PretendoNetwork/plogger-go v1.0.4/go.mod h1:7kD6M4vPq1JL4LTuPg6kuB1OvUBOwQOtAvTaUwMbwvU= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dolthub/maphash v0.1.0 h1:bsQ7JsF4FkkWyrP3oCnFJgrCUAFbFf3kOl4L/QxPDyQ= +github.com/dolthub/maphash v0.1.0/go.mod h1:gkg4Ch4CdCDu5h6PMriVLawB7koZ+5ijb9puGMV50a4= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= +github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/jwalton/go-supportscolor v1.2.0 h1:g6Ha4u7Vm3LIsQ5wmeBpS4gazu0UP1DRDE8y6bre4H8= +github.com/jwalton/go-supportscolor v1.2.0/go.mod h1:hFVUAZV2cWg+WFFC4v8pT2X/S2qUUBYMioBD9AINXGs= +github.com/klauspost/compress v1.17.5 h1:d4vBd+7CHydUqpFBgUEKkSdtSugf9YFmSkvUYPquI5E= +github.com/klauspost/compress v1.17.5/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= +github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= +github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/lxzan/gws v1.8.0 h1:SqRuU6PUez/BA6CHB9BufV6n+gCnRtWHUntjLcaHA44= +github.com/lxzan/gws v1.8.0/go.mod h1:FcGeRMB7HwGuTvMLR24ku0Zx0p6RXqeKASeMc4VYgi4= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= +github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM= +github.com/minio/minio-go/v7 v7.0.63 h1:GbZ2oCvaUdgT5640WJOpyDhhDxvknAJU2/T3yurwcbQ= +github.com/minio/minio-go/v7 v7.0.63/go.mod h1:Q6X7Qjb7WMhvG65qKf4gUgA5XaiSox74kR1uAEjxRS4= +github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= +github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e h1:dCWirM5F3wMY+cmRda/B1BiPsFtmzXqV9b0hLWtVBMs= +github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e/go.mod h1:9leZcVcItj6m9/CfHY5Em/iBrCz7js8LcRQGTKEEv2M= +github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/superwhiskers/crunch/v3 v3.5.7 h1:N9RLxaR65C36i26BUIpzPXGy2f6pQ7wisu2bawbKNqg= +github.com/superwhiskers/crunch/v3 v3.5.7/go.mod h1:4ub2EKgF1MAhTjoOCTU4b9uLMsAweHEa89aRrfAypXA= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= +golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= +golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= +golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/nex-protocols-common-go/match-making-ext/end_participation.go b/nex-protocols-common-go/match-making-ext/end_participation.go new file mode 100644 index 0000000..e7664eb --- /dev/null +++ b/nex-protocols-common-go/match-making-ext/end_participation.go @@ -0,0 +1,115 @@ +package match_making_ext + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/constants" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" + match_making_ext "github.com/PretendoNetwork/nex-protocols-go/v2/match-making-ext" + notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications" + notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types" +) + +func (commonProtocol *CommonProtocol) endParticipation(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + session, ok := common_globals.Sessions[idGathering.Value] + if !ok { + return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + server := endpoint.Server + + matchmakeSession := session.GameMatchmakeSession + ownerPID := matchmakeSession.Gathering.OwnerPID + + var deleteSession bool = false + if connection.PID().Equals(matchmakeSession.Gathering.OwnerPID) { + // * This flag tells the server to change the matchmake session owner if they disconnect + // * If the flag is not set, delete the session + // * More info: https://nintendo-wiki.pretendo.network/docs/nex/protocols/match-making/types#flags + if matchmakeSession.Gathering.Flags.PAND(match_making.GatheringFlags.DisconnectChangeOwner) == 0 { + deleteSession = true + } else { + common_globals.ChangeSessionOwner(connection, idGathering.Value, true) + } + } + + if deleteSession { + delete(common_globals.Sessions, idGathering.Value) + } else { + common_globals.RemoveConnectionIDFromSession(connection.ID, idGathering.Value) + } + + retval := types.NewPrimitiveBool(true) + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + retval.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = match_making_ext.ProtocolID + rmcResponse.MethodID = match_making_ext.MethodEndParticipation + rmcResponse.CallID = callID + + category := notifications.NotificationCategories.Participation + subtype := notifications.NotificationSubTypes.Participation.Ended + + oEvent := notifications_types.NewNotificationEvent() + oEvent.PIDSource = connection.PID().Copy().(*types.PID) + oEvent.Type = types.NewPrimitiveU32(notifications.BuildNotificationType(category, subtype)) + oEvent.Param1 = idGathering.Copy().(*types.PrimitiveU32) + oEvent.Param2 = types.NewPrimitiveU32(connection.PID().LegacyValue()) // TODO - This assumes a legacy client. Will not work on the Switch + oEvent.StrParam = strMessage.Copy().(*types.String) + + stream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + oEvent.WriteTo(stream) + + rmcRequest := nex.NewRMCRequest(endpoint) + rmcRequest.ProtocolID = notifications.ProtocolID + rmcRequest.MethodID = notifications.MethodProcessNotificationEvent + rmcRequest.CallID = common_globals.CurrentMatchmakingCallID.Next() + rmcRequest.Parameters = stream.Bytes() + + rmcRequestBytes := rmcRequest.Bytes() + + target := endpoint.FindConnectionByPID(ownerPID.Value()) + if target == nil { + common_globals.Logger.Warning("Owner client not found") + return nil, nil + } + + var messagePacket nex.PRUDPPacketInterface + + if target.DefaultPRUDPVersion == 0 { + messagePacket, _ = nex.NewPRUDPPacketV0(server, target, nil) + } else { + messagePacket, _ = nex.NewPRUDPPacketV1(server, target, nil) + } + + messagePacket.SetType(constants.DataPacket) + messagePacket.AddFlag(constants.PacketFlagNeedsAck) + messagePacket.AddFlag(constants.PacketFlagReliable) + messagePacket.SetSourceVirtualPortStreamType(target.StreamType) + messagePacket.SetSourceVirtualPortStreamID(endpoint.StreamID) + messagePacket.SetDestinationVirtualPortStreamType(target.StreamType) + messagePacket.SetDestinationVirtualPortStreamID(target.StreamID) + messagePacket.SetPayload(rmcRequestBytes) + + server.Send(messagePacket) + + if commonProtocol.OnAfterEndParticipation != nil { + go commonProtocol.OnAfterEndParticipation(packet, idGathering, strMessage) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/match-making-ext/protocol.go b/nex-protocols-common-go/match-making-ext/protocol.go new file mode 100644 index 0000000..64a4300 --- /dev/null +++ b/nex-protocols-common-go/match-making-ext/protocol.go @@ -0,0 +1,25 @@ +package match_making_ext + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + match_making_ext "github.com/PretendoNetwork/nex-protocols-go/v2/match-making-ext" +) + +type CommonProtocol struct { + endpoint nex.EndpointInterface + protocol match_making_ext.Interface + OnAfterEndParticipation func(acket nex.PacketInterface, idGathering *types.PrimitiveU32, strMessage *types.String) +} + +// NewCommonProtocol returns a new CommonProtocol +func NewCommonProtocol(protocol match_making_ext.Interface) *CommonProtocol { + commonProtocol := &CommonProtocol{ + endpoint: protocol.Endpoint(), + protocol: protocol, + } + + protocol.SetHandlerEndParticipation(commonProtocol.endParticipation) + + return commonProtocol +} diff --git a/nex-protocols-common-go/match-making/find_by_single_id.go b/nex-protocols-common-go/match-making/find_by_single_id.go new file mode 100644 index 0000000..973b80d --- /dev/null +++ b/nex-protocols-common-go/match-making/find_by_single_id.go @@ -0,0 +1,47 @@ +package matchmaking + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" +) + +func (commonProtocol *CommonProtocol) findBySingleID(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + session, ok := common_globals.Sessions[id.Value] + if !ok { + return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + bResult := types.NewPrimitiveBool(true) + pGathering := types.NewAnyDataHolder() + + pGathering.TypeName = types.NewString("MatchmakeSession") + pGathering.ObjectData = session.GameMatchmakeSession.Copy() + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + bResult.WriteTo(rmcResponseStream) + pGathering.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = match_making.ProtocolID + rmcResponse.MethodID = match_making.MethodFindBySingleID + rmcResponse.CallID = callID + + if commonProtocol.OnAfterFindBySingleID != nil { + go commonProtocol.OnAfterFindBySingleID(packet, id) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/match-making/get_session_urls.go b/nex-protocols-common-go/match-making/get_session_urls.go new file mode 100644 index 0000000..783a54d --- /dev/null +++ b/nex-protocols-common-go/match-making/get_session_urls.go @@ -0,0 +1,53 @@ +package matchmaking + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" +) + +func (commonProtocol *CommonProtocol) getSessionURLs(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + session, ok := common_globals.Sessions[gid.Value] + if !ok { + return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + hostPID := session.GameMatchmakeSession.Gathering.HostPID + host := endpoint.FindConnectionByPID(hostPID.Value()) + if host == nil { + // * This popped up once during testing. Leaving it noted here in case it becomes a problem. + common_globals.Logger.Warning("Host client not found, trying with owner client") + host = endpoint.FindConnectionByPID(session.GameMatchmakeSession.Gathering.OwnerPID.Value()) + if host == nil { + // * This popped up once during testing. Leaving it noted here in case it becomes a problem. + common_globals.Logger.Error("Owner client not found") + return nil, nex.NewError(nex.ResultCodes.Core.Exception, "change_error") + } + } + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + host.StationURLs.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = match_making.ProtocolID + rmcResponse.MethodID = match_making.MethodGetSessionURLs + rmcResponse.CallID = callID + + if commonProtocol.OnAfterGetSessionURLs != nil { + go commonProtocol.OnAfterGetSessionURLs(packet, gid) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/match-making/protocol.go b/nex-protocols-common-go/match-making/protocol.go new file mode 100644 index 0000000..96d7271 --- /dev/null +++ b/nex-protocols-common-go/match-making/protocol.go @@ -0,0 +1,45 @@ +package matchmaking + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + _ "github.com/PretendoNetwork/nex-protocols-go/v2" + match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" +) + +type CommonProtocol struct { + endpoint *nex.PRUDPEndPoint + protocol match_making.Interface + OnAfterUnregisterGathering func(packet nex.PacketInterface, idGathering *types.PrimitiveU32) + OnAfterFindBySingleID func(packet nex.PacketInterface, id *types.PrimitiveU32) + OnAfterUpdateSessionURL func(packet nex.PacketInterface, idGathering *types.PrimitiveU32, strURL *types.String) + OnAfterUpdateSessionHostV1 func(packet nex.PacketInterface, gid *types.PrimitiveU32) + OnAfterGetSessionURLs func(packet nex.PacketInterface, gid *types.PrimitiveU32) + OnAfterUpdateSessionHost func(packet nex.PacketInterface, gid *types.PrimitiveU32, isMigrateOwner *types.PrimitiveBool) +} + +// NewCommonProtocol returns a new CommonProtocol +func NewCommonProtocol(protocol match_making.Interface) *CommonProtocol { + endpoint := protocol.Endpoint().(*nex.PRUDPEndPoint) + + commonProtocol := &CommonProtocol{ + endpoint: endpoint, + protocol: protocol, + } + + common_globals.Sessions = make(map[uint32]*common_globals.CommonMatchmakeSession) + + protocol.SetHandlerUnregisterGathering(commonProtocol.unregisterGathering) + protocol.SetHandlerFindBySingleID(commonProtocol.findBySingleID) + protocol.SetHandlerUpdateSessionURL(commonProtocol.updateSessionURL) + protocol.SetHandlerUpdateSessionHostV1(commonProtocol.updateSessionHostV1) + protocol.SetHandlerGetSessionURLs(commonProtocol.getSessionURLs) + protocol.SetHandlerUpdateSessionHost(commonProtocol.updateSessionHost) + + endpoint.OnConnectionEnded(func(connection *nex.PRUDPConnection) { + common_globals.RemoveConnectionFromAllSessions(connection) + }) + + return commonProtocol +} diff --git a/nex-protocols-common-go/match-making/unregister_gathering.go b/nex-protocols-common-go/match-making/unregister_gathering.go new file mode 100644 index 0000000..f77abb4 --- /dev/null +++ b/nex-protocols-common-go/match-making/unregister_gathering.go @@ -0,0 +1,103 @@ +package matchmaking + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/constants" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" + notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications" + notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types" +) + +func (commonProtocol *CommonProtocol) unregisterGathering(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + session, ok := common_globals.Sessions[idGathering.Value] + if !ok { + return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + server := endpoint.Server + + if !session.GameMatchmakeSession.Gathering.OwnerPID.Equals(connection.PID()) { + return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") + } + + gatheringPlayers := session.ConnectionIDs + + delete(common_globals.Sessions, idGathering.Value) + + retval := types.NewPrimitiveBool(true) + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + retval.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = match_making.ProtocolID + rmcResponse.MethodID = match_making.MethodUnregisterGathering + rmcResponse.CallID = callID + + category := notifications.NotificationCategories.GatheringUnregistered + subtype := notifications.NotificationSubTypes.GatheringUnregistered.None + + oEvent := notifications_types.NewNotificationEvent() + oEvent.PIDSource = connection.PID().Copy().(*types.PID) + oEvent.Type = types.NewPrimitiveU32(notifications.BuildNotificationType(category, subtype)) + oEvent.Param1 = idGathering.Copy().(*types.PrimitiveU32) + + stream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + oEvent.WriteTo(stream) + + rmcRequest := nex.NewRMCRequest(endpoint) + rmcRequest.ProtocolID = notifications.ProtocolID + rmcRequest.CallID = common_globals.CurrentMatchmakingCallID.Next() + rmcRequest.MethodID = notifications.MethodProcessNotificationEvent + rmcRequest.Parameters = stream.Bytes() + + rmcRequestBytes := rmcRequest.Bytes() + + gatheringPlayers.Each(func(_ int, connectionID uint32) bool { + target := endpoint.FindConnectionByID(connectionID) + if target == nil { + common_globals.Logger.Warning("Client not found") + return false + } + + var messagePacket nex.PRUDPPacketInterface + + if target.DefaultPRUDPVersion == 0 { + messagePacket, _ = nex.NewPRUDPPacketV0(server, target, nil) + } else { + messagePacket, _ = nex.NewPRUDPPacketV1(server, target, nil) + } + + messagePacket.SetType(constants.DataPacket) + messagePacket.AddFlag(constants.PacketFlagNeedsAck) + messagePacket.AddFlag(constants.PacketFlagReliable) + messagePacket.SetSourceVirtualPortStreamType(target.StreamType) + messagePacket.SetSourceVirtualPortStreamID(endpoint.StreamID) + messagePacket.SetDestinationVirtualPortStreamType(target.StreamType) + messagePacket.SetDestinationVirtualPortStreamID(target.StreamID) + messagePacket.SetPayload(rmcRequestBytes) + + server.Send(messagePacket) + + return false + }) + + if commonProtocol.OnAfterUnregisterGathering != nil { + go commonProtocol.OnAfterUnregisterGathering(packet, idGathering) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/match-making/update_session_host.go b/nex-protocols-common-go/match-making/update_session_host.go new file mode 100644 index 0000000..ee8b413 --- /dev/null +++ b/nex-protocols-common-go/match-making/update_session_host.go @@ -0,0 +1,110 @@ +package matchmaking + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/constants" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" + notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications" + notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types" +) + +func (commonProtocol *CommonProtocol) updateSessionHost(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, isMigrateOwner *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + session, ok := common_globals.Sessions[gid.Value] + if !ok { + return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + server := endpoint.Server + + if common_globals.FindConnectionSession(connection.ID) != gid.Value { + return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") + } + + session.GameMatchmakeSession.Gathering.HostPID = connection.PID().Copy().(*types.PID) + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = match_making.ProtocolID + rmcResponse.MethodID = match_making.MethodUpdateSessionHost + rmcResponse.CallID = callID + + if !isMigrateOwner.Value { + if commonProtocol.OnAfterUpdateSessionHost != nil { + go commonProtocol.OnAfterUpdateSessionHost(packet, gid, isMigrateOwner) + } + + return rmcResponse, nil + } + + originalOwner := session.GameMatchmakeSession.Gathering.OwnerPID + session.GameMatchmakeSession.Gathering.OwnerPID = connection.PID().Copy().(*types.PID) + + category := notifications.NotificationCategories.OwnershipChanged + subtype := notifications.NotificationSubTypes.OwnershipChanged.None + + oEvent := notifications_types.NewNotificationEvent() + oEvent.PIDSource = originalOwner.Copy().(*types.PID) + oEvent.Type = types.NewPrimitiveU32(notifications.BuildNotificationType(category, subtype)) + oEvent.Param1 = gid.Copy().(*types.PrimitiveU32) + oEvent.Param2 = types.NewPrimitiveU32(connection.PID().LegacyValue()) // TODO - This assumes a legacy client. Will not work on the Switch + + // TODO - StrParam doesn't have this value on some servers + // * https://github.com/kinnay/NintendoClients/issues/101 + // * unixTime := time.Now() + // * oEvent.StrParam = strconv.FormatInt(unixTime.UnixMicro(), 10) + + stream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + oEvent.WriteTo(stream) + + rmcRequest := nex.NewRMCRequest(endpoint) + rmcRequest.ProtocolID = notifications.ProtocolID + rmcRequest.CallID = common_globals.CurrentMatchmakingCallID.Next() + rmcRequest.MethodID = notifications.MethodProcessNotificationEvent + rmcRequest.Parameters = stream.Bytes() + + rmcRequestBytes := rmcRequest.Bytes() + + common_globals.Sessions[gid.Value].ConnectionIDs.Each(func(_ int, connectionID uint32) bool { + target := endpoint.FindConnectionByID(connectionID) + if target == nil { + common_globals.Logger.Warning("Client not found") + return false + } + + var messagePacket nex.PRUDPPacketInterface + + if target.DefaultPRUDPVersion == 0 { + messagePacket, _ = nex.NewPRUDPPacketV0(server, target, nil) + } else { + messagePacket, _ = nex.NewPRUDPPacketV1(server, target, nil) + } + + messagePacket.SetType(constants.DataPacket) + messagePacket.AddFlag(constants.PacketFlagNeedsAck) + messagePacket.AddFlag(constants.PacketFlagReliable) + messagePacket.SetSourceVirtualPortStreamType(target.StreamType) + messagePacket.SetSourceVirtualPortStreamID(endpoint.StreamID) + messagePacket.SetDestinationVirtualPortStreamType(target.StreamType) + messagePacket.SetDestinationVirtualPortStreamID(target.StreamID) + messagePacket.SetPayload(rmcRequestBytes) + + server.Send(messagePacket) + + return false + }) + + if commonProtocol.OnAfterUpdateSessionHost != nil { + go commonProtocol.OnAfterUpdateSessionHost(packet, gid, isMigrateOwner) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/match-making/update_session_host_v1.go b/nex-protocols-common-go/match-making/update_session_host_v1.go new file mode 100644 index 0000000..10bc7c6 --- /dev/null +++ b/nex-protocols-common-go/match-making/update_session_host_v1.go @@ -0,0 +1,43 @@ +package matchmaking + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" +) + +func (commonProtocol *CommonProtocol) updateSessionHostV1(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + session, ok := common_globals.Sessions[gid.Value] + if !ok { + return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + if common_globals.FindConnectionSession(connection.ID) != gid.Value { + return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") + } + + session.GameMatchmakeSession.Gathering.HostPID = connection.PID() + if session.GameMatchmakeSession.Gathering.Flags.PAND(match_making.GatheringFlags.DisconnectChangeOwner) != 0 { + session.GameMatchmakeSession.Gathering.OwnerPID = connection.PID() + } + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = match_making.ProtocolID + rmcResponse.MethodID = match_making.MethodUpdateSessionHostV1 + rmcResponse.CallID = callID + + if commonProtocol.OnAfterUpdateSessionHostV1 != nil { + go commonProtocol.OnAfterUpdateSessionHostV1(packet, gid) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/match-making/update_session_url.go b/nex-protocols-common-go/match-making/update_session_url.go new file mode 100644 index 0000000..f61bc3a --- /dev/null +++ b/nex-protocols-common-go/match-making/update_session_url.go @@ -0,0 +1,108 @@ +package matchmaking + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/constants" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" + notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications" + notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types" +) + +func (commonProtocol *CommonProtocol) updateSessionURL(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strURL *types.String) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + session, ok := common_globals.Sessions[idGathering.Value] + if !ok { + return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + server := endpoint.Server + + // * Mario Kart 7 seems to set an empty strURL, so I assume this is what the method does? + session.GameMatchmakeSession.Gathering.HostPID = connection.PID().Copy().(*types.PID) + if session.GameMatchmakeSession.Gathering.Flags.PAND(match_making.GatheringFlags.DisconnectChangeOwner) != 0 { + originalOwner := session.GameMatchmakeSession.Gathering.OwnerPID + session.GameMatchmakeSession.Gathering.OwnerPID = connection.PID().Copy().(*types.PID) + + category := notifications.NotificationCategories.OwnershipChanged + subtype := notifications.NotificationSubTypes.OwnershipChanged.None + + oEvent := notifications_types.NewNotificationEvent() + oEvent.PIDSource = originalOwner.Copy().(*types.PID) + oEvent.Type = types.NewPrimitiveU32(notifications.BuildNotificationType(category, subtype)) + oEvent.Param1 = idGathering.Copy().(*types.PrimitiveU32) + oEvent.Param2 = types.NewPrimitiveU32(connection.PID().LegacyValue()) // TODO - This assumes a legacy client. Will not work on the Switch + + // TODO - StrParam doesn't have this value on some servers + // * https://github.com/kinnay/NintendoClients/issues/101 + // * unixTime := time.Now() + // * oEvent.StrParam = strconv.FormatInt(unixTime.UnixMicro(), 10) + + stream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + oEvent.WriteTo(stream) + + rmcRequest := nex.NewRMCRequest(endpoint) + rmcRequest.ProtocolID = notifications.ProtocolID + rmcRequest.CallID = common_globals.CurrentMatchmakingCallID.Next() + rmcRequest.MethodID = notifications.MethodProcessNotificationEvent + rmcRequest.Parameters = stream.Bytes() + + rmcRequestBytes := rmcRequest.Bytes() + + common_globals.Sessions[idGathering.Value].ConnectionIDs.Each(func(_ int, connectionID uint32) bool { + target := endpoint.FindConnectionByID(connectionID) + if target == nil { + common_globals.Logger.Warning("Client not found") + return false + } + + var messagePacket nex.PRUDPPacketInterface + + if target.DefaultPRUDPVersion == 0 { + messagePacket, _ = nex.NewPRUDPPacketV0(server, target, nil) + } else { + messagePacket, _ = nex.NewPRUDPPacketV1(server, target, nil) + } + + messagePacket.SetType(constants.DataPacket) + messagePacket.AddFlag(constants.PacketFlagNeedsAck) + messagePacket.AddFlag(constants.PacketFlagReliable) + messagePacket.SetSourceVirtualPortStreamType(target.StreamType) + messagePacket.SetSourceVirtualPortStreamID(endpoint.StreamID) + messagePacket.SetDestinationVirtualPortStreamType(target.StreamType) + messagePacket.SetDestinationVirtualPortStreamID(target.StreamID) + messagePacket.SetPayload(rmcRequestBytes) + + server.Send(messagePacket) + + return false + }) + } + + retval := types.NewPrimitiveBool(true) + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + retval.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = match_making.ProtocolID + rmcResponse.MethodID = match_making.MethodGetSessionURLs + rmcResponse.CallID = callID + + if commonProtocol.OnAfterUpdateSessionURL != nil { + go commonProtocol.OnAfterUpdateSessionURL(packet, idGathering, strURL) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/matchmake-extension/auto_matchmake_postpone.go b/nex-protocols-common-go/matchmake-extension/auto_matchmake_postpone.go new file mode 100644 index 0000000..e3d4c23 --- /dev/null +++ b/nex-protocols-common-go/matchmake-extension/auto_matchmake_postpone.go @@ -0,0 +1,82 @@ +package matchmake_extension + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" +) + +func (commonProtocol *CommonProtocol) autoMatchmakePostpone(err error, packet nex.PacketInterface, callID uint32, anyGathering *types.AnyDataHolder, message *types.String) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.CleanupSearchMatchmakeSession == nil { + common_globals.Logger.Warning("MatchmakeExtension::AutoMatchmake_Postpone missing CleanupSearchMatchmakeSession!") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + // * A client may disconnect from a session without leaving reliably, + // * so let's make sure the client is removed from the session + common_globals.RemoveConnectionFromAllSessions(connection) + + var matchmakeSession *match_making_types.MatchmakeSession + anyGatheringDataType := anyGathering.TypeName + + if anyGatheringDataType.Value == "MatchmakeSession" { + matchmakeSession = anyGathering.ObjectData.(*match_making_types.MatchmakeSession) + } else { + common_globals.Logger.Critical("Non-MatchmakeSession DataType?!") + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + searchMatchmakeSession := matchmakeSession.Copy().(*match_making_types.MatchmakeSession) + commonProtocol.CleanupSearchMatchmakeSession(searchMatchmakeSession) + sessionIndex := common_globals.FindSessionByMatchmakeSession(connection.PID(), searchMatchmakeSession) + var session *common_globals.CommonMatchmakeSession + + if sessionIndex == 0 { + var errCode *nex.Error + session, errCode = common_globals.CreateSessionByMatchmakeSession(matchmakeSession, searchMatchmakeSession, connection.PID()) + if err != nil { + common_globals.Logger.Error(errCode.Error()) + return nil, errCode + } + } else { + session = common_globals.Sessions[sessionIndex] + } + + errCode := common_globals.AddPlayersToSession(session, []uint32{connection.ID}, connection, message.Value) + if errCode != nil { + common_globals.Logger.Error(errCode.Error()) + return nil, errCode + } + + matchmakeDataHolder := types.NewAnyDataHolder() + + matchmakeDataHolder.TypeName = types.NewString("MatchmakeSession") + matchmakeDataHolder.ObjectData = session.GameMatchmakeSession.Copy() + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + matchmakeDataHolder.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.MethodID = matchmake_extension.MethodAutoMatchmakePostpone + rmcResponse.CallID = callID + + if commonProtocol.OnAfterAutoMatchmakePostpone != nil { + go commonProtocol.OnAfterAutoMatchmakePostpone(packet, anyGathering, message) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/matchmake-extension/auto_matchmake_with_param_postpone.go b/nex-protocols-common-go/matchmake-extension/auto_matchmake_with_param_postpone.go new file mode 100644 index 0000000..c601397 --- /dev/null +++ b/nex-protocols-common-go/matchmake-extension/auto_matchmake_with_param_postpone.go @@ -0,0 +1,67 @@ +package matchmake_extension + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" +) + +func (commonProtocol *CommonProtocol) autoMatchmakeWithParamPostpone(err error, packet nex.PacketInterface, callID uint32, autoMatchmakeParam *match_making_types.AutoMatchmakeParam) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + // * A client may disconnect from a session without leaving reliably, + // * so let's make sure the client is removed from the session + common_globals.RemoveConnectionFromAllSessions(connection) + + matchmakeSession := autoMatchmakeParam.SourceMatchmakeSession + + sessions := common_globals.FindSessionsByMatchmakeSessionSearchCriterias(connection.PID(), autoMatchmakeParam.LstSearchCriteria.Slice(), commonProtocol.GameSpecificMatchmakeSessionSearchCriteriaChecks) + var session *common_globals.CommonMatchmakeSession + + if len(sessions) == 0 { + var errCode *nex.Error + session, errCode = common_globals.CreateSessionByMatchmakeSession(matchmakeSession, nil, connection.PID()) + if errCode != nil { + common_globals.Logger.Error(errCode.Error()) + return nil, errCode + } + } else { + session = sessions[0] + } + + errCode := common_globals.AddPlayersToSession(session, []uint32{connection.ID}, connection, "") + if errCode != nil { + common_globals.Logger.Error(errCode.Error()) + return nil, errCode + } + + matchmakeDataHolder := types.NewAnyDataHolder() + + matchmakeDataHolder.TypeName = types.NewString("MatchmakeSession") + matchmakeDataHolder.ObjectData = session.GameMatchmakeSession.Copy() + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + session.GameMatchmakeSession.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.MethodID = matchmake_extension.MethodAutoMatchmakeWithParamPostpone + rmcResponse.CallID = callID + + if commonProtocol.OnAfterAutoMatchmakeWithParamPostpone != nil { + go commonProtocol.OnAfterAutoMatchmakeWithParamPostpone(packet, autoMatchmakeParam) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go b/nex-protocols-common-go/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go new file mode 100644 index 0000000..4d478ee --- /dev/null +++ b/nex-protocols-common-go/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go @@ -0,0 +1,74 @@ +package matchmake_extension + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" +) + +func (commonProtocol *CommonProtocol) autoMatchmakeWithSearchCriteriaPostpone(err error, packet nex.PacketInterface, callID uint32, lstSearchCriteria *types.List[*match_making_types.MatchmakeSessionSearchCriteria], anyGathering *types.AnyDataHolder, strMessage *types.String) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + // * A client may disconnect from a session without leaving reliably, + // * so let's make sure the client is removed from the session + common_globals.RemoveConnectionFromAllSessions(connection) + + var matchmakeSession *match_making_types.MatchmakeSession + + if anyGathering.TypeName.Value == "MatchmakeSession" { + matchmakeSession = anyGathering.ObjectData.(*match_making_types.MatchmakeSession) + } else { + common_globals.Logger.Critical("Non-MatchmakeSession DataType?!") + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + sessions := common_globals.FindSessionsByMatchmakeSessionSearchCriterias(connection.PID(), lstSearchCriteria.Slice(), commonProtocol.GameSpecificMatchmakeSessionSearchCriteriaChecks) + var session *common_globals.CommonMatchmakeSession + + if len(sessions) == 0 { + var errCode *nex.Error + session, errCode = common_globals.CreateSessionByMatchmakeSession(matchmakeSession, nil, connection.PID()) + if errCode != nil { + common_globals.Logger.Error(errCode.Error()) + return nil, errCode + } + } else { + session = sessions[0] + } + + errCode := common_globals.AddPlayersToSession(session, []uint32{connection.ID}, connection, strMessage.Value) + if errCode != nil { + common_globals.Logger.Error(errCode.Error()) + return nil, errCode + } + + matchmakeDataHolder := types.NewAnyDataHolder() + + matchmakeDataHolder.TypeName = types.NewString("MatchmakeSession") + matchmakeDataHolder.ObjectData = session.GameMatchmakeSession.Copy() + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + matchmakeDataHolder.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.MethodID = matchmake_extension.MethodAutoMatchmakeWithSearchCriteriaPostpone + rmcResponse.CallID = callID + + if commonProtocol.OnAfterAutoMatchmakeWithSearchCriteriaPostpone != nil { + go commonProtocol.OnAfterAutoMatchmakeWithSearchCriteriaPostpone(packet, lstSearchCriteria, anyGathering, strMessage) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/matchmake-extension/browse_matchmake_session.go b/nex-protocols-common-go/matchmake-extension/browse_matchmake_session.go new file mode 100644 index 0000000..18e8c64 --- /dev/null +++ b/nex-protocols-common-go/matchmake-extension/browse_matchmake_session.go @@ -0,0 +1,67 @@ +package matchmake_extension + +import ( + "math" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" +) + +func (commonProtocol *CommonProtocol) browseMatchmakeSession(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + searchCriterias := []*match_making_types.MatchmakeSessionSearchCriteria{searchCriteria} + + sessions := common_globals.FindSessionsByMatchmakeSessionSearchCriterias(connection.PID(), searchCriterias, commonProtocol.GameSpecificMatchmakeSessionSearchCriteriaChecks) + + // TODO - Is this right? + if resultRange.Offset.Value != math.MaxUint32 { + if len(sessions) < int(resultRange.Offset.Value) { + return nil, nex.NewError(nex.ResultCodes.Core.InvalidIndex, "change_error") + } + + sessions = sessions[resultRange.Offset.Value:] + } + + + if len(sessions) > int(resultRange.Length.Value) { + sessions = sessions[:resultRange.Length.Value] + } + + lstGathering := types.NewList[*types.AnyDataHolder]() + lstGathering.Type = types.NewAnyDataHolder() + + for _, session := range sessions { + matchmakeSessionDataHolder := types.NewAnyDataHolder() + matchmakeSessionDataHolder.TypeName = types.NewString("MatchmakeSession") + matchmakeSessionDataHolder.ObjectData = session.GameMatchmakeSession.Copy() + + lstGathering.Append(matchmakeSessionDataHolder) + } + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lstGathering.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.MethodID = matchmake_extension.MethodBrowseMatchmakeSession + rmcResponse.CallID = callID + + if commonProtocol.OnAfterBrowseMatchmakeSession != nil { + go commonProtocol.OnAfterBrowseMatchmakeSession(packet, searchCriteria, resultRange) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/matchmake-extension/close_participation.go b/nex-protocols-common-go/matchmake-extension/close_participation.go new file mode 100644 index 0000000..6bc1b00 --- /dev/null +++ b/nex-protocols-common-go/matchmake-extension/close_participation.go @@ -0,0 +1,40 @@ +package matchmake_extension + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" +) + +func (commonProtocol *CommonProtocol) closeParticipation(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + session, ok := common_globals.Sessions[gid.Value] + if !ok { + return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + if !session.GameMatchmakeSession.Gathering.OwnerPID.Equals(connection.PID()) { + return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") + } + + session.GameMatchmakeSession.OpenParticipation = types.NewPrimitiveBool(false) + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.MethodID = matchmake_extension.MethodCloseParticipation + rmcResponse.CallID = callID + + if commonProtocol.OnAfterCloseParticipation != nil { + go commonProtocol.OnAfterCloseParticipation(packet, gid) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/matchmake-extension/create_matchmake_session.go b/nex-protocols-common-go/matchmake-extension/create_matchmake_session.go new file mode 100644 index 0000000..b67f76a --- /dev/null +++ b/nex-protocols-common-go/matchmake-extension/create_matchmake_session.go @@ -0,0 +1,66 @@ +package matchmake_extension + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" +) + +func (commonProtocol *CommonProtocol) createMatchmakeSession(err error, packet nex.PacketInterface, callID uint32, anyGathering *types.AnyDataHolder, message *types.String, participationCount *types.PrimitiveU16) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + server := endpoint.Server + + // * A client may disconnect from a session without leaving reliably, + // * so let's make sure the client is removed from the session + common_globals.RemoveConnectionFromAllSessions(connection) + + var matchmakeSession *match_making_types.MatchmakeSession + + if anyGathering.TypeName.Value == "MatchmakeSession" { + matchmakeSession = anyGathering.ObjectData.(*match_making_types.MatchmakeSession) + } else { + common_globals.Logger.Critical("Non-MatchmakeSession DataType?!") + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + session, errCode := common_globals.CreateSessionByMatchmakeSession(matchmakeSession, nil, connection.PID()) + if errCode != nil { + common_globals.Logger.Error(errCode.Error()) + return nil, errCode + } + + errCode = common_globals.AddPlayersToSession(session, []uint32{connection.ID}, connection, message.Value) + if errCode != nil { + common_globals.Logger.Error(errCode.Error()) + return nil, errCode + } + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + session.GameMatchmakeSession.Gathering.ID.WriteTo(rmcResponseStream) + + if server.LibraryVersions.MatchMaking.GreaterOrEqual("3.0.0") { + session.GameMatchmakeSession.SessionKey.WriteTo(rmcResponseStream) + } + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.MethodID = matchmake_extension.MethodCreateMatchmakeSession + rmcResponse.CallID = callID + + if commonProtocol.OnAfterCreateMatchmakeSession != nil { + go commonProtocol.OnAfterCreateMatchmakeSession(packet, anyGathering, message, participationCount) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/matchmake-extension/create_matchmake_session_with_param.go b/nex-protocols-common-go/matchmake-extension/create_matchmake_session_with_param.go new file mode 100644 index 0000000..056ddad --- /dev/null +++ b/nex-protocols-common-go/matchmake-extension/create_matchmake_session_with_param.go @@ -0,0 +1,52 @@ +package matchmake_extension + +import ( + "github.com/PretendoNetwork/nex-go/v2" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" +) + +func (commonProtocol *CommonProtocol) createMatchmakeSessionWithParam(err error, packet nex.PacketInterface, callID uint32, createMatchmakeSessionParam *match_making_types.CreateMatchmakeSessionParam) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + // * A client may disconnect from a session without leaving reliably, + // * so let's make sure the client is removed from all sessions + common_globals.RemoveConnectionFromAllSessions(connection) + + joinedMatchmakeSession := createMatchmakeSessionParam.SourceMatchmakeSession.Copy().(*match_making_types.MatchmakeSession) + session, errCode := common_globals.CreateSessionByMatchmakeSession(joinedMatchmakeSession, nil, connection.PID()) + if errCode != nil { + common_globals.Logger.Error(errCode.Error()) + return nil, errCode + } + + errCode = common_globals.AddPlayersToSession(session, []uint32{connection.ID}, connection, createMatchmakeSessionParam.JoinMessage.Value) + if errCode != nil { + common_globals.Logger.Error(errCode.Error()) + return nil, errCode + } + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + session.GameMatchmakeSession.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.MethodID = matchmake_extension.MethodCreateMatchmakeSessionWithParam + rmcResponse.CallID = callID + + if commonProtocol.OnAfterCreateMatchmakeSessionWithParam != nil { + go commonProtocol.OnAfterCreateMatchmakeSessionWithParam(packet, createMatchmakeSessionParam) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/matchmake-extension/get_simple_playing_session.go b/nex-protocols-common-go/matchmake-extension/get_simple_playing_session.go new file mode 100644 index 0000000..5059426 --- /dev/null +++ b/nex-protocols-common-go/matchmake-extension/get_simple_playing_session.go @@ -0,0 +1,87 @@ +package matchmake_extension + +import ( + "fmt" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" + "golang.org/x/exp/slices" +) + +func (commonProtocol *CommonProtocol) getSimplePlayingSession(err error, packet nex.PacketInterface, callID uint32, listPID *types.List[*types.PID], includeLoginUser *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + // * Does nothing if element is not present in the List + listPID.Remove(connection.PID()) + + if includeLoginUser.Value && !listPID.Contains(connection.PID()) { + listPID.Append(connection.PID().Copy().(*types.PID)) + } + + simplePlayingSessions := make(map[string]*match_making_types.SimplePlayingSession) + + for gatheringID, session := range common_globals.Sessions { + for _, pid := range listPID.Slice() { + key := fmt.Sprintf("%d-%d", gatheringID, pid.Value()) + if simplePlayingSessions[key] == nil { + connectedPIDs := make([]uint64, 0) + session.ConnectionIDs.Each(func(_ int, connectionID uint32) bool { + player := endpoint.FindConnectionByID(connectionID) + if player == nil { + common_globals.Logger.Warning("Player not found") + return false + } + + connectedPIDs = append(connectedPIDs, player.PID().Value()) + return false + }) + + if slices.Contains(connectedPIDs, pid.Value()) { + attribute0, err := session.GameMatchmakeSession.Attributes.Get(0) + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + simplePlayingSessions[key] = match_making_types.NewSimplePlayingSession() + simplePlayingSessions[key].PrincipalID = pid.Copy().(*types.PID) + simplePlayingSessions[key].GatheringID = types.NewPrimitiveU32(gatheringID) + simplePlayingSessions[key].GameMode = session.GameMatchmakeSession.GameMode.Copy().(*types.PrimitiveU32) + simplePlayingSessions[key].Attribute0 = attribute0.Copy().(*types.PrimitiveU32) + } + } + } + } + + lstSimplePlayingSession := types.NewList[*match_making_types.SimplePlayingSession]() + + for _, simplePlayingSession := range simplePlayingSessions { + lstSimplePlayingSession.Append(simplePlayingSession) + } + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lstSimplePlayingSession.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.MethodID = matchmake_extension.MethodGetSimplePlayingSession + rmcResponse.CallID = callID + + if commonProtocol.OnAfterGetSimplePlayingSession != nil { + go commonProtocol.OnAfterGetSimplePlayingSession(packet, listPID, includeLoginUser) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/matchmake-extension/join_matchmake_session.go b/nex-protocols-common-go/matchmake-extension/join_matchmake_session.go new file mode 100644 index 0000000..789523e --- /dev/null +++ b/nex-protocols-common-go/matchmake-extension/join_matchmake_session.go @@ -0,0 +1,52 @@ +package matchmake_extension + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" +) + +func (commonProtocol *CommonProtocol) joinMatchmakeSession(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + session, ok := common_globals.Sessions[gid.Value] + if !ok { + return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + server := endpoint.Server + + // TODO - More checks here + errCode := common_globals.AddPlayersToSession(session, []uint32{connection.ID}, connection, strMessage.Value) + if errCode != nil { + common_globals.Logger.Error(errCode.Error()) + return nil, errCode + } + + joinedMatchmakeSession := session.GameMatchmakeSession + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + if server.LibraryVersions.MatchMaking.GreaterOrEqual("3.0.0") { + joinedMatchmakeSession.SessionKey.WriteTo(rmcResponseStream) + } + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.MethodID = matchmake_extension.MethodJoinMatchmakeSession + rmcResponse.CallID = callID + + if commonProtocol.OnAfterJoinMatchmakeSession != nil { + go commonProtocol.OnAfterJoinMatchmakeSession(packet, gid, strMessage) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/matchmake-extension/join_matchmake_session_ex.go b/nex-protocols-common-go/matchmake-extension/join_matchmake_session_ex.go new file mode 100644 index 0000000..fb3d647 --- /dev/null +++ b/nex-protocols-common-go/matchmake-extension/join_matchmake_session_ex.go @@ -0,0 +1,52 @@ +package matchmake_extension + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" +) + +func (commonProtocol *CommonProtocol) joinMatchmakeSessionEx(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, strMessage *types.String, dontCareMyBlockList *types.PrimitiveBool, participationCount *types.PrimitiveU16) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + session, ok := common_globals.Sessions[gid.Value] + if !ok { + return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + server := endpoint.Server + + // TODO - More checks here + errCode := common_globals.AddPlayersToSession(session, []uint32{connection.ID}, connection, strMessage.Value) + if errCode != nil { + common_globals.Logger.Error(errCode.Error()) + return nil, errCode + } + + joinedMatchmakeSession := session.GameMatchmakeSession + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + if server.LibraryVersions.MatchMaking.GreaterOrEqual("3.0.0") { + joinedMatchmakeSession.SessionKey.WriteTo(rmcResponseStream) + } + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.MethodID = matchmake_extension.MethodJoinMatchmakeSessionEx + rmcResponse.CallID = callID + + if commonProtocol.OnAfterJoinMatchmakeSessionEx != nil { + go commonProtocol.OnAfterJoinMatchmakeSessionEx(packet, gid, strMessage, dontCareMyBlockList, participationCount) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/matchmake-extension/join_matchmake_session_with_param.go b/nex-protocols-common-go/matchmake-extension/join_matchmake_session_with_param.go new file mode 100644 index 0000000..22cf55c --- /dev/null +++ b/nex-protocols-common-go/matchmake-extension/join_matchmake_session_with_param.go @@ -0,0 +1,47 @@ +package matchmake_extension + +import ( + "github.com/PretendoNetwork/nex-go/v2" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" +) + +func (commonProtocol *CommonProtocol) joinMatchmakeSessionWithParam(err error, packet nex.PacketInterface, callID uint32, joinMatchmakeSessionParam *match_making_types.JoinMatchmakeSessionParam) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + session, ok := common_globals.Sessions[joinMatchmakeSessionParam.GID.Value] + if !ok { + return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + // TODO - More checks here + errCode := common_globals.AddPlayersToSession(session, []uint32{connection.ID}, connection, joinMatchmakeSessionParam.JoinMessage.Value) + if errCode != nil { + common_globals.Logger.Error(errCode.Error()) + return nil, errCode + } + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + session.GameMatchmakeSession.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.MethodID = matchmake_extension.MethodJoinMatchmakeSessionWithParam + rmcResponse.CallID = callID + + if commonProtocol.OnAfterJoinMatchmakeSessionWithParam != nil { + go commonProtocol.OnAfterJoinMatchmakeSessionWithParam(packet, joinMatchmakeSessionParam) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/matchmake-extension/modify_current_game_attribute.go b/nex-protocols-common-go/matchmake-extension/modify_current_game_attribute.go new file mode 100644 index 0000000..8a12be3 --- /dev/null +++ b/nex-protocols-common-go/matchmake-extension/modify_current_game_attribute.go @@ -0,0 +1,46 @@ +package matchmake_extension + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" +) + +func (commonProtocol *CommonProtocol) modifyCurrentGameAttribute(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, attribIndex *types.PrimitiveU32, newValue *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + session, ok := common_globals.Sessions[gid.Value] + if !ok { + return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + } + + if !session.GameMatchmakeSession.Gathering.OwnerPID.Equals(connection.PID()) { + return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") + } + + index := int(attribIndex.Value) + + if index > session.GameMatchmakeSession.Attributes.Length() { + return nil, nex.NewError(nex.ResultCodes.Core.InvalidIndex, "change_error") + } + + session.GameMatchmakeSession.Attributes.SetIndex(index, newValue.Copy().(*types.PrimitiveU32)) + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.MethodID = matchmake_extension.MethodModifyCurrentGameAttribute + rmcResponse.CallID = callID + + if commonProtocol.OnAfterModifyCurrentGameAttribute != nil { + go commonProtocol.OnAfterModifyCurrentGameAttribute(packet, gid, attribIndex, newValue) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/matchmake-extension/open_participation.go b/nex-protocols-common-go/matchmake-extension/open_participation.go new file mode 100644 index 0000000..dde2d8a --- /dev/null +++ b/nex-protocols-common-go/matchmake-extension/open_participation.go @@ -0,0 +1,40 @@ +package matchmake_extension + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" +) + +func (commonProtocol *CommonProtocol) openParticipation(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + session, ok := common_globals.Sessions[gid.Value] + if !ok { + return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + } + + if !session.GameMatchmakeSession.Gathering.OwnerPID.Equals(connection.PID()) { + return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") + } + + session.GameMatchmakeSession.OpenParticipation = types.NewPrimitiveBool(true) + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.MethodID = matchmake_extension.MethodOpenParticipation + rmcResponse.CallID = callID + + if commonProtocol.OnAfterOpenParticipation != nil { + go commonProtocol.OnAfterOpenParticipation(packet, gid) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/matchmake-extension/protocol.go b/nex-protocols-common-go/matchmake-extension/protocol.go new file mode 100644 index 0000000..34fb51d --- /dev/null +++ b/nex-protocols-common-go/matchmake-extension/protocol.go @@ -0,0 +1,63 @@ +package matchmake_extension + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" + + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" +) + +type CommonProtocol struct { + endpoint nex.EndpointInterface + protocol matchmake_extension.Interface + CleanupSearchMatchmakeSession func(matchmakeSession *match_making_types.MatchmakeSession) + GameSpecificMatchmakeSessionSearchCriteriaChecks func(searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, matchmakeSession *match_making_types.MatchmakeSession) bool + OnAfterOpenParticipation func(packet nex.PacketInterface, gid *types.PrimitiveU32) + OnAfterCloseParticipation func(packet nex.PacketInterface, gid *types.PrimitiveU32) + OnAfterCreateMatchmakeSession func(packet nex.PacketInterface, anyGathering *types.AnyDataHolder, message *types.String, participationCount *types.PrimitiveU16) + OnAfterGetSimplePlayingSession func(packet nex.PacketInterface, listPID *types.List[*types.PID], includeLoginUser *types.PrimitiveBool) + OnAfterAutoMatchmakePostpone func(packet nex.PacketInterface, anyGathering *types.AnyDataHolder, message *types.String) + OnAfterAutoMatchmakeWithParamPostpone func(packet nex.PacketInterface, autoMatchmakeParam *match_making_types.AutoMatchmakeParam) + OnAfterAutoMatchmakeWithSearchCriteriaPostpone func(packet nex.PacketInterface, lstSearchCriteria *types.List[*match_making_types.MatchmakeSessionSearchCriteria], anyGathering *types.AnyDataHolder, strMessage *types.String) + OnAfterUpdateProgressScore func(packet nex.PacketInterface, gid *types.PrimitiveU32, progressScore *types.PrimitiveU8) + OnAfterCreateMatchmakeSessionWithParam func(packet nex.PacketInterface, createMatchmakeSessionParam *match_making_types.CreateMatchmakeSessionParam) + OnAfterUpdateApplicationBuffer func(packet nex.PacketInterface, gid *types.PrimitiveU32, applicationBuffer *types.Buffer) + OnAfterJoinMatchmakeSession func(packet nex.PacketInterface, gid *types.PrimitiveU32, strMessage *types.String) + OnAfterJoinMatchmakeSessionWithParam func(packet nex.PacketInterface, joinMatchmakeSessionParam *match_making_types.JoinMatchmakeSessionParam) + OnAfterModifyCurrentGameAttribute func(packet nex.PacketInterface, gid *types.PrimitiveU32, attribIndex *types.PrimitiveU32, newValue *types.PrimitiveU32) + OnAfterBrowseMatchmakeSession func(packet nex.PacketInterface, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, resultRange *types.ResultRange) + OnAfterJoinMatchmakeSessionEx func(packet nex.PacketInterface, gid *types.PrimitiveU32, strMessage *types.String, dontCareMyBlockList *types.PrimitiveBool, participationCount *types.PrimitiveU16) +} + +// GetUserFriendPIDs sets the GetUserFriendPIDs handler function +func (commonProtocol *CommonProtocol) GetUserFriendPIDs(handler func(pid uint32) []uint32) { + common_globals.GetUserFriendPIDsHandler = handler +} + +// NewCommonProtocol returns a new CommonProtocol +func NewCommonProtocol(protocol matchmake_extension.Interface) *CommonProtocol { + commonProtocol := &CommonProtocol{ + endpoint: protocol.Endpoint(), + protocol: protocol, + } + + protocol.SetHandlerOpenParticipation(commonProtocol.openParticipation) + protocol.SetHandlerCloseParticipation(commonProtocol.closeParticipation) + protocol.SetHandlerCreateMatchmakeSession(commonProtocol.createMatchmakeSession) + protocol.SetHandlerGetSimplePlayingSession(commonProtocol.getSimplePlayingSession) + protocol.SetHandlerAutoMatchmakePostpone(commonProtocol.autoMatchmakePostpone) + protocol.SetHandlerAutoMatchmakeWithParamPostpone(commonProtocol.autoMatchmakeWithParamPostpone) + protocol.SetHandlerAutoMatchmakeWithSearchCriteriaPostpone(commonProtocol.autoMatchmakeWithSearchCriteriaPostpone) + protocol.SetHandlerUpdateProgressScore(commonProtocol.updateProgressScore) + protocol.SetHandlerCreateMatchmakeSessionWithParam(commonProtocol.createMatchmakeSessionWithParam) + protocol.SetHandlerUpdateApplicationBuffer(commonProtocol.updateApplicationBuffer) + protocol.SetHandlerJoinMatchmakeSession(commonProtocol.joinMatchmakeSession) + protocol.SetHandlerJoinMatchmakeSessionWithParam(commonProtocol.joinMatchmakeSessionWithParam) + protocol.SetHandlerModifyCurrentGameAttribute(commonProtocol.modifyCurrentGameAttribute) + protocol.SetHandlerBrowseMatchmakeSession(commonProtocol.browseMatchmakeSession) + protocol.SetHandlerJoinMatchmakeSessionEx(commonProtocol.joinMatchmakeSessionEx) + + return commonProtocol +} diff --git a/nex-protocols-common-go/matchmake-extension/update_application_buffer.go b/nex-protocols-common-go/matchmake-extension/update_application_buffer.go new file mode 100644 index 0000000..325fc16 --- /dev/null +++ b/nex-protocols-common-go/matchmake-extension/update_application_buffer.go @@ -0,0 +1,38 @@ +package matchmake_extension + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" +) + +func (commonProtocol *CommonProtocol) updateApplicationBuffer(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, applicationBuffer *types.Buffer) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + session, ok := common_globals.Sessions[gid.Value] + if !ok { + return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + } + + // TODO - Should ANYONE be allowed to do this?? + + session.GameMatchmakeSession.ApplicationBuffer = applicationBuffer.Copy().(*types.Buffer) + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.MethodID = matchmake_extension.MethodUpdateApplicationBuffer + rmcResponse.CallID = callID + + if commonProtocol.OnAfterUpdateApplicationBuffer != nil { + go commonProtocol.OnAfterUpdateApplicationBuffer(packet, gid, applicationBuffer) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/matchmake-extension/update_progress_score.go b/nex-protocols-common-go/matchmake-extension/update_progress_score.go new file mode 100644 index 0000000..57a7773 --- /dev/null +++ b/nex-protocols-common-go/matchmake-extension/update_progress_score.go @@ -0,0 +1,44 @@ +package matchmake_extension + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" +) + +func (commonProtocol *CommonProtocol) updateProgressScore(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, progressScore *types.PrimitiveU8) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + session := common_globals.Sessions[gid.Value] + if session == nil { + return nil, nex.NewError(nex.ResultCodes.RendezVous.SessionVoid, "change_error") + } + + if progressScore.Value > 100 { + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + if !session.GameMatchmakeSession.Gathering.OwnerPID.Equals(connection.PID()) { + return nil, nex.NewError(nex.ResultCodes.RendezVous.PermissionDenied, "change_error") + } + + session.GameMatchmakeSession.ProgressScore.Value += progressScore.Value + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.MethodID = matchmake_extension.MethodUpdateProgressScore + rmcResponse.CallID = callID + + if commonProtocol.OnAfterUpdateProgressScore != nil { + go commonProtocol.OnAfterUpdateProgressScore(packet, gid, progressScore) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/nat-traversal/README.md b/nex-protocols-common-go/nat-traversal/README.md new file mode 100644 index 0000000..fc97238 --- /dev/null +++ b/nex-protocols-common-go/nat-traversal/README.md @@ -0,0 +1,2 @@ +# nat-traversal +Implementation of the NEX NAT traversal protocol for Pretendo game servers diff --git a/nex-protocols-common-go/nat-traversal/get_relay_signature_key.go b/nex-protocols-common-go/nat-traversal/get_relay_signature_key.go new file mode 100644 index 0000000..aa5a328 --- /dev/null +++ b/nex-protocols-common-go/nat-traversal/get_relay_signature_key.go @@ -0,0 +1,50 @@ +package nattraversal + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + nat_traversal "github.com/PretendoNetwork/nex-protocols-go/v2/nat-traversal" + + //"encoding/hex" +) + +func (commonProtocol *CommonProtocol) getRelaySignatureKey(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + relayMode := types.NewPrimitiveS32(0xff) // * Unknown, 1 appears to use direct connection? + currentUTCTime := types.NewDateTime(0).Now() // * Current time for the relay server, UTC + address := types.NewString("") // * Relay server address. We don't have one, so for now this is empty. + port := types.NewPrimitiveU16(0) // * Relay server port. We don't have one, so for now this is empty. + relayAddressType := types.NewPrimitiveS32(0xff) // * Unknown, 1 appears to use direct connection? + gameServerID := types.NewPrimitiveU32(0) // * Game Server ID. I don't know if this is checked (it doesn't appear to be though). + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + relayMode.WriteTo(rmcResponseStream) + currentUTCTime.WriteTo(rmcResponseStream) + address.WriteTo(rmcResponseStream) + port.WriteTo(rmcResponseStream) + relayAddressType.WriteTo(rmcResponseStream) + gameServerID.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + //rmcResponseBody, _ = hex.DecodeString("01000000ef748f991f00000021006c312d30303035356430312e722e6e2e6170702e6e696e74656e646f2e6e657400000001000000015d0500") + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = nat_traversal.ProtocolID + rmcResponse.MethodID = nat_traversal.MethodGetRelaySignatureKey + rmcResponse.CallID = callID + + if commonProtocol.OnAfterGetRelaySignatureKey != nil { + go commonProtocol.OnAfterGetRelaySignatureKey(packet) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/nat-traversal/protocol.go b/nex-protocols-common-go/nat-traversal/protocol.go new file mode 100644 index 0000000..81a23f5 --- /dev/null +++ b/nex-protocols-common-go/nat-traversal/protocol.go @@ -0,0 +1,33 @@ +package nattraversal + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + nat_traversal "github.com/PretendoNetwork/nex-protocols-go/v2/nat-traversal" +) + +type CommonProtocol struct { + endpoint nex.EndpointInterface + protocol nat_traversal.Interface + OnAfterRequestProbeInitiationExt func(packet nex.PacketInterface, targetList *types.List[*types.String], stationToProbe *types.String) + OnAfterReportNATProperties func(packet nex.PacketInterface, natmapping *types.PrimitiveU32, natfiltering *types.PrimitiveU32, rtt *types.PrimitiveU32) + OnAfterReportNATTraversalResult func(packet nex.PacketInterface, cid *types.PrimitiveU32, result *types.PrimitiveBool, rtt *types.PrimitiveU32) + OnAfterGetRelaySignatureKey func(packet nex.PacketInterface) + OnAfterReportNATTraversalResultDetail func(packet nex.PacketInterface, cid *types.PrimitiveU32, result *types.PrimitiveBool, detail *types.PrimitiveS32, rtt *types.PrimitiveU32) +} + +// NewCommonProtocol returns a new CommonProtocol +func NewCommonProtocol(protocol nat_traversal.Interface) *CommonProtocol { + commonProtocol := &CommonProtocol{ + endpoint: protocol.Endpoint(), + protocol: protocol, + } + + protocol.SetHandlerRequestProbeInitiationExt(commonProtocol.requestProbeInitiationExt) + protocol.SetHandlerReportNATProperties(commonProtocol.reportNATProperties) + protocol.SetHandlerReportNATTraversalResult(commonProtocol.reportNATTraversalResult) + protocol.SetHandlerGetRelaySignatureKey(commonProtocol.getRelaySignatureKey) + protocol.SetHandlerReportNATTraversalResultDetail(commonProtocol.reportNATTraversalResultDetail) + + return commonProtocol +} diff --git a/nex-protocols-common-go/nat-traversal/report_nat_properties.go b/nex-protocols-common-go/nat-traversal/report_nat_properties.go new file mode 100644 index 0000000..62aa129 --- /dev/null +++ b/nex-protocols-common-go/nat-traversal/report_nat_properties.go @@ -0,0 +1,40 @@ +package nattraversal + +import ( + "github.com/PretendoNetwork/nex-go/v2" + //"github.com/PretendoNetwork/nex-go/v2/constants" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + nat_traversal "github.com/PretendoNetwork/nex-protocols-go/v2/nat-traversal" +) + +func (commonProtocol *CommonProtocol) reportNATProperties(err error, packet nex.PacketInterface, callID uint32, natmapping *types.PrimitiveU32, natfiltering *types.PrimitiveU32, rtt *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + for _, station := range connection.StationURLs.Slice() { + if !station.IsPublic() { + //station.SetNATMapping(constants.NATMappingProperties(natmapping.Value)) + //station.SetNATFiltering(constants.NATFilteringProperties(natfiltering.Value)) + } + + station.SetRVConnectionID(connection.ID) + station.SetPrincipalID(connection.PID()) + } + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = nat_traversal.ProtocolID + rmcResponse.MethodID = nat_traversal.MethodReportNATProperties + rmcResponse.CallID = callID + + if commonProtocol.OnAfterReportNATProperties != nil { + go commonProtocol.OnAfterReportNATProperties(packet, natmapping, natfiltering, rtt) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/nat-traversal/report_nat_traversal_result.go b/nex-protocols-common-go/nat-traversal/report_nat_traversal_result.go new file mode 100644 index 0000000..54bd2ff --- /dev/null +++ b/nex-protocols-common-go/nat-traversal/report_nat_traversal_result.go @@ -0,0 +1,29 @@ +package nattraversal + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + nat_traversal "github.com/PretendoNetwork/nex-protocols-go/v2/nat-traversal" +) + +func (commonProtocol *CommonProtocol) reportNATTraversalResult(err error, packet nex.PacketInterface, callID uint32, cid *types.PrimitiveU32, result *types.PrimitiveBool, rtt *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = nat_traversal.ProtocolID + rmcResponse.MethodID = nat_traversal.MethodReportNATTraversalResult + rmcResponse.CallID = callID + + if commonProtocol.OnAfterReportNATTraversalResult != nil { + go commonProtocol.OnAfterReportNATTraversalResult(packet, cid, result, rtt) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/nat-traversal/report_nat_traversal_result_detail.go b/nex-protocols-common-go/nat-traversal/report_nat_traversal_result_detail.go new file mode 100644 index 0000000..cd38b03 --- /dev/null +++ b/nex-protocols-common-go/nat-traversal/report_nat_traversal_result_detail.go @@ -0,0 +1,29 @@ +package nattraversal + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + nat_traversal "github.com/PretendoNetwork/nex-protocols-go/v2/nat-traversal" +) + +func (commonProtocol *CommonProtocol) reportNATTraversalResultDetail(err error, packet nex.PacketInterface, callID uint32, cid *types.PrimitiveU32, result *types.PrimitiveBool, detail *types.PrimitiveS32, rtt *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = nat_traversal.ProtocolID + rmcResponse.MethodID = nat_traversal.MethodReportNATTraversalResultDetail + rmcResponse.CallID = callID + + if commonProtocol.OnAfterReportNATTraversalResultDetail != nil { + go commonProtocol.OnAfterReportNATTraversalResultDetail(packet, cid, result, detail, rtt) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/nat-traversal/request_probe_initiation_ext.go b/nex-protocols-common-go/nat-traversal/request_probe_initiation_ext.go new file mode 100644 index 0000000..cd8c322 --- /dev/null +++ b/nex-protocols-common-go/nat-traversal/request_probe_initiation_ext.go @@ -0,0 +1,93 @@ +package nattraversal + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/constants" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + nat_traversal "github.com/PretendoNetwork/nex-protocols-go/v2/nat-traversal" + "fmt" +) + +func (commonProtocol *CommonProtocol) requestProbeInitiationExt(err error, packet nex.PacketInterface, callID uint32, targetList *types.List[*types.String], stationToProbe *types.String) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + server := endpoint.Server + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = nat_traversal.ProtocolID + rmcResponse.MethodID = nat_traversal.MethodRequestProbeInitiationExt + rmcResponse.CallID = callID + + rmcRequestStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + //lol nice hack thanks pokemon + stationToProbeStation := types.NewStationURL(stationToProbe.Value) + _, exists := stationToProbeStation.StreamID() + if(!exists){ + stationToProbeStation.SetNATFiltering(0) + stationToProbeStation.SetNATMapping(0) + stationToProbeStation.SetNATPMPSupport(false) + stationToProbeStation.SetStreamID(15) + stationToProbeStation.SetUPnPSupport(false) + //stationToProbe = types.NewString(stationToProbeStation.EncodeToString()) + } + stationToProbe.WriteTo(rmcRequestStream) + fmt.Println("stationToProbe") + fmt.Println(stationToProbe) + fmt.Println(connection.PID()) + + rmcRequestBody := rmcRequestStream.Bytes() + + rmcRequest := nex.NewRMCRequest(endpoint) + rmcRequest.ProtocolID = nat_traversal.ProtocolID + rmcRequest.CallID = 0xFFFF0000 + callID + rmcRequest.MethodID = nat_traversal.MethodInitiateProbe + rmcRequest.Parameters = rmcRequestBody + + rmcRequestBytes := rmcRequest.Bytes() + + for _, target := range targetList.Slice() { + targetStation := types.NewStationURL(target.Value) + fmt.Println("target.Value") + fmt.Println(target.Value) + + if connectionID, ok := targetStation.RVConnectionID(); ok { + target := endpoint.FindConnectionByID(connectionID) + if target == nil { + common_globals.Logger.Warning("Client not found") + continue + } + + var messagePacket nex.PRUDPPacketInterface + + if target.DefaultPRUDPVersion == 0 { + messagePacket, _ = nex.NewPRUDPPacketV0(server, target, nil) + } else { + messagePacket, _ = nex.NewPRUDPPacketV1(server, target, nil) + } + + messagePacket.SetType(constants.DataPacket) + messagePacket.AddFlag(constants.PacketFlagNeedsAck) + messagePacket.AddFlag(constants.PacketFlagReliable) + messagePacket.SetSourceVirtualPortStreamType(target.StreamType) + messagePacket.SetSourceVirtualPortStreamID(endpoint.StreamID) + messagePacket.SetDestinationVirtualPortStreamType(target.StreamType) + messagePacket.SetDestinationVirtualPortStreamID(target.StreamID) + messagePacket.SetPayload(rmcRequestBytes) + + server.Send(messagePacket) + } + } + + if commonProtocol.OnAfterRequestProbeInitiationExt != nil { + go commonProtocol.OnAfterRequestProbeInitiationExt(packet, targetList, stationToProbe) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/ranking/get_cached_top_x_ranking.go b/nex-protocols-common-go/ranking/get_cached_top_x_ranking.go new file mode 100644 index 0000000..2605201 --- /dev/null +++ b/nex-protocols-common-go/ranking/get_cached_top_x_ranking.go @@ -0,0 +1,69 @@ +package ranking + +import ( + "time" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + ranking "github.com/PretendoNetwork/nex-protocols-go/v2/ranking" + ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" +) + +func (commonProtocol *CommonProtocol) getCachedTopXRanking(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.GetRankingsAndCountByCategoryAndRankingOrderParam == nil { + common_globals.Logger.Warning("Ranking::GetCachedTopXRanking missing GetRankingsAndCountByCategoryAndRankingOrderParam!") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Ranking.InvalidArgument, "change_error") + } + + rankDataList, totalCount, err := commonProtocol.GetRankingsAndCountByCategoryAndRankingOrderParam(category, orderParam) + if err != nil { + common_globals.Logger.Critical(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Ranking.Unknown, "change_error") + } + + if totalCount == 0 || rankDataList.Length() == 0 { + return nil, nex.NewError(nex.ResultCodes.Ranking.NotFound, "change_error") + } + + pResult := ranking_types.NewRankingCachedResult() + + pResult.RankingResult.RankDataList = rankDataList + pResult.RankingResult.TotalCount = types.NewPrimitiveU32(totalCount) + pResult.RankingResult.SinceTime = types.NewDateTime(0x1F40420000) // * 2000-01-01T00:00:00.000Z, this is what the real server sends back + + pResult.CreatedTime = types.NewDateTime(0).Now() + // * The real server sends the "CreatedTime" + 5 minutes. + // * It doesn't change, even on subsequent requests, until after the + // * ExpiredTime has passed (seemingly what the "cached" means). + // * Whether we need to replicate this idk, but in case, here's a note. + pResult.ExpiredTime = types.NewDateTime(0).FromTimestamp(time.Now().UTC().Add(time.Minute * time.Duration(5))) + // * This is the length Ultimate NES Remix uses + // TODO - Does this matter? and are other games different? + pResult.MaxLength = types.NewPrimitiveU8(10) + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pResult.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = ranking.ProtocolID + rmcResponse.MethodID = ranking.MethodGetCachedTopXRanking + rmcResponse.CallID = callID + + if commonProtocol.OnAfterGetCachedTopXRanking != nil { + go commonProtocol.OnAfterGetCachedTopXRanking(packet, category, orderParam) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/ranking/get_cached_top_x_rankings.go b/nex-protocols-common-go/ranking/get_cached_top_x_rankings.go new file mode 100644 index 0000000..c610e7d --- /dev/null +++ b/nex-protocols-common-go/ranking/get_cached_top_x_rankings.go @@ -0,0 +1,88 @@ +package ranking + +import ( + "time" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + ranking "github.com/PretendoNetwork/nex-protocols-go/v2/ranking" + ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" +) + +func (commonProtocol *CommonProtocol) getCachedTopXRankings(err error, packet nex.PacketInterface, callID uint32, categories *types.List[*types.PrimitiveU32], orderParams *types.List[*ranking_types.RankingOrderParam]) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.GetRankingsAndCountByCategoryAndRankingOrderParam == nil { + common_globals.Logger.Warning("Ranking::GetCachedTopXRankings missing GetRankingsAndCountByCategoryAndRankingOrderParam!") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Ranking.InvalidArgument, "change_error") + } + + // TODO - Is this true? + if categories.Length() != orderParams.Length() { + return nil, nex.NewError(nex.ResultCodes.Ranking.InvalidArgument, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + pResult := types.NewList[*ranking_types.RankingCachedResult]() + + pResult.Type = ranking_types.NewRankingCachedResult() + + for i, category := range categories.Slice() { + orderParam, err := orderParams.Get(i) + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Ranking.InvalidArgument, "change_error") + } + + rankDataList, totalCount, err := commonProtocol.GetRankingsAndCountByCategoryAndRankingOrderParam(category, orderParam) + if err != nil { + common_globals.Logger.Critical(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Ranking.Unknown, "change_error") + } + + if totalCount == 0 || rankDataList.Length() == 0 { + return nil, nex.NewError(nex.ResultCodes.Ranking.NotFound, "change_error") + } + + result := ranking_types.NewRankingCachedResult() + + result.RankingResult.RankDataList = rankDataList + result.RankingResult.TotalCount = types.NewPrimitiveU32(totalCount) + result.RankingResult.SinceTime = types.NewDateTime(0x1F40420000) // * 2000-01-01T00:00:00.000Z, this is what the real server sends back + + result.CreatedTime = types.NewDateTime(0).Now() + // * The real server sends the "CreatedTime" + 5 minutes. + // * It doesn't change, even on subsequent requests, until after the + // * ExpiredTime has passed (seemingly what the "cached" means). + // * Whether we need to replicate this idk, but in case, here's a note. + result.ExpiredTime = types.NewDateTime(0).FromTimestamp(time.Now().UTC().Add(time.Minute * time.Duration(5))) + // * This is the length Ultimate NES Remix uses + // TODO - Does this matter? and are other games different? + result.MaxLength = types.NewPrimitiveU8(10) + + pResult.Append(result) + } + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pResult.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = ranking.ProtocolID + rmcResponse.MethodID = ranking.MethodGetCachedTopXRankings + rmcResponse.CallID = callID + + if commonProtocol.OnAfterGetCachedTopXRankings != nil { + go commonProtocol.OnAfterGetCachedTopXRankings(packet, categories, orderParams) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/ranking/get_common_data.go b/nex-protocols-common-go/ranking/get_common_data.go new file mode 100644 index 0000000..e6b07f0 --- /dev/null +++ b/nex-protocols-common-go/ranking/get_common_data.go @@ -0,0 +1,45 @@ +package ranking + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + ranking "github.com/PretendoNetwork/nex-protocols-go/v2/ranking" +) + +func (commonProtocol *CommonProtocol) getCommonData(err error, packet nex.PacketInterface, callID uint32, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.GetCommonData == nil { + common_globals.Logger.Warning("Ranking::GetCommonData missing GetCommonData!") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Ranking.InvalidArgument, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + commonData, err := commonProtocol.GetCommonData(uniqueID) + if err != nil { + return nil, nex.NewError(nex.ResultCodes.Ranking.NotFound, "change_error") + } + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + commonData.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = ranking.ProtocolID + rmcResponse.MethodID = ranking.MethodGetCommonData + rmcResponse.CallID = callID + + if commonProtocol.OnAfterGetCommonData != nil { + go commonProtocol.OnAfterGetCommonData(packet, uniqueID) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/ranking/get_ranking.go b/nex-protocols-common-go/ranking/get_ranking.go new file mode 100644 index 0000000..3e97628 --- /dev/null +++ b/nex-protocols-common-go/ranking/get_ranking.go @@ -0,0 +1,57 @@ +package ranking + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + ranking "github.com/PretendoNetwork/nex-protocols-go/v2/ranking" + ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" +) + +func (commonProtocol *CommonProtocol) getRanking(err error, packet nex.PacketInterface, callID uint32, rankingMode *types.PrimitiveU8, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, uniqueID *types.PrimitiveU64, principalID *types.PID) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.GetRankingsAndCountByCategoryAndRankingOrderParam == nil { + common_globals.Logger.Warning("Ranking::GetRanking missing GetRankingsAndCountByCategoryAndRankingOrderParam!") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Ranking.InvalidArgument, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + rankDataList, totalCount, err := commonProtocol.GetRankingsAndCountByCategoryAndRankingOrderParam(category, orderParam) + if err != nil { + common_globals.Logger.Critical(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Ranking.Unknown, "change_error") + } + + if totalCount == 0 || rankDataList.Length() == 0 { + return nil, nex.NewError(nex.ResultCodes.Ranking.NotFound, "change_error") + } + + pResult := ranking_types.NewRankingResult() + + pResult.RankDataList = rankDataList + pResult.TotalCount = types.NewPrimitiveU32(totalCount) + pResult.SinceTime = types.NewDateTime(0x1F40420000) // * 2000-01-01T00:00:00.000Z, this is what the real server sends back + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pResult.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = ranking.ProtocolID + rmcResponse.MethodID = ranking.MethodGetRanking + rmcResponse.CallID = callID + + if commonProtocol.OnAfterGetRanking != nil { + go commonProtocol.OnAfterGetRanking(packet, rankingMode, category, orderParam, uniqueID, principalID) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/ranking/protocol.go b/nex-protocols-common-go/ranking/protocol.go new file mode 100644 index 0000000..de02f11 --- /dev/null +++ b/nex-protocols-common-go/ranking/protocol.go @@ -0,0 +1,40 @@ +package ranking + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + ranking "github.com/PretendoNetwork/nex-protocols-go/v2/ranking" + ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" +) + +type CommonProtocol struct { + endpoint nex.EndpointInterface + protocol ranking.Interface + GetCommonData func(uniqueID *types.PrimitiveU64) (*types.Buffer, error) + UploadCommonData func(pid *types.PID, uniqueID *types.PrimitiveU64, commonData *types.Buffer) error + InsertRankingByPIDAndRankingScoreData func(pid *types.PID, rankingScoreData *ranking_types.RankingScoreData, uniqueID *types.PrimitiveU64) error + GetRankingsAndCountByCategoryAndRankingOrderParam func(category *types.PrimitiveU32, rankingOrderParam *ranking_types.RankingOrderParam) (*types.List[*ranking_types.RankingRankData], uint32, error) + OnAfterGetCachedTopXRanking func(packet nex.PacketInterface, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam) + OnAfterGetCachedTopXRankings func(packet nex.PacketInterface, categories *types.List[*types.PrimitiveU32], orderParams *types.List[*ranking_types.RankingOrderParam]) + OnAfterGetCommonData func(packet nex.PacketInterface, uniqueID *types.PrimitiveU64) + OnAfterGetRanking func(packet nex.PacketInterface, rankingMode *types.PrimitiveU8, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, uniqueID *types.PrimitiveU64, principalID *types.PID) + OnAfterUploadCommonData func(packet nex.PacketInterface, commonData *types.Buffer, uniqueID *types.PrimitiveU64) + OnAfterUploadScore func(packet nex.PacketInterface, scoreData *ranking_types.RankingScoreData, uniqueID *types.PrimitiveU64) +} + +// NewCommonProtocol returns a new CommonProtocol +func NewCommonProtocol(protocol ranking.Interface) *CommonProtocol { + commonProtocol := &CommonProtocol{ + endpoint: protocol.Endpoint(), + protocol: protocol, + } + + protocol.SetHandlerGetCachedTopXRanking(commonProtocol.getCachedTopXRanking) + protocol.SetHandlerGetCachedTopXRankings(commonProtocol.getCachedTopXRankings) + protocol.SetHandlerGetCommonData(commonProtocol.getCommonData) + protocol.SetHandlerGetRanking(commonProtocol.getRanking) + protocol.SetHandlerUploadCommonData(commonProtocol.uploadCommonData) + protocol.SetHandlerUploadScore(commonProtocol.uploadScore) + + return commonProtocol +} diff --git a/nex-protocols-common-go/ranking/upload_common_data.go b/nex-protocols-common-go/ranking/upload_common_data.go new file mode 100644 index 0000000..c30d51a --- /dev/null +++ b/nex-protocols-common-go/ranking/upload_common_data.go @@ -0,0 +1,40 @@ +package ranking + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + ranking "github.com/PretendoNetwork/nex-protocols-go/v2/ranking" +) + +func (commonProtocol *CommonProtocol) uploadCommonData(err error, packet nex.PacketInterface, callID uint32, commonData *types.Buffer, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.UploadCommonData == nil { + common_globals.Logger.Warning("Ranking::UploadCommonData missing UploadCommonData!") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Ranking.InvalidArgument, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + err = commonProtocol.UploadCommonData(connection.PID(), uniqueID, commonData) + if err != nil { + common_globals.Logger.Critical(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Ranking.Unknown, "change_error") + } + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = ranking.ProtocolID + rmcResponse.MethodID = ranking.MethodUploadCommonData + rmcResponse.CallID = callID + + if commonProtocol.OnAfterUploadCommonData != nil { + go commonProtocol.OnAfterUploadCommonData(packet, commonData, uniqueID) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/ranking/upload_score.go b/nex-protocols-common-go/ranking/upload_score.go new file mode 100644 index 0000000..65d22c9 --- /dev/null +++ b/nex-protocols-common-go/ranking/upload_score.go @@ -0,0 +1,41 @@ +package ranking + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + ranking "github.com/PretendoNetwork/nex-protocols-go/v2/ranking" + ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" +) + +func (commonProtocol *CommonProtocol) uploadScore(err error, packet nex.PacketInterface, callID uint32, scoreData *ranking_types.RankingScoreData, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.InsertRankingByPIDAndRankingScoreData == nil { + common_globals.Logger.Warning("Ranking::UploadScore missing InsertRankingByPIDAndRankingScoreData!") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Ranking.InvalidArgument, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + err = commonProtocol.InsertRankingByPIDAndRankingScoreData(connection.PID(), scoreData, uniqueID) + if err != nil { + common_globals.Logger.Critical(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Ranking.Unknown, "change_error") + } + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = ranking.ProtocolID + rmcResponse.MethodID = ranking.MethodUploadScore + rmcResponse.CallID = callID + + if commonProtocol.OnAfterUploadScore != nil { + go commonProtocol.OnAfterUploadScore(packet, scoreData, uniqueID) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/secure-connection/README.md b/nex-protocols-common-go/secure-connection/README.md new file mode 100644 index 0000000..bd6ae1e --- /dev/null +++ b/nex-protocols-common-go/secure-connection/README.md @@ -0,0 +1,2 @@ +# secure-connection +Implementation of the NEX secure connection protocol for Pretendo game servers diff --git a/nex-protocols-common-go/secure-connection/protocol.go b/nex-protocols-common-go/secure-connection/protocol.go new file mode 100644 index 0000000..c489ca0 --- /dev/null +++ b/nex-protocols-common-go/secure-connection/protocol.go @@ -0,0 +1,30 @@ +package secureconnection + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + secure_connection "github.com/PretendoNetwork/nex-protocols-go/v2/secure-connection" +) + +type CommonProtocol struct { + endpoint nex.EndpointInterface + protocol secure_connection.Interface + CreateReportDBRecord func(pid *types.PID, reportID *types.PrimitiveU32, reportData *types.QBuffer) error + OnAfterRegister func(packet nex.PacketInterface, vecMyURLs *types.List[*types.StationURL]) + OnAfterReplaceURL func(packet nex.PacketInterface, target *types.StationURL, url *types.StationURL) + OnAfterSendReport func(packet nex.PacketInterface, reportID *types.PrimitiveU32, reportData *types.QBuffer) +} + +// NewCommonProtocol returns a new CommonProtocol +func NewCommonProtocol(protocol secure_connection.Interface) *CommonProtocol { + commonProtocol := &CommonProtocol{ + endpoint: protocol.Endpoint(), + protocol: protocol, + } + + protocol.SetHandlerRegister(commonProtocol.register) + protocol.SetHandlerReplaceURL(commonProtocol.replaceURL) + protocol.SetHandlerSendReport(commonProtocol.sendReport) + + return commonProtocol +} diff --git a/nex-protocols-common-go/secure-connection/register.go b/nex-protocols-common-go/secure-connection/register.go new file mode 100644 index 0000000..691b48a --- /dev/null +++ b/nex-protocols-common-go/secure-connection/register.go @@ -0,0 +1,115 @@ +package secureconnection + +import ( + "net" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/constants" + "github.com/PretendoNetwork/nex-go/v2/types" + secure_connection "github.com/PretendoNetwork/nex-protocols-go/v2/secure-connection" + + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + + "fmt" +) + +func (commonProtocol *CommonProtocol) register(err error, packet nex.PacketInterface, callID uint32, vecMyURLs *types.List[*types.StationURL]) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint() + + // * vecMyURLs may contain multiple StationURLs. Search them all + var localStation *types.StationURL + var publicStation *types.StationURL + + for _, stationURL := range vecMyURLs.Slice() { + natf, ok := stationURL.NATFiltering() + if !ok { + continue + } + + natm, ok := stationURL.NATMapping() + if !ok { + continue + } + + // * Station reports itself as being non-public (local) + if localStation == nil && !stationURL.IsPublic() { + localStation = stationURL.Copy().(*types.StationURL) + } + + // * Still did not find the station, trying heuristics + if localStation == nil && natf == constants.UnknownNATFiltering && natm == constants.UnknownNATMapping { + localStation = stationURL.Copy().(*types.StationURL) + } + + if publicStation == nil && stationURL.IsPublic() { + publicStation = stationURL.Copy().(*types.StationURL) + } + } + + if localStation == nil { + common_globals.Logger.Error("Failed to find local station") + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + if publicStation == nil { + publicStation = localStation.Copy().(*types.StationURL) + + var address string + var port uint16 + + // * We have to duplicate this because Go automatically breaks on switch statements + switch clientAddress := connection.Address().(type) { + case *net.UDPAddr: + address = clientAddress.IP.String() + port = uint16(clientAddress.Port) + case *net.TCPAddr: + address = clientAddress.IP.String() + port = uint16(clientAddress.Port) + } + + publicStation.SetAddress(address) + publicStation.SetPortNumber(port) + publicStation.SetNATFiltering(constants.UnknownNATFiltering) + publicStation.SetNATMapping(constants.UnknownNATMapping) + publicStation.SetType(uint8(constants.StationURLFlagPublic) | uint8(constants.StationURLFlagBehindNAT)) + } + + /*localStation.SetPrincipalID(connection.PID()) + publicStation.SetPrincipalID(connection.PID()) + + localStation.SetRVConnectionID(connection.ID) + publicStation.SetRVConnectionID(connection.ID)*/ + + connection.StationURLs.Append(localStation) + connection.StationURLs.Append(publicStation) + + retval := types.NewQResultSuccess(nex.ResultCodes.Core.Unknown) + pidConnectionID := types.NewPrimitiveU32(connection.ID) + urlPublic := types.NewString(publicStation.EncodeToString()) + fmt.Println(publicStation) + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + retval.WriteTo(rmcResponseStream) + pidConnectionID.WriteTo(rmcResponseStream) + urlPublic.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = secure_connection.ProtocolID + rmcResponse.MethodID = secure_connection.MethodRegister + rmcResponse.CallID = callID + + if commonProtocol.OnAfterRegister != nil { + go commonProtocol.OnAfterRegister(packet, vecMyURLs) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/secure-connection/replace_url.go b/nex-protocols-common-go/secure-connection/replace_url.go new file mode 100644 index 0000000..4676c9a --- /dev/null +++ b/nex-protocols-common-go/secure-connection/replace_url.go @@ -0,0 +1,51 @@ +package secureconnection + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + secure_connection "github.com/PretendoNetwork/nex-protocols-go/v2/secure-connection" + + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" +) + +func (commonProtocol *CommonProtocol) replaceURL(err error, packet nex.PacketInterface, callID uint32, target *types.StationURL, url *types.StationURL) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint() + + connection.StationURLs.Each(func(i int, station *types.StationURL) bool { + currentStationAddress, currentStationAddressOk := station.Address() + currentStationPort, currentStationPortOk := station.PortNumber() + oldStationAddress, oldStationAddressOk := target.Address() + oldStationPort, oldStationPortOk := target.PortNumber() + + if currentStationAddressOk && currentStationPortOk && oldStationAddressOk && oldStationPortOk { + if currentStationAddress == oldStationAddress && currentStationPort == oldStationPort { + // * This fixes Minecraft, but is obviously incorrect + // TODO - What are we really meant to do here? + newStation := url.Copy().(*types.StationURL) + + newStation.SetPrincipalID(connection.PID()) + + connection.StationURLs.SetIndex(i, newStation) + } + } + + return false + }) + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = secure_connection.ProtocolID + rmcResponse.MethodID = secure_connection.MethodReplaceURL + rmcResponse.CallID = callID + + if commonProtocol.OnAfterReplaceURL != nil { + go commonProtocol.OnAfterReplaceURL(packet, target, url) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/secure-connection/send_report.go b/nex-protocols-common-go/secure-connection/send_report.go new file mode 100644 index 0000000..31c3150 --- /dev/null +++ b/nex-protocols-common-go/secure-connection/send_report.go @@ -0,0 +1,41 @@ +package secureconnection + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + secure_connection "github.com/PretendoNetwork/nex-protocols-go/v2/secure-connection" + + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" +) + +func (commonProtocol *CommonProtocol) sendReport(err error, packet nex.PacketInterface, callID uint32, reportID *types.PrimitiveU32, reportData *types.QBuffer) (*nex.RMCMessage, *nex.Error) { + if commonProtocol.CreateReportDBRecord == nil { + common_globals.Logger.Warning("SecureConnection::SendReport missing CreateReportDBRecord!") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + if err != nil { + common_globals.Logger.Critical(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.Unknown, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + err = commonProtocol.CreateReportDBRecord(connection.PID(), reportID, reportData) + if err != nil { + common_globals.Logger.Critical(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.Unknown, "change_error") + } + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = secure_connection.ProtocolID + rmcResponse.MethodID = secure_connection.MethodSendReport + rmcResponse.CallID = callID + + if commonProtocol.OnAfterSendReport != nil { + go commonProtocol.OnAfterSendReport(packet, reportID, reportData) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/ticket-granting/generate_ticket.go b/nex-protocols-common-go/ticket-granting/generate_ticket.go new file mode 100644 index 0000000..15863cb --- /dev/null +++ b/nex-protocols-common-go/ticket-granting/generate_ticket.go @@ -0,0 +1,51 @@ +package ticket_granting + +import ( + "crypto/rand" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" +) + +func generateTicket(source, target *nex.Account, sessionKeyLength int, endpoint *nex.PRUDPEndPoint) ([]byte, *nex.Error) { + if source == nil || target == nil { + return []byte{}, nex.NewError(nex.ResultCodes.Authentication.Unknown, "Source or target account is nil") + } + + sourceKey := nex.DeriveKerberosKey(source.PID, []byte(source.Password)) + targetKey := nex.DeriveKerberosKey(target.PID, []byte(target.Password)) + sessionKey := make([]byte, sessionKeyLength) + + _, err := rand.Read(sessionKey) + if err != nil { + common_globals.Logger.Error(err.Error()) + return []byte{}, nex.NewError(nex.ResultCodes.Authentication.Unknown, "Failed to generate session key") + } + + ticketInternalData := nex.NewKerberosTicketInternalData(endpoint.Server) + serverTime := types.NewDateTime(0).Now() + + ticketInternalData.Issued = serverTime + ticketInternalData.SourcePID = source.PID + ticketInternalData.SessionKey = sessionKey + + encryptedTicketInternalData, err := ticketInternalData.Encrypt(targetKey, nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())) + if err != nil { + common_globals.Logger.Error(err.Error()) + return []byte{}, nex.NewError(nex.ResultCodes.Authentication.Unknown, "Failed to encrypt Ticket Internal Data") + } + + ticket := nex.NewKerberosTicket() + ticket.SessionKey = sessionKey + ticket.TargetPID = target.PID + ticket.InternalData = types.NewBuffer(encryptedTicketInternalData) + + encryptedTicket, err := ticket.Encrypt(sourceKey, nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings())) + if err != nil { + common_globals.Logger.Error(err.Error()) + return []byte{}, nex.NewError(nex.ResultCodes.Authentication.Unknown, "Failed to encrypt Ticket") + } + + return encryptedTicket, nil +} diff --git a/nex-protocols-common-go/ticket-granting/login.go b/nex-protocols-common-go/ticket-granting/login.go new file mode 100644 index 0000000..5d00cfb --- /dev/null +++ b/nex-protocols-common-go/ticket-granting/login.go @@ -0,0 +1,95 @@ +package ticket_granting + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + ticket_granting "github.com/PretendoNetwork/nex-protocols-go/v2/ticket-granting" +) + +func (commonProtocol *CommonProtocol) login(err error, packet nex.PacketInterface, callID uint32, strUserName *types.String) (*nex.RMCMessage, *nex.Error) { + if !commonProtocol.allowInsecureLoginMethod { + return nil, nex.NewError(nex.ResultCodes.Authentication.ValidationFailed, "change_error") + } + + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + sourceAccount, errorCode := endpoint.AccountDetailsByUsername(strUserName.Value) + if errorCode != nil && errorCode.ResultCode != nex.ResultCodes.RendezVous.InvalidUsername { + // * Some other error happened + return nil, errorCode + } + + targetAccount, errorCode := endpoint.AccountDetailsByUsername(commonProtocol.SecureServerAccount.Username) + if errorCode != nil && errorCode.ResultCode != nex.ResultCodes.RendezVous.InvalidUsername { + // * Some other error happened + return nil, errorCode + } + + encryptedTicket, errorCode := generateTicket(sourceAccount, targetAccount, commonProtocol.SessionKeyLength, endpoint) + + if errorCode != nil && errorCode.ResultCode != nex.ResultCodes.RendezVous.InvalidUsername { + // * Some other error happened + return nil, errorCode + } + + var retval *types.QResult + pidPrincipal := types.NewPID(0) + pbufResponse := types.NewBuffer([]byte{}) + pConnectionData := types.NewRVConnectionData() + strReturnMsg := types.NewString("") + + // * From the wiki: + // * + // * "If the username does not exist, the %retval% field is set to + // * RendezVous::InvalidUsername and the other fields are left blank." + if errorCode != nil && errorCode.ResultCode == nex.ResultCodes.RendezVous.InvalidUsername { + retval = types.NewQResultError(errorCode.ResultCode) + } else { + retval = types.NewQResultSuccess(nex.ResultCodes.Core.Unknown) + pidPrincipal = sourceAccount.PID + pbufResponse = types.NewBuffer(encryptedTicket) + strReturnMsg = commonProtocol.BuildName.Copy().(*types.String) + + specialProtocols := types.NewList[*types.PrimitiveU8]() + + specialProtocols.Type = types.NewPrimitiveU8(0) + specialProtocols.SetFromData(commonProtocol.SpecialProtocols) + + pConnectionData.StationURL = commonProtocol.SecureStationURL + pConnectionData.SpecialProtocols = specialProtocols + pConnectionData.StationURLSpecialProtocols = commonProtocol.StationURLSpecialProtocols + pConnectionData.Time = types.NewDateTime(0).Now() + + if endpoint.LibraryVersions().Main.GreaterOrEqual("v3.5.0") { + pConnectionData.StructureVersion = 1 + } + } + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + retval.WriteTo(rmcResponseStream) + pidPrincipal.WriteTo(rmcResponseStream) + pbufResponse.WriteTo(rmcResponseStream) + pConnectionData.WriteTo(rmcResponseStream) + strReturnMsg.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = ticket_granting.ProtocolID + rmcResponse.MethodID = ticket_granting.MethodLogin + rmcResponse.CallID = callID + + if commonProtocol.OnAfterLogin != nil { + go commonProtocol.OnAfterLogin(packet, strUserName) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/ticket-granting/login_ex.go b/nex-protocols-common-go/ticket-granting/login_ex.go new file mode 100644 index 0000000..8a99d14 --- /dev/null +++ b/nex-protocols-common-go/ticket-granting/login_ex.go @@ -0,0 +1,93 @@ +package ticket_granting + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + ticket_granting "github.com/PretendoNetwork/nex-protocols-go/v2/ticket-granting" +) + +func (commonProtocol *CommonProtocol) loginEx(err error, packet nex.PacketInterface, callID uint32, strUserName *types.String, oExtraData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + // TODO - VALIDATE oExtraData! + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + sourceAccount, errorCode := endpoint.AccountDetailsByUsername(strUserName.Value) + if errorCode != nil && errorCode.ResultCode != nex.ResultCodes.RendezVous.InvalidUsername { + // * Some other error happened + return nil, errorCode + } + + targetAccount, errorCode := endpoint.AccountDetailsByUsername(commonProtocol.SecureServerAccount.Username) + if errorCode != nil && errorCode.ResultCode != nex.ResultCodes.RendezVous.InvalidUsername { + // * Some other error happened + return nil, errorCode + } + + encryptedTicket, errorCode := generateTicket(sourceAccount, targetAccount, commonProtocol.SessionKeyLength, endpoint) + + if errorCode != nil && errorCode.ResultCode != nex.ResultCodes.RendezVous.InvalidUsername { + // * Some other error happened + return nil, errorCode + } + + var retval *types.QResult + pidPrincipal := types.NewPID(0) + pbufResponse := types.NewBuffer([]byte{}) + pConnectionData := types.NewRVConnectionData() + strReturnMsg := types.NewString("") + + // * From the wiki: + // * + // * "If the username does not exist, the %retval% field is set to + // * RendezVous::InvalidUsername and the other fields are left blank." + if errorCode != nil && errorCode.ResultCode == nex.ResultCodes.RendezVous.InvalidUsername { + retval = types.NewQResultError(errorCode.ResultCode) + } else { + retval = types.NewQResultSuccess(nex.ResultCodes.Core.Unknown) + pidPrincipal = sourceAccount.PID + pbufResponse = types.NewBuffer(encryptedTicket) + strReturnMsg = commonProtocol.BuildName.Copy().(*types.String) + + specialProtocols := types.NewList[*types.PrimitiveU8]() + + specialProtocols.Type = types.NewPrimitiveU8(0) + specialProtocols.SetFromData(commonProtocol.SpecialProtocols) + + pConnectionData.StationURL = commonProtocol.SecureStationURL + pConnectionData.SpecialProtocols = specialProtocols + pConnectionData.StationURLSpecialProtocols = commonProtocol.StationURLSpecialProtocols + pConnectionData.Time = types.NewDateTime(0).Now() + + if endpoint.LibraryVersions().Main.GreaterOrEqual("v3.5.0") { + pConnectionData.StructureVersion = 1 + } + } + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + retval.WriteTo(rmcResponseStream) + pidPrincipal.WriteTo(rmcResponseStream) + pbufResponse.WriteTo(rmcResponseStream) + pConnectionData.WriteTo(rmcResponseStream) + strReturnMsg.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = ticket_granting.ProtocolID + rmcResponse.MethodID = ticket_granting.MethodLoginEx + rmcResponse.CallID = callID + + if commonProtocol.OnAfterLoginEx != nil { + go commonProtocol.OnAfterLoginEx(packet, strUserName, oExtraData) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/ticket-granting/protocol.go b/nex-protocols-common-go/ticket-granting/protocol.go new file mode 100644 index 0000000..647a5e9 --- /dev/null +++ b/nex-protocols-common-go/ticket-granting/protocol.go @@ -0,0 +1,54 @@ +package ticket_granting + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + _ "github.com/PretendoNetwork/nex-protocols-go/v2" + ticket_granting "github.com/PretendoNetwork/nex-protocols-go/v2/ticket-granting" + + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" +) + +type CommonProtocol struct { + protocol ticket_granting.Interface + SecureStationURL *types.StationURL + SpecialProtocols []*types.PrimitiveU8 + StationURLSpecialProtocols *types.StationURL + BuildName *types.String + allowInsecureLoginMethod bool + SessionKeyLength int // TODO - Use server SessionKeyLength? + SecureServerAccount *nex.Account + OnAfterLogin func(packet nex.PacketInterface, strUserName *types.String) + OnAfterLoginEx func(packet nex.PacketInterface, strUserName *types.String, oExtraData *types.AnyDataHolder) + OnAfterRequestTicket func(packet nex.PacketInterface, idSource *types.PID, idTarget *types.PID) +} + +func (commonProtocol *CommonProtocol) DisableInsecureLogin() { + commonProtocol.allowInsecureLoginMethod = false +} + +func (commonProtocol *CommonProtocol) EnableInsecureLogin() { + common_globals.Logger.Warning("INSECURE LOGIN HAS BEEN ENABLED. THIS ALLOWS THE USE OF CUSTOM CLIENTS TO BYPASS THE ACCOUNT SERVER AND CONNECT DIRECTLY TO THIS GAME SERVER, EVADING BANS! USE WITH CAUTION!") + commonProtocol.allowInsecureLoginMethod = true +} + +// NewCommonProtocol returns a new CommonProtocol +func NewCommonProtocol(protocol ticket_granting.Interface) *CommonProtocol { + commonProtocol := &CommonProtocol{ + protocol: protocol, + SecureStationURL: types.NewStationURL("prudp:/"), + SpecialProtocols: make([]*types.PrimitiveU8, 0), + StationURLSpecialProtocols: types.NewStationURL(""), + BuildName: types.NewString(""), + allowInsecureLoginMethod: false, + SessionKeyLength: 32, + } + + protocol.SetHandlerLogin(commonProtocol.login) + protocol.SetHandlerLoginEx(commonProtocol.loginEx) + protocol.SetHandlerRequestTicket(commonProtocol.requestTicket) + + commonProtocol.DisableInsecureLogin() // * Disable insecure login by default + + return commonProtocol +} diff --git a/nex-protocols-common-go/ticket-granting/request_ticket.go b/nex-protocols-common-go/ticket-granting/request_ticket.go new file mode 100644 index 0000000..0a819ce --- /dev/null +++ b/nex-protocols-common-go/ticket-granting/request_ticket.go @@ -0,0 +1,62 @@ +package ticket_granting + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + ticket_granting "github.com/PretendoNetwork/nex-protocols-go/v2/ticket-granting" +) + +func (commonProtocol *CommonProtocol) requestTicket(err error, packet nex.PacketInterface, callID uint32, idSource *types.PID, idTarget *types.PID) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + sourceAccount, errorCode := endpoint.AccountDetailsByPID(idSource) + if errorCode != nil && errorCode.ResultCode != nex.ResultCodes.Core.AccessDenied { + return nil, errorCode + } + + targetAccount, errorCode := endpoint.AccountDetailsByPID(idTarget) + if errorCode != nil && errorCode.ResultCode != nex.ResultCodes.Core.AccessDenied { + return nil, errorCode + } + + encryptedTicket, errorCode := generateTicket(sourceAccount, targetAccount, commonProtocol.SessionKeyLength, endpoint) + if errorCode != nil && errorCode.ResultCode != nex.ResultCodes.Core.AccessDenied { + return nil, errorCode + } + + // * From the wiki: + // * + // * "If the source or target pid is invalid, the %retval% field is set to Core::AccessDenied and the ticket is empty." + retval := types.NewQResultSuccess(nex.ResultCodes.Core.Unknown) + bufResponse := types.NewBuffer(encryptedTicket) + + if errorCode != nil { + retval = types.NewQResultError(nex.ResultCodes.Core.AccessDenied) + bufResponse = types.NewBuffer([]byte{}) + } + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + retval.WriteTo(rmcResponseStream) + bufResponse.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = ticket_granting.ProtocolID + rmcResponse.MethodID = ticket_granting.MethodRequestTicket + rmcResponse.CallID = callID + + if commonProtocol.OnAfterRequestTicket != nil { + go commonProtocol.OnAfterRequestTicket(packet, idSource, idTarget) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/utility/acquire_nex_unique_id.go b/nex-protocols-common-go/utility/acquire_nex_unique_id.go new file mode 100644 index 0000000..cf7a9f9 --- /dev/null +++ b/nex-protocols-common-go/utility/acquire_nex_unique_id.go @@ -0,0 +1,42 @@ +package utility + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + utility "github.com/PretendoNetwork/nex-protocols-go/v2/utility" +) + +func (commonProtocol *CommonProtocol) acquireNexUniqueID(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + if commonProtocol.GenerateNEXUniqueID == nil { + common_globals.Logger.Warning("Utility::AcquireNexUniqueID missing GenerateNEXUniqueID!") + return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error") + } + + connection := packet.Sender() + endpoint := connection.Endpoint() + + pNexUniqueID := types.NewPrimitiveU64(commonProtocol.GenerateNEXUniqueID()) + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pNexUniqueID.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = utility.ProtocolID + rmcResponse.MethodID = utility.MethodAcquireNexUniqueID + rmcResponse.CallID = callID + + if commonProtocol.OnAfterAcquireNexUniqueID != nil { + go commonProtocol.OnAfterAcquireNexUniqueID(packet) + } + + return rmcResponse, nil +} diff --git a/nex-protocols-common-go/utility/protocol.go b/nex-protocols-common-go/utility/protocol.go new file mode 100644 index 0000000..65dafea --- /dev/null +++ b/nex-protocols-common-go/utility/protocol.go @@ -0,0 +1,25 @@ +package utility + +import ( + "github.com/PretendoNetwork/nex-go/v2" + utility "github.com/PretendoNetwork/nex-protocols-go/v2/utility" +) + +type CommonProtocol struct { + endpoint nex.EndpointInterface + protocol utility.Interface + GenerateNEXUniqueID func() uint64 + OnAfterAcquireNexUniqueID func(packet nex.PacketInterface) +} + +// NewCommonProtocol returns a new CommonProtocol +func NewCommonProtocol(protocol utility.Interface) *CommonProtocol { + commonProtocol := &CommonProtocol{ + endpoint: protocol.Endpoint(), + protocol: protocol, + } + + protocol.SetHandlerAcquireNexUniqueID(commonProtocol.acquireNexUniqueID) + + return commonProtocol +} diff --git a/nex-protocols-go/.gitignore b/nex-protocols-go/.gitignore new file mode 100644 index 0000000..c42ec53 --- /dev/null +++ b/nex-protocols-go/.gitignore @@ -0,0 +1,30 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work +go.work.sum + +# custom +.vscode +.env +build +log +*.pem +*.key \ No newline at end of file diff --git a/nex-protocols-go/.golangci.yml b/nex-protocols-go/.golangci.yml new file mode 100644 index 0000000..43dad57 --- /dev/null +++ b/nex-protocols-go/.golangci.yml @@ -0,0 +1,17 @@ +linters: + enable: + - revive +linters-settings: + revive: + ignore-generated-header: true + severity: error + rules: + - name: exported + - name: unexported-naming + - name: unexported-return + - name: package-comments + - name: var-naming +issues: + exclude-use-default: false + max-issues-per-linter: 0 + max-same-issues: 0 \ No newline at end of file diff --git a/nex-protocols-go/LICENSE b/nex-protocols-go/LICENSE new file mode 100644 index 0000000..0ad25db --- /dev/null +++ b/nex-protocols-go/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/nex-protocols-go/README.md b/nex-protocols-go/README.md new file mode 100644 index 0000000..8746b1d --- /dev/null +++ b/nex-protocols-go/README.md @@ -0,0 +1,59 @@ +# NEX Protocols Go +## NEX servers with protocol support in Go + +[![GoDoc](https://godoc.org/github.com/PretendoNetwork/nex-protocols-go/v2?status.svg)](https://godoc.org/github.com/PretendoNetwork/nex-protocols-go/v2) + +### Other NEX libraries +[nex-go](https://github.com/PretendoNetwork/nex-go/v2) - Barebones NEX/PRUDP server implementation + +[nex-protocols-common-go](https://github.com/PretendoNetwork/nex-protocols-common-go) - NEX protocols used by many games with premade handlers and a high level API + +### Install + +`go get github.com/PretendoNetwork/nex-protocols-go/v2` + +### Usage + +`nex-protocols-go` provides a higher level API than the [NEX Go module](https://github.com/PretendoNetwork/nex-go/v2) to the underlying PRUDP server by providing a set of NEX protocols. This module only provides access to the lower level raw RMC method calls, however, and all method handlers must be defined in full manually. For a higher level API, see the [common NEX method handlers module](https://github.com/PretendoNetwork/nex-protocols-common-go) + +### Example, friends (Wii U) authentication server +### For a complete example, see the complete [Friends Server](https://github.com/PretendoNetwork/friends), and other game servers + +```go +package main + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + ticket_granting "github.com/PretendoNetwork/nex-protocols-go/v2/ticket-granting" +) + +var nexServer *nex.PRUDPServer + +func main() { + nexServer := nex.NewPRUDPServer() + + endpoint := nex.NewPRUDPEndPoint(1) + endpoint.ServerAccount = nex.NewAccount(types.NewPID(1), "Quazal Authentication", "password")) + endpoint.AccountDetailsByPID = accountDetailsByPID + endpoint.AccountDetailsByUsername = accountDetailsByUsername + + nexServer.BindPRUDPEndPoint(endpoint) + nexServer.SetFragmentSize(962) + nexServer.LibraryVersions.SetDefault(nex.NewLibraryVersion(1, 1, 0)) + nexServer.SessionKeyLength = 16 + nexServer.AccessKey = "ridfebb9" + + ticketGrantingProtocol := ticket_granting.NewProtocol(endpoint) + + // Handle Login RMC method + ticketGrantingProtocol.Login = login + + // Handle RequestTicket RMC method + ticketGrantingProtocol.RequestTicket = requestTicket + + // Register the protocol on the endpoint + endpoint.RegisterServiceProtocol(ticketGrantingProtocol) + + nexServer.Listen(60000) +} +``` diff --git a/nex-protocols-go/aa-user/get_application_info.go b/nex-protocols-go/aa-user/get_application_info.go new file mode 100644 index 0000000..06b0486 --- /dev/null +++ b/nex-protocols-go/aa-user/get_application_info.go @@ -0,0 +1,29 @@ +// Package protocol implements the AAUser protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetApplicationInfo(packet nex.PacketInterface) { + if protocol.GetApplicationInfo == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AAUser::GetApplicationInfo not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetApplicationInfo(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/aa-user/protocol.go b/nex-protocols-go/aa-user/protocol.go new file mode 100644 index 0000000..6274f30 --- /dev/null +++ b/nex-protocols-go/aa-user/protocol.go @@ -0,0 +1,116 @@ +// Package protocol implements the AAUser protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + aauser_types "github.com/PretendoNetwork/nex-protocols-go/v2/aa-user/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the AAUser protocol + ProtocolID = 0x7B + + // MethodRegisterApplication is the method ID for the method RegisterApplication + MethodRegisterApplication = 0x1 + + // MethodUnregisterApplication is the method ID for the method UnregisterApplication + MethodUnregisterApplication = 0x2 + + // MethodSetApplicationInfo is the method ID for the method RegisterApplication + MethodSetApplicationInfo = 0x3 + + // MethodGetApplicationInfo is the method ID for the method GetApplicationInfo + MethodGetApplicationInfo = 0x4 +) + +// Protocol stores all the RMC method handlers for the AAUser protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + RegisterApplication func(err error, packet nex.PacketInterface, callID uint32, titleID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + UnregisterApplication func(err error, packet nex.PacketInterface, callID uint32, titleID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + SetApplicationInfo func(err error, packet nex.PacketInterface, callID uint32, applicationInfo *types.List[*aauser_types.ApplicationInfo]) (*nex.RMCMessage, *nex.Error) + GetApplicationInfo func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the AAUser Protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerRegisterApplication(handler func(err error, packet nex.PacketInterface, callID uint32, titleID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerUnregisterApplication(handler func(err error, packet nex.PacketInterface, callID uint32, titleID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerSetApplicationInfo(handler func(err error, packet nex.PacketInterface, callID uint32, applicationInfo *types.List[*aauser_types.ApplicationInfo]) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetApplicationInfo(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerRegisterApplication sets the handler for the RegisterApplication method +func (protocol *Protocol) SetHandlerRegisterApplication(handler func(err error, packet nex.PacketInterface, callID uint32, titleID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.RegisterApplication = handler +} + +// SetHandlerUnregisterApplication sets the handler for the UnregisterApplication method +func (protocol *Protocol) SetHandlerUnregisterApplication(handler func(err error, packet nex.PacketInterface, callID uint32, titleID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.UnregisterApplication = handler +} + +// SetHandlerSetApplicationInfo sets the handler for the SetApplicationInfo method +func (protocol *Protocol) SetHandlerSetApplicationInfo(handler func(err error, packet nex.PacketInterface, callID uint32, applicationInfo *types.List[*aauser_types.ApplicationInfo]) (*nex.RMCMessage, *nex.Error)) { + protocol.SetApplicationInfo = handler +} + +// SetHandlerGetApplicationInfo sets the handler for the GetApplicationInfo method +func (protocol *Protocol) SetHandlerGetApplicationInfo(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetApplicationInfo = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodRegisterApplication: + protocol.handleRegisterApplication(packet) + case MethodUnregisterApplication: + protocol.handleUnregisterApplication(packet) + case MethodSetApplicationInfo: + protocol.handleSetApplicationInfo(packet) + case MethodGetApplicationInfo: + protocol.handleGetApplicationInfo(packet) + default: + errMessage := fmt.Sprintf("Unsupported AAUser method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new AAUser protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/aa-user/register_application.go b/nex-protocols-go/aa-user/register_application.go new file mode 100644 index 0000000..5a2b1c2 --- /dev/null +++ b/nex-protocols-go/aa-user/register_application.go @@ -0,0 +1,47 @@ +// Package protocol implements the AAUser protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRegisterApplication(packet nex.PacketInterface) { + if protocol.RegisterApplication == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AAUser::RegisterApplication not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + titleID := types.NewPrimitiveU64(0) + + err := titleID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RegisterApplication(fmt.Errorf("Failed to read titleID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RegisterApplication(nil, packet, callID, titleID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/aa-user/set_application_info.go b/nex-protocols-go/aa-user/set_application_info.go new file mode 100644 index 0000000..572f2cb --- /dev/null +++ b/nex-protocols-go/aa-user/set_application_info.go @@ -0,0 +1,49 @@ +// Package protocol implements the AAUser protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + aauser_types "github.com/PretendoNetwork/nex-protocols-go/v2/aa-user/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSetApplicationInfo(packet nex.PacketInterface) { + if protocol.SetApplicationInfo == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AAUser::SetApplicationInfo not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + applicationInfo := types.NewList[*aauser_types.ApplicationInfo]() + applicationInfo.Type = aauser_types.NewApplicationInfo() + + err := applicationInfo.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SetApplicationInfo(fmt.Errorf("Failed to read applicationInfo from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SetApplicationInfo(nil, packet, callID, applicationInfo) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/aa-user/types/application_info.go b/nex-protocols-go/aa-user/types/application_info.go new file mode 100644 index 0000000..7bc5934 --- /dev/null +++ b/nex-protocols-go/aa-user/types/application_info.go @@ -0,0 +1,127 @@ +// Package types implements all the types used by the AAUser protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ApplicationInfo is a type within the AAUser protocol +type ApplicationInfo struct { + types.Structure + *types.Data + TitleID *types.PrimitiveU64 + TitleVersion *types.PrimitiveU16 +} + +// WriteTo writes the ApplicationInfo to the given writable +func (ai *ApplicationInfo) WriteTo(writable types.Writable) { + ai.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + ai.TitleID.WriteTo(contentWritable) + ai.TitleVersion.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + ai.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ApplicationInfo from the given readable +func (ai *ApplicationInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = ai.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ApplicationInfo.Data. %s", err.Error()) + } + + err = ai.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ApplicationInfo header. %s", err.Error()) + } + + err = ai.TitleID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ApplicationInfo.TitleID. %s", err.Error()) + } + + err = ai.TitleVersion.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ApplicationInfo.TitleVersion. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ApplicationInfo +func (ai *ApplicationInfo) Copy() types.RVType { + copied := NewApplicationInfo() + + copied.StructureVersion = ai.StructureVersion + copied.Data = ai.Data.Copy().(*types.Data) + copied.TitleID = ai.TitleID.Copy().(*types.PrimitiveU64) + copied.TitleVersion = ai.TitleVersion.Copy().(*types.PrimitiveU16) + + return copied +} + +// Equals checks if the given ApplicationInfo contains the same data as the current ApplicationInfo +func (ai *ApplicationInfo) Equals(o types.RVType) bool { + if _, ok := o.(*ApplicationInfo); !ok { + return false + } + + other := o.(*ApplicationInfo) + + if ai.StructureVersion != other.StructureVersion { + return false + } + + if !ai.Data.Equals(other.Data) { + return false + } + + if !ai.TitleID.Equals(other.TitleID) { + return false + } + + return ai.TitleVersion.Equals(other.TitleVersion) +} + +// String returns the string representation of the ApplicationInfo +func (ai *ApplicationInfo) String() string { + return ai.FormatToString(0) +} + +// FormatToString pretty-prints the ApplicationInfo using the provided indentation level +func (ai *ApplicationInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ApplicationInfo{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, ai.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sTitleID: %s,\n", indentationValues, ai.TitleID)) + b.WriteString(fmt.Sprintf("%sTitleVersion: %s,\n", indentationValues, ai.TitleVersion)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewApplicationInfo returns a new ApplicationInfo +func NewApplicationInfo() *ApplicationInfo { + ai := &ApplicationInfo{ + Data: types.NewData(), + TitleID: types.NewPrimitiveU64(0), + TitleVersion: types.NewPrimitiveU16(0), + } + + return ai +} diff --git a/nex-protocols-go/aa-user/unregister_application.go b/nex-protocols-go/aa-user/unregister_application.go new file mode 100644 index 0000000..323d0d4 --- /dev/null +++ b/nex-protocols-go/aa-user/unregister_application.go @@ -0,0 +1,47 @@ +// Package protocol implements the AAUser protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUnregisterApplication(packet nex.PacketInterface) { + if protocol.UnregisterApplication == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AAUser::UnregisterApplication not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + titleID := types.NewPrimitiveU64(0) + + err := titleID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UnregisterApplication(fmt.Errorf("Failed to read titleID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UnregisterApplication(nil, packet, callID, titleID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/change_password.go b/nex-protocols-go/account-management/change_password.go new file mode 100644 index 0000000..ebed087 --- /dev/null +++ b/nex-protocols-go/account-management/change_password.go @@ -0,0 +1,47 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleChangePassword(packet nex.PacketInterface) { + if protocol.ChangePassword == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::ChangePassword not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strNewKey := types.NewString("") + + err := strNewKey.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangePassword(fmt.Errorf("Failed to read strNewKey from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ChangePassword(nil, packet, callID, strNewKey) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/change_password_by_guest.go b/nex-protocols-go/account-management/change_password_by_guest.go new file mode 100644 index 0000000..fdaab46 --- /dev/null +++ b/nex-protocols-go/account-management/change_password_by_guest.go @@ -0,0 +1,71 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleChangePasswordByGuest(packet nex.PacketInterface) { + if protocol.ChangePasswordByGuest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::ChangePasswordByGuest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strPrincipalName := types.NewString("") + strKey := types.NewString("") + strEmail := types.NewString("") + + var err error + + err = strPrincipalName.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangePasswordByGuest(fmt.Errorf("Failed to read strPrincipalName from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strKey.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangePasswordByGuest(fmt.Errorf("Failed to read strKey from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strEmail.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangePasswordByGuest(fmt.Errorf("Failed to read strEmail from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ChangePasswordByGuest(nil, packet, callID, strPrincipalName, strKey, strEmail) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/create_account.go b/nex-protocols-go/account-management/create_account.go new file mode 100644 index 0000000..9b12c29 --- /dev/null +++ b/nex-protocols-go/account-management/create_account.go @@ -0,0 +1,82 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCreateAccount(packet nex.PacketInterface) { + if protocol.CreateAccount == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::CreateAccount not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strPrincipalName := types.NewString("") + strKey := types.NewString("") + uiGroups := types.NewPrimitiveU32(0) + strEmail := types.NewString("") + + var err error + + err = strPrincipalName.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateAccount(fmt.Errorf("Failed to read strPrincipalName from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strKey.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateAccount(fmt.Errorf("Failed to read strKey from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uiGroups.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateAccount(fmt.Errorf("Failed to read uiGroups from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strEmail.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateAccount(fmt.Errorf("Failed to read strEmail from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CreateAccount(nil, packet, callID, strPrincipalName, strKey, uiGroups, strEmail) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/create_account_with_custom_data.go b/nex-protocols-go/account-management/create_account_with_custom_data.go new file mode 100644 index 0000000..9b5782e --- /dev/null +++ b/nex-protocols-go/account-management/create_account_with_custom_data.go @@ -0,0 +1,104 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCreateAccountWithCustomData(packet nex.PacketInterface) { + if protocol.CreateAccountWithCustomData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::CreateAccountWithCustomData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strPrincipalName := types.NewString("") + strKey := types.NewString("") + uiGroups := types.NewPrimitiveU32(0) + strEmail := types.NewString("") + oPublicData := types.NewAnyDataHolder() + oPrivateData := types.NewAnyDataHolder() + + var err error + + err = strPrincipalName.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateAccountWithCustomData(fmt.Errorf("Failed to read strPrincipalName from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strKey.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateAccountWithCustomData(fmt.Errorf("Failed to read strKey from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uiGroups.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateAccountWithCustomData(fmt.Errorf("Failed to read uiGroups from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strEmail.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateAccountWithCustomData(fmt.Errorf("Failed to read strEmail from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = oPublicData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateAccountWithCustomData(fmt.Errorf("Failed to read oPublicData from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = oPrivateData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateAccountWithCustomData(fmt.Errorf("Failed to read oPrivateData from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CreateAccountWithCustomData(nil, packet, callID, strPrincipalName, strKey, uiGroups, strEmail, oPublicData, oPrivateData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/custom_create_account.go b/nex-protocols-go/account-management/custom_create_account.go new file mode 100644 index 0000000..4ffad77 --- /dev/null +++ b/nex-protocols-go/account-management/custom_create_account.go @@ -0,0 +1,93 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCustomCreateAccount(packet nex.PacketInterface) { + if protocol.CustomCreateAccount == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::CustomCreateAccount not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strPrincipalName := types.NewString("") + strKey := types.NewString("") + uiGroups := types.NewPrimitiveU32(0) + strEmail := types.NewString("") + oAuthData := types.NewAnyDataHolder() + + var err error + + err = strPrincipalName.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CustomCreateAccount(fmt.Errorf("Failed to read strPrincipalName from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strKey.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CustomCreateAccount(fmt.Errorf("Failed to read strKey from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uiGroups.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CustomCreateAccount(fmt.Errorf("Failed to read uiGroups from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strEmail.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CustomCreateAccount(fmt.Errorf("Failed to read strEmail from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = oAuthData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CustomCreateAccount(fmt.Errorf("Failed to read oAuthData from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CustomCreateAccount(nil, packet, callID, strPrincipalName, strKey, uiGroups, strEmail, oAuthData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/delete_account.go b/nex-protocols-go/account-management/delete_account.go new file mode 100644 index 0000000..2792d89 --- /dev/null +++ b/nex-protocols-go/account-management/delete_account.go @@ -0,0 +1,47 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteAccount(packet nex.PacketInterface) { + if protocol.DeleteAccount == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::DeleteAccount not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idPrincipal := types.NewPID(0) + + err := idPrincipal.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteAccount(fmt.Errorf("Failed to read idPrincipal from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteAccount(nil, packet, callID, idPrincipal) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/disable_account.go b/nex-protocols-go/account-management/disable_account.go new file mode 100644 index 0000000..cba3978 --- /dev/null +++ b/nex-protocols-go/account-management/disable_account.go @@ -0,0 +1,71 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDisableAccount(packet nex.PacketInterface) { + if protocol.DisableAccount == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::DisableAccount not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idPrincipal := types.NewPID(0) + dtUntil := types.NewDateTime(0) + strMessage := types.NewString("") + + var err error + + err = idPrincipal.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DisableAccount(fmt.Errorf("Failed to read idPrincipal from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = dtUntil.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DisableAccount(fmt.Errorf("Failed to read dtUntil from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DisableAccount(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DisableAccount(nil, packet, callID, idPrincipal, dtUntil, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/disconnect_all_principals.go b/nex-protocols-go/account-management/disconnect_all_principals.go new file mode 100644 index 0000000..21de740 --- /dev/null +++ b/nex-protocols-go/account-management/disconnect_all_principals.go @@ -0,0 +1,29 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDisconnectAllPrincipals(packet nex.PacketInterface) { + if protocol.DisconnectAllPrincipals == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::DisconnectAllPrincipals not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.DisconnectAllPrincipals(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/disconnect_principal.go b/nex-protocols-go/account-management/disconnect_principal.go new file mode 100644 index 0000000..bf383a7 --- /dev/null +++ b/nex-protocols-go/account-management/disconnect_principal.go @@ -0,0 +1,47 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDisconnectPrincipal(packet nex.PacketInterface) { + if protocol.DisconnectPrincipal == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::DisconnectPrincipal not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idPrincipal := types.NewPID(0) + + err := idPrincipal.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DisconnectPrincipal(fmt.Errorf("Failed to read idPrincipal from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DisconnectPrincipal(nil, packet, callID, idPrincipal) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/find_by_name_like.go b/nex-protocols-go/account-management/find_by_name_like.go new file mode 100644 index 0000000..710fb3a --- /dev/null +++ b/nex-protocols-go/account-management/find_by_name_like.go @@ -0,0 +1,71 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindByNameLike(packet nex.PacketInterface) { + if protocol.FindByNameLike == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::FindByNameLike not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiGroups := types.NewPrimitiveU32(0) + strLike := types.NewString("") + resultRange := types.NewResultRange() + + var err error + + err = uiGroups.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByNameLike(fmt.Errorf("Failed to read uiGroups from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strLike.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByNameLike(fmt.Errorf("Failed to read strLike from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByNameLike(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindByNameLike(nil, packet, callID, uiGroups, strLike, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/find_by_name_regex.go b/nex-protocols-go/account-management/find_by_name_regex.go new file mode 100644 index 0000000..792cb31 --- /dev/null +++ b/nex-protocols-go/account-management/find_by_name_regex.go @@ -0,0 +1,71 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindByNameRegex(packet nex.PacketInterface) { + if protocol.FindByNameRegex == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::FindByNameRegex not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiGroups := types.NewPrimitiveU32(0) + strRegex := types.NewString("") + resultRange := types.NewResultRange() + + var err error + + err = uiGroups.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByNameRegex(fmt.Errorf("Failed to read uiGroups from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strRegex.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByNameRegex(fmt.Errorf("Failed to read strRegex from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByNameRegex(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindByNameRegex(nil, packet, callID, uiGroups, strRegex, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/get_account_data.go b/nex-protocols-go/account-management/get_account_data.go new file mode 100644 index 0000000..ff30c1c --- /dev/null +++ b/nex-protocols-go/account-management/get_account_data.go @@ -0,0 +1,29 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetAccountData(packet nex.PacketInterface) { + if protocol.GetAccountData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::GetAccountData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetAccountData(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/get_last_connection_stats.go b/nex-protocols-go/account-management/get_last_connection_stats.go new file mode 100644 index 0000000..8f5c5db --- /dev/null +++ b/nex-protocols-go/account-management/get_last_connection_stats.go @@ -0,0 +1,47 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetLastConnectionStats(packet nex.PacketInterface) { + if protocol.GetLastConnectionStats == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::GetLastConnectionStats not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idPrincipal := types.NewPID(0) + + err := idPrincipal.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetLastConnectionStats(fmt.Errorf("Failed to read idPrincipal from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetLastConnectionStats(nil, packet, callID, idPrincipal) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/get_multiple_public_data.go b/nex-protocols-go/account-management/get_multiple_public_data.go new file mode 100644 index 0000000..5541a46 --- /dev/null +++ b/nex-protocols-go/account-management/get_multiple_public_data.go @@ -0,0 +1,48 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetMultiplePublicData(packet nex.PacketInterface) { + if protocol.GetMultiplePublicData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::GetMultiplePublicData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lstPrincipals := types.NewList[*types.PID]() + lstPrincipals.Type = types.NewPID(0) + + err := lstPrincipals.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetMultiplePublicData(fmt.Errorf("Failed to read lstPrincipals from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetMultiplePublicData(nil, packet, callID, lstPrincipals) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/get_name.go b/nex-protocols-go/account-management/get_name.go new file mode 100644 index 0000000..8ad9215 --- /dev/null +++ b/nex-protocols-go/account-management/get_name.go @@ -0,0 +1,47 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetName(packet nex.PacketInterface) { + if protocol.GetName == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::GetName not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idPrincipal := types.NewPID(0) + + err := idPrincipal.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetName(fmt.Errorf("Failed to read idPrincipal from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetName(nil, packet, callID, idPrincipal) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/get_private_data.go b/nex-protocols-go/account-management/get_private_data.go new file mode 100644 index 0000000..d52c8d4 --- /dev/null +++ b/nex-protocols-go/account-management/get_private_data.go @@ -0,0 +1,29 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetPrivateData(packet nex.PacketInterface) { + if protocol.GetPrivateData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::GetPrivateData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetPrivateData(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/get_public_data.go b/nex-protocols-go/account-management/get_public_data.go new file mode 100644 index 0000000..ee1bb55 --- /dev/null +++ b/nex-protocols-go/account-management/get_public_data.go @@ -0,0 +1,47 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetPublicData(packet nex.PacketInterface) { + if protocol.GetPublicData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::GetPublicData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idPrincipal := types.NewPID(0) + + err := idPrincipal.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPublicData(fmt.Errorf("Failed to read idPrincipal from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetPublicData(nil, packet, callID, idPrincipal) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/get_status.go b/nex-protocols-go/account-management/get_status.go new file mode 100644 index 0000000..01b10d2 --- /dev/null +++ b/nex-protocols-go/account-management/get_status.go @@ -0,0 +1,47 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetStatus(packet nex.PacketInterface) { + if protocol.GetStatus == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::GetStatus not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idPrincipal := types.NewPID(0) + + err := idPrincipal.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetStatus(fmt.Errorf("Failed to read idPrincipal from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetStatus(nil, packet, callID, idPrincipal) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/lookup_or_create_account.go b/nex-protocols-go/account-management/lookup_or_create_account.go new file mode 100644 index 0000000..3497162 --- /dev/null +++ b/nex-protocols-go/account-management/lookup_or_create_account.go @@ -0,0 +1,93 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleLookupOrCreateAccount(packet nex.PacketInterface) { + if protocol.LookupOrCreateAccount == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::LookupOrCreateAccount not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strPrincipalName := types.NewString("") + strKey := types.NewString("") + uiGroups := types.NewPrimitiveU32(0) + strEmail := types.NewString("") + oAuthData := types.NewAnyDataHolder() + + var err error + + err = strPrincipalName.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.LookupOrCreateAccount(fmt.Errorf("Failed to read strPrincipalName from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strKey.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.LookupOrCreateAccount(fmt.Errorf("Failed to read strKey from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uiGroups.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.LookupOrCreateAccount(fmt.Errorf("Failed to read uiGroups from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strEmail.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.LookupOrCreateAccount(fmt.Errorf("Failed to read strEmail from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = oAuthData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.LookupOrCreateAccount(fmt.Errorf("Failed to read oAuthData from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.LookupOrCreateAccount(nil, packet, callID, strPrincipalName, strKey, uiGroups, strEmail, oAuthData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/nintendo_create_account.go b/nex-protocols-go/account-management/nintendo_create_account.go new file mode 100644 index 0000000..3914c12 --- /dev/null +++ b/nex-protocols-go/account-management/nintendo_create_account.go @@ -0,0 +1,93 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleNintendoCreateAccount(packet nex.PacketInterface) { + if protocol.NintendoCreateAccount == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::NintendoCreateAccount not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strPrincipalName := types.NewString("") + strKey := types.NewString("") + uiGroups := types.NewPrimitiveU32(0) + strEmail := types.NewString("") + oAuthData := types.NewAnyDataHolder() + + var err error + + err = strPrincipalName.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.NintendoCreateAccount(fmt.Errorf("Failed to read strPrincipalName from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strKey.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.NintendoCreateAccount(fmt.Errorf("Failed to read strKey from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uiGroups.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.NintendoCreateAccount(fmt.Errorf("Failed to read uiGroups from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strEmail.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.NintendoCreateAccount(fmt.Errorf("Failed to read strEmail from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = oAuthData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.NintendoCreateAccount(fmt.Errorf("Failed to read oAuthData from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.NintendoCreateAccount(nil, packet, callID, strPrincipalName, strKey, uiGroups, strEmail, oAuthData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/protocol.go b/nex-protocols-go/account-management/protocol.go new file mode 100644 index 0000000..419986f --- /dev/null +++ b/nex-protocols-go/account-management/protocol.go @@ -0,0 +1,427 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the Account Management protocol + ProtocolID = 0x19 + + // MethodCreateAccount is the method ID for method CreateAccount + MethodCreateAccount = 0x1 + + // MethodDeleteAccount is the method ID for method DeleteAccount + MethodDeleteAccount = 0x2 + + // MethodDisableAccount is the method ID for method DisableAccount + MethodDisableAccount = 0x3 + + // MethodChangePassword is the method ID for method ChangePassword + MethodChangePassword = 0x4 + + // MethodTestCapability is the method ID for method TestCapability + MethodTestCapability = 0x5 + + // MethodGetName is the method ID for method GetName + MethodGetName = 0x6 + + // MethodGetAccountData is the method ID for method GetAccountData + MethodGetAccountData = 0x7 + + // MethodGetPrivateData is the method ID for method GetPrivateData + MethodGetPrivateData = 0x8 + + // MethodGetPublicData is the method ID for method GetPublicData + MethodGetPublicData = 0x9 + + // MethodGetMultiplePublicData is the method ID for method GetMultiplePublicData + MethodGetMultiplePublicData = 0xA + + // MethodUpdateAccountName is the method ID for method UpdateAccountName + MethodUpdateAccountName = 0xB + + // MethodUpdateAccountEmail is the method ID for method UpdateAccountEmail + MethodUpdateAccountEmail = 0xC + + // MethodUpdateCustomData is the method ID for method UpdateCustomData + MethodUpdateCustomData = 0xD + + // MethodFindByNameRegex is the method ID for method FindByNameRegex + MethodFindByNameRegex = 0xE + + // MethodUpdateAccountExpiryDate is the method ID for method UpdateAccountExpiryDate + MethodUpdateAccountExpiryDate = 0xF + + // MethodUpdateAccountEffectiveDate is the method ID for method UpdateAccountEffectiveDate + MethodUpdateAccountEffectiveDate = 0x10 + + // MethodUpdateStatus is the method ID for method UpdateStatus + MethodUpdateStatus = 0x11 + + // MethodGetStatus is the method ID for method GetStatus + MethodGetStatus = 0x12 + + // MethodGetLastConnectionStats is the method ID for method GetLastConnectionStats + MethodGetLastConnectionStats = 0x13 + + // MethodResetPassword is the method ID for method ResetPassword + MethodResetPassword = 0x14 + + // MethodCreateAccountWithCustomData is the method ID for method CreateAccountWithCustomData + MethodCreateAccountWithCustomData = 0x15 + + // MethodRetrieveAccount is the method ID for method RetrieveAccount + MethodRetrieveAccount = 0x16 + + // MethodUpdateAccount is the method ID for method UpdateAccount + MethodUpdateAccount = 0x17 + + // MethodChangePasswordByGuest is the method ID for method ChangePasswordByGuest + MethodChangePasswordByGuest = 0x18 + + // MethodFindByNameLike is the method ID for method FindByNameLike + MethodFindByNameLike = 0x19 + + // MethodCustomCreateAccount is the method ID for method CustomCreateAccount + MethodCustomCreateAccount = 0x1A + + // MethodNintendoCreateAccount is the method ID for method NintendoCreateAccount + MethodNintendoCreateAccount = 0x1B + + // MethodLookupOrCreateAccount is the method ID for method LookupOrCreateAccount + MethodLookupOrCreateAccount = 0x1C + + // MethodDisconnectPrincipal is the method ID for method DisconnectPrincipal + MethodDisconnectPrincipal = 0x1D + + // MethodDisconnectAllPrincipals is the method ID for method DisconnectAllPrincipals + MethodDisconnectAllPrincipals = 0x1E +) + +// Protocol stores all the RMC method handlers for the Account Management protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + CreateAccount func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, uiGroups *types.PrimitiveU32, strEmail *types.String) (*nex.RMCMessage, *nex.Error) + DeleteAccount func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error) + DisableAccount func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID, dtUntil *types.DateTime, strMessage *types.String) (*nex.RMCMessage, *nex.Error) + ChangePassword func(err error, packet nex.PacketInterface, callID uint32, strNewKey *types.String) (*nex.RMCMessage, *nex.Error) + TestCapability func(err error, packet nex.PacketInterface, callID uint32, uiCapability *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetName func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error) + GetAccountData func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + GetPrivateData func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + GetPublicData func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error) + GetMultiplePublicData func(err error, packet nex.PacketInterface, callID uint32, lstPrincipals *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error) + UpdateAccountName func(err error, packet nex.PacketInterface, callID uint32, strName *types.String) (*nex.RMCMessage, *nex.Error) + UpdateAccountEmail func(err error, packet nex.PacketInterface, callID uint32, strName *types.String) (*nex.RMCMessage, *nex.Error) + UpdateCustomData func(err error, packet nex.PacketInterface, callID uint32, oPublicData *types.AnyDataHolder, oPrivateData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error) + FindByNameRegex func(err error, packet nex.PacketInterface, callID uint32, uiGroups *types.PrimitiveU32, strRegex *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + UpdateAccountExpiryDate func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID, dtExpiry *types.DateTime, strExpiredMessage *types.String) (*nex.RMCMessage, *nex.Error) + UpdateAccountEffectiveDate func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID, dtEffectiveFrom *types.DateTime, strNotEffectiveMessage *types.String) (*nex.RMCMessage, *nex.Error) + UpdateStatus func(err error, packet nex.PacketInterface, callID uint32, strStatus *types.String) (*nex.RMCMessage, *nex.Error) + GetStatus func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error) + GetLastConnectionStats func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error) + ResetPassword func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + CreateAccountWithCustomData func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, uiGroups *types.PrimitiveU32, strEmail *types.String, oPublicData *types.AnyDataHolder, oPrivateData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error) + RetrieveAccount func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + UpdateAccount func(err error, packet nex.PacketInterface, callID uint32, strKey *types.String, strEmail *types.String, oPublicData *types.AnyDataHolder, oPrivateData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error) + ChangePasswordByGuest func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, strEmail *types.String) (*nex.RMCMessage, *nex.Error) + FindByNameLike func(err error, packet nex.PacketInterface, callID uint32, uiGroups *types.PrimitiveU32, strLike *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + CustomCreateAccount func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, uiGroups *types.PrimitiveU32, strEmail *types.String, oAuthData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error) + NintendoCreateAccount func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, uiGroups *types.PrimitiveU32, strEmail *types.String, oAuthData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error) + LookupOrCreateAccount func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, uiGroups *types.PrimitiveU32, strEmail *types.String, oAuthData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error) + DisconnectPrincipal func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error) + DisconnectAllPrincipals func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Account Management Protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerCreateAccount(handler func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, uiGroups *types.PrimitiveU32, strEmail *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeleteAccount(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error)) + SetHandlerDisableAccount(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID, dtUntil *types.DateTime, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerChangePassword(handler func(err error, packet nex.PacketInterface, callID uint32, strNewKey *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerTestCapability(handler func(err error, packet nex.PacketInterface, callID uint32, uiCapability *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetName(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetAccountData(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetPrivateData(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetPublicData(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetMultiplePublicData(handler func(err error, packet nex.PacketInterface, callID uint32, lstPrincipals *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateAccountName(handler func(err error, packet nex.PacketInterface, callID uint32, strName *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateAccountEmail(handler func(err error, packet nex.PacketInterface, callID uint32, strName *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateCustomData(handler func(err error, packet nex.PacketInterface, callID uint32, oPublicData *types.AnyDataHolder, oPrivateData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindByNameRegex(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroups *types.PrimitiveU32, strRegex *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateAccountExpiryDate(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID, dtExpiry *types.DateTime, strExpiredMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateAccountEffectiveDate(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID, dtEffectiveFrom *types.DateTime, strNotEffectiveMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateStatus(handler func(err error, packet nex.PacketInterface, callID uint32, strStatus *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetStatus(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetLastConnectionStats(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error)) + SetHandlerResetPassword(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerCreateAccountWithCustomData(handler func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, uiGroups *types.PrimitiveU32, strEmail *types.String, oPublicData *types.AnyDataHolder, oPrivateData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) + SetHandlerRetrieveAccount(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateAccount(handler func(err error, packet nex.PacketInterface, callID uint32, strKey *types.String, strEmail *types.String, oPublicData *types.AnyDataHolder, oPrivateData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) + SetHandlerChangePasswordByGuest(handler func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, strEmail *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindByNameLike(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroups *types.PrimitiveU32, strLike *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerCustomCreateAccount(handler func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, uiGroups *types.PrimitiveU32, strEmail *types.String, oAuthData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) + SetHandlerNintendoCreateAccount(handler func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, uiGroups *types.PrimitiveU32, strEmail *types.String, oAuthData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) + SetHandlerLookupOrCreateAccount(handler func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, uiGroups *types.PrimitiveU32, strEmail *types.String, oAuthData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) + SetHandlerDisconnectPrincipal(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error)) + SetHandlerDisconnectAllPrincipals(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerCreateAccount sets the handler for the CreateAccount method +func (protocol *Protocol) SetHandlerCreateAccount(handler func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, uiGroups *types.PrimitiveU32, strEmail *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.CreateAccount = handler +} + +// SetHandlerDeleteAccount sets the handler for the DeleteAccount method +func (protocol *Protocol) SetHandlerDeleteAccount(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.DeleteAccount = handler +} + +// SetHandlerDisableAccount sets the handler for the DisableAccount method +func (protocol *Protocol) SetHandlerDisableAccount(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID, dtUntil *types.DateTime, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.DisableAccount = handler +} + +// SetHandlerChangePassword sets the handler for the ChangePassword method +func (protocol *Protocol) SetHandlerChangePassword(handler func(err error, packet nex.PacketInterface, callID uint32, strNewKey *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.ChangePassword = handler +} + +// SetHandlerTestCapability sets the handler for the TestCapability method +func (protocol *Protocol) SetHandlerTestCapability(handler func(err error, packet nex.PacketInterface, callID uint32, uiCapability *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.TestCapability = handler +} + +// SetHandlerGetName sets the handler for the GetName method +func (protocol *Protocol) SetHandlerGetName(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.GetName = handler +} + +// SetHandlerGetAccountData sets the handler for the GetAccountData method +func (protocol *Protocol) SetHandlerGetAccountData(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetAccountData = handler +} + +// SetHandlerGetPrivateData sets the handler for the GetPrivateData method +func (protocol *Protocol) SetHandlerGetPrivateData(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetPrivateData = handler +} + +// SetHandlerGetPublicData sets the handler for the GetPublicData method +func (protocol *Protocol) SetHandlerGetPublicData(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.GetPublicData = handler +} + +// SetHandlerGetMultiplePublicData sets the handler for the GetMultiplePublicData method +func (protocol *Protocol) SetHandlerGetMultiplePublicData(handler func(err error, packet nex.PacketInterface, callID uint32, lstPrincipals *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetMultiplePublicData = handler +} + +// SetHandlerUpdateAccountName sets the handler for the UpdateAccountName method +func (protocol *Protocol) SetHandlerUpdateAccountName(handler func(err error, packet nex.PacketInterface, callID uint32, strName *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateAccountName = handler +} + +// SetHandlerUpdateAccountEmail sets the handler for the UpdateAccountEmail method +func (protocol *Protocol) SetHandlerUpdateAccountEmail(handler func(err error, packet nex.PacketInterface, callID uint32, strName *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateAccountEmail = handler +} + +// SetHandlerUpdateCustomData sets the handler for the UpdateCustomData method +func (protocol *Protocol) SetHandlerUpdateCustomData(handler func(err error, packet nex.PacketInterface, callID uint32, oPublicData *types.AnyDataHolder, oPrivateData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateCustomData = handler +} + +// SetHandlerFindByNameRegex sets the handler for the FindByNameRegex method +func (protocol *Protocol) SetHandlerFindByNameRegex(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroups *types.PrimitiveU32, strRegex *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.FindByNameRegex = handler +} + +// SetHandlerUpdateAccountExpiryDate sets the handler for the UpdateAccountExpiryDate method +func (protocol *Protocol) SetHandlerUpdateAccountExpiryDate(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID, dtExpiry *types.DateTime, strExpiredMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateAccountExpiryDate = handler +} + +// SetHandlerUpdateAccountEffectiveDate sets the handler for the UpdateAccountEffectiveDate method +func (protocol *Protocol) SetHandlerUpdateAccountEffectiveDate(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID, dtEffectiveFrom *types.DateTime, strNotEffectiveMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateAccountEffectiveDate = handler +} + +// SetHandlerUpdateStatus sets the handler for the UpdateStatus method +func (protocol *Protocol) SetHandlerUpdateStatus(handler func(err error, packet nex.PacketInterface, callID uint32, strStatus *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateStatus = handler +} + +// SetHandlerGetStatus sets the handler for the GetStatus method +func (protocol *Protocol) SetHandlerGetStatus(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.GetStatus = handler +} + +// SetHandlerGetLastConnectionStats sets the handler for the GetLastConnectionStats method +func (protocol *Protocol) SetHandlerGetLastConnectionStats(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.GetLastConnectionStats = handler +} + +// SetHandlerResetPassword sets the handler for the ResetPassword method +func (protocol *Protocol) SetHandlerResetPassword(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.ResetPassword = handler +} + +// SetHandlerCreateAccountWithCustomData sets the handler for the CreateAccountWithCustomData method +func (protocol *Protocol) SetHandlerCreateAccountWithCustomData(handler func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, uiGroups *types.PrimitiveU32, strEmail *types.String, oPublicData *types.AnyDataHolder, oPrivateData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) { + protocol.CreateAccountWithCustomData = handler +} + +// SetHandlerRetrieveAccount sets the handler for the RetrieveAccount method +func (protocol *Protocol) SetHandlerRetrieveAccount(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.RetrieveAccount = handler +} + +// SetHandlerUpdateAccount sets the handler for the UpdateAccount method +func (protocol *Protocol) SetHandlerUpdateAccount(handler func(err error, packet nex.PacketInterface, callID uint32, strKey *types.String, strEmail *types.String, oPublicData *types.AnyDataHolder, oPrivateData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateAccount = handler +} + +// SetHandlerChangePasswordByGuest sets the handler for the ChangePasswordByGuest method +func (protocol *Protocol) SetHandlerChangePasswordByGuest(handler func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, strEmail *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.ChangePasswordByGuest = handler +} + +// SetHandlerFindByNameLike sets the handler for the FindByNameLike method +func (protocol *Protocol) SetHandlerFindByNameLike(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroups *types.PrimitiveU32, strLike *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.FindByNameLike = handler +} + +// SetHandlerCustomCreateAccount sets the handler for the CustomCreateAccount method +func (protocol *Protocol) SetHandlerCustomCreateAccount(handler func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, uiGroups *types.PrimitiveU32, strEmail *types.String, oAuthData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) { + protocol.CustomCreateAccount = handler +} + +// SetHandlerNintendoCreateAccount sets the handler for the NintendoCreateAccount method +func (protocol *Protocol) SetHandlerNintendoCreateAccount(handler func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, uiGroups *types.PrimitiveU32, strEmail *types.String, oAuthData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) { + protocol.NintendoCreateAccount = handler +} + +// SetHandlerLookupOrCreateAccount sets the handler for the LookupOrCreateAccount method +func (protocol *Protocol) SetHandlerLookupOrCreateAccount(handler func(err error, packet nex.PacketInterface, callID uint32, strPrincipalName *types.String, strKey *types.String, uiGroups *types.PrimitiveU32, strEmail *types.String, oAuthData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) { + protocol.LookupOrCreateAccount = handler +} + +// SetHandlerDisconnectPrincipal sets the handler for the DisconnectPrincipal method +func (protocol *Protocol) SetHandlerDisconnectPrincipal(handler func(err error, packet nex.PacketInterface, callID uint32, idPrincipal *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.DisconnectPrincipal = handler +} + +// SetHandlerDisconnectAllPrincipals sets the handler for the DisconnectAllPrincipals method +func (protocol *Protocol) SetHandlerDisconnectAllPrincipals(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.DisconnectAllPrincipals = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodCreateAccount: + protocol.handleCreateAccount(packet) + case MethodDeleteAccount: + protocol.handleDeleteAccount(packet) + case MethodDisableAccount: + protocol.handleDisableAccount(packet) + case MethodChangePassword: + protocol.handleChangePassword(packet) + case MethodTestCapability: + protocol.handleTestCapability(packet) + case MethodGetName: + protocol.handleGetName(packet) + case MethodGetAccountData: + protocol.handleGetAccountData(packet) + case MethodGetPrivateData: + protocol.handleGetPrivateData(packet) + case MethodGetPublicData: + protocol.handleGetPublicData(packet) + case MethodGetMultiplePublicData: + protocol.handleGetMultiplePublicData(packet) + case MethodUpdateAccountName: + protocol.handleUpdateAccountName(packet) + case MethodUpdateAccountEmail: + protocol.handleUpdateAccountEmail(packet) + case MethodUpdateCustomData: + protocol.handleUpdateCustomData(packet) + case MethodFindByNameRegex: + protocol.handleFindByNameRegex(packet) + case MethodUpdateAccountExpiryDate: + protocol.handleUpdateAccountExpiryDate(packet) + case MethodUpdateAccountEffectiveDate: + protocol.handleUpdateAccountEffectiveDate(packet) + case MethodUpdateStatus: + protocol.handleUpdateStatus(packet) + case MethodGetStatus: + protocol.handleGetStatus(packet) + case MethodGetLastConnectionStats: + protocol.handleGetLastConnectionStats(packet) + case MethodResetPassword: + protocol.handleResetPassword(packet) + case MethodCreateAccountWithCustomData: + protocol.handleCreateAccountWithCustomData(packet) + case MethodRetrieveAccount: + protocol.handleRetrieveAccount(packet) + case MethodUpdateAccount: + protocol.handleUpdateAccount(packet) + case MethodChangePasswordByGuest: + protocol.handleChangePasswordByGuest(packet) + case MethodFindByNameLike: + protocol.handleFindByNameLike(packet) + case MethodCustomCreateAccount: + protocol.handleCustomCreateAccount(packet) + case MethodNintendoCreateAccount: + protocol.handleNintendoCreateAccount(packet) + case MethodLookupOrCreateAccount: + protocol.handleLookupOrCreateAccount(packet) + case MethodDisconnectPrincipal: + protocol.handleDisconnectPrincipal(packet) + case MethodDisconnectAllPrincipals: + protocol.handleDisconnectAllPrincipals(packet) + default: + errMessage := fmt.Sprintf("Unsupported AccountManagement method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Account Management protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/account-management/reset_password.go b/nex-protocols-go/account-management/reset_password.go new file mode 100644 index 0000000..d45ca0b --- /dev/null +++ b/nex-protocols-go/account-management/reset_password.go @@ -0,0 +1,29 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleResetPassword(packet nex.PacketInterface) { + if protocol.ResetPassword == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::ResetPassword not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.ResetPassword(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/retrieve_account.go b/nex-protocols-go/account-management/retrieve_account.go new file mode 100644 index 0000000..ee735d4 --- /dev/null +++ b/nex-protocols-go/account-management/retrieve_account.go @@ -0,0 +1,29 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRetrieveAccount(packet nex.PacketInterface) { + if protocol.RetrieveAccount == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::RetrieveAccount not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.RetrieveAccount(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/test_capability.go b/nex-protocols-go/account-management/test_capability.go new file mode 100644 index 0000000..7b6f057 --- /dev/null +++ b/nex-protocols-go/account-management/test_capability.go @@ -0,0 +1,47 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleTestCapability(packet nex.PacketInterface) { + if protocol.TestCapability == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::TestCapability not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiCapability := types.NewPrimitiveU32(0) + + err := uiCapability.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.TestCapability(fmt.Errorf("Failed to read uiCapability from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.TestCapability(nil, packet, callID, uiCapability) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/types/account_data.go b/nex-protocols-go/account-management/types/account_data.go new file mode 100644 index 0000000..cf23f77 --- /dev/null +++ b/nex-protocols-go/account-management/types/account_data.go @@ -0,0 +1,210 @@ +// Package types implements all the types used by the AccountManagement protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// AccountData is a type within the AccountManagement protocol +type AccountData struct { + types.Structure + PID *types.PID + StrName *types.String + UIGroups *types.PrimitiveU32 + StrEmail *types.String + DTCreationDate *types.DateTime + DTEffectiveDate *types.DateTime + StrNotEffectiveMsg *types.String + DTExpiryDate *types.DateTime + StrExpiredMsg *types.String +} + +// WriteTo writes the AccountData to the given writable +func (ad *AccountData) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + ad.PID.WriteTo(contentWritable) + ad.StrName.WriteTo(contentWritable) + ad.UIGroups.WriteTo(contentWritable) + ad.StrEmail.WriteTo(contentWritable) + ad.DTCreationDate.WriteTo(contentWritable) + ad.DTEffectiveDate.WriteTo(contentWritable) + ad.StrNotEffectiveMsg.WriteTo(contentWritable) + ad.DTExpiryDate.WriteTo(contentWritable) + ad.StrExpiredMsg.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + ad.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the AccountData from the given readable +func (ad *AccountData) ExtractFrom(readable types.Readable) error { + var err error + + err = ad.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AccountData header. %s", err.Error()) + } + + err = ad.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AccountData.PID. %s", err.Error()) + } + + err = ad.StrName.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AccountData.StrName. %s", err.Error()) + } + + err = ad.UIGroups.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AccountData.UIGroups. %s", err.Error()) + } + + err = ad.StrEmail.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AccountData.StrEmail. %s", err.Error()) + } + + err = ad.DTCreationDate.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AccountData.DTCreationDate. %s", err.Error()) + } + + err = ad.DTEffectiveDate.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AccountData.DTEffectiveDate. %s", err.Error()) + } + + err = ad.StrNotEffectiveMsg.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AccountData.StrNotEffectiveMsg. %s", err.Error()) + } + + err = ad.DTExpiryDate.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AccountData.DTExpiryDate. %s", err.Error()) + } + + err = ad.StrExpiredMsg.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AccountData.StrExpiredMsg. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of AccountData +func (ad *AccountData) Copy() types.RVType { + copied := NewAccountData() + + copied.StructureVersion = ad.StructureVersion + copied.PID = ad.PID.Copy().(*types.PID) + copied.StrName = ad.StrName.Copy().(*types.String) + copied.UIGroups = ad.UIGroups.Copy().(*types.PrimitiveU32) + copied.StrEmail = ad.StrEmail.Copy().(*types.String) + copied.DTCreationDate = ad.DTCreationDate.Copy().(*types.DateTime) + copied.DTEffectiveDate = ad.DTEffectiveDate.Copy().(*types.DateTime) + copied.StrNotEffectiveMsg = ad.StrNotEffectiveMsg.Copy().(*types.String) + copied.DTExpiryDate = ad.DTExpiryDate.Copy().(*types.DateTime) + copied.StrExpiredMsg = ad.StrExpiredMsg.Copy().(*types.String) + + return copied +} + +// Equals checks if the given AccountData contains the same data as the current AccountData +func (ad *AccountData) Equals(o types.RVType) bool { + if _, ok := o.(*AccountData); !ok { + return false + } + + other := o.(*AccountData) + + if ad.StructureVersion != other.StructureVersion { + return false + } + + if !ad.PID.Equals(other.PID) { + return false + } + + if !ad.StrName.Equals(other.StrName) { + return false + } + + if !ad.UIGroups.Equals(other.UIGroups) { + return false + } + + if !ad.StrEmail.Equals(other.StrEmail) { + return false + } + + if !ad.DTCreationDate.Equals(other.DTCreationDate) { + return false + } + + if !ad.DTEffectiveDate.Equals(other.DTEffectiveDate) { + return false + } + + if !ad.StrNotEffectiveMsg.Equals(other.StrNotEffectiveMsg) { + return false + } + + if !ad.DTExpiryDate.Equals(other.DTExpiryDate) { + return false + } + + return ad.StrExpiredMsg.Equals(other.StrExpiredMsg) +} + +// String returns the string representation of the AccountData +func (ad *AccountData) String() string { + return ad.FormatToString(0) +} + +// FormatToString pretty-prints the AccountData using the provided indentation level +func (ad *AccountData) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("AccountData{\n") + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, ad.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sStrName: %s,\n", indentationValues, ad.StrName)) + b.WriteString(fmt.Sprintf("%sUIGroups: %s,\n", indentationValues, ad.UIGroups)) + b.WriteString(fmt.Sprintf("%sStrEmail: %s,\n", indentationValues, ad.StrEmail)) + b.WriteString(fmt.Sprintf("%sDTCreationDate: %s,\n", indentationValues, ad.DTCreationDate.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sDTEffectiveDate: %s,\n", indentationValues, ad.DTEffectiveDate.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sStrNotEffectiveMsg: %s,\n", indentationValues, ad.StrNotEffectiveMsg)) + b.WriteString(fmt.Sprintf("%sDTExpiryDate: %s,\n", indentationValues, ad.DTExpiryDate.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sStrExpiredMsg: %s,\n", indentationValues, ad.StrExpiredMsg)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewAccountData returns a new AccountData +func NewAccountData() *AccountData { + ad := &AccountData{ + PID: types.NewPID(0), + StrName: types.NewString(""), + UIGroups: types.NewPrimitiveU32(0), + StrEmail: types.NewString(""), + DTCreationDate: types.NewDateTime(0), + DTEffectiveDate: types.NewDateTime(0), + StrNotEffectiveMsg: types.NewString(""), + DTExpiryDate: types.NewDateTime(0), + StrExpiredMsg: types.NewString(""), + } + + return ad +} diff --git a/nex-protocols-go/account-management/types/account_extra_info.go b/nex-protocols-go/account-management/types/account_extra_info.go new file mode 100644 index 0000000..2016fc3 --- /dev/null +++ b/nex-protocols-go/account-management/types/account_extra_info.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the AccountManagement protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// AccountExtraInfo is a type within the AccountManagement protocol +type AccountExtraInfo struct { + types.Structure + Unknown *types.PrimitiveU32 + Unknown2 *types.PrimitiveU32 + Unknown3 *types.PrimitiveU32 + NEXToken *types.String +} + +// WriteTo writes the AccountExtraInfo to the given writable +func (aei *AccountExtraInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + aei.Unknown.WriteTo(contentWritable) + aei.Unknown2.WriteTo(contentWritable) + aei.Unknown3.WriteTo(contentWritable) + aei.NEXToken.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + aei.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the AccountExtraInfo from the given readable +func (aei *AccountExtraInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = aei.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AccountExtraInfo header. %s", err.Error()) + } + + err = aei.Unknown.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AccountExtraInfo.Unknown. %s", err.Error()) + } + + err = aei.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AccountExtraInfo.Unknown2. %s", err.Error()) + } + + err = aei.Unknown3.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AccountExtraInfo.Unknown3. %s", err.Error()) + } + + err = aei.NEXToken.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AccountExtraInfo.NEXToken. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of AccountExtraInfo +func (aei *AccountExtraInfo) Copy() types.RVType { + copied := NewAccountExtraInfo() + + copied.StructureVersion = aei.StructureVersion + copied.Unknown = aei.Unknown.Copy().(*types.PrimitiveU32) + copied.Unknown2 = aei.Unknown2.Copy().(*types.PrimitiveU32) + copied.Unknown3 = aei.Unknown3.Copy().(*types.PrimitiveU32) + copied.NEXToken = aei.NEXToken.Copy().(*types.String) + + return copied +} + +// Equals checks if the given AccountExtraInfo contains the same data as the current AccountExtraInfo +func (aei *AccountExtraInfo) Equals(o types.RVType) bool { + if _, ok := o.(*AccountExtraInfo); !ok { + return false + } + + other := o.(*AccountExtraInfo) + + if aei.StructureVersion != other.StructureVersion { + return false + } + + if !aei.Unknown.Equals(other.Unknown) { + return false + } + + if !aei.Unknown2.Equals(other.Unknown2) { + return false + } + + if !aei.Unknown3.Equals(other.Unknown3) { + return false + } + + return aei.NEXToken.Equals(other.NEXToken) +} + +// String returns the string representation of the AccountExtraInfo +func (aei *AccountExtraInfo) String() string { + return aei.FormatToString(0) +} + +// FormatToString pretty-prints the AccountExtraInfo using the provided indentation level +func (aei *AccountExtraInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("AccountExtraInfo{\n") + b.WriteString(fmt.Sprintf("%sUnknown: %s,\n", indentationValues, aei.Unknown)) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, aei.Unknown2)) + b.WriteString(fmt.Sprintf("%sUnknown3: %s,\n", indentationValues, aei.Unknown3)) + b.WriteString(fmt.Sprintf("%sNEXToken: %s,\n", indentationValues, aei.NEXToken)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewAccountExtraInfo returns a new AccountExtraInfo +func NewAccountExtraInfo() *AccountExtraInfo { + aei := &AccountExtraInfo{ + Unknown: types.NewPrimitiveU32(0), + Unknown2: types.NewPrimitiveU32(0), + Unknown3: types.NewPrimitiveU32(0), + NEXToken: types.NewString(""), + } + + return aei +} diff --git a/nex-protocols-go/account-management/types/basic_account_info.go b/nex-protocols-go/account-management/types/basic_account_info.go new file mode 100644 index 0000000..c64954d --- /dev/null +++ b/nex-protocols-go/account-management/types/basic_account_info.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the AccountManagement protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// BasicAccountInfo is a type within the AccountManagement protocol +type BasicAccountInfo struct { + types.Structure + PIDOwner *types.PID + StrName *types.String +} + +// WriteTo writes the BasicAccountInfo to the given writable +func (bai *BasicAccountInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + bai.PIDOwner.WriteTo(contentWritable) + bai.StrName.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + bai.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the BasicAccountInfo from the given readable +func (bai *BasicAccountInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = bai.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BasicAccountInfo header. %s", err.Error()) + } + + err = bai.PIDOwner.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BasicAccountInfo.PIDOwner. %s", err.Error()) + } + + err = bai.StrName.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BasicAccountInfo.StrName. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of BasicAccountInfo +func (bai *BasicAccountInfo) Copy() types.RVType { + copied := NewBasicAccountInfo() + + copied.StructureVersion = bai.StructureVersion + copied.PIDOwner = bai.PIDOwner.Copy().(*types.PID) + copied.StrName = bai.StrName.Copy().(*types.String) + + return copied +} + +// Equals checks if the given BasicAccountInfo contains the same data as the current BasicAccountInfo +func (bai *BasicAccountInfo) Equals(o types.RVType) bool { + if _, ok := o.(*BasicAccountInfo); !ok { + return false + } + + other := o.(*BasicAccountInfo) + + if bai.StructureVersion != other.StructureVersion { + return false + } + + if !bai.PIDOwner.Equals(other.PIDOwner) { + return false + } + + return bai.StrName.Equals(other.StrName) +} + +// String returns the string representation of the BasicAccountInfo +func (bai *BasicAccountInfo) String() string { + return bai.FormatToString(0) +} + +// FormatToString pretty-prints the BasicAccountInfo using the provided indentation level +func (bai *BasicAccountInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("BasicAccountInfo{\n") + b.WriteString(fmt.Sprintf("%sPIDOwner: %s,\n", indentationValues, bai.PIDOwner.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sStrName: %s,\n", indentationValues, bai.StrName)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewBasicAccountInfo returns a new BasicAccountInfo +func NewBasicAccountInfo() *BasicAccountInfo { + bai := &BasicAccountInfo{ + PIDOwner: types.NewPID(0), + StrName: types.NewString(""), + } + + return bai +} diff --git a/nex-protocols-go/account-management/types/nintendo_create_account_data.go b/nex-protocols-go/account-management/types/nintendo_create_account_data.go new file mode 100644 index 0000000..21b9722 --- /dev/null +++ b/nex-protocols-go/account-management/types/nintendo_create_account_data.go @@ -0,0 +1,141 @@ +// Package types implements all the types used by the AccountManagement protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" + friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-wiiu/types" +) + +// NintendoCreateAccountData is a type within the AccountManagement protocol +type NintendoCreateAccountData struct { + types.Structure + NNAInfo *friends_wiiu_types.NNAInfo + Token *types.String + Birthday *types.DateTime + Unknown *types.PrimitiveU64 +} + +// WriteTo writes the NintendoCreateAccountData to the given writable +func (ncad *NintendoCreateAccountData) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + ncad.NNAInfo.WriteTo(contentWritable) + ncad.Token.WriteTo(contentWritable) + ncad.Birthday.WriteTo(contentWritable) + ncad.Unknown.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + ncad.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the NintendoCreateAccountData from the given readable +func (ncad *NintendoCreateAccountData) ExtractFrom(readable types.Readable) error { + var err error + + err = ncad.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoCreateAccountData header. %s", err.Error()) + } + + err = ncad.NNAInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoCreateAccountData.NNAInfo. %s", err.Error()) + } + + err = ncad.Token.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoCreateAccountData.Token. %s", err.Error()) + } + + err = ncad.Birthday.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoCreateAccountData.Birthday. %s", err.Error()) + } + + err = ncad.Unknown.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoCreateAccountData.Unknown. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of NintendoCreateAccountData +func (ncad *NintendoCreateAccountData) Copy() types.RVType { + copied := NewNintendoCreateAccountData() + + copied.StructureVersion = ncad.StructureVersion + copied.NNAInfo = ncad.NNAInfo.Copy().(*friends_wiiu_types.NNAInfo) + copied.Token = ncad.Token.Copy().(*types.String) + copied.Birthday = ncad.Birthday.Copy().(*types.DateTime) + copied.Unknown = ncad.Unknown.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given NintendoCreateAccountData contains the same data as the current NintendoCreateAccountData +func (ncad *NintendoCreateAccountData) Equals(o types.RVType) bool { + if _, ok := o.(*NintendoCreateAccountData); !ok { + return false + } + + other := o.(*NintendoCreateAccountData) + + if ncad.StructureVersion != other.StructureVersion { + return false + } + + if !ncad.NNAInfo.Equals(other.NNAInfo) { + return false + } + + if !ncad.Token.Equals(other.Token) { + return false + } + + if !ncad.Birthday.Equals(other.Birthday) { + return false + } + + return ncad.Unknown.Equals(other.Unknown) +} + +// String returns the string representation of the NintendoCreateAccountData +func (ncad *NintendoCreateAccountData) String() string { + return ncad.FormatToString(0) +} + +// FormatToString pretty-prints the NintendoCreateAccountData using the provided indentation level +func (ncad *NintendoCreateAccountData) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("NintendoCreateAccountData{\n") + b.WriteString(fmt.Sprintf("%sNNAInfo: %s,\n", indentationValues, ncad.NNAInfo.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sToken: %s,\n", indentationValues, ncad.Token)) + b.WriteString(fmt.Sprintf("%sBirthday: %s,\n", indentationValues, ncad.Birthday.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUnknown: %s,\n", indentationValues, ncad.Unknown)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewNintendoCreateAccountData returns a new NintendoCreateAccountData +func NewNintendoCreateAccountData() *NintendoCreateAccountData { + ncad := &NintendoCreateAccountData{ + NNAInfo: friends_wiiu_types.NewNNAInfo(), + Token: types.NewString(""), + Birthday: types.NewDateTime(0), + Unknown: types.NewPrimitiveU64(0), + } + + return ncad +} diff --git a/nex-protocols-go/account-management/update_account.go b/nex-protocols-go/account-management/update_account.go new file mode 100644 index 0000000..78ea938 --- /dev/null +++ b/nex-protocols-go/account-management/update_account.go @@ -0,0 +1,82 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateAccount(packet nex.PacketInterface) { + if protocol.UpdateAccount == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::UpdateAccount not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strKey := types.NewString("") + strEmail := types.NewString("") + oPublicData := types.NewAnyDataHolder() + oPrivateData := types.NewAnyDataHolder() + + var err error + + err = strKey.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateAccount(fmt.Errorf("Failed to read strKey from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strEmail.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateAccount(fmt.Errorf("Failed to read strEmail from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = oPublicData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateAccount(fmt.Errorf("Failed to read oPublicData from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = oPrivateData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateAccount(fmt.Errorf("Failed to read oPrivateData from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateAccount(nil, packet, callID, strKey, strEmail, oPublicData, oPrivateData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/update_account_effective_date.go b/nex-protocols-go/account-management/update_account_effective_date.go new file mode 100644 index 0000000..d826fa8 --- /dev/null +++ b/nex-protocols-go/account-management/update_account_effective_date.go @@ -0,0 +1,71 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateAccountEffectiveDate(packet nex.PacketInterface) { + if protocol.UpdateAccountEffectiveDate == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::UpdateAccountEffectiveDate not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idPrincipal := types.NewPID(0) + dtEffectiveFrom := types.NewDateTime(0) + strNotEffectiveMessage := types.NewString("") + + var err error + + err = idPrincipal.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateAccountEffectiveDate(fmt.Errorf("Failed to read idPrincipal from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = dtEffectiveFrom.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateAccountEffectiveDate(fmt.Errorf("Failed to read dtEffectiveFrom from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strNotEffectiveMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateAccountEffectiveDate(fmt.Errorf("Failed to read strNotEffectiveMessage from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateAccountEffectiveDate(nil, packet, callID, idPrincipal, dtEffectiveFrom, strNotEffectiveMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/update_account_email.go b/nex-protocols-go/account-management/update_account_email.go new file mode 100644 index 0000000..6acd4f7 --- /dev/null +++ b/nex-protocols-go/account-management/update_account_email.go @@ -0,0 +1,47 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateAccountEmail(packet nex.PacketInterface) { + if protocol.UpdateAccountEmail == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::UpdateAccountEmail not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strName := types.NewString("") + + err := strName.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateAccountEmail(fmt.Errorf("Failed to read strName from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateAccountEmail(nil, packet, callID, strName) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/update_account_expiry_date.go b/nex-protocols-go/account-management/update_account_expiry_date.go new file mode 100644 index 0000000..f91c212 --- /dev/null +++ b/nex-protocols-go/account-management/update_account_expiry_date.go @@ -0,0 +1,71 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateAccountExpiryDate(packet nex.PacketInterface) { + if protocol.UpdateAccountExpiryDate == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::UpdateAccountExpiryDate not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idPrincipal := types.NewPID(0) + dtExpiry := types.NewDateTime(0) + strExpiredMessage := types.NewString("") + + var err error + + err = idPrincipal.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateAccountExpiryDate(fmt.Errorf("Failed to read idPrincipal from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = dtExpiry.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateAccountExpiryDate(fmt.Errorf("Failed to read dtExpiry from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strExpiredMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateAccountExpiryDate(fmt.Errorf("Failed to read strExpiredMessage from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateAccountExpiryDate(nil, packet, callID, idPrincipal, dtExpiry, strExpiredMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/update_account_name.go b/nex-protocols-go/account-management/update_account_name.go new file mode 100644 index 0000000..a0453b9 --- /dev/null +++ b/nex-protocols-go/account-management/update_account_name.go @@ -0,0 +1,47 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateAccountName(packet nex.PacketInterface) { + if protocol.UpdateAccountName == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::UpdateAccountName not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strName := types.NewString("") + + err := strName.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateAccountName(fmt.Errorf("Failed to read strName from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateAccountName(nil, packet, callID, strName) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/update_custom_data.go b/nex-protocols-go/account-management/update_custom_data.go new file mode 100644 index 0000000..321fcd7 --- /dev/null +++ b/nex-protocols-go/account-management/update_custom_data.go @@ -0,0 +1,60 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateCustomData(packet nex.PacketInterface) { + if protocol.UpdateCustomData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::UpdateCustomData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + oPublicData := types.NewAnyDataHolder() + oPrivateData := types.NewAnyDataHolder() + + var err error + + err = oPublicData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateCustomData(fmt.Errorf("Failed to read oPublicData from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = oPrivateData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateCustomData(fmt.Errorf("Failed to read oPrivateData from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateCustomData(nil, packet, callID, oPublicData, oPrivateData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/account-management/update_status.go b/nex-protocols-go/account-management/update_status.go new file mode 100644 index 0000000..47d5ef7 --- /dev/null +++ b/nex-protocols-go/account-management/update_status.go @@ -0,0 +1,47 @@ +// Package protocol implements the Account Management protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateStatus(packet nex.PacketInterface) { + if protocol.UpdateStatus == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "AccountManagement::UpdateStatus not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strStatus := types.NewString("") + + err := strStatus.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateStatus(fmt.Errorf("Failed to read strStatus from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateStatus(nil, packet, callID, strStatus) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/change_meta.go b/nex-protocols-go/datastore/change_meta.go new file mode 100644 index 0000000..2396f25 --- /dev/null +++ b/nex-protocols-go/datastore/change_meta.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleChangeMeta(packet nex.PacketInterface) { + if protocol.ChangeMeta == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::ChangeMeta not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreChangeMetaParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangeMeta(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ChangeMeta(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/change_meta_v1.go b/nex-protocols-go/datastore/change_meta_v1.go new file mode 100644 index 0000000..8ebc601 --- /dev/null +++ b/nex-protocols-go/datastore/change_meta_v1.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleChangeMetaV1(packet nex.PacketInterface) { + if protocol.ChangeMetaV1 == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::ChangeMetaV1 not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreChangeMetaParamV1() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangeMetaV1(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ChangeMetaV1(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/change_metas.go b/nex-protocols-go/datastore/change_metas.go new file mode 100644 index 0000000..bad5f24 --- /dev/null +++ b/nex-protocols-go/datastore/change_metas.go @@ -0,0 +1,74 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleChangeMetas(packet nex.PacketInterface) { + if protocol.ChangeMetas == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::ChangeMetas not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + dataIDs := types.NewList[*types.PrimitiveU64]() + dataIDs.Type = types.NewPrimitiveU64(0) + params := types.NewList[*datastore_types.DataStoreChangeMetaParam]() + params.Type = datastore_types.NewDataStoreChangeMetaParam() + transactional := types.NewPrimitiveBool(false) + + var err error + + err = dataIDs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangeMetas(fmt.Errorf("Failed to read dataIDs from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = params.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangeMetas(fmt.Errorf("Failed to read params from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = transactional.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangeMetas(fmt.Errorf("Failed to read transactional from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ChangeMetas(nil, packet, callID, dataIDs, params, transactional) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/change_metas_v1.go b/nex-protocols-go/datastore/change_metas_v1.go new file mode 100644 index 0000000..6352cd0 --- /dev/null +++ b/nex-protocols-go/datastore/change_metas_v1.go @@ -0,0 +1,74 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleChangeMetasV1(packet nex.PacketInterface) { + if protocol.ChangeMetasV1 == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::ChangeMetasV1 not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + dataIDs := types.NewList[*types.PrimitiveU64]() + dataIDs.Type = types.NewPrimitiveU64(0) + params := types.NewList[*datastore_types.DataStoreChangeMetaParamV1]() + params.Type = datastore_types.NewDataStoreChangeMetaParamV1() + transactional := types.NewPrimitiveBool(false) + + var err error + + err = dataIDs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangeMetasV1(fmt.Errorf("Failed to read dataIDs from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = params.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangeMetasV1(fmt.Errorf("Failed to read params from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = transactional.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangeMetasV1(fmt.Errorf("Failed to read transactional from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ChangeMetasV1(nil, packet, callID, dataIDs, params, transactional) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/complete_post_object.go b/nex-protocols-go/datastore/complete_post_object.go new file mode 100644 index 0000000..c55b95d --- /dev/null +++ b/nex-protocols-go/datastore/complete_post_object.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCompletePostObject(packet nex.PacketInterface) { + if protocol.CompletePostObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::CompletePostObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreCompletePostParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CompletePostObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CompletePostObject(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/complete_post_object_v1.go b/nex-protocols-go/datastore/complete_post_object_v1.go new file mode 100644 index 0000000..239096f --- /dev/null +++ b/nex-protocols-go/datastore/complete_post_object_v1.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCompletePostObjectV1(packet nex.PacketInterface) { + if protocol.CompletePostObjectV1 == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::CompletePostObjectV1 not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreCompletePostParamV1() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CompletePostObjectV1(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CompletePostObjectV1(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/complete_post_objects.go b/nex-protocols-go/datastore/complete_post_objects.go new file mode 100644 index 0000000..2528818 --- /dev/null +++ b/nex-protocols-go/datastore/complete_post_objects.go @@ -0,0 +1,48 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCompletePostObjects(packet nex.PacketInterface) { + if protocol.CompletePostObjects == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::CompletePostObjects not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + dataIDs := types.NewList[*types.PrimitiveU64]() + dataIDs.Type = types.NewPrimitiveU64(0) + + err := dataIDs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CompletePostObjects(fmt.Errorf("Failed to read dataIDs from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CompletePostObjects(nil, packet, callID, dataIDs) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/complete_update_object.go b/nex-protocols-go/datastore/complete_update_object.go new file mode 100644 index 0000000..dccc658 --- /dev/null +++ b/nex-protocols-go/datastore/complete_update_object.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCompleteUpdateObject(packet nex.PacketInterface) { + if protocol.CompleteUpdateObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::CompleteUpdateObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreCompleteUpdateParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CompleteUpdateObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CompleteUpdateObject(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/delete_object.go b/nex-protocols-go/datastore/delete_object.go new file mode 100644 index 0000000..6cc9938 --- /dev/null +++ b/nex-protocols-go/datastore/delete_object.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteObject(packet nex.PacketInterface) { + if protocol.DeleteObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::DeleteObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreDeleteParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteObject(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/delete_objects.go b/nex-protocols-go/datastore/delete_objects.go new file mode 100644 index 0000000..740d8f9 --- /dev/null +++ b/nex-protocols-go/datastore/delete_objects.go @@ -0,0 +1,62 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteObjects(packet nex.PacketInterface) { + if protocol.DeleteObjects == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::DeleteObjects not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + params := types.NewList[*datastore_types.DataStoreDeleteParam]() + params.Type = datastore_types.NewDataStoreDeleteParam() + transactional := types.NewPrimitiveBool(false) + + var err error + + err = params.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteObjects(fmt.Errorf("Failed to read params from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = transactional.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteObjects(fmt.Errorf("Failed to read transactional from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteObjects(nil, packet, callID, params, transactional) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/get_meta.go b/nex-protocols-go/datastore/get_meta.go new file mode 100644 index 0000000..3c85ca5 --- /dev/null +++ b/nex-protocols-go/datastore/get_meta.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetMeta(packet nex.PacketInterface) { + if protocol.GetMeta == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::GetMeta not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreGetMetaParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetMeta(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetMeta(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/get_metas.go b/nex-protocols-go/datastore/get_metas.go new file mode 100644 index 0000000..34823b9 --- /dev/null +++ b/nex-protocols-go/datastore/get_metas.go @@ -0,0 +1,62 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetMetas(packet nex.PacketInterface) { + if protocol.GetMetas == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::GetMetas not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + dataIDs := types.NewList[*types.PrimitiveU64]() + dataIDs.Type = types.NewPrimitiveU64(0) + param := datastore_types.NewDataStoreGetMetaParam() + + var err error + + err = dataIDs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetMetas(fmt.Errorf("Failed to read dataIDs from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetMetas(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetMetas(nil, packet, callID, dataIDs, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/get_metas_multiple_param.go b/nex-protocols-go/datastore/get_metas_multiple_param.go new file mode 100644 index 0000000..f7ceed9 --- /dev/null +++ b/nex-protocols-go/datastore/get_metas_multiple_param.go @@ -0,0 +1,49 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetMetasMultipleParam(packet nex.PacketInterface) { + if protocol.GetMetasMultipleParam == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::GetMetasMultipleParam not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + params := types.NewList[*datastore_types.DataStoreGetMetaParam]() + params.Type = datastore_types.NewDataStoreGetMetaParam() + + err := params.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetMetasMultipleParam(fmt.Errorf("Failed to read params from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetMetasMultipleParam(nil, packet, callID, params) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/get_new_arrived_notifications.go b/nex-protocols-go/datastore/get_new_arrived_notifications.go new file mode 100644 index 0000000..1c4ebf5 --- /dev/null +++ b/nex-protocols-go/datastore/get_new_arrived_notifications.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetNewArrivedNotifications(packet nex.PacketInterface) { + if protocol.GetNewArrivedNotifications == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::GetNewArrivedNotifications not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreGetNewArrivedNotificationsParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetNewArrivedNotifications(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetNewArrivedNotifications(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/get_new_arrived_notifications_v1.go b/nex-protocols-go/datastore/get_new_arrived_notifications_v1.go new file mode 100644 index 0000000..e3d2b1b --- /dev/null +++ b/nex-protocols-go/datastore/get_new_arrived_notifications_v1.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetNewArrivedNotificationsV1(packet nex.PacketInterface) { + if protocol.GetNewArrivedNotificationsV1 == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::GetNewArrivedNotificationsV1 not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreGetNewArrivedNotificationsParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetNewArrivedNotificationsV1(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetNewArrivedNotificationsV1(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/get_notification_url.go b/nex-protocols-go/datastore/get_notification_url.go new file mode 100644 index 0000000..867a3e1 --- /dev/null +++ b/nex-protocols-go/datastore/get_notification_url.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetNotificationURL(packet nex.PacketInterface) { + if protocol.GetNotificationURL == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::GetNotificationURL not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreGetNotificationURLParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetNotificationURL(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetNotificationURL(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/get_object_infos.go b/nex-protocols-go/datastore/get_object_infos.go new file mode 100644 index 0000000..88cd02c --- /dev/null +++ b/nex-protocols-go/datastore/get_object_infos.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetObjectInfos(packet nex.PacketInterface) { + if protocol.GetObjectInfos == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::GetObjectInfos not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + dataIDs := types.NewPrimitiveU64(0) + + err := dataIDs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetObjectInfos(fmt.Errorf("Failed to read dataIDs from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetObjectInfos(nil, packet, callID, dataIDs) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/get_password_info.go b/nex-protocols-go/datastore/get_password_info.go new file mode 100644 index 0000000..6ac4af8 --- /dev/null +++ b/nex-protocols-go/datastore/get_password_info.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetPasswordInfo(packet nex.PacketInterface) { + if protocol.GetPasswordInfo == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::GetPasswordInfo not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + dataID := types.NewPrimitiveU64(0) + + err := dataID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPasswordInfo(fmt.Errorf("Failed to read dataID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetPasswordInfo(nil, packet, callID, dataID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/get_password_infos.go b/nex-protocols-go/datastore/get_password_infos.go new file mode 100644 index 0000000..2140bdc --- /dev/null +++ b/nex-protocols-go/datastore/get_password_infos.go @@ -0,0 +1,48 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetPasswordInfos(packet nex.PacketInterface) { + if protocol.GetPasswordInfos == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::GetPasswordInfos not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + dataIDs := types.NewList[*types.PrimitiveU64]() + dataIDs.Type = types.NewPrimitiveU64(0) + + err := dataIDs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPasswordInfos(fmt.Errorf("Failed to read dataIDs from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetPasswordInfos(nil, packet, callID, dataIDs) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/get_persistence_info.go b/nex-protocols-go/datastore/get_persistence_info.go new file mode 100644 index 0000000..ca172b0 --- /dev/null +++ b/nex-protocols-go/datastore/get_persistence_info.go @@ -0,0 +1,60 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetPersistenceInfo(packet nex.PacketInterface) { + if protocol.GetPersistenceInfo == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::GetPersistenceInfo not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + ownerID := types.NewPID(0) + persistenceSlotID := types.NewPrimitiveU16(0) + + var err error + + err = ownerID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPersistenceInfo(fmt.Errorf("Failed to read ownerID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = persistenceSlotID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPersistenceInfo(fmt.Errorf("Failed to read persistenceSlotID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetPersistenceInfo(nil, packet, callID, ownerID, persistenceSlotID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/get_persistence_infos.go b/nex-protocols-go/datastore/get_persistence_infos.go new file mode 100644 index 0000000..45e6bb0 --- /dev/null +++ b/nex-protocols-go/datastore/get_persistence_infos.go @@ -0,0 +1,61 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetPersistenceInfos(packet nex.PacketInterface) { + if protocol.GetPersistenceInfos == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::GetPersistenceInfos not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + ownerID := types.NewPID(0) + persistenceSlotIDs := types.NewList[*types.PrimitiveU16]() + persistenceSlotIDs.Type = types.NewPrimitiveU16(0) + + var err error + + err = ownerID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPersistenceInfos(fmt.Errorf("Failed to read ownerID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = persistenceSlotIDs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPersistenceInfos(fmt.Errorf("Failed to read persistenceSlotIDs from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetPersistenceInfos(nil, packet, callID, ownerID, persistenceSlotIDs) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/get_rating.go b/nex-protocols-go/datastore/get_rating.go new file mode 100644 index 0000000..1051d5c --- /dev/null +++ b/nex-protocols-go/datastore/get_rating.go @@ -0,0 +1,61 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetRating(packet nex.PacketInterface) { + if protocol.GetRating == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::GetRating not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + target := datastore_types.NewDataStoreRatingTarget() + accessPassword := types.NewPrimitiveU64(0) + + var err error + + err = target.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRating(fmt.Errorf("Failed to read target from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = accessPassword.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRating(fmt.Errorf("Failed to read accessPassword from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetRating(nil, packet, callID, target, accessPassword) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/get_rating_with_log.go b/nex-protocols-go/datastore/get_rating_with_log.go new file mode 100644 index 0000000..ea4d2e2 --- /dev/null +++ b/nex-protocols-go/datastore/get_rating_with_log.go @@ -0,0 +1,61 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetRatingWithLog(packet nex.PacketInterface) { + if protocol.GetRatingWithLog == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::GetRatingWithLog not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + target := datastore_types.NewDataStoreRatingTarget() + accessPassword := types.NewPrimitiveU64(0) + + var err error + + err = target.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRatingWithLog(fmt.Errorf("Failed to read target from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = accessPassword.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRatingWithLog(fmt.Errorf("Failed to read accessPassword from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetRatingWithLog(nil, packet, callID, target, accessPassword) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/get_ratings.go b/nex-protocols-go/datastore/get_ratings.go new file mode 100644 index 0000000..6d6bee8 --- /dev/null +++ b/nex-protocols-go/datastore/get_ratings.go @@ -0,0 +1,61 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetRatings(packet nex.PacketInterface) { + if protocol.GetRatings == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::GetRatings not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + dataIDs := types.NewList[*types.PrimitiveU64]() + dataIDs.Type = types.NewPrimitiveU64(0) + accessPassword := types.NewPrimitiveU64(0) + + var err error + + err = dataIDs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRatings(fmt.Errorf("Failed to read dataIDs from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = accessPassword.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRatings(fmt.Errorf("Failed to read accessPassword from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetRatings(nil, packet, callID, dataIDs, accessPassword) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/get_specific_meta.go b/nex-protocols-go/datastore/get_specific_meta.go new file mode 100644 index 0000000..14751e7 --- /dev/null +++ b/nex-protocols-go/datastore/get_specific_meta.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetSpecificMeta(packet nex.PacketInterface) { + if protocol.GetSpecificMeta == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::GetSpecificMeta not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreGetSpecificMetaParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetSpecificMeta(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetSpecificMeta(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/get_specific_meta_v1.go b/nex-protocols-go/datastore/get_specific_meta_v1.go new file mode 100644 index 0000000..0650b3a --- /dev/null +++ b/nex-protocols-go/datastore/get_specific_meta_v1.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetSpecificMetaV1(packet nex.PacketInterface) { + if protocol.GetSpecificMetaV1 == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::GetSpecificMetaV1 not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreGetSpecificMetaParamV1() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetSpecificMetaV1(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetSpecificMetaV1(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/miitopia/protocol.go b/nex-protocols-go/datastore/miitopia/protocol.go new file mode 100644 index 0000000..ec536b7 --- /dev/null +++ b/nex-protocols-go/datastore/miitopia/protocol.go @@ -0,0 +1,67 @@ +// Package protocol implements the Miitopia DataStore protocol +package protocol + +import ( + "fmt" + "slices" + + "github.com/PretendoNetwork/nex-go/v2" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_miitopia_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/miitopia/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the Protocol ID for the DataStore (Miitopia) protocol. ID is the same as the DataStore protocol + ProtocolID = 0x73 + + // MethodSearchMii is the method ID for SearchMii + MethodSearchMii = 0x2F +) + +var patchedMethods = []uint32{ + MethodSearchMii, +} + +type dataStoreProtocol = datastore.Protocol + +// Protocol stores all the RMC method handlers for the DataStore (Miitopia) protocol and listens for requests +// Embeds the DataStore protocol +type Protocol struct { + endpoint nex.EndpointInterface + dataStoreProtocol + SearchMii func(err error, packet nex.PacketInterface, callId uint32, param *datastore_miitopia_types.MiiTubeSearchParam) (*nex.RMCMessage, *nex.Error) +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if !slices.Contains(patchedMethods, message.MethodID) { + protocol.dataStoreProtocol.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodSearchMii: + protocol.handleSearchMii(packet) + default: + errMessage := fmt.Sprintf("Unsupported DataStoreMiitopia method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new DataStore (Miitopia) protocol +func NewProtocol(endpoint nex.EndpointInterface) *Protocol { + protocol := &Protocol{endpoint: endpoint} + protocol.dataStoreProtocol.SetEndpoint(endpoint) + + return protocol +} diff --git a/nex-protocols-go/datastore/miitopia/search_mii.go b/nex-protocols-go/datastore/miitopia/search_mii.go new file mode 100644 index 0000000..7fa884c --- /dev/null +++ b/nex-protocols-go/datastore/miitopia/search_mii.go @@ -0,0 +1,47 @@ +// Package protocol implements the Miitopia DataStore protocol +package protocol + +import ( + "fmt" + + "github.com/PretendoNetwork/nex-go/v2" + datastore_miitopia_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/miitopia/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSearchMii(packet nex.PacketInterface) { + if protocol.SearchMii == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreMiitopia::SearchMii not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_miitopia_types.NewMiiTubeSearchParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SearchMii(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SearchMii(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/miitopia/types/mii_tube_mii_info.go b/nex-protocols-go/datastore/miitopia/types/mii_tube_mii_info.go new file mode 100644 index 0000000..5bf901b --- /dev/null +++ b/nex-protocols-go/datastore/miitopia/types/mii_tube_mii_info.go @@ -0,0 +1,122 @@ +// Package types implements all the types used by the DataStoreMiitopia protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +// MiiTubeMiiInfo is a type within the DataStoreMiitopia protocol +type MiiTubeMiiInfo struct { + types.Structure + MetaInfo *datastore_types.DataStoreMetaInfo + Category *types.PrimitiveU8 + RankingType *types.PrimitiveU8 +} + +// WriteTo writes the MiiTubeMiiInfo to the given writable +func (mtmi *MiiTubeMiiInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + mtmi.MetaInfo.WriteTo(contentWritable) + mtmi.Category.WriteTo(contentWritable) + mtmi.RankingType.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + mtmi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MiiTubeMiiInfo from the given readable +func (mtmi *MiiTubeMiiInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = mtmi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiTubeMiiInfo header. %s", err.Error()) + } + + err = mtmi.MetaInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiTubeMiiInfo.MetaInfo. %s", err.Error()) + } + + err = mtmi.Category.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiTubeMiiInfo.Category. %s", err.Error()) + } + + err = mtmi.RankingType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiTubeMiiInfo.RankingType. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of MiiTubeMiiInfo +func (mtmi *MiiTubeMiiInfo) Copy() types.RVType { + copied := NewMiiTubeMiiInfo() + + copied.MetaInfo = mtmi.MetaInfo + copied.Category = mtmi.Category + copied.RankingType = mtmi.RankingType + + return copied +} + +// Equals checks if the given MiiTubeMiiInfo contains the same data as the current MiiTubeMiiInfo +func (mtmi *MiiTubeMiiInfo) Equals(o types.RVType) bool { + if _, ok := o.(*MiiTubeMiiInfo); !ok { + return false + } + + other := o.(*MiiTubeMiiInfo) + + if !mtmi.MetaInfo.Equals(other.MetaInfo) { + return false + } + + if !mtmi.Category.Equals(other.Category) { + return false + } + + return mtmi.RankingType.Equals(other.RankingType) +} + +// String returns the string representation of the MiiTubeMiiInfo +func (mtmi *MiiTubeMiiInfo) String() string { + return mtmi.FormatToString(0) +} + +// FormatToString pretty-prints the MiiTubeMiiInfo using the provided indentation level +func (mtmi *MiiTubeMiiInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MiiTubeMiiInfo{\n") + b.WriteString(fmt.Sprintf("%sMetaInfo: %s,\n", indentationValues, mtmi.MetaInfo.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sCategory: %s,\n", indentationValues, mtmi.Category)) + b.WriteString(fmt.Sprintf("%sRankingType: %s,\n", indentationValues, mtmi.RankingType)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMiiTubeMiiInfo returns a new MiiTubeMiiInfo +func NewMiiTubeMiiInfo() *MiiTubeMiiInfo { + mtmi := &MiiTubeMiiInfo{ + MetaInfo: datastore_types.NewDataStoreMetaInfo(), + Category: types.NewPrimitiveU8(0), + RankingType: types.NewPrimitiveU8(0), + } + + return mtmi +} diff --git a/nex-protocols-go/datastore/miitopia/types/mii_tube_search_param.go b/nex-protocols-go/datastore/miitopia/types/mii_tube_search_param.go new file mode 100644 index 0000000..daf3960 --- /dev/null +++ b/nex-protocols-go/datastore/miitopia/types/mii_tube_search_param.go @@ -0,0 +1,177 @@ +// Package types implements all the types used by the DataStoreMiitopia protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// MiiTubeSearchParam is a type within the DataStoreMiitopia protocol +type MiiTubeSearchParam struct { + types.Structure + Name *types.String + Page *types.PrimitiveU32 + Category *types.PrimitiveU8 + Gender *types.PrimitiveU8 + Country *types.PrimitiveU8 + SearchType *types.PrimitiveU8 + ResultOption *types.PrimitiveU8 +} + +// WriteTo writes the MiiTubeSearchParam to the given variable +func (mtsp *MiiTubeSearchParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + mtsp.Name.WriteTo(contentWritable) + mtsp.Page.WriteTo(contentWritable) + mtsp.Category.WriteTo(contentWritable) + mtsp.Gender.WriteTo(contentWritable) + mtsp.Country.WriteTo(contentWritable) + mtsp.SearchType.WriteTo(contentWritable) + mtsp.ResultOption.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + mtsp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MiiTubeSearchParam from the given readable +func (mtsp *MiiTubeSearchParam) ExtractFrom(readable types.Readable) error { + var err error + + err = mtsp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiTubeSearchParam header. %s", err.Error()) + } + + err = mtsp.Name.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiTubeSearchParam.Name. %s", err.Error()) + } + + err = mtsp.Page.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiTubeSearchParam.Page. %s", err.Error()) + } + + err = mtsp.Category.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiTubeSearchParam.Category. %s", err.Error()) + } + + err = mtsp.Gender.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiTubeSearchParam.Gender. %s", err.Error()) + } + + err = mtsp.Country.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiTubeSearchParam.Country. %s", err.Error()) + } + + err = mtsp.SearchType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiTubeSearchParam.SearchType. %s", err.Error()) + } + + err = mtsp.ResultOption.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiTubeSearchParam.ResultOption. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of MiiTubeSearchParam +func (mtsp *MiiTubeSearchParam) Copy() types.RVType { + copied := NewMiiTubeSearchParam() + + copied.Name = mtsp.Name + copied.Page = mtsp.Page + copied.Category = mtsp.Category + copied.Gender = mtsp.Gender + copied.Country = mtsp.Country + copied.SearchType = mtsp.SearchType + copied.ResultOption = mtsp.ResultOption + + return copied +} + +// Equals checks if the given MiiTubeSearchParam contains the same data as the current MiiTubeSearchParam +func (mtsp *MiiTubeSearchParam) Equals(o types.RVType) bool { + if _, ok := o.(*MiiTubeSearchParam); !ok { + return false + } + + other := o.(*MiiTubeSearchParam) + + if !mtsp.Name.Equals(other.Name) { + return false + } + + if !mtsp.Page.Equals(other.Page) { + return false + } + + if !mtsp.Category.Equals(other.Category) { + return false + } + + if !mtsp.Gender.Equals(other.Gender) { + return false + } + + if !mtsp.Country.Equals(other.Country) { + return false + } + + if !mtsp.SearchType.Equals(other.SearchType) { + return false + } + + return mtsp.ResultOption.Equals(other.ResultOption) +} + +// String returns the string representation of the MiiTubeSearchParam +func (mtsp *MiiTubeSearchParam) String() string { + return mtsp.FormatToString(0) +} + +// FormatToString pretty-prints the MiiTubeSearchParam using the provided indentation level +func (mtsp *MiiTubeSearchParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MiiTubeSearchParam{\n") + b.WriteString(fmt.Sprintf("%sName: %s,\n", indentationValues, mtsp.Name)) + b.WriteString(fmt.Sprintf("%sPage: %s,\n", indentationValues, mtsp.Page)) + b.WriteString(fmt.Sprintf("%sCategory: %s,\n", indentationValues, mtsp.Category)) + b.WriteString(fmt.Sprintf("%sGender: %s,\n", indentationValues, mtsp.Gender)) + b.WriteString(fmt.Sprintf("%sCountry: %s,\n", indentationValues, mtsp.Country)) + b.WriteString(fmt.Sprintf("%sSearchType: %s,\n", indentationValues, mtsp.SearchType)) + b.WriteString(fmt.Sprintf("%sResultOption: %s,\n", indentationValues, mtsp.ResultOption)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMiiTubeSearchParam returns a new MiiTubeSearchParam +func NewMiiTubeSearchParam() *MiiTubeSearchParam { + mtsp := &MiiTubeSearchParam{ + Name: types.NewString(""), + Page: types.NewPrimitiveU32(0), + Category: types.NewPrimitiveU8(0), + Gender: types.NewPrimitiveU8(0), + Country: types.NewPrimitiveU8(0), + SearchType: types.NewPrimitiveU8(0), + ResultOption: types.NewPrimitiveU8(0), + } + + return mtsp +} diff --git a/nex-protocols-go/datastore/miitopia/types/mii_tube_search_result.go b/nex-protocols-go/datastore/miitopia/types/mii_tube_search_result.go new file mode 100644 index 0000000..73d2635 --- /dev/null +++ b/nex-protocols-go/datastore/miitopia/types/mii_tube_search_result.go @@ -0,0 +1,138 @@ +// Package types implements all the types used by the DataStoreMiitopia protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// MiiTubeSearchResult is a type within the DataStoreMiitopia protocol +type MiiTubeSearchResult struct { + types.Structure + + Result *types.List[*MiiTubeMiiInfo] + Count *types.PrimitiveU32 + Page *types.PrimitiveU32 + HasNext *types.PrimitiveBool +} + +// WriteTo writes the MiiTubeSearchResult to the given variable +func (mtsr *MiiTubeSearchResult) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + mtsr.Result.WriteTo(contentWritable) + mtsr.Count.WriteTo(contentWritable) + mtsr.Page.WriteTo(contentWritable) + mtsr.HasNext.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + mtsr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MiiTubeSearchResult from the given readable +func (mtsr *MiiTubeSearchResult) ExtractFrom(readable types.Readable) error { + var err error + + err = mtsr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiTubeSearchResult header. %s", err.Error()) + } + + err = mtsr.Result.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiTubeSearchResult.Result. %s", err.Error()) + } + + err = mtsr.Count.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiTubeSearchResult.Count. %s", err.Error()) + } + + err = mtsr.Page.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiTubeSearchResult.Page. %s", err.Error()) + } + + err = mtsr.HasNext.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiTubeSearchResult.ExtractNext. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of MiiTubeSearchResult +func (mtsr *MiiTubeSearchResult) Copy() types.RVType { + copied := NewMiiTubeSearchResult() + + copied.Result = mtsr.Result + copied.Count = mtsr.Count + copied.Page = mtsr.Page + copied.HasNext = mtsr.HasNext + + return copied +} + +// Equals checks if the given MiiTubeSearchResult contains the same data as the current MiiTubeSearchResult +func (mtsr *MiiTubeSearchResult) Equals(o types.RVType) bool { + if _, ok := o.(*MiiTubeSearchResult); !ok { + return false + } + + other := o.(*MiiTubeSearchResult) + + if !mtsr.Result.Equals(other.Result) { + return false + } + + if !mtsr.Count.Equals(other.Count) { + return false + } + + if !mtsr.Page.Equals(other.Page) { + return false + } + + return mtsr.HasNext.Equals(other.HasNext) +} + +// String returns the string representation of the MiiTubeSearchResult +func (mtsr *MiiTubeSearchResult) String() string { + return mtsr.FormatToString(0) +} + +// FormatToString pretty-prints the MiiTubeSearchResult using the provided indentation level +func (mtsr *MiiTubeSearchResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MiiTubeSearchResult{\n") + b.WriteString(fmt.Sprintf("%sResult: %s,\n", indentationValues, mtsr.Result)) + b.WriteString(fmt.Sprintf("%sCount: %s,\n", indentationValues, mtsr.Count)) + b.WriteString(fmt.Sprintf("%sPage: %s,\n", indentationValues, mtsr.Page)) + b.WriteString(fmt.Sprintf("%sHasNext: %s,\n", indentationValues, mtsr.HasNext)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMiiTubeSearchResult returns a new MiiTubeSearchResult +func NewMiiTubeSearchResult() *MiiTubeSearchResult { + mtsr := &MiiTubeSearchResult{ + Result: types.NewList[*MiiTubeMiiInfo](), + Count: types.NewPrimitiveU32(0), + Page: types.NewPrimitiveU32(0), + HasNext: types.NewPrimitiveBool(false), + } + + mtsr.Result.Type = NewMiiTubeMiiInfo() + + return mtsr +} diff --git a/nex-protocols-go/datastore/nintendo-badge-arcade/get_meta_by_owner_id.go b/nex-protocols-go/datastore/nintendo-badge-arcade/get_meta_by_owner_id.go new file mode 100644 index 0000000..d1eb2e0 --- /dev/null +++ b/nex-protocols-go/datastore/nintendo-badge-arcade/get_meta_by_owner_id.go @@ -0,0 +1,47 @@ +// Package protocol implements the Nintendo Badge Arcade DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_nintendo_badge_arcade_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/nintendo-badge-arcade/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetMetaByOwnerID(packet nex.PacketInterface) { + if protocol.GetMetaByOwnerID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreBadgeArcade::GetMetaByOwnerID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_nintendo_badge_arcade_types.NewDataStoreGetMetaByOwnerIDParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetMetaByOwnerID(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetMetaByOwnerID(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/nintendo-badge-arcade/protocol.go b/nex-protocols-go/datastore/nintendo-badge-arcade/protocol.go new file mode 100644 index 0000000..1200a91 --- /dev/null +++ b/nex-protocols-go/datastore/nintendo-badge-arcade/protocol.go @@ -0,0 +1,67 @@ +// Package protocol implements the Nintendo Badge Arcade DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_nintendo_badge_arcade_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/nintendo-badge-arcade/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + "golang.org/x/exp/slices" +) + +const ( + // ProtocolID is the Protocol ID for the DataStore (Nintendo Badge Arcade) protocol. ID is the same as the DataStore protocol + ProtocolID = 0x73 + + // MethodGetMetaByOwnerID is the method ID for GetMetaByOwnerID + MethodGetMetaByOwnerID = 0x2D +) + +var patchedMethods = []uint32{ + MethodGetMetaByOwnerID, +} + +type dataStoreProtocol = datastore.Protocol + +// Protocol stores all the RMC method handlers for the DataStore (Nintendo Badge Arcade) protocol and listens for requests +// Embeds the DataStore protocol +type Protocol struct { + endpoint nex.EndpointInterface + dataStoreProtocol + GetMetaByOwnerID func(err error, packet nex.PacketInterface, callID uint32, param *datastore_nintendo_badge_arcade_types.DataStoreGetMetaByOwnerIDParam) (*nex.RMCMessage, *nex.Error) +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if !slices.Contains(patchedMethods, message.MethodID) { + protocol.dataStoreProtocol.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodGetMetaByOwnerID: + protocol.handleGetMetaByOwnerID(packet) + default: + errMessage := fmt.Sprintf("Unsupported DataStoreBadgeArcade method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new DataStore (Nintendo Badge Arcade) protocol +func NewProtocol(endpoint nex.EndpointInterface) *Protocol { + protocol := &Protocol{endpoint: endpoint} + protocol.dataStoreProtocol.SetEndpoint(endpoint) + + return protocol +} diff --git a/nex-protocols-go/datastore/nintendo-badge-arcade/types/datastore_get_meta_by_owner_id_param.go b/nex-protocols-go/datastore/nintendo-badge-arcade/types/datastore_get_meta_by_owner_id_param.go new file mode 100644 index 0000000..66d0d3f --- /dev/null +++ b/nex-protocols-go/datastore/nintendo-badge-arcade/types/datastore_get_meta_by_owner_id_param.go @@ -0,0 +1,143 @@ +// Package types implements all the types used by the DataStoreNintendoBadgeArcade protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreGetMetaByOwnerIDParam is a type within the DataStoreNintendoBadgeArcade protocol +type DataStoreGetMetaByOwnerIDParam struct { + types.Structure + OwnerIDs *types.List[*types.PID] + DataTypes *types.List[*types.PrimitiveU16] + ResultOption *types.PrimitiveU8 + ResultRange *types.ResultRange +} + +// WriteTo writes the DataStoreGetMetaByOwnerIDParam to the given writable +func (dsgmboidp *DataStoreGetMetaByOwnerIDParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsgmboidp.OwnerIDs.WriteTo(contentWritable) + dsgmboidp.DataTypes.WriteTo(contentWritable) + dsgmboidp.ResultOption.WriteTo(contentWritable) + dsgmboidp.ResultRange.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsgmboidp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreGetMetaByOwnerIDParam from the given readable +func (dsgmboidp *DataStoreGetMetaByOwnerIDParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsgmboidp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetMetaByOwnerIDParam header. %s", err.Error()) + } + + err = dsgmboidp.OwnerIDs.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetMetaByOwnerIDParam.OwnerIDs. %s", err.Error()) + } + + err = dsgmboidp.DataTypes.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetMetaByOwnerIDParam.DataTypes. %s", err.Error()) + } + + err = dsgmboidp.ResultOption.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetMetaByOwnerIDParam.ResultOption. %s", err.Error()) + } + + err = dsgmboidp.ResultRange.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetMetaByOwnerIDParam.ResultRange. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreGetMetaByOwnerIDParam +func (dsgmboidp *DataStoreGetMetaByOwnerIDParam) Copy() types.RVType { + copied := NewDataStoreGetMetaByOwnerIDParam() + + copied.StructureVersion = dsgmboidp.StructureVersion + copied.OwnerIDs = dsgmboidp.OwnerIDs.Copy().(*types.List[*types.PID]) + copied.DataTypes = dsgmboidp.DataTypes.Copy().(*types.List[*types.PrimitiveU16]) + copied.ResultOption = dsgmboidp.ResultOption.Copy().(*types.PrimitiveU8) + copied.ResultRange = dsgmboidp.ResultRange.Copy().(*types.ResultRange) + + return copied +} + +// Equals checks if the given DataStoreGetMetaByOwnerIDParam contains the same data as the current DataStoreGetMetaByOwnerIDParam +func (dsgmboidp *DataStoreGetMetaByOwnerIDParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreGetMetaByOwnerIDParam); !ok { + return false + } + + other := o.(*DataStoreGetMetaByOwnerIDParam) + + if dsgmboidp.StructureVersion != other.StructureVersion { + return false + } + + if !dsgmboidp.OwnerIDs.Equals(other.OwnerIDs) { + return false + } + + if !dsgmboidp.DataTypes.Equals(other.DataTypes) { + return false + } + + if !dsgmboidp.ResultOption.Equals(other.ResultOption) { + return false + } + + return dsgmboidp.ResultRange.Equals(other.ResultRange) +} + +// String returns the string representation of the DataStoreGetMetaByOwnerIDParam +func (dsgmboidp *DataStoreGetMetaByOwnerIDParam) String() string { + return dsgmboidp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreGetMetaByOwnerIDParam using the provided indentation level +func (dsgmboidp *DataStoreGetMetaByOwnerIDParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreGetMetaByOwnerIDParam{\n") + b.WriteString(fmt.Sprintf("%sOwnerIDs: %s,\n", indentationValues, dsgmboidp.OwnerIDs)) + b.WriteString(fmt.Sprintf("%sDataTypes: %s,\n", indentationValues, dsgmboidp.DataTypes)) + b.WriteString(fmt.Sprintf("%sResultOption: %s,\n", indentationValues, dsgmboidp.ResultOption)) + b.WriteString(fmt.Sprintf("%sResultRange: %s,\n", indentationValues, dsgmboidp.ResultRange.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreGetMetaByOwnerIDParam returns a new DataStoreGetMetaByOwnerIDParam +func NewDataStoreGetMetaByOwnerIDParam() *DataStoreGetMetaByOwnerIDParam { + dsgmboidp := &DataStoreGetMetaByOwnerIDParam{ + OwnerIDs: types.NewList[*types.PID](), + DataTypes: types.NewList[*types.PrimitiveU16](), + ResultOption: types.NewPrimitiveU8(0), + ResultRange: types.NewResultRange(), + } + + dsgmboidp.OwnerIDs.Type = types.NewPID(0) + dsgmboidp.DataTypes.Type = types.NewPrimitiveU16(0) + + return dsgmboidp +} diff --git a/nex-protocols-go/datastore/perpetuate_object.go b/nex-protocols-go/datastore/perpetuate_object.go new file mode 100644 index 0000000..96f9772 --- /dev/null +++ b/nex-protocols-go/datastore/perpetuate_object.go @@ -0,0 +1,71 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePerpetuateObject(packet nex.PacketInterface) { + if protocol.PerpetuateObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::PerpetuateObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + persistenceSlotID := types.NewPrimitiveU16(0) + dataID := types.NewPrimitiveU64(0) + deleteLastObject := types.NewPrimitiveBool(false) + + var err error + + err = persistenceSlotID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PerpetuateObject(fmt.Errorf("Failed to read persistenceSlotID from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = dataID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PerpetuateObject(fmt.Errorf("Failed to read dataID from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = deleteLastObject.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PerpetuateObject(fmt.Errorf("Failed to read deleteLastObject from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PerpetuateObject(nil, packet, callID, persistenceSlotID, dataID, deleteLastObject) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-bank/complete_post_bank_object.go b/nex-protocols-go/datastore/pokemon-bank/complete_post_bank_object.go new file mode 100644 index 0000000..bbe0035 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/complete_post_bank_object.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonBank protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCompletePostBankObject(packet nex.PacketInterface) { + if protocol.CompletePostBankObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonBank::CompletePostBankObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreCompletePostParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CompletePostBankObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CompletePostBankObject(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-bank/complete_update_bank_object.go b/nex-protocols-go/datastore/pokemon-bank/complete_update_bank_object.go new file mode 100644 index 0000000..5c8cf7d --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/complete_update_bank_object.go @@ -0,0 +1,72 @@ +// Package protocol implements the DataStorePokemonBank protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_pokemon_bank_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-bank/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCompleteUpdateBankObject(packet nex.PacketInterface) { + if protocol.CompleteUpdateBankObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonBank::CompleteUpdateBankObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + slotID := types.NewPrimitiveU16(0) + transactionParam := datastore_pokemon_bank_types.NewBankTransactionParam() + isForce := types.NewPrimitiveBool(false) + + var err error + + err = slotID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CompleteUpdateBankObject(fmt.Errorf("Failed to read slotID from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = transactionParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CompleteUpdateBankObject(fmt.Errorf("Failed to read transactionParam from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = isForce.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CompleteUpdateBankObject(fmt.Errorf("Failed to read isForce from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CompleteUpdateBankObject(nil, packet, callID, slotID, transactionParam, isForce) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-bank/delete_pokemon.go b/nex-protocols-go/datastore/pokemon-bank/delete_pokemon.go new file mode 100644 index 0000000..ebca264 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/delete_pokemon.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonBank protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_pokemon_bank_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-bank/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeletePokemon(packet nex.PacketInterface) { + if protocol.DeletePokemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonBank::DeletePokemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_pokemon_bank_types.NewGlobalTradeStationDeletePokemonParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeletePokemon(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeletePokemon(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-bank/download_my_pokemon.go b/nex-protocols-go/datastore/pokemon-bank/download_my_pokemon.go new file mode 100644 index 0000000..6739aed --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/download_my_pokemon.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonBank protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_pokemon_bank_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-bank/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDownloadMyPokemon(packet nex.PacketInterface) { + if protocol.DownloadMyPokemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonBank::DownloadMyPokemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_pokemon_bank_types.NewGlobalTradeStationDownloadMyPokemonParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DownloadMyPokemon(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DownloadMyPokemon(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-bank/download_other_pokemon.go b/nex-protocols-go/datastore/pokemon-bank/download_other_pokemon.go new file mode 100644 index 0000000..837a320 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/download_other_pokemon.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonBank protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_pokemon_bank_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-bank/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDownloadOtherPokemon(packet nex.PacketInterface) { + if protocol.DownloadOtherPokemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonBank::DownloadOtherPokemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_pokemon_bank_types.NewGlobalTradeStationDownloadOtherPokemonParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DownloadOtherPokemon(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DownloadOtherPokemon(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-bank/get_transaction_param.go b/nex-protocols-go/datastore/pokemon-bank/get_transaction_param.go new file mode 100644 index 0000000..dd31d30 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/get_transaction_param.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonBank protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetTransactionParam(packet nex.PacketInterface) { + if protocol.GetTransactionParam == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonBank::GetTransactionParam not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + slotID := types.NewPrimitiveU16(0) + + err := slotID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetTransactionParam(fmt.Errorf("Failed to read slotID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetTransactionParam(nil, packet, callID, slotID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-bank/get_unlock_key.go b/nex-protocols-go/datastore/pokemon-bank/get_unlock_key.go new file mode 100644 index 0000000..63b1a2c --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/get_unlock_key.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonBank protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetUnlockKey(packet nex.PacketInterface) { + if protocol.GetUnlockKey == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonBank::GetUnlockKey not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + challengeValue := types.NewPrimitiveU32(0) + + err := challengeValue.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetUnlockKey(fmt.Errorf("Failed to read challengeValue from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetUnlockKey(nil, packet, callID, challengeValue) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-bank/prepare_get_bank_object.go b/nex-protocols-go/datastore/pokemon-bank/prepare_get_bank_object.go new file mode 100644 index 0000000..f401c72 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/prepare_get_bank_object.go @@ -0,0 +1,60 @@ +// Package protocol implements the DataStorePokemonBank protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePrepareGetBankObject(packet nex.PacketInterface) { + if protocol.PrepareGetBankObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonBank::PrepareGetBankObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + slotID := types.NewPrimitiveU16(0) + applicationID := types.NewPrimitiveU16(0) + + var err error + + err = slotID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PrepareGetBankObject(fmt.Errorf("Failed to read slotID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = applicationID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PrepareGetBankObject(fmt.Errorf("Failed to read applicationID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PrepareGetBankObject(nil, packet, callID, slotID, applicationID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-bank/prepare_post_bank_object.go b/nex-protocols-go/datastore/pokemon-bank/prepare_post_bank_object.go new file mode 100644 index 0000000..58765b3 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/prepare_post_bank_object.go @@ -0,0 +1,60 @@ +// Package protocol implements the DataStorePokemonBank protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePreparePostBankObject(packet nex.PacketInterface) { + if protocol.PreparePostBankObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonBank::PreparePostBankObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + slotID := types.NewPrimitiveU16(0) + size := types.NewPrimitiveU32(0) + + var err error + + err = slotID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PreparePostBankObject(fmt.Errorf("Failed to read slotID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = size.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PreparePostBankObject(fmt.Errorf("Failed to read size from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PreparePostBankObject(nil, packet, callID, slotID, size) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-bank/prepare_trade_pokemon.go b/nex-protocols-go/datastore/pokemon-bank/prepare_trade_pokemon.go new file mode 100644 index 0000000..fc9add4 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/prepare_trade_pokemon.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonBank protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_pokemon_bank_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-bank/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePrepareTradePokemon(packet nex.PacketInterface) { + if protocol.PrepareTradePokemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonBank::PrepareTradePokemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_pokemon_bank_types.NewGlobalTradeStationPrepareTradePokemonParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PrepareTradePokemon(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PrepareTradePokemon(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-bank/prepare_update_bank_object.go b/nex-protocols-go/datastore/pokemon-bank/prepare_update_bank_object.go new file mode 100644 index 0000000..a5dc15d --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/prepare_update_bank_object.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonBank protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_pokemon_bank_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-bank/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePrepareUpdateBankObject(packet nex.PacketInterface) { + if protocol.PrepareUpdateBankObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonBank::PrepareUpdateBankObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + transactionParam := datastore_pokemon_bank_types.NewBankTransactionParam() + + err := transactionParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PrepareUpdateBankObject(fmt.Errorf("Failed to read transactionParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PrepareUpdateBankObject(nil, packet, callID, transactionParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-bank/prepare_upload_pokemon.go b/nex-protocols-go/datastore/pokemon-bank/prepare_upload_pokemon.go new file mode 100644 index 0000000..b8a1337 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/prepare_upload_pokemon.go @@ -0,0 +1,28 @@ +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePrepareUploadPokemon(packet nex.PacketInterface) { + if protocol.PrepareUploadPokemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonBank::PrepareUploadPokemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.PrepareUploadPokemon(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-bank/protocol.go b/nex-protocols-go/datastore/pokemon-bank/protocol.go new file mode 100644 index 0000000..40dcddc --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/protocol.go @@ -0,0 +1,181 @@ +// Package protocol implements the DataStorePokemonBank protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_pokemon_bank_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-bank/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + "golang.org/x/exp/slices" +) + +const ( + // ProtocolID is the Protocol ID for the DataStore (Pokemon Bank) protocol + ProtocolID = 0x73 + + // MethodPrepareUploadPokemon is the method ID for the PrepareUploadPokemon method + MethodPrepareUploadPokemon = 0x28 + + // MethodUploadPokemon is the method ID for the UploadPokemon method + MethodUploadPokemon = 0x29 + + // MethodSearchPokemon is the method ID for the SearchPokemon method + MethodSearchPokemon = 0x2A + + // MethodPrepareTradePokemon is the method ID for the PrepareTradePokemon method + MethodPrepareTradePokemon = 0x2B + + // MethodTradePokemon is the method ID for the TradePokemon method + MethodTradePokemon = 0x2C + + // MethodDownloadOtherPokemon is the method ID for the DownloadOtherPokemon method + MethodDownloadOtherPokemon = 0x2D + + // MethodDownloadMyPokemon is the method ID for the DownloadMyPokemon method + MethodDownloadMyPokemon = 0x2E + + // MethodDeletePokemon is the method ID for the DeletePokemon method + MethodDeletePokemon = 0x2F + + // MethodGetTransactionParam is the method ID for the GetTransactionParam method + MethodGetTransactionParam = 0x30 + + // MethodPreparePostBankObject is the method ID for the PreparePostBankObject method + MethodPreparePostBankObject = 0x31 + + // MethodCompletePostBankObject is the method ID for the CompletePostBankObject method + MethodCompletePostBankObject = 0x32 + + // MethodPrepareGetBankObject is the method ID for the PrepareGetBankObject method + MethodPrepareGetBankObject = 0x33 + + // MethodPrepareUpdateBankObject is the method ID for the PrepareUpdateBankObject method + MethodPrepareUpdateBankObject = 0x34 + + // MethodCompleteUpdateBankObject is the method ID for the CompleteUpdateBankObject method + MethodCompleteUpdateBankObject = 0x35 + + // MethodRollbackBankObject is the method ID for the RollbackBankObject method + MethodRollbackBankObject = 0x36 + + // MethodGetUnlockKey is the method ID for the GetUnlockKey method + MethodGetUnlockKey = 0x37 + + // MethodRequestMigration is the method ID for the RequestMigration method + MethodRequestMigration = 0x38 +) + +var patchedMethods = []uint32{ + MethodPrepareUploadPokemon, + MethodUploadPokemon, + MethodSearchPokemon, + MethodPrepareTradePokemon, + MethodTradePokemon, + MethodDownloadOtherPokemon, + MethodDownloadMyPokemon, + MethodDeletePokemon, + MethodGetTransactionParam, + MethodPreparePostBankObject, + MethodCompletePostBankObject, + MethodPrepareGetBankObject, + MethodPrepareUpdateBankObject, + MethodCompleteUpdateBankObject, + MethodRollbackBankObject, + MethodGetUnlockKey, + MethodRequestMigration, +} + +type dataStoreProtocol = datastore.Protocol + +// Protocol stores all the RMC method handlers for the DataStore (Pokemon Bank) protocol and listens for requests +// Embeds the DataStore protocol +type Protocol struct { + endpoint nex.EndpointInterface + dataStoreProtocol + PrepareUploadPokemon func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + UploadPokemon func(err error, packet nex.PacketInterface, callID uint32, param *datastore_pokemon_bank_types.GlobalTradeStationUploadPokemonParam) (*nex.RMCMessage, *nex.Error) + SearchPokemon func(err error, packet nex.PacketInterface, callID uint32, param *datastore_pokemon_bank_types.GlobalTradeStationSearchPokemonParam) (*nex.RMCMessage, *nex.Error) + PrepareTradePokemon func(err error, packet nex.PacketInterface, callID uint32, param *datastore_pokemon_bank_types.GlobalTradeStationPrepareTradePokemonParam) (*nex.RMCMessage, *nex.Error) + TradePokemon func(err error, packet nex.PacketInterface, callID uint32, param *datastore_pokemon_bank_types.GlobalTradeStationTradePokemonParam) (*nex.RMCMessage, *nex.Error) + DownloadOtherPokemon func(err error, packet nex.PacketInterface, callID uint32, param *datastore_pokemon_bank_types.GlobalTradeStationDownloadOtherPokemonParam) (*nex.RMCMessage, *nex.Error) + DownloadMyPokemon func(err error, packet nex.PacketInterface, callID uint32, param *datastore_pokemon_bank_types.GlobalTradeStationDownloadMyPokemonParam) (*nex.RMCMessage, *nex.Error) + DeletePokemon func(err error, packet nex.PacketInterface, callID uint32, param *datastore_pokemon_bank_types.GlobalTradeStationDeletePokemonParam) (*nex.RMCMessage, *nex.Error) + GetTransactionParam func(err error, packet nex.PacketInterface, callID uint32, slotID *types.PrimitiveU16) (*nex.RMCMessage, *nex.Error) + PreparePostBankObject func(err error, packet nex.PacketInterface, callID uint32, slotID *types.PrimitiveU16, size *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + CompletePostBankObject func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreCompletePostParam) (*nex.RMCMessage, *nex.Error) + PrepareGetBankObject func(err error, packet nex.PacketInterface, callID uint32, slotID *types.PrimitiveU16, applicationID *types.PrimitiveU16) (*nex.RMCMessage, *nex.Error) + PrepareUpdateBankObject func(err error, packet nex.PacketInterface, callID uint32, transactionParam *datastore_pokemon_bank_types.BankTransactionParam) (*nex.RMCMessage, *nex.Error) + CompleteUpdateBankObject func(err error, packet nex.PacketInterface, callID uint32, slotID *types.PrimitiveU16, transactionParam *datastore_pokemon_bank_types.BankTransactionParam, isForce *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + RollbackBankObject func(err error, packet nex.PacketInterface, callID uint32, slotID *types.PrimitiveU16, transactionParam *datastore_pokemon_bank_types.BankTransactionParam, isForce *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + GetUnlockKey func(err error, packet nex.PacketInterface, callID uint32, challengeValue *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + RequestMigration func(err error, packet nex.PacketInterface, callID uint32, oneTimePassword *types.String, boxes *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error) +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if !slices.Contains(patchedMethods, message.MethodID) { + protocol.dataStoreProtocol.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodPrepareUploadPokemon: + protocol.handlePrepareUploadPokemon(packet) + case MethodUploadPokemon: + protocol.handleUploadPokemon(packet) + case MethodSearchPokemon: + protocol.handleSearchPokemon(packet) + case MethodPrepareTradePokemon: + protocol.handlePrepareTradePokemon(packet) + case MethodTradePokemon: + protocol.handleTradePokemon(packet) + case MethodDownloadOtherPokemon: + protocol.handleDownloadOtherPokemon(packet) + case MethodDownloadMyPokemon: + protocol.handleDownloadMyPokemon(packet) + case MethodDeletePokemon: + protocol.handleDeletePokemon(packet) + case MethodGetTransactionParam: + protocol.handleGetTransactionParam(packet) + case MethodPreparePostBankObject: + protocol.handlePreparePostBankObject(packet) + case MethodCompletePostBankObject: + protocol.handleCompletePostBankObject(packet) + case MethodPrepareGetBankObject: + protocol.handlePrepareGetBankObject(packet) + case MethodPrepareUpdateBankObject: + protocol.handlePrepareUpdateBankObject(packet) + case MethodCompleteUpdateBankObject: + protocol.handleCompleteUpdateBankObject(packet) + case MethodRollbackBankObject: + protocol.handleRollbackBankObject(packet) + case MethodGetUnlockKey: + protocol.handleGetUnlockKey(packet) + case MethodRequestMigration: + protocol.handleRequestMigration(packet) + default: + errMessage := fmt.Sprintf("Unsupported DataStore (Pokemon Bank) method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new DataStorePokemonBank protocol +func NewProtocol(endpoint nex.EndpointInterface) *Protocol { + protocol := &Protocol{endpoint: endpoint} + protocol.dataStoreProtocol.SetEndpoint(endpoint) + + return protocol +} diff --git a/nex-protocols-go/datastore/pokemon-bank/request_migration.go b/nex-protocols-go/datastore/pokemon-bank/request_migration.go new file mode 100644 index 0000000..3935aa9 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/request_migration.go @@ -0,0 +1,61 @@ +// Package protocol implements the DataStorePokemonBank protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRequestMigration(packet nex.PacketInterface) { + if protocol.RequestMigration == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonBank::RequestMigration not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + oneTimePassword := types.NewString("") + boxes := types.NewList[*types.PrimitiveU32]() + boxes.Type = types.NewPrimitiveU32(0) + + var err error + + err = oneTimePassword.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RequestMigration(fmt.Errorf("Failed to read oneTimePassword from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = boxes.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RequestMigration(fmt.Errorf("Failed to read boxes from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RequestMigration(nil, packet, callID, oneTimePassword, boxes) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-bank/rollback_bank_object.go b/nex-protocols-go/datastore/pokemon-bank/rollback_bank_object.go new file mode 100644 index 0000000..59ec120 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/rollback_bank_object.go @@ -0,0 +1,72 @@ +// Package protocol implements the DataStorePokemonBank protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_pokemon_bank_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-bank/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRollbackBankObject(packet nex.PacketInterface) { + if protocol.RollbackBankObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonBank::RollbackBankObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + slotID := types.NewPrimitiveU16(0) + transactionParam := datastore_pokemon_bank_types.NewBankTransactionParam() + isForce := types.NewPrimitiveBool(false) + + var err error + + err = slotID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RollbackBankObject(fmt.Errorf("Failed to read slotID from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = transactionParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RollbackBankObject(fmt.Errorf("Failed to read transactionParam from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = isForce.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RollbackBankObject(fmt.Errorf("Failed to read isForce from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RollbackBankObject(nil, packet, callID, slotID, transactionParam, isForce) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-bank/search_pokemon.go b/nex-protocols-go/datastore/pokemon-bank/search_pokemon.go new file mode 100644 index 0000000..5168846 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/search_pokemon.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonBank protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_pokemon_bank_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-bank/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSearchPokemon(packet nex.PacketInterface) { + if protocol.SearchPokemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonBank::SearchPokemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_pokemon_bank_types.NewGlobalTradeStationSearchPokemonParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SearchPokemon(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SearchPokemon(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-bank/trade_pokemon.go b/nex-protocols-go/datastore/pokemon-bank/trade_pokemon.go new file mode 100644 index 0000000..4213540 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/trade_pokemon.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonBank protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_pokemon_bank_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-bank/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleTradePokemon(packet nex.PacketInterface) { + if protocol.TradePokemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonBank::TradePokemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_pokemon_bank_types.NewGlobalTradeStationTradePokemonParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.TradePokemon(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.TradePokemon(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-bank/types/bank_migration_info.go b/nex-protocols-go/datastore/pokemon-bank/types/bank_migration_info.go new file mode 100644 index 0000000..bec756e --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/types/bank_migration_info.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// BankMigrationInfo is a type within the DataStore protocol +type BankMigrationInfo struct { + types.Structure + MigrationStatus *types.PrimitiveU32 + UpdatedTime *types.DateTime +} + +// WriteTo writes the BankMigrationInfo to the given writable +func (bmi *BankMigrationInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + bmi.MigrationStatus.WriteTo(contentWritable) + bmi.UpdatedTime.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + bmi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the BankMigrationInfo from the given readable +func (bmi *BankMigrationInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = bmi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BankMigrationInfo header. %s", err.Error()) + } + + err = bmi.MigrationStatus.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BankMigrationInfo.MigrationStatus. %s", err.Error()) + } + + err = bmi.UpdatedTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BankMigrationInfo.UpdatedTime. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of BankMigrationInfo +func (bmi *BankMigrationInfo) Copy() types.RVType { + copied := NewBankMigrationInfo() + + copied.StructureVersion = bmi.StructureVersion + copied.MigrationStatus = bmi.MigrationStatus.Copy().(*types.PrimitiveU32) + copied.UpdatedTime = bmi.UpdatedTime.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given BankMigrationInfo contains the same data as the current BankMigrationInfo +func (bmi *BankMigrationInfo) Equals(o types.RVType) bool { + if _, ok := o.(*BankMigrationInfo); !ok { + return false + } + + other := o.(*BankMigrationInfo) + + if bmi.StructureVersion != other.StructureVersion { + return false + } + + if !bmi.MigrationStatus.Equals(other.MigrationStatus) { + return false + } + + return bmi.UpdatedTime.Equals(other.UpdatedTime) +} + +// String returns the string representation of the BankMigrationInfo +func (bmi *BankMigrationInfo) String() string { + return bmi.FormatToString(0) +} + +// FormatToString pretty-prints the BankMigrationInfo using the provided indentation level +func (bmi *BankMigrationInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("BankMigrationInfo{\n") + b.WriteString(fmt.Sprintf("%sMigrationStatus: %s,\n", indentationValues, bmi.MigrationStatus)) + b.WriteString(fmt.Sprintf("%sUpdatedTime: %s,\n", indentationValues, bmi.UpdatedTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewBankMigrationInfo returns a new BankMigrationInfo +func NewBankMigrationInfo() *BankMigrationInfo { + bmi := &BankMigrationInfo{ + MigrationStatus: types.NewPrimitiveU32(0), + UpdatedTime: types.NewDateTime(0), + } + + return bmi +} diff --git a/nex-protocols-go/datastore/pokemon-bank/types/bank_transaction_param.go b/nex-protocols-go/datastore/pokemon-bank/types/bank_transaction_param.go new file mode 100644 index 0000000..04872ee --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/types/bank_transaction_param.go @@ -0,0 +1,154 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// BankTransactionParam is a type within the DataStore protocol +type BankTransactionParam struct { + types.Structure + DataID *types.PrimitiveU64 + CurVersion *types.PrimitiveU32 + UpdateVersion *types.PrimitiveU32 + Size *types.PrimitiveU32 + TransactionPassword *types.PrimitiveU64 +} + +// WriteTo writes the BankTransactionParam to the given writable +func (btp *BankTransactionParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + btp.DataID.WriteTo(contentWritable) + btp.CurVersion.WriteTo(contentWritable) + btp.UpdateVersion.WriteTo(contentWritable) + btp.Size.WriteTo(contentWritable) + btp.TransactionPassword.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + btp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the BankTransactionParam from the given readable +func (btp *BankTransactionParam) ExtractFrom(readable types.Readable) error { + var err error + + err = btp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BankTransactionParam header. %s", err.Error()) + } + + err = btp.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BankTransactionParam.DataID. %s", err.Error()) + } + + err = btp.CurVersion.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BankTransactionParam.CurVersion. %s", err.Error()) + } + + err = btp.UpdateVersion.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BankTransactionParam.UpdateVersion. %s", err.Error()) + } + + err = btp.Size.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BankTransactionParam.Size. %s", err.Error()) + } + + err = btp.TransactionPassword.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BankTransactionParam.TransactionPassword. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of BankTransactionParam +func (btp *BankTransactionParam) Copy() types.RVType { + copied := NewBankTransactionParam() + + copied.StructureVersion = btp.StructureVersion + copied.DataID = btp.DataID.Copy().(*types.PrimitiveU64) + copied.CurVersion = btp.CurVersion.Copy().(*types.PrimitiveU32) + copied.UpdateVersion = btp.UpdateVersion.Copy().(*types.PrimitiveU32) + copied.Size = btp.Size.Copy().(*types.PrimitiveU32) + copied.TransactionPassword = btp.TransactionPassword.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given BankTransactionParam contains the same data as the current BankTransactionParam +func (btp *BankTransactionParam) Equals(o types.RVType) bool { + if _, ok := o.(*BankTransactionParam); !ok { + return false + } + + other := o.(*BankTransactionParam) + + if btp.StructureVersion != other.StructureVersion { + return false + } + + if !btp.DataID.Equals(other.DataID) { + return false + } + + if !btp.CurVersion.Equals(other.CurVersion) { + return false + } + + if !btp.UpdateVersion.Equals(other.UpdateVersion) { + return false + } + + if !btp.Size.Equals(other.Size) { + return false + } + + return btp.TransactionPassword.Equals(other.TransactionPassword) +} + +// String returns the string representation of the BankTransactionParam +func (btp *BankTransactionParam) String() string { + return btp.FormatToString(0) +} + +// FormatToString pretty-prints the BankTransactionParam using the provided indentation level +func (btp *BankTransactionParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("BankTransactionParam{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, btp.DataID)) + b.WriteString(fmt.Sprintf("%sCurVersion: %s,\n", indentationValues, btp.CurVersion)) + b.WriteString(fmt.Sprintf("%sUpdateVersion: %s,\n", indentationValues, btp.UpdateVersion)) + b.WriteString(fmt.Sprintf("%sSize: %s,\n", indentationValues, btp.Size)) + b.WriteString(fmt.Sprintf("%sTransactionPassword: %s,\n", indentationValues, btp.TransactionPassword)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewBankTransactionParam returns a new BankTransactionParam +func NewBankTransactionParam() *BankTransactionParam { + btp := &BankTransactionParam{ + DataID: types.NewPrimitiveU64(0), + CurVersion: types.NewPrimitiveU32(0), + UpdateVersion: types.NewPrimitiveU32(0), + Size: types.NewPrimitiveU32(0), + TransactionPassword: types.NewPrimitiveU64(0), + } + + return btp +} diff --git a/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_data.go b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_data.go new file mode 100644 index 0000000..53f0308 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_data.go @@ -0,0 +1,154 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationData is a type within the DataStore protocol +type GlobalTradeStationData struct { + types.Structure + DataID *types.PrimitiveU64 + OwnerID *types.PID + UpdatedTime *types.DateTime + IndexData *types.QBuffer + Version *types.PrimitiveU32 +} + +// WriteTo writes the GlobalTradeStationData to the given writable +func (gtsd *GlobalTradeStationData) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsd.DataID.WriteTo(contentWritable) + gtsd.OwnerID.WriteTo(contentWritable) + gtsd.UpdatedTime.WriteTo(contentWritable) + gtsd.IndexData.WriteTo(contentWritable) + gtsd.Version.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsd.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationData from the given readable +func (gtsd *GlobalTradeStationData) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsd.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationData header. %s", err.Error()) + } + + err = gtsd.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationData.DataID. %s", err.Error()) + } + + err = gtsd.OwnerID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationData.OwnerID. %s", err.Error()) + } + + err = gtsd.UpdatedTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationData.UpdatedTime. %s", err.Error()) + } + + err = gtsd.IndexData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationData.IndexData. %s", err.Error()) + } + + err = gtsd.Version.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationData.Version. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationData +func (gtsd *GlobalTradeStationData) Copy() types.RVType { + copied := NewGlobalTradeStationData() + + copied.StructureVersion = gtsd.StructureVersion + copied.DataID = gtsd.DataID.Copy().(*types.PrimitiveU64) + copied.OwnerID = gtsd.OwnerID.Copy().(*types.PID) + copied.UpdatedTime = gtsd.UpdatedTime.Copy().(*types.DateTime) + copied.IndexData = gtsd.IndexData.Copy().(*types.QBuffer) + copied.Version = gtsd.Version.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given GlobalTradeStationData contains the same data as the current GlobalTradeStationData +func (gtsd *GlobalTradeStationData) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationData); !ok { + return false + } + + other := o.(*GlobalTradeStationData) + + if gtsd.StructureVersion != other.StructureVersion { + return false + } + + if !gtsd.DataID.Equals(other.DataID) { + return false + } + + if !gtsd.OwnerID.Equals(other.OwnerID) { + return false + } + + if !gtsd.UpdatedTime.Equals(other.UpdatedTime) { + return false + } + + if !gtsd.IndexData.Equals(other.IndexData) { + return false + } + + return gtsd.Version.Equals(other.Version) +} + +// String returns the string representation of the GlobalTradeStationData +func (gtsd *GlobalTradeStationData) String() string { + return gtsd.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationData using the provided indentation level +func (gtsd *GlobalTradeStationData) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationData{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, gtsd.DataID)) + b.WriteString(fmt.Sprintf("%sOwnerID: %s,\n", indentationValues, gtsd.OwnerID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUpdatedTime: %s,\n", indentationValues, gtsd.UpdatedTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sIndexData: %s,\n", indentationValues, gtsd.IndexData)) + b.WriteString(fmt.Sprintf("%sVersion: %s,\n", indentationValues, gtsd.Version)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationData returns a new GlobalTradeStationData +func NewGlobalTradeStationData() *GlobalTradeStationData { + gtsd := &GlobalTradeStationData{ + DataID: types.NewPrimitiveU64(0), + OwnerID: types.NewPID(0), + UpdatedTime: types.NewDateTime(0), + IndexData: types.NewQBuffer(nil), + Version: types.NewPrimitiveU32(0), + } + + return gtsd +} diff --git a/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_delete_pokemon_param.go b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_delete_pokemon_param.go new file mode 100644 index 0000000..3ac6555 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_delete_pokemon_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationDeletePokemonParam is a type within the DataStore protocol +type GlobalTradeStationDeletePokemonParam struct { + types.Structure + PrepareUploadKey *GlobalTradeStationRecordKey + DeleteFlag *types.PrimitiveU8 +} + +// WriteTo writes the GlobalTradeStationDeletePokemonParam to the given writable +func (gtsdpp *GlobalTradeStationDeletePokemonParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsdpp.PrepareUploadKey.WriteTo(contentWritable) + gtsdpp.DeleteFlag.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsdpp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationDeletePokemonParam from the given readable +func (gtsdpp *GlobalTradeStationDeletePokemonParam) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsdpp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDeletePokemonParam header. %s", err.Error()) + } + + err = gtsdpp.PrepareUploadKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDeletePokemonParam.PrepareUploadKey. %s", err.Error()) + } + + err = gtsdpp.DeleteFlag.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDeletePokemonParam.DeleteFlag. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationDeletePokemonParam +func (gtsdpp *GlobalTradeStationDeletePokemonParam) Copy() types.RVType { + copied := NewGlobalTradeStationDeletePokemonParam() + + copied.StructureVersion = gtsdpp.StructureVersion + copied.PrepareUploadKey = gtsdpp.PrepareUploadKey.Copy().(*GlobalTradeStationRecordKey) + copied.DeleteFlag = gtsdpp.DeleteFlag.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given GlobalTradeStationDeletePokemonParam contains the same data as the current GlobalTradeStationDeletePokemonParam +func (gtsdpp *GlobalTradeStationDeletePokemonParam) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationDeletePokemonParam); !ok { + return false + } + + other := o.(*GlobalTradeStationDeletePokemonParam) + + if gtsdpp.StructureVersion != other.StructureVersion { + return false + } + + if !gtsdpp.PrepareUploadKey.Equals(other.PrepareUploadKey) { + return false + } + + return gtsdpp.DeleteFlag.Equals(other.DeleteFlag) +} + +// String returns the string representation of the GlobalTradeStationDeletePokemonParam +func (gtsdpp *GlobalTradeStationDeletePokemonParam) String() string { + return gtsdpp.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationDeletePokemonParam using the provided indentation level +func (gtsdpp *GlobalTradeStationDeletePokemonParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationDeletePokemonParam{\n") + b.WriteString(fmt.Sprintf("%sPrepareUploadKey: %s,\n", indentationValues, gtsdpp.PrepareUploadKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sDeleteFlag: %s,\n", indentationValues, gtsdpp.DeleteFlag)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationDeletePokemonParam returns a new GlobalTradeStationDeletePokemonParam +func NewGlobalTradeStationDeletePokemonParam() *GlobalTradeStationDeletePokemonParam { + gtsdpp := &GlobalTradeStationDeletePokemonParam{ + PrepareUploadKey: NewGlobalTradeStationRecordKey(), + DeleteFlag: types.NewPrimitiveU8(0), + } + + return gtsdpp +} diff --git a/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_download_my_pokemon_param.go b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_download_my_pokemon_param.go new file mode 100644 index 0000000..8045ccf --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_download_my_pokemon_param.go @@ -0,0 +1,98 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationDownloadMyPokemonParam is a type within the DataStore protocol +type GlobalTradeStationDownloadMyPokemonParam struct { + types.Structure + PrepareUploadKey *GlobalTradeStationRecordKey +} + +// WriteTo writes the GlobalTradeStationDownloadMyPokemonParam to the given writable +func (gtsdmpp *GlobalTradeStationDownloadMyPokemonParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsdmpp.PrepareUploadKey.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsdmpp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationDownloadMyPokemonParam from the given readable +func (gtsdmpp *GlobalTradeStationDownloadMyPokemonParam) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsdmpp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadMyPokemonParam header. %s", err.Error()) + } + + err = gtsdmpp.PrepareUploadKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadMyPokemonParam.PrepareUploadKey. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationDownloadMyPokemonParam +func (gtsdmpp *GlobalTradeStationDownloadMyPokemonParam) Copy() types.RVType { + copied := NewGlobalTradeStationDownloadMyPokemonParam() + + copied.StructureVersion = gtsdmpp.StructureVersion + copied.PrepareUploadKey = gtsdmpp.PrepareUploadKey.Copy().(*GlobalTradeStationRecordKey) + + return copied +} + +// Equals checks if the given GlobalTradeStationDownloadMyPokemonParam contains the same data as the current GlobalTradeStationDownloadMyPokemonParam +func (gtsdmpp *GlobalTradeStationDownloadMyPokemonParam) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationDownloadMyPokemonParam); !ok { + return false + } + + other := o.(*GlobalTradeStationDownloadMyPokemonParam) + + if gtsdmpp.StructureVersion != other.StructureVersion { + return false + } + + return gtsdmpp.PrepareUploadKey.Equals(other.PrepareUploadKey) +} + +// String returns the string representation of the GlobalTradeStationDownloadMyPokemonParam +func (gtsdmpp *GlobalTradeStationDownloadMyPokemonParam) String() string { + return gtsdmpp.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationDownloadMyPokemonParam using the provided indentation level +func (gtsdmpp *GlobalTradeStationDownloadMyPokemonParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationDownloadMyPokemonParam{\n") + b.WriteString(fmt.Sprintf("%sPrepareUploadKey: %s,\n", indentationValues, gtsdmpp.PrepareUploadKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationDownloadMyPokemonParam returns a new GlobalTradeStationDownloadMyPokemonParam +func NewGlobalTradeStationDownloadMyPokemonParam() *GlobalTradeStationDownloadMyPokemonParam { + gtsdmpp := &GlobalTradeStationDownloadMyPokemonParam{ + PrepareUploadKey: NewGlobalTradeStationRecordKey(), + } + + return gtsdmpp +} diff --git a/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_download_my_pokemon_result.go b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_download_my_pokemon_result.go new file mode 100644 index 0000000..d878775 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_download_my_pokemon_result.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationDownloadMyPokemonResult is a type within the DataStore protocol +type GlobalTradeStationDownloadMyPokemonResult struct { + types.Structure + Result *GlobalTradeStationDownloadPokemonResult + IsTraded *types.PrimitiveBool +} + +// WriteTo writes the GlobalTradeStationDownloadMyPokemonResult to the given writable +func (gtsdmpr *GlobalTradeStationDownloadMyPokemonResult) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsdmpr.Result.WriteTo(contentWritable) + gtsdmpr.IsTraded.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsdmpr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationDownloadMyPokemonResult from the given readable +func (gtsdmpr *GlobalTradeStationDownloadMyPokemonResult) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsdmpr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadMyPokemonResult header. %s", err.Error()) + } + + err = gtsdmpr.Result.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadMyPokemonResult.Result. %s", err.Error()) + } + + err = gtsdmpr.IsTraded.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadMyPokemonResult.IsTraded. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationDownloadMyPokemonResult +func (gtsdmpr *GlobalTradeStationDownloadMyPokemonResult) Copy() types.RVType { + copied := NewGlobalTradeStationDownloadMyPokemonResult() + + copied.StructureVersion = gtsdmpr.StructureVersion + copied.Result = gtsdmpr.Result.Copy().(*GlobalTradeStationDownloadPokemonResult) + copied.IsTraded = gtsdmpr.IsTraded.Copy().(*types.PrimitiveBool) + + return copied +} + +// Equals checks if the given GlobalTradeStationDownloadMyPokemonResult contains the same data as the current GlobalTradeStationDownloadMyPokemonResult +func (gtsdmpr *GlobalTradeStationDownloadMyPokemonResult) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationDownloadMyPokemonResult); !ok { + return false + } + + other := o.(*GlobalTradeStationDownloadMyPokemonResult) + + if gtsdmpr.StructureVersion != other.StructureVersion { + return false + } + + if !gtsdmpr.Result.Equals(other.Result) { + return false + } + + return gtsdmpr.IsTraded.Equals(other.IsTraded) +} + +// String returns the string representation of the GlobalTradeStationDownloadMyPokemonResult +func (gtsdmpr *GlobalTradeStationDownloadMyPokemonResult) String() string { + return gtsdmpr.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationDownloadMyPokemonResult using the provided indentation level +func (gtsdmpr *GlobalTradeStationDownloadMyPokemonResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationDownloadMyPokemonResult{\n") + b.WriteString(fmt.Sprintf("%sResult: %s,\n", indentationValues, gtsdmpr.Result.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sIsTraded: %s,\n", indentationValues, gtsdmpr.IsTraded)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationDownloadMyPokemonResult returns a new GlobalTradeStationDownloadMyPokemonResult +func NewGlobalTradeStationDownloadMyPokemonResult() *GlobalTradeStationDownloadMyPokemonResult { + gtsdmpr := &GlobalTradeStationDownloadMyPokemonResult{ + Result: NewGlobalTradeStationDownloadPokemonResult(), + IsTraded: types.NewPrimitiveBool(false), + } + + return gtsdmpr +} diff --git a/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_download_other_pokemon_param.go b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_download_other_pokemon_param.go new file mode 100644 index 0000000..9adc566 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_download_other_pokemon_param.go @@ -0,0 +1,98 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationDownloadOtherPokemonParam is a type within the DataStore protocol +type GlobalTradeStationDownloadOtherPokemonParam struct { + types.Structure + PrepareUploadKey *GlobalTradeStationRecordKey +} + +// WriteTo writes the GlobalTradeStationDownloadOtherPokemonParam to the given writable +func (gtsdopp *GlobalTradeStationDownloadOtherPokemonParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsdopp.PrepareUploadKey.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsdopp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationDownloadOtherPokemonParam from the given readable +func (gtsdopp *GlobalTradeStationDownloadOtherPokemonParam) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsdopp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadOtherPokemonParam header. %s", err.Error()) + } + + err = gtsdopp.PrepareUploadKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadOtherPokemonParam.PrepareUploadKey. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationDownloadOtherPokemonParam +func (gtsdopp *GlobalTradeStationDownloadOtherPokemonParam) Copy() types.RVType { + copied := NewGlobalTradeStationDownloadOtherPokemonParam() + + copied.StructureVersion = gtsdopp.StructureVersion + copied.PrepareUploadKey = gtsdopp.PrepareUploadKey.Copy().(*GlobalTradeStationRecordKey) + + return copied +} + +// Equals checks if the given GlobalTradeStationDownloadOtherPokemonParam contains the same data as the current GlobalTradeStationDownloadOtherPokemonParam +func (gtsdopp *GlobalTradeStationDownloadOtherPokemonParam) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationDownloadOtherPokemonParam); !ok { + return false + } + + other := o.(*GlobalTradeStationDownloadOtherPokemonParam) + + if gtsdopp.StructureVersion != other.StructureVersion { + return false + } + + return gtsdopp.PrepareUploadKey.Equals(other.PrepareUploadKey) +} + +// String returns the string representation of the GlobalTradeStationDownloadOtherPokemonParam +func (gtsdopp *GlobalTradeStationDownloadOtherPokemonParam) String() string { + return gtsdopp.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationDownloadOtherPokemonParam using the provided indentation level +func (gtsdopp *GlobalTradeStationDownloadOtherPokemonParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationDownloadOtherPokemonParam{\n") + b.WriteString(fmt.Sprintf("%sPrepareUploadKey: %s,\n", indentationValues, gtsdopp.PrepareUploadKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationDownloadOtherPokemonParam returns a new GlobalTradeStationDownloadOtherPokemonParam +func NewGlobalTradeStationDownloadOtherPokemonParam() *GlobalTradeStationDownloadOtherPokemonParam { + gtsdopp := &GlobalTradeStationDownloadOtherPokemonParam{ + PrepareUploadKey: NewGlobalTradeStationRecordKey(), + } + + return gtsdopp +} diff --git a/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_download_pokemon_result.go b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_download_pokemon_result.go new file mode 100644 index 0000000..e7ecec6 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_download_pokemon_result.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationDownloadPokemonResult is a type within the DataStore protocol +type GlobalTradeStationDownloadPokemonResult struct { + types.Structure + DataID *types.PrimitiveU64 + IndexData *types.QBuffer + PokemonData *types.QBuffer +} + +// WriteTo writes the GlobalTradeStationDownloadPokemonResult to the given writable +func (gtsdpr *GlobalTradeStationDownloadPokemonResult) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsdpr.DataID.WriteTo(contentWritable) + gtsdpr.IndexData.WriteTo(contentWritable) + gtsdpr.PokemonData.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsdpr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationDownloadPokemonResult from the given readable +func (gtsdpr *GlobalTradeStationDownloadPokemonResult) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsdpr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadPokemonResult header. %s", err.Error()) + } + + err = gtsdpr.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadPokemonResult.DataID. %s", err.Error()) + } + + err = gtsdpr.IndexData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadPokemonResult.IndexData. %s", err.Error()) + } + + err = gtsdpr.PokemonData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadPokemonResult.PokemonData. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationDownloadPokemonResult +func (gtsdpr *GlobalTradeStationDownloadPokemonResult) Copy() types.RVType { + copied := NewGlobalTradeStationDownloadPokemonResult() + + copied.StructureVersion = gtsdpr.StructureVersion + copied.DataID = gtsdpr.DataID.Copy().(*types.PrimitiveU64) + copied.IndexData = gtsdpr.IndexData.Copy().(*types.QBuffer) + copied.PokemonData = gtsdpr.PokemonData.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given GlobalTradeStationDownloadPokemonResult contains the same data as the current GlobalTradeStationDownloadPokemonResult +func (gtsdpr *GlobalTradeStationDownloadPokemonResult) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationDownloadPokemonResult); !ok { + return false + } + + other := o.(*GlobalTradeStationDownloadPokemonResult) + + if gtsdpr.StructureVersion != other.StructureVersion { + return false + } + + if !gtsdpr.DataID.Equals(other.DataID) { + return false + } + + if !gtsdpr.IndexData.Equals(other.IndexData) { + return false + } + + return gtsdpr.PokemonData.Equals(other.PokemonData) +} + +// String returns the string representation of the GlobalTradeStationDownloadPokemonResult +func (gtsdpr *GlobalTradeStationDownloadPokemonResult) String() string { + return gtsdpr.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationDownloadPokemonResult using the provided indentation level +func (gtsdpr *GlobalTradeStationDownloadPokemonResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationDownloadPokemonResult{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, gtsdpr.DataID)) + b.WriteString(fmt.Sprintf("%sIndexData: %s,\n", indentationValues, gtsdpr.IndexData)) + b.WriteString(fmt.Sprintf("%sPokemonData: %s,\n", indentationValues, gtsdpr.PokemonData)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationDownloadPokemonResult returns a new GlobalTradeStationDownloadPokemonResult +func NewGlobalTradeStationDownloadPokemonResult() *GlobalTradeStationDownloadPokemonResult { + gtsdpr := &GlobalTradeStationDownloadPokemonResult{ + DataID: types.NewPrimitiveU64(0), + IndexData: types.NewQBuffer(nil), + PokemonData: types.NewQBuffer(nil), + } + + return gtsdpr +} diff --git a/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_prepare_trade_pokemon_param.go b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_prepare_trade_pokemon_param.go new file mode 100644 index 0000000..0da8ef9 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_prepare_trade_pokemon_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationPrepareTradePokemonParam is a type within the DataStore protocol +type GlobalTradeStationPrepareTradePokemonParam struct { + types.Structure + TradeKey *GlobalTradeStationTradeKey + PrepareUploadKey *GlobalTradeStationRecordKey +} + +// WriteTo writes the GlobalTradeStationPrepareTradePokemonParam to the given writable +func (gtsptpp *GlobalTradeStationPrepareTradePokemonParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsptpp.TradeKey.WriteTo(contentWritable) + gtsptpp.PrepareUploadKey.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsptpp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationPrepareTradePokemonParam from the given readable +func (gtsptpp *GlobalTradeStationPrepareTradePokemonParam) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsptpp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationPrepareTradePokemonParam header. %s", err.Error()) + } + + err = gtsptpp.TradeKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationPrepareTradePokemonParam.TradeKey. %s", err.Error()) + } + + err = gtsptpp.PrepareUploadKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationPrepareTradePokemonParam.PrepareUploadKey. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationPrepareTradePokemonParam +func (gtsptpp *GlobalTradeStationPrepareTradePokemonParam) Copy() types.RVType { + copied := NewGlobalTradeStationPrepareTradePokemonParam() + + copied.StructureVersion = gtsptpp.StructureVersion + copied.TradeKey = gtsptpp.TradeKey.Copy().(*GlobalTradeStationTradeKey) + copied.PrepareUploadKey = gtsptpp.PrepareUploadKey.Copy().(*GlobalTradeStationRecordKey) + + return copied +} + +// Equals checks if the given GlobalTradeStationPrepareTradePokemonParam contains the same data as the current GlobalTradeStationPrepareTradePokemonParam +func (gtsptpp *GlobalTradeStationPrepareTradePokemonParam) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationPrepareTradePokemonParam); !ok { + return false + } + + other := o.(*GlobalTradeStationPrepareTradePokemonParam) + + if gtsptpp.StructureVersion != other.StructureVersion { + return false + } + + if !gtsptpp.TradeKey.Equals(other.TradeKey) { + return false + } + + return gtsptpp.PrepareUploadKey.Equals(other.PrepareUploadKey) +} + +// String returns the string representation of the GlobalTradeStationPrepareTradePokemonParam +func (gtsptpp *GlobalTradeStationPrepareTradePokemonParam) String() string { + return gtsptpp.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationPrepareTradePokemonParam using the provided indentation level +func (gtsptpp *GlobalTradeStationPrepareTradePokemonParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationPrepareTradePokemonParam{\n") + b.WriteString(fmt.Sprintf("%sTradeKey: %s,\n", indentationValues, gtsptpp.TradeKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPrepareUploadKey: %s,\n", indentationValues, gtsptpp.PrepareUploadKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationPrepareTradePokemonParam returns a new GlobalTradeStationPrepareTradePokemonParam +func NewGlobalTradeStationPrepareTradePokemonParam() *GlobalTradeStationPrepareTradePokemonParam { + gtsptpp := &GlobalTradeStationPrepareTradePokemonParam{ + TradeKey: NewGlobalTradeStationTradeKey(), + PrepareUploadKey: NewGlobalTradeStationRecordKey(), + } + + return gtsptpp +} diff --git a/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_prepare_trade_pokemon_result.go b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_prepare_trade_pokemon_result.go new file mode 100644 index 0000000..3f19d7f --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_prepare_trade_pokemon_result.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationPrepareTradePokemonResult is a type within the DataStore protocol +type GlobalTradeStationPrepareTradePokemonResult struct { + types.Structure + Result *GlobalTradeStationDownloadPokemonResult + PrepareTradeKey *GlobalTradeStationRecordKey +} + +// WriteTo writes the GlobalTradeStationPrepareTradePokemonResult to the given writable +func (gtsptpr *GlobalTradeStationPrepareTradePokemonResult) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsptpr.Result.WriteTo(contentWritable) + gtsptpr.PrepareTradeKey.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsptpr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationPrepareTradePokemonResult from the given readable +func (gtsptpr *GlobalTradeStationPrepareTradePokemonResult) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsptpr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationPrepareTradePokemonResult header. %s", err.Error()) + } + + err = gtsptpr.Result.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationPrepareTradePokemonResult.Result. %s", err.Error()) + } + + err = gtsptpr.PrepareTradeKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationPrepareTradePokemonResult.PrepareTradeKey. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationPrepareTradePokemonResult +func (gtsptpr *GlobalTradeStationPrepareTradePokemonResult) Copy() types.RVType { + copied := NewGlobalTradeStationPrepareTradePokemonResult() + + copied.StructureVersion = gtsptpr.StructureVersion + copied.Result = gtsptpr.Result.Copy().(*GlobalTradeStationDownloadPokemonResult) + copied.PrepareTradeKey = gtsptpr.PrepareTradeKey.Copy().(*GlobalTradeStationRecordKey) + + return copied +} + +// Equals checks if the given GlobalTradeStationPrepareTradePokemonResult contains the same data as the current GlobalTradeStationPrepareTradePokemonResult +func (gtsptpr *GlobalTradeStationPrepareTradePokemonResult) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationPrepareTradePokemonResult); !ok { + return false + } + + other := o.(*GlobalTradeStationPrepareTradePokemonResult) + + if gtsptpr.StructureVersion != other.StructureVersion { + return false + } + + if !gtsptpr.Result.Equals(other.Result) { + return false + } + + return gtsptpr.PrepareTradeKey.Equals(other.PrepareTradeKey) +} + +// String returns the string representation of the GlobalTradeStationPrepareTradePokemonResult +func (gtsptpr *GlobalTradeStationPrepareTradePokemonResult) String() string { + return gtsptpr.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationPrepareTradePokemonResult using the provided indentation level +func (gtsptpr *GlobalTradeStationPrepareTradePokemonResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationPrepareTradePokemonResult{\n") + b.WriteString(fmt.Sprintf("%sResult: %s,\n", indentationValues, gtsptpr.Result.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPrepareTradeKey: %s,\n", indentationValues, gtsptpr.PrepareTradeKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationPrepareTradePokemonResult returns a new GlobalTradeStationPrepareTradePokemonResult +func NewGlobalTradeStationPrepareTradePokemonResult() *GlobalTradeStationPrepareTradePokemonResult { + gtsptpr := &GlobalTradeStationPrepareTradePokemonResult{ + Result: NewGlobalTradeStationDownloadPokemonResult(), + PrepareTradeKey: NewGlobalTradeStationRecordKey(), + } + + return gtsptpr +} diff --git a/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_record_key.go b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_record_key.go new file mode 100644 index 0000000..cae44a0 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_record_key.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationRecordKey is a type within the DataStore protocol +type GlobalTradeStationRecordKey struct { + types.Structure + DataID *types.PrimitiveU64 + Password *types.PrimitiveU64 +} + +// WriteTo writes the GlobalTradeStationRecordKey to the given writable +func (gtsrk *GlobalTradeStationRecordKey) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsrk.DataID.WriteTo(contentWritable) + gtsrk.Password.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsrk.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationRecordKey from the given readable +func (gtsrk *GlobalTradeStationRecordKey) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsrk.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationRecordKey header. %s", err.Error()) + } + + err = gtsrk.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationRecordKey.DataID. %s", err.Error()) + } + + err = gtsrk.Password.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationRecordKey.Password. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationRecordKey +func (gtsrk *GlobalTradeStationRecordKey) Copy() types.RVType { + copied := NewGlobalTradeStationRecordKey() + + copied.StructureVersion = gtsrk.StructureVersion + copied.DataID = gtsrk.DataID.Copy().(*types.PrimitiveU64) + copied.Password = gtsrk.Password.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given GlobalTradeStationRecordKey contains the same data as the current GlobalTradeStationRecordKey +func (gtsrk *GlobalTradeStationRecordKey) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationRecordKey); !ok { + return false + } + + other := o.(*GlobalTradeStationRecordKey) + + if gtsrk.StructureVersion != other.StructureVersion { + return false + } + + if !gtsrk.DataID.Equals(other.DataID) { + return false + } + + return gtsrk.Password.Equals(other.Password) +} + +// String returns the string representation of the GlobalTradeStationRecordKey +func (gtsrk *GlobalTradeStationRecordKey) String() string { + return gtsrk.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationRecordKey using the provided indentation level +func (gtsrk *GlobalTradeStationRecordKey) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationRecordKey{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, gtsrk.DataID)) + b.WriteString(fmt.Sprintf("%sPassword: %s,\n", indentationValues, gtsrk.Password)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationRecordKey returns a new GlobalTradeStationRecordKey +func NewGlobalTradeStationRecordKey() *GlobalTradeStationRecordKey { + gtsrk := &GlobalTradeStationRecordKey{ + DataID: types.NewPrimitiveU64(0), + Password: types.NewPrimitiveU64(0), + } + + return gtsrk +} diff --git a/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_search_pokemon_param.go b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_search_pokemon_param.go new file mode 100644 index 0000000..e4c1561 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_search_pokemon_param.go @@ -0,0 +1,184 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationSearchPokemonParam is a type within the DataStore protocol +type GlobalTradeStationSearchPokemonParam struct { + types.Structure + PrepareUploadKey *GlobalTradeStationRecordKey + Conditions *types.List[*types.PrimitiveU32] + ResultOrderColumn *types.PrimitiveU8 + ResultOrder *types.PrimitiveU8 + UploadedAfter *types.DateTime + UploadedBefore *types.DateTime + ResultRange *types.ResultRange +} + +// WriteTo writes the GlobalTradeStationSearchPokemonParam to the given writable +func (gtsspp *GlobalTradeStationSearchPokemonParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsspp.PrepareUploadKey.WriteTo(contentWritable) + gtsspp.Conditions.WriteTo(contentWritable) + gtsspp.ResultOrderColumn.WriteTo(contentWritable) + gtsspp.ResultOrder.WriteTo(contentWritable) + gtsspp.UploadedAfter.WriteTo(contentWritable) + gtsspp.UploadedBefore.WriteTo(contentWritable) + gtsspp.ResultRange.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsspp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationSearchPokemonParam from the given readable +func (gtsspp *GlobalTradeStationSearchPokemonParam) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsspp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonParam header. %s", err.Error()) + } + + err = gtsspp.PrepareUploadKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonParam.PrepareUploadKey. %s", err.Error()) + } + + err = gtsspp.Conditions.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonParam.Conditions. %s", err.Error()) + } + + err = gtsspp.ResultOrderColumn.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonParam.ResultOrderColumn. %s", err.Error()) + } + + err = gtsspp.ResultOrder.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonParam.ResultOrder. %s", err.Error()) + } + + err = gtsspp.UploadedAfter.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonParam.UploadedAfter. %s", err.Error()) + } + + err = gtsspp.UploadedBefore.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonParam.UploadedBefore. %s", err.Error()) + } + + err = gtsspp.ResultRange.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonParam.ResultRange. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationSearchPokemonParam +func (gtsspp *GlobalTradeStationSearchPokemonParam) Copy() types.RVType { + copied := NewGlobalTradeStationSearchPokemonParam() + + copied.StructureVersion = gtsspp.StructureVersion + copied.PrepareUploadKey = gtsspp.PrepareUploadKey.Copy().(*GlobalTradeStationRecordKey) + copied.Conditions = gtsspp.Conditions.Copy().(*types.List[*types.PrimitiveU32]) + copied.ResultOrderColumn = gtsspp.ResultOrderColumn.Copy().(*types.PrimitiveU8) + copied.ResultOrder = gtsspp.ResultOrder.Copy().(*types.PrimitiveU8) + copied.UploadedAfter = gtsspp.UploadedAfter.Copy().(*types.DateTime) + copied.UploadedBefore = gtsspp.UploadedBefore.Copy().(*types.DateTime) + copied.ResultRange = gtsspp.ResultRange.Copy().(*types.ResultRange) + + return copied +} + +// Equals checks if the given GlobalTradeStationSearchPokemonParam contains the same data as the current GlobalTradeStationSearchPokemonParam +func (gtsspp *GlobalTradeStationSearchPokemonParam) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationSearchPokemonParam); !ok { + return false + } + + other := o.(*GlobalTradeStationSearchPokemonParam) + + if gtsspp.StructureVersion != other.StructureVersion { + return false + } + + if !gtsspp.PrepareUploadKey.Equals(other.PrepareUploadKey) { + return false + } + + if !gtsspp.Conditions.Equals(other.Conditions) { + return false + } + + if !gtsspp.ResultOrderColumn.Equals(other.ResultOrderColumn) { + return false + } + + if !gtsspp.ResultOrder.Equals(other.ResultOrder) { + return false + } + + if !gtsspp.UploadedAfter.Equals(other.UploadedAfter) { + return false + } + + if !gtsspp.UploadedBefore.Equals(other.UploadedBefore) { + return false + } + + return gtsspp.ResultRange.Equals(other.ResultRange) +} + +// String returns the string representation of the GlobalTradeStationSearchPokemonParam +func (gtsspp *GlobalTradeStationSearchPokemonParam) String() string { + return gtsspp.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationSearchPokemonParam using the provided indentation level +func (gtsspp *GlobalTradeStationSearchPokemonParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationSearchPokemonParam{\n") + b.WriteString(fmt.Sprintf("%sPrepareUploadKey: %s,\n", indentationValues, gtsspp.PrepareUploadKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sConditions: %s,\n", indentationValues, gtsspp.Conditions)) + b.WriteString(fmt.Sprintf("%sResultOrderColumn: %s,\n", indentationValues, gtsspp.ResultOrderColumn)) + b.WriteString(fmt.Sprintf("%sResultOrder: %s,\n", indentationValues, gtsspp.ResultOrder)) + b.WriteString(fmt.Sprintf("%sUploadedAfter: %s,\n", indentationValues, gtsspp.UploadedAfter.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUploadedBefore: %s,\n", indentationValues, gtsspp.UploadedBefore.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sResultRange: %s,\n", indentationValues, gtsspp.ResultRange.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationSearchPokemonParam returns a new GlobalTradeStationSearchPokemonParam +func NewGlobalTradeStationSearchPokemonParam() *GlobalTradeStationSearchPokemonParam { + gtsspp := &GlobalTradeStationSearchPokemonParam{ + PrepareUploadKey: NewGlobalTradeStationRecordKey(), + Conditions: types.NewList[*types.PrimitiveU32](), + ResultOrderColumn: types.NewPrimitiveU8(0), + ResultOrder: types.NewPrimitiveU8(0), + UploadedAfter: types.NewDateTime(0), + UploadedBefore: types.NewDateTime(0), + ResultRange: types.NewResultRange(), + } + + gtsspp.Conditions.Type = types.NewPrimitiveU32(0) + + return gtsspp +} diff --git a/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_search_pokemon_result.go b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_search_pokemon_result.go new file mode 100644 index 0000000..b127ea6 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_search_pokemon_result.go @@ -0,0 +1,128 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationSearchPokemonResult is a type within the DataStore protocol +type GlobalTradeStationSearchPokemonResult struct { + types.Structure + TotalCount *types.PrimitiveU32 + Result *types.List[*GlobalTradeStationData] + TotalCountType *types.PrimitiveU8 +} + +// WriteTo writes the GlobalTradeStationSearchPokemonResult to the given writable +func (gtsspr *GlobalTradeStationSearchPokemonResult) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsspr.TotalCount.WriteTo(contentWritable) + gtsspr.Result.WriteTo(contentWritable) + gtsspr.TotalCountType.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsspr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationSearchPokemonResult from the given readable +func (gtsspr *GlobalTradeStationSearchPokemonResult) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsspr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonResult header. %s", err.Error()) + } + + err = gtsspr.TotalCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonResult.TotalCount. %s", err.Error()) + } + + err = gtsspr.Result.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonResult.Result. %s", err.Error()) + } + + err = gtsspr.TotalCountType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonResult.TotalCountType. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationSearchPokemonResult +func (gtsspr *GlobalTradeStationSearchPokemonResult) Copy() types.RVType { + copied := NewGlobalTradeStationSearchPokemonResult() + + copied.StructureVersion = gtsspr.StructureVersion + copied.TotalCount = gtsspr.TotalCount.Copy().(*types.PrimitiveU32) + copied.Result = gtsspr.Result.Copy().(*types.List[*GlobalTradeStationData]) + copied.TotalCountType = gtsspr.TotalCountType.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given GlobalTradeStationSearchPokemonResult contains the same data as the current GlobalTradeStationSearchPokemonResult +func (gtsspr *GlobalTradeStationSearchPokemonResult) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationSearchPokemonResult); !ok { + return false + } + + other := o.(*GlobalTradeStationSearchPokemonResult) + + if gtsspr.StructureVersion != other.StructureVersion { + return false + } + + if !gtsspr.TotalCount.Equals(other.TotalCount) { + return false + } + + if !gtsspr.Result.Equals(other.Result) { + return false + } + + return gtsspr.TotalCountType.Equals(other.TotalCountType) +} + +// String returns the string representation of the GlobalTradeStationSearchPokemonResult +func (gtsspr *GlobalTradeStationSearchPokemonResult) String() string { + return gtsspr.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationSearchPokemonResult using the provided indentation level +func (gtsspr *GlobalTradeStationSearchPokemonResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationSearchPokemonResult{\n") + b.WriteString(fmt.Sprintf("%sTotalCount: %s,\n", indentationValues, gtsspr.TotalCount)) + b.WriteString(fmt.Sprintf("%sResult: %s,\n", indentationValues, gtsspr.Result)) + b.WriteString(fmt.Sprintf("%sTotalCountType: %s,\n", indentationValues, gtsspr.TotalCountType)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationSearchPokemonResult returns a new GlobalTradeStationSearchPokemonResult +func NewGlobalTradeStationSearchPokemonResult() *GlobalTradeStationSearchPokemonResult { + gtsspr := &GlobalTradeStationSearchPokemonResult{ + TotalCount: types.NewPrimitiveU32(0), + Result: types.NewList[*GlobalTradeStationData](), + TotalCountType: types.NewPrimitiveU8(0), + } + + gtsspr.Result.Type = NewGlobalTradeStationData() + + return gtsspr +} diff --git a/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_trade_key.go b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_trade_key.go new file mode 100644 index 0000000..a15eaf9 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_trade_key.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationTradeKey is a type within the DataStore protocol +type GlobalTradeStationTradeKey struct { + types.Structure + DataID *types.PrimitiveU64 + Version *types.PrimitiveU32 +} + +// WriteTo writes the GlobalTradeStationTradeKey to the given writable +func (gtstk *GlobalTradeStationTradeKey) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtstk.DataID.WriteTo(contentWritable) + gtstk.Version.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtstk.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationTradeKey from the given readable +func (gtstk *GlobalTradeStationTradeKey) ExtractFrom(readable types.Readable) error { + var err error + + err = gtstk.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradeKey header. %s", err.Error()) + } + + err = gtstk.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradeKey.DataID. %s", err.Error()) + } + + err = gtstk.Version.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradeKey.Version. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationTradeKey +func (gtstk *GlobalTradeStationTradeKey) Copy() types.RVType { + copied := NewGlobalTradeStationTradeKey() + + copied.StructureVersion = gtstk.StructureVersion + copied.DataID = gtstk.DataID.Copy().(*types.PrimitiveU64) + copied.Version = gtstk.Version.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given GlobalTradeStationTradeKey contains the same data as the current GlobalTradeStationTradeKey +func (gtstk *GlobalTradeStationTradeKey) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationTradeKey); !ok { + return false + } + + other := o.(*GlobalTradeStationTradeKey) + + if gtstk.StructureVersion != other.StructureVersion { + return false + } + + if !gtstk.DataID.Equals(other.DataID) { + return false + } + + return gtstk.Version.Equals(other.Version) +} + +// String returns the string representation of the GlobalTradeStationTradeKey +func (gtstk *GlobalTradeStationTradeKey) String() string { + return gtstk.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationTradeKey using the provided indentation level +func (gtstk *GlobalTradeStationTradeKey) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationTradeKey{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, gtstk.DataID)) + b.WriteString(fmt.Sprintf("%sVersion: %s,\n", indentationValues, gtstk.Version)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationTradeKey returns a new GlobalTradeStationTradeKey +func NewGlobalTradeStationTradeKey() *GlobalTradeStationTradeKey { + gtstk := &GlobalTradeStationTradeKey{ + DataID: types.NewPrimitiveU64(0), + Version: types.NewPrimitiveU32(0), + } + + return gtstk +} diff --git a/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_trade_pokemon_param.go b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_trade_pokemon_param.go new file mode 100644 index 0000000..6073a9f --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_trade_pokemon_param.go @@ -0,0 +1,196 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationTradePokemonParam is a type within the DataStore protocol +type GlobalTradeStationTradePokemonParam struct { + types.Structure + TradeKey *GlobalTradeStationTradeKey + PrepareTradeKey *GlobalTradeStationRecordKey + PrepareUploadKey *GlobalTradeStationRecordKey + Period *types.PrimitiveU16 + IndexData *types.QBuffer + PokemonData *types.QBuffer + Signature *types.QBuffer + NeedData *types.PrimitiveBool +} + +// WriteTo writes the GlobalTradeStationTradePokemonParam to the given writable +func (gtstpp *GlobalTradeStationTradePokemonParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtstpp.TradeKey.WriteTo(contentWritable) + gtstpp.PrepareTradeKey.WriteTo(contentWritable) + gtstpp.PrepareUploadKey.WriteTo(contentWritable) + gtstpp.Period.WriteTo(contentWritable) + gtstpp.IndexData.WriteTo(contentWritable) + gtstpp.PokemonData.WriteTo(contentWritable) + gtstpp.Signature.WriteTo(contentWritable) + gtstpp.NeedData.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtstpp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationTradePokemonParam from the given readable +func (gtstpp *GlobalTradeStationTradePokemonParam) ExtractFrom(readable types.Readable) error { + var err error + + err = gtstpp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam header. %s", err.Error()) + } + + err = gtstpp.TradeKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam.TradeKey. %s", err.Error()) + } + + err = gtstpp.PrepareTradeKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam.PrepareTradeKey. %s", err.Error()) + } + + err = gtstpp.PrepareUploadKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam.PrepareUploadKey. %s", err.Error()) + } + + err = gtstpp.Period.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam.Period. %s", err.Error()) + } + + err = gtstpp.IndexData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam.IndexData. %s", err.Error()) + } + + err = gtstpp.PokemonData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam.PokemonData. %s", err.Error()) + } + + err = gtstpp.Signature.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam.Signature. %s", err.Error()) + } + + err = gtstpp.NeedData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam.NeedData. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationTradePokemonParam +func (gtstpp *GlobalTradeStationTradePokemonParam) Copy() types.RVType { + copied := NewGlobalTradeStationTradePokemonParam() + + copied.StructureVersion = gtstpp.StructureVersion + copied.TradeKey = gtstpp.TradeKey.Copy().(*GlobalTradeStationTradeKey) + copied.PrepareTradeKey = gtstpp.PrepareTradeKey.Copy().(*GlobalTradeStationRecordKey) + copied.PrepareUploadKey = gtstpp.PrepareUploadKey.Copy().(*GlobalTradeStationRecordKey) + copied.Period = gtstpp.Period.Copy().(*types.PrimitiveU16) + copied.IndexData = gtstpp.IndexData.Copy().(*types.QBuffer) + copied.PokemonData = gtstpp.PokemonData.Copy().(*types.QBuffer) + copied.Signature = gtstpp.Signature.Copy().(*types.QBuffer) + copied.NeedData = gtstpp.NeedData.Copy().(*types.PrimitiveBool) + + return copied +} + +// Equals checks if the given GlobalTradeStationTradePokemonParam contains the same data as the current GlobalTradeStationTradePokemonParam +func (gtstpp *GlobalTradeStationTradePokemonParam) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationTradePokemonParam); !ok { + return false + } + + other := o.(*GlobalTradeStationTradePokemonParam) + + if gtstpp.StructureVersion != other.StructureVersion { + return false + } + + if !gtstpp.TradeKey.Equals(other.TradeKey) { + return false + } + + if !gtstpp.PrepareTradeKey.Equals(other.PrepareTradeKey) { + return false + } + + if !gtstpp.PrepareUploadKey.Equals(other.PrepareUploadKey) { + return false + } + + if !gtstpp.Period.Equals(other.Period) { + return false + } + + if !gtstpp.IndexData.Equals(other.IndexData) { + return false + } + + if !gtstpp.PokemonData.Equals(other.PokemonData) { + return false + } + + if !gtstpp.Signature.Equals(other.Signature) { + return false + } + + return gtstpp.NeedData.Equals(other.NeedData) +} + +// String returns the string representation of the GlobalTradeStationTradePokemonParam +func (gtstpp *GlobalTradeStationTradePokemonParam) String() string { + return gtstpp.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationTradePokemonParam using the provided indentation level +func (gtstpp *GlobalTradeStationTradePokemonParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationTradePokemonParam{\n") + b.WriteString(fmt.Sprintf("%sTradeKey: %s,\n", indentationValues, gtstpp.TradeKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPrepareTradeKey: %s,\n", indentationValues, gtstpp.PrepareTradeKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPrepareUploadKey: %s,\n", indentationValues, gtstpp.PrepareUploadKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPeriod: %s,\n", indentationValues, gtstpp.Period)) + b.WriteString(fmt.Sprintf("%sIndexData: %s,\n", indentationValues, gtstpp.IndexData)) + b.WriteString(fmt.Sprintf("%sPokemonData: %s,\n", indentationValues, gtstpp.PokemonData)) + b.WriteString(fmt.Sprintf("%sSignature: %s,\n", indentationValues, gtstpp.Signature)) + b.WriteString(fmt.Sprintf("%sNeedData: %s,\n", indentationValues, gtstpp.NeedData)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationTradePokemonParam returns a new GlobalTradeStationTradePokemonParam +func NewGlobalTradeStationTradePokemonParam() *GlobalTradeStationTradePokemonParam { + gtstpp := &GlobalTradeStationTradePokemonParam{ + TradeKey: NewGlobalTradeStationTradeKey(), + PrepareTradeKey: NewGlobalTradeStationRecordKey(), + PrepareUploadKey: NewGlobalTradeStationRecordKey(), + Period: types.NewPrimitiveU16(0), + IndexData: types.NewQBuffer(nil), + PokemonData: types.NewQBuffer(nil), + Signature: types.NewQBuffer(nil), + NeedData: types.NewPrimitiveBool(false), + } + + return gtstpp +} diff --git a/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_trade_pokemon_result.go b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_trade_pokemon_result.go new file mode 100644 index 0000000..82d838a --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_trade_pokemon_result.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationTradePokemonResult is a type within the DataStore protocol +type GlobalTradeStationTradePokemonResult struct { + types.Structure + Result *GlobalTradeStationDownloadPokemonResult + MyDataID *types.PrimitiveU64 +} + +// WriteTo writes the GlobalTradeStationTradePokemonResult to the given writable +func (gtstpr *GlobalTradeStationTradePokemonResult) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtstpr.Result.WriteTo(contentWritable) + gtstpr.MyDataID.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtstpr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationTradePokemonResult from the given readable +func (gtstpr *GlobalTradeStationTradePokemonResult) ExtractFrom(readable types.Readable) error { + var err error + + err = gtstpr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonResult header. %s", err.Error()) + } + + err = gtstpr.Result.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonResult.Result. %s", err.Error()) + } + + err = gtstpr.MyDataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonResult.MyDataID. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationTradePokemonResult +func (gtstpr *GlobalTradeStationTradePokemonResult) Copy() types.RVType { + copied := NewGlobalTradeStationTradePokemonResult() + + copied.StructureVersion = gtstpr.StructureVersion + copied.Result = gtstpr.Result.Copy().(*GlobalTradeStationDownloadPokemonResult) + copied.MyDataID = gtstpr.MyDataID.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given GlobalTradeStationTradePokemonResult contains the same data as the current GlobalTradeStationTradePokemonResult +func (gtstpr *GlobalTradeStationTradePokemonResult) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationTradePokemonResult); !ok { + return false + } + + other := o.(*GlobalTradeStationTradePokemonResult) + + if gtstpr.StructureVersion != other.StructureVersion { + return false + } + + if !gtstpr.Result.Equals(other.Result) { + return false + } + + return gtstpr.MyDataID.Equals(other.MyDataID) +} + +// String returns the string representation of the GlobalTradeStationTradePokemonResult +func (gtstpr *GlobalTradeStationTradePokemonResult) String() string { + return gtstpr.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationTradePokemonResult using the provided indentation level +func (gtstpr *GlobalTradeStationTradePokemonResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationTradePokemonResult{\n") + b.WriteString(fmt.Sprintf("%sResult: %s,\n", indentationValues, gtstpr.Result.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sMyDataID: %s,\n", indentationValues, gtstpr.MyDataID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationTradePokemonResult returns a new GlobalTradeStationTradePokemonResult +func NewGlobalTradeStationTradePokemonResult() *GlobalTradeStationTradePokemonResult { + gtstpr := &GlobalTradeStationTradePokemonResult{ + Result: NewGlobalTradeStationDownloadPokemonResult(), + MyDataID: types.NewPrimitiveU64(0), + } + + return gtstpr +} diff --git a/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_upload_pokemon_param.go b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_upload_pokemon_param.go new file mode 100644 index 0000000..492037f --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/types/global_trade_station_upload_pokemon_param.go @@ -0,0 +1,154 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationUploadPokemonParam is a type within the DataStore protocol +type GlobalTradeStationUploadPokemonParam struct { + types.Structure + PrepareUploadKey *GlobalTradeStationRecordKey + Period *types.PrimitiveU16 + IndexData *types.QBuffer + PokemonData *types.QBuffer + Signature *types.QBuffer +} + +// WriteTo writes the GlobalTradeStationUploadPokemonParam to the given writable +func (gtsupp *GlobalTradeStationUploadPokemonParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsupp.PrepareUploadKey.WriteTo(contentWritable) + gtsupp.Period.WriteTo(contentWritable) + gtsupp.IndexData.WriteTo(contentWritable) + gtsupp.PokemonData.WriteTo(contentWritable) + gtsupp.Signature.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsupp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationUploadPokemonParam from the given readable +func (gtsupp *GlobalTradeStationUploadPokemonParam) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsupp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationUploadPokemonParam header. %s", err.Error()) + } + + err = gtsupp.PrepareUploadKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationUploadPokemonParam.PrepareUploadKey. %s", err.Error()) + } + + err = gtsupp.Period.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationUploadPokemonParam.Period. %s", err.Error()) + } + + err = gtsupp.IndexData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationUploadPokemonParam.IndexData. %s", err.Error()) + } + + err = gtsupp.PokemonData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationUploadPokemonParam.PokemonData. %s", err.Error()) + } + + err = gtsupp.Signature.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationUploadPokemonParam.Signature. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationUploadPokemonParam +func (gtsupp *GlobalTradeStationUploadPokemonParam) Copy() types.RVType { + copied := NewGlobalTradeStationUploadPokemonParam() + + copied.StructureVersion = gtsupp.StructureVersion + copied.PrepareUploadKey = gtsupp.PrepareUploadKey.Copy().(*GlobalTradeStationRecordKey) + copied.Period = gtsupp.Period.Copy().(*types.PrimitiveU16) + copied.IndexData = gtsupp.IndexData.Copy().(*types.QBuffer) + copied.PokemonData = gtsupp.PokemonData.Copy().(*types.QBuffer) + copied.Signature = gtsupp.Signature.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given GlobalTradeStationUploadPokemonParam contains the same data as the current GlobalTradeStationUploadPokemonParam +func (gtsupp *GlobalTradeStationUploadPokemonParam) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationUploadPokemonParam); !ok { + return false + } + + other := o.(*GlobalTradeStationUploadPokemonParam) + + if gtsupp.StructureVersion != other.StructureVersion { + return false + } + + if !gtsupp.PrepareUploadKey.Equals(other.PrepareUploadKey) { + return false + } + + if !gtsupp.Period.Equals(other.Period) { + return false + } + + if !gtsupp.IndexData.Equals(other.IndexData) { + return false + } + + if !gtsupp.PokemonData.Equals(other.PokemonData) { + return false + } + + return gtsupp.Signature.Equals(other.Signature) +} + +// String returns the string representation of the GlobalTradeStationUploadPokemonParam +func (gtsupp *GlobalTradeStationUploadPokemonParam) String() string { + return gtsupp.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationUploadPokemonParam using the provided indentation level +func (gtsupp *GlobalTradeStationUploadPokemonParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationUploadPokemonParam{\n") + b.WriteString(fmt.Sprintf("%sPrepareUploadKey: %s,\n", indentationValues, gtsupp.PrepareUploadKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPeriod: %s,\n", indentationValues, gtsupp.Period)) + b.WriteString(fmt.Sprintf("%sIndexData: %s,\n", indentationValues, gtsupp.IndexData)) + b.WriteString(fmt.Sprintf("%sPokemonData: %s,\n", indentationValues, gtsupp.PokemonData)) + b.WriteString(fmt.Sprintf("%sSignature: %s,\n", indentationValues, gtsupp.Signature)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationUploadPokemonParam returns a new GlobalTradeStationUploadPokemonParam +func NewGlobalTradeStationUploadPokemonParam() *GlobalTradeStationUploadPokemonParam { + gtsupp := &GlobalTradeStationUploadPokemonParam{ + PrepareUploadKey: NewGlobalTradeStationRecordKey(), + Period: types.NewPrimitiveU16(0), + IndexData: types.NewQBuffer(nil), + PokemonData: types.NewQBuffer(nil), + Signature: types.NewQBuffer(nil), + } + + return gtsupp +} diff --git a/nex-protocols-go/datastore/pokemon-bank/upload_pokemon.go b/nex-protocols-go/datastore/pokemon-bank/upload_pokemon.go new file mode 100644 index 0000000..dc6c66a --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-bank/upload_pokemon.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonBank protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_pokemon_bank_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-bank/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUploadPokemon(packet nex.PacketInterface) { + if protocol.UploadPokemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonBank::UploadPokemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_pokemon_bank_types.NewGlobalTradeStationUploadPokemonParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UploadPokemon(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UploadPokemon(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/delete_pokemon.go b/nex-protocols-go/datastore/pokemon-gen6/delete_pokemon.go new file mode 100644 index 0000000..9031d32 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/delete_pokemon.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonGen6 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_pokemon_gen6_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-gen6/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeletePokemon(packet nex.PacketInterface) { + if protocol.DeletePokemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonGen6::DeletePokemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_pokemon_gen6_types.NewGlobalTradeStationDeletePokemonParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeletePokemon(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeletePokemon(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/download_my_pokemon.go b/nex-protocols-go/datastore/pokemon-gen6/download_my_pokemon.go new file mode 100644 index 0000000..7d53b09 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/download_my_pokemon.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonGen6 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_pokemon_gen6_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-gen6/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDownloadMyPokemon(packet nex.PacketInterface) { + if protocol.DownloadMyPokemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonGen6::DownloadMyPokemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_pokemon_gen6_types.NewGlobalTradeStationDownloadMyPokemonParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DownloadMyPokemon(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DownloadMyPokemon(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/download_other_pokemon.go b/nex-protocols-go/datastore/pokemon-gen6/download_other_pokemon.go new file mode 100644 index 0000000..8bac77d --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/download_other_pokemon.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonGen6 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_pokemon_gen6_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-gen6/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDownloadOtherPokemon(packet nex.PacketInterface) { + if protocol.DownloadOtherPokemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonGen6::DownloadOtherPokemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_pokemon_gen6_types.NewGlobalTradeStationDownloadOtherPokemonParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DownloadOtherPokemon(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DownloadOtherPokemon(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/prepare_trade_pokemon.go b/nex-protocols-go/datastore/pokemon-gen6/prepare_trade_pokemon.go new file mode 100644 index 0000000..9c720e3 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/prepare_trade_pokemon.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonGen6 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_pokemon_gen6_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-gen6/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePrepareTradePokemon(packet nex.PacketInterface) { + if protocol.PrepareTradePokemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonGen6::PrepareTradePokemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_pokemon_gen6_types.NewGlobalTradeStationPrepareTradePokemonParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PrepareTradePokemon(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PrepareTradePokemon(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/prepare_upload_pokemon.go b/nex-protocols-go/datastore/pokemon-gen6/prepare_upload_pokemon.go new file mode 100644 index 0000000..a31ac0b --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/prepare_upload_pokemon.go @@ -0,0 +1,28 @@ +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePrepareUploadPokemon(packet nex.PacketInterface) { + if protocol.PrepareUploadPokemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonGen6::PrepareUploadPokemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.PrepareUploadPokemon(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/protocol.go b/nex-protocols-go/datastore/pokemon-gen6/protocol.go new file mode 100644 index 0000000..992deef --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/protocol.go @@ -0,0 +1,116 @@ +// Package protocol implements the DataStorePokemonGen6 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_pokemon_gen6_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-gen6/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + "golang.org/x/exp/slices" +) + +const ( + // ProtocolID is the Protocol ID for the DataStore (Pokemon Gen6) protocol + ProtocolID = 0x73 + + // MethodPrepareUploadPokemon is the method ID for the PrepareUploadPokemon method + MethodPrepareUploadPokemon = 0x28 + + // MethodUploadPokemon is the method ID for the UploadPokemon method + MethodUploadPokemon = 0x29 + + // MethodSearchPokemon is the method ID for the SearchPokemon method + MethodSearchPokemon = 0x2A + + // MethodPrepareTradePokemon is the method ID for the PrepareTradePokemon method + MethodPrepareTradePokemon = 0x2B + + // MethodTradePokemon is the method ID for the TradePokemon method + MethodTradePokemon = 0x2C + + // MethodDownloadOtherPokemon is the method ID for the DownloadOtherPokemon method + MethodDownloadOtherPokemon = 0x2D + + // MethodDownloadMyPokemon is the method ID for the DownloadMyPokemon method + MethodDownloadMyPokemon = 0x2E + + // MethodDeletePokemon is the method ID for the DeletePokemon method + MethodDeletePokemon = 0x2F +) + +var patchedMethods = []uint32{ + MethodPrepareUploadPokemon, + MethodUploadPokemon, + MethodSearchPokemon, + MethodPrepareTradePokemon, + MethodTradePokemon, + MethodDownloadOtherPokemon, + MethodDownloadMyPokemon, + MethodDeletePokemon, +} + +type dataStoreProtocol = datastore.Protocol + +// Protocol stores all the RMC method handlers for the DataStore (Pokemon Gen6) protocol and listens for requests +// Embeds the DataStore protocol +type Protocol struct { + endpoint nex.EndpointInterface + dataStoreProtocol + PrepareUploadPokemon func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + UploadPokemon func(err error, packet nex.PacketInterface, callID uint32, param *datastore_pokemon_gen6_types.GlobalTradeStationUploadPokemonParam) (*nex.RMCMessage, *nex.Error) + SearchPokemon func(err error, packet nex.PacketInterface, callID uint32, param *datastore_pokemon_gen6_types.GlobalTradeStationSearchPokemonParam) (*nex.RMCMessage, *nex.Error) + PrepareTradePokemon func(err error, packet nex.PacketInterface, callID uint32, param *datastore_pokemon_gen6_types.GlobalTradeStationPrepareTradePokemonParam) (*nex.RMCMessage, *nex.Error) + TradePokemon func(err error, packet nex.PacketInterface, callID uint32, param *datastore_pokemon_gen6_types.GlobalTradeStationTradePokemonParam) (*nex.RMCMessage, *nex.Error) + DownloadOtherPokemon func(err error, packet nex.PacketInterface, callID uint32, param *datastore_pokemon_gen6_types.GlobalTradeStationDownloadOtherPokemonParam) (*nex.RMCMessage, *nex.Error) + DownloadMyPokemon func(err error, packet nex.PacketInterface, callID uint32, param *datastore_pokemon_gen6_types.GlobalTradeStationDownloadMyPokemonParam) (*nex.RMCMessage, *nex.Error) + DeletePokemon func(err error, packet nex.PacketInterface, callID uint32, param *datastore_pokemon_gen6_types.GlobalTradeStationDeletePokemonParam) (*nex.RMCMessage, *nex.Error) +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if !slices.Contains(patchedMethods, message.MethodID) { + protocol.dataStoreProtocol.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodPrepareUploadPokemon: + protocol.handlePrepareUploadPokemon(packet) + case MethodUploadPokemon: + protocol.handleUploadPokemon(packet) + case MethodSearchPokemon: + protocol.handleSearchPokemon(packet) + case MethodPrepareTradePokemon: + protocol.handlePrepareTradePokemon(packet) + case MethodTradePokemon: + protocol.handleTradePokemon(packet) + case MethodDownloadOtherPokemon: + protocol.handleDownloadOtherPokemon(packet) + case MethodDownloadMyPokemon: + protocol.handleDownloadMyPokemon(packet) + case MethodDeletePokemon: + protocol.handleDeletePokemon(packet) + default: + errMessage := fmt.Sprintf("Unsupported DataStore (Pokemon Gen6) method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new DataStorePokemonGen6 protocol +func NewProtocol(endpoint nex.EndpointInterface) *Protocol { + protocol := &Protocol{endpoint: endpoint} + protocol.dataStoreProtocol.SetEndpoint(endpoint) + + return protocol +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/search_pokemon.go b/nex-protocols-go/datastore/pokemon-gen6/search_pokemon.go new file mode 100644 index 0000000..02210c4 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/search_pokemon.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonGen6 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_pokemon_gen6_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-gen6/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSearchPokemon(packet nex.PacketInterface) { + if protocol.SearchPokemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonGen6::SearchPokemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_pokemon_gen6_types.NewGlobalTradeStationSearchPokemonParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SearchPokemon(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SearchPokemon(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/trade_pokemon.go b/nex-protocols-go/datastore/pokemon-gen6/trade_pokemon.go new file mode 100644 index 0000000..9d2c57f --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/trade_pokemon.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonGen6 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_pokemon_gen6_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-gen6/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleTradePokemon(packet nex.PacketInterface) { + if protocol.TradePokemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonGen6::TradePokemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_pokemon_gen6_types.NewGlobalTradeStationTradePokemonParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.TradePokemon(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.TradePokemon(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_data.go b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_data.go new file mode 100644 index 0000000..53f0308 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_data.go @@ -0,0 +1,154 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationData is a type within the DataStore protocol +type GlobalTradeStationData struct { + types.Structure + DataID *types.PrimitiveU64 + OwnerID *types.PID + UpdatedTime *types.DateTime + IndexData *types.QBuffer + Version *types.PrimitiveU32 +} + +// WriteTo writes the GlobalTradeStationData to the given writable +func (gtsd *GlobalTradeStationData) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsd.DataID.WriteTo(contentWritable) + gtsd.OwnerID.WriteTo(contentWritable) + gtsd.UpdatedTime.WriteTo(contentWritable) + gtsd.IndexData.WriteTo(contentWritable) + gtsd.Version.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsd.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationData from the given readable +func (gtsd *GlobalTradeStationData) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsd.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationData header. %s", err.Error()) + } + + err = gtsd.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationData.DataID. %s", err.Error()) + } + + err = gtsd.OwnerID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationData.OwnerID. %s", err.Error()) + } + + err = gtsd.UpdatedTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationData.UpdatedTime. %s", err.Error()) + } + + err = gtsd.IndexData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationData.IndexData. %s", err.Error()) + } + + err = gtsd.Version.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationData.Version. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationData +func (gtsd *GlobalTradeStationData) Copy() types.RVType { + copied := NewGlobalTradeStationData() + + copied.StructureVersion = gtsd.StructureVersion + copied.DataID = gtsd.DataID.Copy().(*types.PrimitiveU64) + copied.OwnerID = gtsd.OwnerID.Copy().(*types.PID) + copied.UpdatedTime = gtsd.UpdatedTime.Copy().(*types.DateTime) + copied.IndexData = gtsd.IndexData.Copy().(*types.QBuffer) + copied.Version = gtsd.Version.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given GlobalTradeStationData contains the same data as the current GlobalTradeStationData +func (gtsd *GlobalTradeStationData) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationData); !ok { + return false + } + + other := o.(*GlobalTradeStationData) + + if gtsd.StructureVersion != other.StructureVersion { + return false + } + + if !gtsd.DataID.Equals(other.DataID) { + return false + } + + if !gtsd.OwnerID.Equals(other.OwnerID) { + return false + } + + if !gtsd.UpdatedTime.Equals(other.UpdatedTime) { + return false + } + + if !gtsd.IndexData.Equals(other.IndexData) { + return false + } + + return gtsd.Version.Equals(other.Version) +} + +// String returns the string representation of the GlobalTradeStationData +func (gtsd *GlobalTradeStationData) String() string { + return gtsd.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationData using the provided indentation level +func (gtsd *GlobalTradeStationData) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationData{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, gtsd.DataID)) + b.WriteString(fmt.Sprintf("%sOwnerID: %s,\n", indentationValues, gtsd.OwnerID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUpdatedTime: %s,\n", indentationValues, gtsd.UpdatedTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sIndexData: %s,\n", indentationValues, gtsd.IndexData)) + b.WriteString(fmt.Sprintf("%sVersion: %s,\n", indentationValues, gtsd.Version)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationData returns a new GlobalTradeStationData +func NewGlobalTradeStationData() *GlobalTradeStationData { + gtsd := &GlobalTradeStationData{ + DataID: types.NewPrimitiveU64(0), + OwnerID: types.NewPID(0), + UpdatedTime: types.NewDateTime(0), + IndexData: types.NewQBuffer(nil), + Version: types.NewPrimitiveU32(0), + } + + return gtsd +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_delete_pokemon_param.go b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_delete_pokemon_param.go new file mode 100644 index 0000000..3ac6555 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_delete_pokemon_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationDeletePokemonParam is a type within the DataStore protocol +type GlobalTradeStationDeletePokemonParam struct { + types.Structure + PrepareUploadKey *GlobalTradeStationRecordKey + DeleteFlag *types.PrimitiveU8 +} + +// WriteTo writes the GlobalTradeStationDeletePokemonParam to the given writable +func (gtsdpp *GlobalTradeStationDeletePokemonParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsdpp.PrepareUploadKey.WriteTo(contentWritable) + gtsdpp.DeleteFlag.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsdpp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationDeletePokemonParam from the given readable +func (gtsdpp *GlobalTradeStationDeletePokemonParam) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsdpp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDeletePokemonParam header. %s", err.Error()) + } + + err = gtsdpp.PrepareUploadKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDeletePokemonParam.PrepareUploadKey. %s", err.Error()) + } + + err = gtsdpp.DeleteFlag.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDeletePokemonParam.DeleteFlag. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationDeletePokemonParam +func (gtsdpp *GlobalTradeStationDeletePokemonParam) Copy() types.RVType { + copied := NewGlobalTradeStationDeletePokemonParam() + + copied.StructureVersion = gtsdpp.StructureVersion + copied.PrepareUploadKey = gtsdpp.PrepareUploadKey.Copy().(*GlobalTradeStationRecordKey) + copied.DeleteFlag = gtsdpp.DeleteFlag.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given GlobalTradeStationDeletePokemonParam contains the same data as the current GlobalTradeStationDeletePokemonParam +func (gtsdpp *GlobalTradeStationDeletePokemonParam) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationDeletePokemonParam); !ok { + return false + } + + other := o.(*GlobalTradeStationDeletePokemonParam) + + if gtsdpp.StructureVersion != other.StructureVersion { + return false + } + + if !gtsdpp.PrepareUploadKey.Equals(other.PrepareUploadKey) { + return false + } + + return gtsdpp.DeleteFlag.Equals(other.DeleteFlag) +} + +// String returns the string representation of the GlobalTradeStationDeletePokemonParam +func (gtsdpp *GlobalTradeStationDeletePokemonParam) String() string { + return gtsdpp.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationDeletePokemonParam using the provided indentation level +func (gtsdpp *GlobalTradeStationDeletePokemonParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationDeletePokemonParam{\n") + b.WriteString(fmt.Sprintf("%sPrepareUploadKey: %s,\n", indentationValues, gtsdpp.PrepareUploadKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sDeleteFlag: %s,\n", indentationValues, gtsdpp.DeleteFlag)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationDeletePokemonParam returns a new GlobalTradeStationDeletePokemonParam +func NewGlobalTradeStationDeletePokemonParam() *GlobalTradeStationDeletePokemonParam { + gtsdpp := &GlobalTradeStationDeletePokemonParam{ + PrepareUploadKey: NewGlobalTradeStationRecordKey(), + DeleteFlag: types.NewPrimitiveU8(0), + } + + return gtsdpp +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_download_my_pokemon_param.go b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_download_my_pokemon_param.go new file mode 100644 index 0000000..8045ccf --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_download_my_pokemon_param.go @@ -0,0 +1,98 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationDownloadMyPokemonParam is a type within the DataStore protocol +type GlobalTradeStationDownloadMyPokemonParam struct { + types.Structure + PrepareUploadKey *GlobalTradeStationRecordKey +} + +// WriteTo writes the GlobalTradeStationDownloadMyPokemonParam to the given writable +func (gtsdmpp *GlobalTradeStationDownloadMyPokemonParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsdmpp.PrepareUploadKey.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsdmpp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationDownloadMyPokemonParam from the given readable +func (gtsdmpp *GlobalTradeStationDownloadMyPokemonParam) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsdmpp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadMyPokemonParam header. %s", err.Error()) + } + + err = gtsdmpp.PrepareUploadKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadMyPokemonParam.PrepareUploadKey. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationDownloadMyPokemonParam +func (gtsdmpp *GlobalTradeStationDownloadMyPokemonParam) Copy() types.RVType { + copied := NewGlobalTradeStationDownloadMyPokemonParam() + + copied.StructureVersion = gtsdmpp.StructureVersion + copied.PrepareUploadKey = gtsdmpp.PrepareUploadKey.Copy().(*GlobalTradeStationRecordKey) + + return copied +} + +// Equals checks if the given GlobalTradeStationDownloadMyPokemonParam contains the same data as the current GlobalTradeStationDownloadMyPokemonParam +func (gtsdmpp *GlobalTradeStationDownloadMyPokemonParam) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationDownloadMyPokemonParam); !ok { + return false + } + + other := o.(*GlobalTradeStationDownloadMyPokemonParam) + + if gtsdmpp.StructureVersion != other.StructureVersion { + return false + } + + return gtsdmpp.PrepareUploadKey.Equals(other.PrepareUploadKey) +} + +// String returns the string representation of the GlobalTradeStationDownloadMyPokemonParam +func (gtsdmpp *GlobalTradeStationDownloadMyPokemonParam) String() string { + return gtsdmpp.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationDownloadMyPokemonParam using the provided indentation level +func (gtsdmpp *GlobalTradeStationDownloadMyPokemonParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationDownloadMyPokemonParam{\n") + b.WriteString(fmt.Sprintf("%sPrepareUploadKey: %s,\n", indentationValues, gtsdmpp.PrepareUploadKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationDownloadMyPokemonParam returns a new GlobalTradeStationDownloadMyPokemonParam +func NewGlobalTradeStationDownloadMyPokemonParam() *GlobalTradeStationDownloadMyPokemonParam { + gtsdmpp := &GlobalTradeStationDownloadMyPokemonParam{ + PrepareUploadKey: NewGlobalTradeStationRecordKey(), + } + + return gtsdmpp +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_download_my_pokemon_result.go b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_download_my_pokemon_result.go new file mode 100644 index 0000000..d878775 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_download_my_pokemon_result.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationDownloadMyPokemonResult is a type within the DataStore protocol +type GlobalTradeStationDownloadMyPokemonResult struct { + types.Structure + Result *GlobalTradeStationDownloadPokemonResult + IsTraded *types.PrimitiveBool +} + +// WriteTo writes the GlobalTradeStationDownloadMyPokemonResult to the given writable +func (gtsdmpr *GlobalTradeStationDownloadMyPokemonResult) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsdmpr.Result.WriteTo(contentWritable) + gtsdmpr.IsTraded.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsdmpr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationDownloadMyPokemonResult from the given readable +func (gtsdmpr *GlobalTradeStationDownloadMyPokemonResult) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsdmpr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadMyPokemonResult header. %s", err.Error()) + } + + err = gtsdmpr.Result.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadMyPokemonResult.Result. %s", err.Error()) + } + + err = gtsdmpr.IsTraded.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadMyPokemonResult.IsTraded. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationDownloadMyPokemonResult +func (gtsdmpr *GlobalTradeStationDownloadMyPokemonResult) Copy() types.RVType { + copied := NewGlobalTradeStationDownloadMyPokemonResult() + + copied.StructureVersion = gtsdmpr.StructureVersion + copied.Result = gtsdmpr.Result.Copy().(*GlobalTradeStationDownloadPokemonResult) + copied.IsTraded = gtsdmpr.IsTraded.Copy().(*types.PrimitiveBool) + + return copied +} + +// Equals checks if the given GlobalTradeStationDownloadMyPokemonResult contains the same data as the current GlobalTradeStationDownloadMyPokemonResult +func (gtsdmpr *GlobalTradeStationDownloadMyPokemonResult) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationDownloadMyPokemonResult); !ok { + return false + } + + other := o.(*GlobalTradeStationDownloadMyPokemonResult) + + if gtsdmpr.StructureVersion != other.StructureVersion { + return false + } + + if !gtsdmpr.Result.Equals(other.Result) { + return false + } + + return gtsdmpr.IsTraded.Equals(other.IsTraded) +} + +// String returns the string representation of the GlobalTradeStationDownloadMyPokemonResult +func (gtsdmpr *GlobalTradeStationDownloadMyPokemonResult) String() string { + return gtsdmpr.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationDownloadMyPokemonResult using the provided indentation level +func (gtsdmpr *GlobalTradeStationDownloadMyPokemonResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationDownloadMyPokemonResult{\n") + b.WriteString(fmt.Sprintf("%sResult: %s,\n", indentationValues, gtsdmpr.Result.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sIsTraded: %s,\n", indentationValues, gtsdmpr.IsTraded)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationDownloadMyPokemonResult returns a new GlobalTradeStationDownloadMyPokemonResult +func NewGlobalTradeStationDownloadMyPokemonResult() *GlobalTradeStationDownloadMyPokemonResult { + gtsdmpr := &GlobalTradeStationDownloadMyPokemonResult{ + Result: NewGlobalTradeStationDownloadPokemonResult(), + IsTraded: types.NewPrimitiveBool(false), + } + + return gtsdmpr +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_download_other_pokemon_param.go b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_download_other_pokemon_param.go new file mode 100644 index 0000000..9adc566 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_download_other_pokemon_param.go @@ -0,0 +1,98 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationDownloadOtherPokemonParam is a type within the DataStore protocol +type GlobalTradeStationDownloadOtherPokemonParam struct { + types.Structure + PrepareUploadKey *GlobalTradeStationRecordKey +} + +// WriteTo writes the GlobalTradeStationDownloadOtherPokemonParam to the given writable +func (gtsdopp *GlobalTradeStationDownloadOtherPokemonParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsdopp.PrepareUploadKey.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsdopp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationDownloadOtherPokemonParam from the given readable +func (gtsdopp *GlobalTradeStationDownloadOtherPokemonParam) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsdopp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadOtherPokemonParam header. %s", err.Error()) + } + + err = gtsdopp.PrepareUploadKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadOtherPokemonParam.PrepareUploadKey. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationDownloadOtherPokemonParam +func (gtsdopp *GlobalTradeStationDownloadOtherPokemonParam) Copy() types.RVType { + copied := NewGlobalTradeStationDownloadOtherPokemonParam() + + copied.StructureVersion = gtsdopp.StructureVersion + copied.PrepareUploadKey = gtsdopp.PrepareUploadKey.Copy().(*GlobalTradeStationRecordKey) + + return copied +} + +// Equals checks if the given GlobalTradeStationDownloadOtherPokemonParam contains the same data as the current GlobalTradeStationDownloadOtherPokemonParam +func (gtsdopp *GlobalTradeStationDownloadOtherPokemonParam) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationDownloadOtherPokemonParam); !ok { + return false + } + + other := o.(*GlobalTradeStationDownloadOtherPokemonParam) + + if gtsdopp.StructureVersion != other.StructureVersion { + return false + } + + return gtsdopp.PrepareUploadKey.Equals(other.PrepareUploadKey) +} + +// String returns the string representation of the GlobalTradeStationDownloadOtherPokemonParam +func (gtsdopp *GlobalTradeStationDownloadOtherPokemonParam) String() string { + return gtsdopp.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationDownloadOtherPokemonParam using the provided indentation level +func (gtsdopp *GlobalTradeStationDownloadOtherPokemonParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationDownloadOtherPokemonParam{\n") + b.WriteString(fmt.Sprintf("%sPrepareUploadKey: %s,\n", indentationValues, gtsdopp.PrepareUploadKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationDownloadOtherPokemonParam returns a new GlobalTradeStationDownloadOtherPokemonParam +func NewGlobalTradeStationDownloadOtherPokemonParam() *GlobalTradeStationDownloadOtherPokemonParam { + gtsdopp := &GlobalTradeStationDownloadOtherPokemonParam{ + PrepareUploadKey: NewGlobalTradeStationRecordKey(), + } + + return gtsdopp +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_download_pokemon_result.go b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_download_pokemon_result.go new file mode 100644 index 0000000..e7ecec6 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_download_pokemon_result.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationDownloadPokemonResult is a type within the DataStore protocol +type GlobalTradeStationDownloadPokemonResult struct { + types.Structure + DataID *types.PrimitiveU64 + IndexData *types.QBuffer + PokemonData *types.QBuffer +} + +// WriteTo writes the GlobalTradeStationDownloadPokemonResult to the given writable +func (gtsdpr *GlobalTradeStationDownloadPokemonResult) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsdpr.DataID.WriteTo(contentWritable) + gtsdpr.IndexData.WriteTo(contentWritable) + gtsdpr.PokemonData.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsdpr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationDownloadPokemonResult from the given readable +func (gtsdpr *GlobalTradeStationDownloadPokemonResult) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsdpr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadPokemonResult header. %s", err.Error()) + } + + err = gtsdpr.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadPokemonResult.DataID. %s", err.Error()) + } + + err = gtsdpr.IndexData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadPokemonResult.IndexData. %s", err.Error()) + } + + err = gtsdpr.PokemonData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationDownloadPokemonResult.PokemonData. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationDownloadPokemonResult +func (gtsdpr *GlobalTradeStationDownloadPokemonResult) Copy() types.RVType { + copied := NewGlobalTradeStationDownloadPokemonResult() + + copied.StructureVersion = gtsdpr.StructureVersion + copied.DataID = gtsdpr.DataID.Copy().(*types.PrimitiveU64) + copied.IndexData = gtsdpr.IndexData.Copy().(*types.QBuffer) + copied.PokemonData = gtsdpr.PokemonData.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given GlobalTradeStationDownloadPokemonResult contains the same data as the current GlobalTradeStationDownloadPokemonResult +func (gtsdpr *GlobalTradeStationDownloadPokemonResult) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationDownloadPokemonResult); !ok { + return false + } + + other := o.(*GlobalTradeStationDownloadPokemonResult) + + if gtsdpr.StructureVersion != other.StructureVersion { + return false + } + + if !gtsdpr.DataID.Equals(other.DataID) { + return false + } + + if !gtsdpr.IndexData.Equals(other.IndexData) { + return false + } + + return gtsdpr.PokemonData.Equals(other.PokemonData) +} + +// String returns the string representation of the GlobalTradeStationDownloadPokemonResult +func (gtsdpr *GlobalTradeStationDownloadPokemonResult) String() string { + return gtsdpr.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationDownloadPokemonResult using the provided indentation level +func (gtsdpr *GlobalTradeStationDownloadPokemonResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationDownloadPokemonResult{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, gtsdpr.DataID)) + b.WriteString(fmt.Sprintf("%sIndexData: %s,\n", indentationValues, gtsdpr.IndexData)) + b.WriteString(fmt.Sprintf("%sPokemonData: %s,\n", indentationValues, gtsdpr.PokemonData)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationDownloadPokemonResult returns a new GlobalTradeStationDownloadPokemonResult +func NewGlobalTradeStationDownloadPokemonResult() *GlobalTradeStationDownloadPokemonResult { + gtsdpr := &GlobalTradeStationDownloadPokemonResult{ + DataID: types.NewPrimitiveU64(0), + IndexData: types.NewQBuffer(nil), + PokemonData: types.NewQBuffer(nil), + } + + return gtsdpr +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_prepare_trade_pokemon_param.go b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_prepare_trade_pokemon_param.go new file mode 100644 index 0000000..0da8ef9 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_prepare_trade_pokemon_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationPrepareTradePokemonParam is a type within the DataStore protocol +type GlobalTradeStationPrepareTradePokemonParam struct { + types.Structure + TradeKey *GlobalTradeStationTradeKey + PrepareUploadKey *GlobalTradeStationRecordKey +} + +// WriteTo writes the GlobalTradeStationPrepareTradePokemonParam to the given writable +func (gtsptpp *GlobalTradeStationPrepareTradePokemonParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsptpp.TradeKey.WriteTo(contentWritable) + gtsptpp.PrepareUploadKey.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsptpp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationPrepareTradePokemonParam from the given readable +func (gtsptpp *GlobalTradeStationPrepareTradePokemonParam) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsptpp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationPrepareTradePokemonParam header. %s", err.Error()) + } + + err = gtsptpp.TradeKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationPrepareTradePokemonParam.TradeKey. %s", err.Error()) + } + + err = gtsptpp.PrepareUploadKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationPrepareTradePokemonParam.PrepareUploadKey. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationPrepareTradePokemonParam +func (gtsptpp *GlobalTradeStationPrepareTradePokemonParam) Copy() types.RVType { + copied := NewGlobalTradeStationPrepareTradePokemonParam() + + copied.StructureVersion = gtsptpp.StructureVersion + copied.TradeKey = gtsptpp.TradeKey.Copy().(*GlobalTradeStationTradeKey) + copied.PrepareUploadKey = gtsptpp.PrepareUploadKey.Copy().(*GlobalTradeStationRecordKey) + + return copied +} + +// Equals checks if the given GlobalTradeStationPrepareTradePokemonParam contains the same data as the current GlobalTradeStationPrepareTradePokemonParam +func (gtsptpp *GlobalTradeStationPrepareTradePokemonParam) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationPrepareTradePokemonParam); !ok { + return false + } + + other := o.(*GlobalTradeStationPrepareTradePokemonParam) + + if gtsptpp.StructureVersion != other.StructureVersion { + return false + } + + if !gtsptpp.TradeKey.Equals(other.TradeKey) { + return false + } + + return gtsptpp.PrepareUploadKey.Equals(other.PrepareUploadKey) +} + +// String returns the string representation of the GlobalTradeStationPrepareTradePokemonParam +func (gtsptpp *GlobalTradeStationPrepareTradePokemonParam) String() string { + return gtsptpp.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationPrepareTradePokemonParam using the provided indentation level +func (gtsptpp *GlobalTradeStationPrepareTradePokemonParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationPrepareTradePokemonParam{\n") + b.WriteString(fmt.Sprintf("%sTradeKey: %s,\n", indentationValues, gtsptpp.TradeKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPrepareUploadKey: %s,\n", indentationValues, gtsptpp.PrepareUploadKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationPrepareTradePokemonParam returns a new GlobalTradeStationPrepareTradePokemonParam +func NewGlobalTradeStationPrepareTradePokemonParam() *GlobalTradeStationPrepareTradePokemonParam { + gtsptpp := &GlobalTradeStationPrepareTradePokemonParam{ + TradeKey: NewGlobalTradeStationTradeKey(), + PrepareUploadKey: NewGlobalTradeStationRecordKey(), + } + + return gtsptpp +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_prepare_trade_pokemon_result.go b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_prepare_trade_pokemon_result.go new file mode 100644 index 0000000..3f19d7f --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_prepare_trade_pokemon_result.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationPrepareTradePokemonResult is a type within the DataStore protocol +type GlobalTradeStationPrepareTradePokemonResult struct { + types.Structure + Result *GlobalTradeStationDownloadPokemonResult + PrepareTradeKey *GlobalTradeStationRecordKey +} + +// WriteTo writes the GlobalTradeStationPrepareTradePokemonResult to the given writable +func (gtsptpr *GlobalTradeStationPrepareTradePokemonResult) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsptpr.Result.WriteTo(contentWritable) + gtsptpr.PrepareTradeKey.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsptpr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationPrepareTradePokemonResult from the given readable +func (gtsptpr *GlobalTradeStationPrepareTradePokemonResult) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsptpr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationPrepareTradePokemonResult header. %s", err.Error()) + } + + err = gtsptpr.Result.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationPrepareTradePokemonResult.Result. %s", err.Error()) + } + + err = gtsptpr.PrepareTradeKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationPrepareTradePokemonResult.PrepareTradeKey. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationPrepareTradePokemonResult +func (gtsptpr *GlobalTradeStationPrepareTradePokemonResult) Copy() types.RVType { + copied := NewGlobalTradeStationPrepareTradePokemonResult() + + copied.StructureVersion = gtsptpr.StructureVersion + copied.Result = gtsptpr.Result.Copy().(*GlobalTradeStationDownloadPokemonResult) + copied.PrepareTradeKey = gtsptpr.PrepareTradeKey.Copy().(*GlobalTradeStationRecordKey) + + return copied +} + +// Equals checks if the given GlobalTradeStationPrepareTradePokemonResult contains the same data as the current GlobalTradeStationPrepareTradePokemonResult +func (gtsptpr *GlobalTradeStationPrepareTradePokemonResult) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationPrepareTradePokemonResult); !ok { + return false + } + + other := o.(*GlobalTradeStationPrepareTradePokemonResult) + + if gtsptpr.StructureVersion != other.StructureVersion { + return false + } + + if !gtsptpr.Result.Equals(other.Result) { + return false + } + + return gtsptpr.PrepareTradeKey.Equals(other.PrepareTradeKey) +} + +// String returns the string representation of the GlobalTradeStationPrepareTradePokemonResult +func (gtsptpr *GlobalTradeStationPrepareTradePokemonResult) String() string { + return gtsptpr.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationPrepareTradePokemonResult using the provided indentation level +func (gtsptpr *GlobalTradeStationPrepareTradePokemonResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationPrepareTradePokemonResult{\n") + b.WriteString(fmt.Sprintf("%sResult: %s,\n", indentationValues, gtsptpr.Result.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPrepareTradeKey: %s,\n", indentationValues, gtsptpr.PrepareTradeKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationPrepareTradePokemonResult returns a new GlobalTradeStationPrepareTradePokemonResult +func NewGlobalTradeStationPrepareTradePokemonResult() *GlobalTradeStationPrepareTradePokemonResult { + gtsptpr := &GlobalTradeStationPrepareTradePokemonResult{ + Result: NewGlobalTradeStationDownloadPokemonResult(), + PrepareTradeKey: NewGlobalTradeStationRecordKey(), + } + + return gtsptpr +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_record_key.go b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_record_key.go new file mode 100644 index 0000000..cae44a0 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_record_key.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationRecordKey is a type within the DataStore protocol +type GlobalTradeStationRecordKey struct { + types.Structure + DataID *types.PrimitiveU64 + Password *types.PrimitiveU64 +} + +// WriteTo writes the GlobalTradeStationRecordKey to the given writable +func (gtsrk *GlobalTradeStationRecordKey) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsrk.DataID.WriteTo(contentWritable) + gtsrk.Password.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsrk.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationRecordKey from the given readable +func (gtsrk *GlobalTradeStationRecordKey) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsrk.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationRecordKey header. %s", err.Error()) + } + + err = gtsrk.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationRecordKey.DataID. %s", err.Error()) + } + + err = gtsrk.Password.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationRecordKey.Password. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationRecordKey +func (gtsrk *GlobalTradeStationRecordKey) Copy() types.RVType { + copied := NewGlobalTradeStationRecordKey() + + copied.StructureVersion = gtsrk.StructureVersion + copied.DataID = gtsrk.DataID.Copy().(*types.PrimitiveU64) + copied.Password = gtsrk.Password.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given GlobalTradeStationRecordKey contains the same data as the current GlobalTradeStationRecordKey +func (gtsrk *GlobalTradeStationRecordKey) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationRecordKey); !ok { + return false + } + + other := o.(*GlobalTradeStationRecordKey) + + if gtsrk.StructureVersion != other.StructureVersion { + return false + } + + if !gtsrk.DataID.Equals(other.DataID) { + return false + } + + return gtsrk.Password.Equals(other.Password) +} + +// String returns the string representation of the GlobalTradeStationRecordKey +func (gtsrk *GlobalTradeStationRecordKey) String() string { + return gtsrk.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationRecordKey using the provided indentation level +func (gtsrk *GlobalTradeStationRecordKey) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationRecordKey{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, gtsrk.DataID)) + b.WriteString(fmt.Sprintf("%sPassword: %s,\n", indentationValues, gtsrk.Password)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationRecordKey returns a new GlobalTradeStationRecordKey +func NewGlobalTradeStationRecordKey() *GlobalTradeStationRecordKey { + gtsrk := &GlobalTradeStationRecordKey{ + DataID: types.NewPrimitiveU64(0), + Password: types.NewPrimitiveU64(0), + } + + return gtsrk +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_search_pokemon_param.go b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_search_pokemon_param.go new file mode 100644 index 0000000..e4c1561 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_search_pokemon_param.go @@ -0,0 +1,184 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationSearchPokemonParam is a type within the DataStore protocol +type GlobalTradeStationSearchPokemonParam struct { + types.Structure + PrepareUploadKey *GlobalTradeStationRecordKey + Conditions *types.List[*types.PrimitiveU32] + ResultOrderColumn *types.PrimitiveU8 + ResultOrder *types.PrimitiveU8 + UploadedAfter *types.DateTime + UploadedBefore *types.DateTime + ResultRange *types.ResultRange +} + +// WriteTo writes the GlobalTradeStationSearchPokemonParam to the given writable +func (gtsspp *GlobalTradeStationSearchPokemonParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsspp.PrepareUploadKey.WriteTo(contentWritable) + gtsspp.Conditions.WriteTo(contentWritable) + gtsspp.ResultOrderColumn.WriteTo(contentWritable) + gtsspp.ResultOrder.WriteTo(contentWritable) + gtsspp.UploadedAfter.WriteTo(contentWritable) + gtsspp.UploadedBefore.WriteTo(contentWritable) + gtsspp.ResultRange.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsspp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationSearchPokemonParam from the given readable +func (gtsspp *GlobalTradeStationSearchPokemonParam) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsspp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonParam header. %s", err.Error()) + } + + err = gtsspp.PrepareUploadKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonParam.PrepareUploadKey. %s", err.Error()) + } + + err = gtsspp.Conditions.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonParam.Conditions. %s", err.Error()) + } + + err = gtsspp.ResultOrderColumn.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonParam.ResultOrderColumn. %s", err.Error()) + } + + err = gtsspp.ResultOrder.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonParam.ResultOrder. %s", err.Error()) + } + + err = gtsspp.UploadedAfter.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonParam.UploadedAfter. %s", err.Error()) + } + + err = gtsspp.UploadedBefore.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonParam.UploadedBefore. %s", err.Error()) + } + + err = gtsspp.ResultRange.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonParam.ResultRange. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationSearchPokemonParam +func (gtsspp *GlobalTradeStationSearchPokemonParam) Copy() types.RVType { + copied := NewGlobalTradeStationSearchPokemonParam() + + copied.StructureVersion = gtsspp.StructureVersion + copied.PrepareUploadKey = gtsspp.PrepareUploadKey.Copy().(*GlobalTradeStationRecordKey) + copied.Conditions = gtsspp.Conditions.Copy().(*types.List[*types.PrimitiveU32]) + copied.ResultOrderColumn = gtsspp.ResultOrderColumn.Copy().(*types.PrimitiveU8) + copied.ResultOrder = gtsspp.ResultOrder.Copy().(*types.PrimitiveU8) + copied.UploadedAfter = gtsspp.UploadedAfter.Copy().(*types.DateTime) + copied.UploadedBefore = gtsspp.UploadedBefore.Copy().(*types.DateTime) + copied.ResultRange = gtsspp.ResultRange.Copy().(*types.ResultRange) + + return copied +} + +// Equals checks if the given GlobalTradeStationSearchPokemonParam contains the same data as the current GlobalTradeStationSearchPokemonParam +func (gtsspp *GlobalTradeStationSearchPokemonParam) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationSearchPokemonParam); !ok { + return false + } + + other := o.(*GlobalTradeStationSearchPokemonParam) + + if gtsspp.StructureVersion != other.StructureVersion { + return false + } + + if !gtsspp.PrepareUploadKey.Equals(other.PrepareUploadKey) { + return false + } + + if !gtsspp.Conditions.Equals(other.Conditions) { + return false + } + + if !gtsspp.ResultOrderColumn.Equals(other.ResultOrderColumn) { + return false + } + + if !gtsspp.ResultOrder.Equals(other.ResultOrder) { + return false + } + + if !gtsspp.UploadedAfter.Equals(other.UploadedAfter) { + return false + } + + if !gtsspp.UploadedBefore.Equals(other.UploadedBefore) { + return false + } + + return gtsspp.ResultRange.Equals(other.ResultRange) +} + +// String returns the string representation of the GlobalTradeStationSearchPokemonParam +func (gtsspp *GlobalTradeStationSearchPokemonParam) String() string { + return gtsspp.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationSearchPokemonParam using the provided indentation level +func (gtsspp *GlobalTradeStationSearchPokemonParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationSearchPokemonParam{\n") + b.WriteString(fmt.Sprintf("%sPrepareUploadKey: %s,\n", indentationValues, gtsspp.PrepareUploadKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sConditions: %s,\n", indentationValues, gtsspp.Conditions)) + b.WriteString(fmt.Sprintf("%sResultOrderColumn: %s,\n", indentationValues, gtsspp.ResultOrderColumn)) + b.WriteString(fmt.Sprintf("%sResultOrder: %s,\n", indentationValues, gtsspp.ResultOrder)) + b.WriteString(fmt.Sprintf("%sUploadedAfter: %s,\n", indentationValues, gtsspp.UploadedAfter.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUploadedBefore: %s,\n", indentationValues, gtsspp.UploadedBefore.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sResultRange: %s,\n", indentationValues, gtsspp.ResultRange.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationSearchPokemonParam returns a new GlobalTradeStationSearchPokemonParam +func NewGlobalTradeStationSearchPokemonParam() *GlobalTradeStationSearchPokemonParam { + gtsspp := &GlobalTradeStationSearchPokemonParam{ + PrepareUploadKey: NewGlobalTradeStationRecordKey(), + Conditions: types.NewList[*types.PrimitiveU32](), + ResultOrderColumn: types.NewPrimitiveU8(0), + ResultOrder: types.NewPrimitiveU8(0), + UploadedAfter: types.NewDateTime(0), + UploadedBefore: types.NewDateTime(0), + ResultRange: types.NewResultRange(), + } + + gtsspp.Conditions.Type = types.NewPrimitiveU32(0) + + return gtsspp +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_search_pokemon_result.go b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_search_pokemon_result.go new file mode 100644 index 0000000..b127ea6 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_search_pokemon_result.go @@ -0,0 +1,128 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationSearchPokemonResult is a type within the DataStore protocol +type GlobalTradeStationSearchPokemonResult struct { + types.Structure + TotalCount *types.PrimitiveU32 + Result *types.List[*GlobalTradeStationData] + TotalCountType *types.PrimitiveU8 +} + +// WriteTo writes the GlobalTradeStationSearchPokemonResult to the given writable +func (gtsspr *GlobalTradeStationSearchPokemonResult) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsspr.TotalCount.WriteTo(contentWritable) + gtsspr.Result.WriteTo(contentWritable) + gtsspr.TotalCountType.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsspr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationSearchPokemonResult from the given readable +func (gtsspr *GlobalTradeStationSearchPokemonResult) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsspr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonResult header. %s", err.Error()) + } + + err = gtsspr.TotalCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonResult.TotalCount. %s", err.Error()) + } + + err = gtsspr.Result.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonResult.Result. %s", err.Error()) + } + + err = gtsspr.TotalCountType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationSearchPokemonResult.TotalCountType. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationSearchPokemonResult +func (gtsspr *GlobalTradeStationSearchPokemonResult) Copy() types.RVType { + copied := NewGlobalTradeStationSearchPokemonResult() + + copied.StructureVersion = gtsspr.StructureVersion + copied.TotalCount = gtsspr.TotalCount.Copy().(*types.PrimitiveU32) + copied.Result = gtsspr.Result.Copy().(*types.List[*GlobalTradeStationData]) + copied.TotalCountType = gtsspr.TotalCountType.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given GlobalTradeStationSearchPokemonResult contains the same data as the current GlobalTradeStationSearchPokemonResult +func (gtsspr *GlobalTradeStationSearchPokemonResult) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationSearchPokemonResult); !ok { + return false + } + + other := o.(*GlobalTradeStationSearchPokemonResult) + + if gtsspr.StructureVersion != other.StructureVersion { + return false + } + + if !gtsspr.TotalCount.Equals(other.TotalCount) { + return false + } + + if !gtsspr.Result.Equals(other.Result) { + return false + } + + return gtsspr.TotalCountType.Equals(other.TotalCountType) +} + +// String returns the string representation of the GlobalTradeStationSearchPokemonResult +func (gtsspr *GlobalTradeStationSearchPokemonResult) String() string { + return gtsspr.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationSearchPokemonResult using the provided indentation level +func (gtsspr *GlobalTradeStationSearchPokemonResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationSearchPokemonResult{\n") + b.WriteString(fmt.Sprintf("%sTotalCount: %s,\n", indentationValues, gtsspr.TotalCount)) + b.WriteString(fmt.Sprintf("%sResult: %s,\n", indentationValues, gtsspr.Result)) + b.WriteString(fmt.Sprintf("%sTotalCountType: %s,\n", indentationValues, gtsspr.TotalCountType)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationSearchPokemonResult returns a new GlobalTradeStationSearchPokemonResult +func NewGlobalTradeStationSearchPokemonResult() *GlobalTradeStationSearchPokemonResult { + gtsspr := &GlobalTradeStationSearchPokemonResult{ + TotalCount: types.NewPrimitiveU32(0), + Result: types.NewList[*GlobalTradeStationData](), + TotalCountType: types.NewPrimitiveU8(0), + } + + gtsspr.Result.Type = NewGlobalTradeStationData() + + return gtsspr +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_trade_key.go b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_trade_key.go new file mode 100644 index 0000000..a15eaf9 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_trade_key.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationTradeKey is a type within the DataStore protocol +type GlobalTradeStationTradeKey struct { + types.Structure + DataID *types.PrimitiveU64 + Version *types.PrimitiveU32 +} + +// WriteTo writes the GlobalTradeStationTradeKey to the given writable +func (gtstk *GlobalTradeStationTradeKey) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtstk.DataID.WriteTo(contentWritable) + gtstk.Version.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtstk.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationTradeKey from the given readable +func (gtstk *GlobalTradeStationTradeKey) ExtractFrom(readable types.Readable) error { + var err error + + err = gtstk.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradeKey header. %s", err.Error()) + } + + err = gtstk.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradeKey.DataID. %s", err.Error()) + } + + err = gtstk.Version.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradeKey.Version. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationTradeKey +func (gtstk *GlobalTradeStationTradeKey) Copy() types.RVType { + copied := NewGlobalTradeStationTradeKey() + + copied.StructureVersion = gtstk.StructureVersion + copied.DataID = gtstk.DataID.Copy().(*types.PrimitiveU64) + copied.Version = gtstk.Version.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given GlobalTradeStationTradeKey contains the same data as the current GlobalTradeStationTradeKey +func (gtstk *GlobalTradeStationTradeKey) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationTradeKey); !ok { + return false + } + + other := o.(*GlobalTradeStationTradeKey) + + if gtstk.StructureVersion != other.StructureVersion { + return false + } + + if !gtstk.DataID.Equals(other.DataID) { + return false + } + + return gtstk.Version.Equals(other.Version) +} + +// String returns the string representation of the GlobalTradeStationTradeKey +func (gtstk *GlobalTradeStationTradeKey) String() string { + return gtstk.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationTradeKey using the provided indentation level +func (gtstk *GlobalTradeStationTradeKey) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationTradeKey{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, gtstk.DataID)) + b.WriteString(fmt.Sprintf("%sVersion: %s,\n", indentationValues, gtstk.Version)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationTradeKey returns a new GlobalTradeStationTradeKey +func NewGlobalTradeStationTradeKey() *GlobalTradeStationTradeKey { + gtstk := &GlobalTradeStationTradeKey{ + DataID: types.NewPrimitiveU64(0), + Version: types.NewPrimitiveU32(0), + } + + return gtstk +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_trade_pokemon_param.go b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_trade_pokemon_param.go new file mode 100644 index 0000000..6073a9f --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_trade_pokemon_param.go @@ -0,0 +1,196 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationTradePokemonParam is a type within the DataStore protocol +type GlobalTradeStationTradePokemonParam struct { + types.Structure + TradeKey *GlobalTradeStationTradeKey + PrepareTradeKey *GlobalTradeStationRecordKey + PrepareUploadKey *GlobalTradeStationRecordKey + Period *types.PrimitiveU16 + IndexData *types.QBuffer + PokemonData *types.QBuffer + Signature *types.QBuffer + NeedData *types.PrimitiveBool +} + +// WriteTo writes the GlobalTradeStationTradePokemonParam to the given writable +func (gtstpp *GlobalTradeStationTradePokemonParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtstpp.TradeKey.WriteTo(contentWritable) + gtstpp.PrepareTradeKey.WriteTo(contentWritable) + gtstpp.PrepareUploadKey.WriteTo(contentWritable) + gtstpp.Period.WriteTo(contentWritable) + gtstpp.IndexData.WriteTo(contentWritable) + gtstpp.PokemonData.WriteTo(contentWritable) + gtstpp.Signature.WriteTo(contentWritable) + gtstpp.NeedData.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtstpp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationTradePokemonParam from the given readable +func (gtstpp *GlobalTradeStationTradePokemonParam) ExtractFrom(readable types.Readable) error { + var err error + + err = gtstpp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam header. %s", err.Error()) + } + + err = gtstpp.TradeKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam.TradeKey. %s", err.Error()) + } + + err = gtstpp.PrepareTradeKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam.PrepareTradeKey. %s", err.Error()) + } + + err = gtstpp.PrepareUploadKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam.PrepareUploadKey. %s", err.Error()) + } + + err = gtstpp.Period.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam.Period. %s", err.Error()) + } + + err = gtstpp.IndexData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam.IndexData. %s", err.Error()) + } + + err = gtstpp.PokemonData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam.PokemonData. %s", err.Error()) + } + + err = gtstpp.Signature.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam.Signature. %s", err.Error()) + } + + err = gtstpp.NeedData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonParam.NeedData. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationTradePokemonParam +func (gtstpp *GlobalTradeStationTradePokemonParam) Copy() types.RVType { + copied := NewGlobalTradeStationTradePokemonParam() + + copied.StructureVersion = gtstpp.StructureVersion + copied.TradeKey = gtstpp.TradeKey.Copy().(*GlobalTradeStationTradeKey) + copied.PrepareTradeKey = gtstpp.PrepareTradeKey.Copy().(*GlobalTradeStationRecordKey) + copied.PrepareUploadKey = gtstpp.PrepareUploadKey.Copy().(*GlobalTradeStationRecordKey) + copied.Period = gtstpp.Period.Copy().(*types.PrimitiveU16) + copied.IndexData = gtstpp.IndexData.Copy().(*types.QBuffer) + copied.PokemonData = gtstpp.PokemonData.Copy().(*types.QBuffer) + copied.Signature = gtstpp.Signature.Copy().(*types.QBuffer) + copied.NeedData = gtstpp.NeedData.Copy().(*types.PrimitiveBool) + + return copied +} + +// Equals checks if the given GlobalTradeStationTradePokemonParam contains the same data as the current GlobalTradeStationTradePokemonParam +func (gtstpp *GlobalTradeStationTradePokemonParam) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationTradePokemonParam); !ok { + return false + } + + other := o.(*GlobalTradeStationTradePokemonParam) + + if gtstpp.StructureVersion != other.StructureVersion { + return false + } + + if !gtstpp.TradeKey.Equals(other.TradeKey) { + return false + } + + if !gtstpp.PrepareTradeKey.Equals(other.PrepareTradeKey) { + return false + } + + if !gtstpp.PrepareUploadKey.Equals(other.PrepareUploadKey) { + return false + } + + if !gtstpp.Period.Equals(other.Period) { + return false + } + + if !gtstpp.IndexData.Equals(other.IndexData) { + return false + } + + if !gtstpp.PokemonData.Equals(other.PokemonData) { + return false + } + + if !gtstpp.Signature.Equals(other.Signature) { + return false + } + + return gtstpp.NeedData.Equals(other.NeedData) +} + +// String returns the string representation of the GlobalTradeStationTradePokemonParam +func (gtstpp *GlobalTradeStationTradePokemonParam) String() string { + return gtstpp.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationTradePokemonParam using the provided indentation level +func (gtstpp *GlobalTradeStationTradePokemonParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationTradePokemonParam{\n") + b.WriteString(fmt.Sprintf("%sTradeKey: %s,\n", indentationValues, gtstpp.TradeKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPrepareTradeKey: %s,\n", indentationValues, gtstpp.PrepareTradeKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPrepareUploadKey: %s,\n", indentationValues, gtstpp.PrepareUploadKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPeriod: %s,\n", indentationValues, gtstpp.Period)) + b.WriteString(fmt.Sprintf("%sIndexData: %s,\n", indentationValues, gtstpp.IndexData)) + b.WriteString(fmt.Sprintf("%sPokemonData: %s,\n", indentationValues, gtstpp.PokemonData)) + b.WriteString(fmt.Sprintf("%sSignature: %s,\n", indentationValues, gtstpp.Signature)) + b.WriteString(fmt.Sprintf("%sNeedData: %s,\n", indentationValues, gtstpp.NeedData)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationTradePokemonParam returns a new GlobalTradeStationTradePokemonParam +func NewGlobalTradeStationTradePokemonParam() *GlobalTradeStationTradePokemonParam { + gtstpp := &GlobalTradeStationTradePokemonParam{ + TradeKey: NewGlobalTradeStationTradeKey(), + PrepareTradeKey: NewGlobalTradeStationRecordKey(), + PrepareUploadKey: NewGlobalTradeStationRecordKey(), + Period: types.NewPrimitiveU16(0), + IndexData: types.NewQBuffer(nil), + PokemonData: types.NewQBuffer(nil), + Signature: types.NewQBuffer(nil), + NeedData: types.NewPrimitiveBool(false), + } + + return gtstpp +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_trade_pokemon_result.go b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_trade_pokemon_result.go new file mode 100644 index 0000000..82d838a --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_trade_pokemon_result.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationTradePokemonResult is a type within the DataStore protocol +type GlobalTradeStationTradePokemonResult struct { + types.Structure + Result *GlobalTradeStationDownloadPokemonResult + MyDataID *types.PrimitiveU64 +} + +// WriteTo writes the GlobalTradeStationTradePokemonResult to the given writable +func (gtstpr *GlobalTradeStationTradePokemonResult) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtstpr.Result.WriteTo(contentWritable) + gtstpr.MyDataID.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtstpr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationTradePokemonResult from the given readable +func (gtstpr *GlobalTradeStationTradePokemonResult) ExtractFrom(readable types.Readable) error { + var err error + + err = gtstpr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonResult header. %s", err.Error()) + } + + err = gtstpr.Result.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonResult.Result. %s", err.Error()) + } + + err = gtstpr.MyDataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationTradePokemonResult.MyDataID. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationTradePokemonResult +func (gtstpr *GlobalTradeStationTradePokemonResult) Copy() types.RVType { + copied := NewGlobalTradeStationTradePokemonResult() + + copied.StructureVersion = gtstpr.StructureVersion + copied.Result = gtstpr.Result.Copy().(*GlobalTradeStationDownloadPokemonResult) + copied.MyDataID = gtstpr.MyDataID.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given GlobalTradeStationTradePokemonResult contains the same data as the current GlobalTradeStationTradePokemonResult +func (gtstpr *GlobalTradeStationTradePokemonResult) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationTradePokemonResult); !ok { + return false + } + + other := o.(*GlobalTradeStationTradePokemonResult) + + if gtstpr.StructureVersion != other.StructureVersion { + return false + } + + if !gtstpr.Result.Equals(other.Result) { + return false + } + + return gtstpr.MyDataID.Equals(other.MyDataID) +} + +// String returns the string representation of the GlobalTradeStationTradePokemonResult +func (gtstpr *GlobalTradeStationTradePokemonResult) String() string { + return gtstpr.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationTradePokemonResult using the provided indentation level +func (gtstpr *GlobalTradeStationTradePokemonResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationTradePokemonResult{\n") + b.WriteString(fmt.Sprintf("%sResult: %s,\n", indentationValues, gtstpr.Result.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sMyDataID: %s,\n", indentationValues, gtstpr.MyDataID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationTradePokemonResult returns a new GlobalTradeStationTradePokemonResult +func NewGlobalTradeStationTradePokemonResult() *GlobalTradeStationTradePokemonResult { + gtstpr := &GlobalTradeStationTradePokemonResult{ + Result: NewGlobalTradeStationDownloadPokemonResult(), + MyDataID: types.NewPrimitiveU64(0), + } + + return gtstpr +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_upload_pokemon_param.go b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_upload_pokemon_param.go new file mode 100644 index 0000000..492037f --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/types/global_trade_station_upload_pokemon_param.go @@ -0,0 +1,154 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GlobalTradeStationUploadPokemonParam is a type within the DataStore protocol +type GlobalTradeStationUploadPokemonParam struct { + types.Structure + PrepareUploadKey *GlobalTradeStationRecordKey + Period *types.PrimitiveU16 + IndexData *types.QBuffer + PokemonData *types.QBuffer + Signature *types.QBuffer +} + +// WriteTo writes the GlobalTradeStationUploadPokemonParam to the given writable +func (gtsupp *GlobalTradeStationUploadPokemonParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gtsupp.PrepareUploadKey.WriteTo(contentWritable) + gtsupp.Period.WriteTo(contentWritable) + gtsupp.IndexData.WriteTo(contentWritable) + gtsupp.PokemonData.WriteTo(contentWritable) + gtsupp.Signature.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gtsupp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GlobalTradeStationUploadPokemonParam from the given readable +func (gtsupp *GlobalTradeStationUploadPokemonParam) ExtractFrom(readable types.Readable) error { + var err error + + err = gtsupp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationUploadPokemonParam header. %s", err.Error()) + } + + err = gtsupp.PrepareUploadKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationUploadPokemonParam.PrepareUploadKey. %s", err.Error()) + } + + err = gtsupp.Period.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationUploadPokemonParam.Period. %s", err.Error()) + } + + err = gtsupp.IndexData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationUploadPokemonParam.IndexData. %s", err.Error()) + } + + err = gtsupp.PokemonData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationUploadPokemonParam.PokemonData. %s", err.Error()) + } + + err = gtsupp.Signature.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GlobalTradeStationUploadPokemonParam.Signature. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GlobalTradeStationUploadPokemonParam +func (gtsupp *GlobalTradeStationUploadPokemonParam) Copy() types.RVType { + copied := NewGlobalTradeStationUploadPokemonParam() + + copied.StructureVersion = gtsupp.StructureVersion + copied.PrepareUploadKey = gtsupp.PrepareUploadKey.Copy().(*GlobalTradeStationRecordKey) + copied.Period = gtsupp.Period.Copy().(*types.PrimitiveU16) + copied.IndexData = gtsupp.IndexData.Copy().(*types.QBuffer) + copied.PokemonData = gtsupp.PokemonData.Copy().(*types.QBuffer) + copied.Signature = gtsupp.Signature.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given GlobalTradeStationUploadPokemonParam contains the same data as the current GlobalTradeStationUploadPokemonParam +func (gtsupp *GlobalTradeStationUploadPokemonParam) Equals(o types.RVType) bool { + if _, ok := o.(*GlobalTradeStationUploadPokemonParam); !ok { + return false + } + + other := o.(*GlobalTradeStationUploadPokemonParam) + + if gtsupp.StructureVersion != other.StructureVersion { + return false + } + + if !gtsupp.PrepareUploadKey.Equals(other.PrepareUploadKey) { + return false + } + + if !gtsupp.Period.Equals(other.Period) { + return false + } + + if !gtsupp.IndexData.Equals(other.IndexData) { + return false + } + + if !gtsupp.PokemonData.Equals(other.PokemonData) { + return false + } + + return gtsupp.Signature.Equals(other.Signature) +} + +// String returns the string representation of the GlobalTradeStationUploadPokemonParam +func (gtsupp *GlobalTradeStationUploadPokemonParam) String() string { + return gtsupp.FormatToString(0) +} + +// FormatToString pretty-prints the GlobalTradeStationUploadPokemonParam using the provided indentation level +func (gtsupp *GlobalTradeStationUploadPokemonParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GlobalTradeStationUploadPokemonParam{\n") + b.WriteString(fmt.Sprintf("%sPrepareUploadKey: %s,\n", indentationValues, gtsupp.PrepareUploadKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPeriod: %s,\n", indentationValues, gtsupp.Period)) + b.WriteString(fmt.Sprintf("%sIndexData: %s,\n", indentationValues, gtsupp.IndexData)) + b.WriteString(fmt.Sprintf("%sPokemonData: %s,\n", indentationValues, gtsupp.PokemonData)) + b.WriteString(fmt.Sprintf("%sSignature: %s,\n", indentationValues, gtsupp.Signature)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGlobalTradeStationUploadPokemonParam returns a new GlobalTradeStationUploadPokemonParam +func NewGlobalTradeStationUploadPokemonParam() *GlobalTradeStationUploadPokemonParam { + gtsupp := &GlobalTradeStationUploadPokemonParam{ + PrepareUploadKey: NewGlobalTradeStationRecordKey(), + Period: types.NewPrimitiveU16(0), + IndexData: types.NewQBuffer(nil), + PokemonData: types.NewQBuffer(nil), + Signature: types.NewQBuffer(nil), + } + + return gtsupp +} diff --git a/nex-protocols-go/datastore/pokemon-gen6/upload_pokemon.go b/nex-protocols-go/datastore/pokemon-gen6/upload_pokemon.go new file mode 100644 index 0000000..891fa65 --- /dev/null +++ b/nex-protocols-go/datastore/pokemon-gen6/upload_pokemon.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStorePokemonGen6 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_pokemon_gen6_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/pokemon-gen6/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUploadPokemon(packet nex.PacketInterface) { + if protocol.UploadPokemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStorePokemonGen6::UploadPokemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_pokemon_gen6_types.NewGlobalTradeStationUploadPokemonParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UploadPokemon(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UploadPokemon(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/post_meta_binaries_with_data_id.go b/nex-protocols-go/datastore/post_meta_binaries_with_data_id.go new file mode 100644 index 0000000..577b31b --- /dev/null +++ b/nex-protocols-go/datastore/post_meta_binaries_with_data_id.go @@ -0,0 +1,74 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePostMetaBinariesWithDataID(packet nex.PacketInterface) { + if protocol.PostMetaBinariesWithDataID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::PostMetaBinariesWithDataID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + dataIDs := types.NewList[*types.PrimitiveU64]() + dataIDs.Type = types.NewPrimitiveU64(0) + params := types.NewList[*datastore_types.DataStorePreparePostParam]() + params.Type = datastore_types.NewDataStorePreparePostParam() + transactional := types.NewPrimitiveBool(false) + + var err error + + err = dataIDs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PostMetaBinariesWithDataID(fmt.Errorf("Failed to read dataIDs from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = params.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PostMetaBinariesWithDataID(fmt.Errorf("Failed to read params from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = transactional.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PostMetaBinariesWithDataID(fmt.Errorf("Failed to read transactional from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PostMetaBinariesWithDataID(nil, packet, callID, dataIDs, params, transactional) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/post_meta_binary.go b/nex-protocols-go/datastore/post_meta_binary.go new file mode 100644 index 0000000..46565c3 --- /dev/null +++ b/nex-protocols-go/datastore/post_meta_binary.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePostMetaBinary(packet nex.PacketInterface) { + if protocol.PostMetaBinary == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::PostMetaBinary not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStorePreparePostParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PostMetaBinary(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PostMetaBinary(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/post_meta_binary_with_data_id.go b/nex-protocols-go/datastore/post_meta_binary_with_data_id.go new file mode 100644 index 0000000..3d1ff34 --- /dev/null +++ b/nex-protocols-go/datastore/post_meta_binary_with_data_id.go @@ -0,0 +1,61 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePostMetaBinaryWithDataID(packet nex.PacketInterface) { + if protocol.PostMetaBinaryWithDataID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::PostMetaBinaryWithDataID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + dataID := types.NewPrimitiveU64(0) + param := datastore_types.NewDataStorePreparePostParam() + + var err error + + err = dataID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PostMetaBinaryWithDataID(fmt.Errorf("Failed to read dataID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PostMetaBinaryWithDataID(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PostMetaBinaryWithDataID(nil, packet, callID, dataID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/prepare_get_object.go b/nex-protocols-go/datastore/prepare_get_object.go new file mode 100644 index 0000000..e64c0a5 --- /dev/null +++ b/nex-protocols-go/datastore/prepare_get_object.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePrepareGetObject(packet nex.PacketInterface) { + if protocol.PrepareGetObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::PrepareGetObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStorePrepareGetParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PrepareGetObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PrepareGetObject(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/prepare_get_object_or_meta_binary.go b/nex-protocols-go/datastore/prepare_get_object_or_meta_binary.go new file mode 100644 index 0000000..0e488fd --- /dev/null +++ b/nex-protocols-go/datastore/prepare_get_object_or_meta_binary.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePrepareGetObjectOrMetaBinary(packet nex.PacketInterface) { + if protocol.PrepareGetObjectOrMetaBinary == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::PrepareGetObjectOrMetaBinary not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStorePrepareGetParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PrepareGetObjectOrMetaBinary(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PrepareGetObjectOrMetaBinary(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/prepare_get_object_v1.go b/nex-protocols-go/datastore/prepare_get_object_v1.go new file mode 100644 index 0000000..d0f0d1c --- /dev/null +++ b/nex-protocols-go/datastore/prepare_get_object_v1.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePrepareGetObjectV1(packet nex.PacketInterface) { + if protocol.PrepareGetObjectV1 == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::PrepareGetObjectV1 not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStorePrepareGetParamV1() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PrepareGetObjectV1(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PrepareGetObjectV1(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/prepare_post_object.go b/nex-protocols-go/datastore/prepare_post_object.go new file mode 100644 index 0000000..8845ccd --- /dev/null +++ b/nex-protocols-go/datastore/prepare_post_object.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePreparePostObject(packet nex.PacketInterface) { + if protocol.PreparePostObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::PreparePostObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStorePreparePostParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PreparePostObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PreparePostObject(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/prepare_post_object_v1.go b/nex-protocols-go/datastore/prepare_post_object_v1.go new file mode 100644 index 0000000..7c105de --- /dev/null +++ b/nex-protocols-go/datastore/prepare_post_object_v1.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePreparePostObjectV1(packet nex.PacketInterface) { + if protocol.PreparePostObjectV1 == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::PreparePostObjectV1 not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStorePreparePostParamV1() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PreparePostObjectV1(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PreparePostObjectV1(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/prepare_update_object.go b/nex-protocols-go/datastore/prepare_update_object.go new file mode 100644 index 0000000..a1dcc28 --- /dev/null +++ b/nex-protocols-go/datastore/prepare_update_object.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePrepareUpdateObject(packet nex.PacketInterface) { + if protocol.PrepareUpdateObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::PrepareUpdateObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStorePrepareUpdateParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PrepareUpdateObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PrepareUpdateObject(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/protocol.go b/nex-protocols-go/datastore/protocol.go new file mode 100644 index 0000000..02c6853 --- /dev/null +++ b/nex-protocols-go/datastore/protocol.go @@ -0,0 +1,620 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the DataStore protocol + ProtocolID = 0x73 + + // MethodPrepareGetObjectV1 is the method ID for the method PrepareGetObjectV1 + MethodPrepareGetObjectV1 = 0x1 + + // MethodPreparePostObjectV1 is the method ID for the method PreparePostObjectV1 + MethodPreparePostObjectV1 = 0x2 + + // MethodCompletePostObjectV1 is the method ID for the method CompletePostObjectV1 + MethodCompletePostObjectV1 = 0x3 + + // MethodDeleteObject is the method ID for the method DeleteObject + MethodDeleteObject = 0x4 + + // MethodDeleteObjects is the method ID for the method DeleteObjects + MethodDeleteObjects = 0x5 + + // MethodChangeMetaV1 is the method ID for the method ChangeMetaV1 + MethodChangeMetaV1 = 0x6 + + // MethodChangeMetasV1 is the method ID for the method ChangeMetasV1 + MethodChangeMetasV1 = 0x7 + + // MethodGetMeta is the method ID for the method GetMeta + MethodGetMeta = 0x8 + + // MethodGetMetas is the method ID for the method GetMetas + MethodGetMetas = 0x9 + + // MethodPrepareUpdateObject is the method ID for the method PrepareUpdateObject + MethodPrepareUpdateObject = 0xA + + // MethodCompleteUpdateObject is the method ID for the method CompleteUpdateObject + MethodCompleteUpdateObject = 0xB + + // MethodSearchObject is the method ID for the method SearchObject + MethodSearchObject = 0xC + + // MethodGetNotificationURL is the method ID for the method GetNotificationURL + MethodGetNotificationURL = 0xD + + // MethodGetNewArrivedNotificationsV1 is the method ID for the method GetNewArrivedNotificationsV1 + MethodGetNewArrivedNotificationsV1 = 0xE + + // MethodRateObject is the method ID for the method RateObject + MethodRateObject = 0xF + + // MethodGetRating is the method ID for the method GetRating + MethodGetRating = 0x10 + + // MethodGetRatings is the method ID for the method GetRatings + MethodGetRatings = 0x11 + + // MethodResetRating is the method ID for the method ResetRating + MethodResetRating = 0x12 + + // MethodResetRatings is the method ID for the method ResetRatings + MethodResetRatings = 0x13 + + // MethodGetSpecificMetaV1 is the method ID for the method GetSpecificMetaV1 + MethodGetSpecificMetaV1 = 0x14 + + // MethodPostMetaBinary is the method ID for the method PostMetaBinary + MethodPostMetaBinary = 0x15 + + // MethodTouchObject is the method ID for the method TouchObject + MethodTouchObject = 0x16 + + // MethodGetRatingWithLog is the method ID for the method GetRatingWithLog + MethodGetRatingWithLog = 0x17 + + // MethodPreparePostObject is the method ID for the method PreparePostObject + MethodPreparePostObject = 0x18 + + // MethodPrepareGetObject is the method ID for the method PrepareGetObject + MethodPrepareGetObject = 0x19 + + // MethodCompletePostObject is the method ID for the method CompletePostObject + MethodCompletePostObject = 0x1A + + // MethodGetNewArrivedNotifications is the method ID for the method GetNewArrivedNotifications + MethodGetNewArrivedNotifications = 0x1B + + // MethodGetSpecificMeta is the method ID for the method GetSpecificMeta + MethodGetSpecificMeta = 0x1C + + // MethodGetPersistenceInfo is the method ID for the method GetPersistenceInfo + MethodGetPersistenceInfo = 0x1D + + // MethodGetPersistenceInfos is the method ID for the method GetPersistenceInfos + MethodGetPersistenceInfos = 0x1E + + // MethodPerpetuateObject is the method ID for the method PerpetuateObject + MethodPerpetuateObject = 0x1F + + // MethodUnperpetuateObject is the method ID for the method UnperpetuateObject + MethodUnperpetuateObject = 0x20 + + // MethodPrepareGetObjectOrMetaBinary is the method ID for the method PrepareGetObjectOrMetaBinary + MethodPrepareGetObjectOrMetaBinary = 0x21 + + // MethodGetPasswordInfo is the method ID for the method GetPasswordInfo + MethodGetPasswordInfo = 0x22 + + // MethodGetPasswordInfos is the method ID for the method GetPasswordInfos + MethodGetPasswordInfos = 0x23 + + // MethodGetMetasMultipleParam is the method ID for the method GetMetasMultipleParam + MethodGetMetasMultipleParam = 0x24 + + // MethodCompletePostObjects is the method ID for the method CompletePostObjects + MethodCompletePostObjects = 0x25 + + // MethodChangeMeta is the method ID for the method ChangeMeta + MethodChangeMeta = 0x26 + + // MethodChangeMetas is the method ID for the method ChangeMetas + MethodChangeMetas = 0x27 + + // MethodRateObjects is the method ID for the method RateObjects + MethodRateObjects = 0x28 + + // MethodPostMetaBinaryWithDataID is the method ID for the method PostMetaBinaryWithDataID + MethodPostMetaBinaryWithDataID = 0x29 + + // MethodPostMetaBinariesWithDataID is the method ID for the method PostMetaBinariesWithDataID + MethodPostMetaBinariesWithDataID = 0x2A + + // MethodRateObjectWithPosting is the method ID for the method RateObjectWithPosting + MethodRateObjectWithPosting = 0x2B + + // MethodRateObjectsWithPosting is the method ID for the method RateObjectsWithPosting + MethodRateObjectsWithPosting = 0x2C + + // MethodGetObjectInfos is the method ID for the method GetObjectInfos + MethodGetObjectInfos = 0x2D + + // MethodSearchObjectLight is the method ID for the method SearchObjectLight + MethodSearchObjectLight = 0x2E +) + +// Protocol stores all the RMC method handlers for the DataStore protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + PrepareGetObjectV1 func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePrepareGetParamV1) (*nex.RMCMessage, *nex.Error) + PreparePostObjectV1 func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePreparePostParamV1) (*nex.RMCMessage, *nex.Error) + CompletePostObjectV1 func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreCompletePostParamV1) (*nex.RMCMessage, *nex.Error) + DeleteObject func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreDeleteParam) (*nex.RMCMessage, *nex.Error) + DeleteObjects func(err error, packet nex.PacketInterface, callID uint32, params *types.List[*datastore_types.DataStoreDeleteParam], transactional *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + ChangeMetaV1 func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreChangeMetaParamV1) (*nex.RMCMessage, *nex.Error) + ChangeMetasV1 func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], params *types.List[*datastore_types.DataStoreChangeMetaParamV1], transactional *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + GetMeta func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error) + GetMetas func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], param *datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error) + PrepareUpdateObject func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePrepareUpdateParam) (*nex.RMCMessage, *nex.Error) + CompleteUpdateObject func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreCompleteUpdateParam) (*nex.RMCMessage, *nex.Error) + SearchObject func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam) (*nex.RMCMessage, *nex.Error) + GetNotificationURL func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetNotificationURLParam) (*nex.RMCMessage, *nex.Error) + GetNewArrivedNotificationsV1 func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetNewArrivedNotificationsParam) (*nex.RMCMessage, *nex.Error) + RateObject func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, param *datastore_types.DataStoreRateObjectParam, fetchRatings *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + GetRating func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, accessPassword *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + GetRatings func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], accessPassword *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + ResetRating func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, accessPassword *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + ResetRatings func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, transactional *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + GetSpecificMetaV1 func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetSpecificMetaParamV1) (*nex.RMCMessage, *nex.Error) + PostMetaBinary func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error) + TouchObject func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreTouchObjectParam) (*nex.RMCMessage, *nex.Error) + GetRatingWithLog func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, accessPassword *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + PreparePostObject func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error) + PrepareGetObject func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePrepareGetParam) (*nex.RMCMessage, *nex.Error) + CompletePostObject func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreCompletePostParam) (*nex.RMCMessage, *nex.Error) + GetNewArrivedNotifications func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetNewArrivedNotificationsParam) (*nex.RMCMessage, *nex.Error) + GetSpecificMeta func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetSpecificMetaParam) (*nex.RMCMessage, *nex.Error) + GetPersistenceInfo func(err error, packet nex.PacketInterface, callID uint32, ownerID *types.PID, persistenceSlotID *types.PrimitiveU16) (*nex.RMCMessage, *nex.Error) + GetPersistenceInfos func(err error, packet nex.PacketInterface, callID uint32, ownerID *types.PID, persistenceSlotIDs *types.List[*types.PrimitiveU16]) (*nex.RMCMessage, *nex.Error) + PerpetuateObject func(err error, packet nex.PacketInterface, callID uint32, persistenceSlotID *types.PrimitiveU16, dataID *types.PrimitiveU64, deleteLastObject *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + UnperpetuateObject func(err error, packet nex.PacketInterface, callID uint32, persistenceSlotID *types.PrimitiveU16, deleteLastObject *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + PrepareGetObjectOrMetaBinary func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePrepareGetParam) (*nex.RMCMessage, *nex.Error) + GetPasswordInfo func(err error, packet nex.PacketInterface, callID uint32, dataID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + GetPasswordInfos func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error) + GetMetasMultipleParam func(err error, packet nex.PacketInterface, callID uint32, params *types.List[*datastore_types.DataStoreGetMetaParam]) (*nex.RMCMessage, *nex.Error) + CompletePostObjects func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error) + ChangeMeta func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreChangeMetaParam) (*nex.RMCMessage, *nex.Error) + ChangeMetas func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], params *types.List[*datastore_types.DataStoreChangeMetaParam], transactional *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + RateObjects func(err error, packet nex.PacketInterface, callID uint32, targets *types.List[*datastore_types.DataStoreRatingTarget], params *types.List[*datastore_types.DataStoreRateObjectParam], transactional *types.PrimitiveBool, fetchRatings *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + PostMetaBinaryWithDataID func(err error, packet nex.PacketInterface, callID uint32, dataID *types.PrimitiveU64, param *datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error) + PostMetaBinariesWithDataID func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], params *types.List[*datastore_types.DataStorePreparePostParam], transactional *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + RateObjectWithPosting func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, rateParam *datastore_types.DataStoreRateObjectParam, postParam *datastore_types.DataStorePreparePostParam, fetchRatings *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + RateObjectsWithPosting func(err error, packet nex.PacketInterface, callID uint32, targets *types.List[*datastore_types.DataStoreRatingTarget], rateParams *types.List[*datastore_types.DataStoreRateObjectParam], postParams *types.List[*datastore_types.DataStorePreparePostParam], transactional *types.PrimitiveBool, fetchRatings *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + GetObjectInfos func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + SearchObjectLight func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the DataStore Protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerPrepareGetObjectV1(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePrepareGetParamV1) (*nex.RMCMessage, *nex.Error)) + SetHandlerPreparePostObjectV1(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePreparePostParamV1) (*nex.RMCMessage, *nex.Error)) + SetHandlerCompletePostObjectV1(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreCompletePostParamV1) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeleteObject(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreDeleteParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeleteObjects(handler func(err error, packet nex.PacketInterface, callID uint32, params *types.List[*datastore_types.DataStoreDeleteParam], transactional *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerChangeMetaV1(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreChangeMetaParamV1) (*nex.RMCMessage, *nex.Error)) + SetHandlerChangeMetasV1(handler func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], params *types.List[*datastore_types.DataStoreChangeMetaParamV1], transactional *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetMeta(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetMetas(handler func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], param *datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerPrepareUpdateObject(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePrepareUpdateParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerCompleteUpdateObject(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreCompleteUpdateParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerSearchObject(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetNotificationURL(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetNotificationURLParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetNewArrivedNotificationsV1(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetNewArrivedNotificationsParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerRateObject(handler func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, param *datastore_types.DataStoreRateObjectParam, fetchRatings *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetRating(handler func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, accessPassword *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetRatings(handler func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], accessPassword *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerResetRating(handler func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, accessPassword *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerResetRatings(handler func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, transactional *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetSpecificMetaV1(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetSpecificMetaParamV1) (*nex.RMCMessage, *nex.Error)) + SetHandlerPostMetaBinary(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerTouchObject(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreTouchObjectParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetRatingWithLog(handler func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, accessPassword *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerPreparePostObject(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerPrepareGetObject(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePrepareGetParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerCompletePostObject(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreCompletePostParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetNewArrivedNotifications(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetNewArrivedNotificationsParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetSpecificMeta(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetSpecificMetaParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetPersistenceInfo(handler func(err error, packet nex.PacketInterface, callID uint32, ownerID *types.PID, persistenceSlotID *types.PrimitiveU16) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetPersistenceInfos(handler func(err error, packet nex.PacketInterface, callID uint32, ownerID *types.PID, persistenceSlotIDs *types.List[*types.PrimitiveU16]) (*nex.RMCMessage, *nex.Error)) + SetHandlerPerpetuateObject(handler func(err error, packet nex.PacketInterface, callID uint32, persistenceSlotID *types.PrimitiveU16, dataID *types.PrimitiveU64, deleteLastObject *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerUnperpetuateObject(handler func(err error, packet nex.PacketInterface, callID uint32, persistenceSlotID *types.PrimitiveU16, deleteLastObject *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerPrepareGetObjectOrMetaBinary(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePrepareGetParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetPasswordInfo(handler func(err error, packet nex.PacketInterface, callID uint32, dataID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetPasswordInfos(handler func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetMetasMultipleParam(handler func(err error, packet nex.PacketInterface, callID uint32, params *types.List[*datastore_types.DataStoreGetMetaParam]) (*nex.RMCMessage, *nex.Error)) + SetHandlerCompletePostObjects(handler func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error)) + SetHandlerChangeMeta(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreChangeMetaParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerChangeMetas(handler func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], params *types.List[*datastore_types.DataStoreChangeMetaParam], transactional *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerRateObjects(handler func(err error, packet nex.PacketInterface, callID uint32, targets *types.List[*datastore_types.DataStoreRatingTarget], params *types.List[*datastore_types.DataStoreRateObjectParam], transactional *types.PrimitiveBool, fetchRatings *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerPostMetaBinaryWithDataID(handler func(err error, packet nex.PacketInterface, callID uint32, dataID *types.PrimitiveU64, param *datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerPostMetaBinariesWithDataID(handler func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], params *types.List[*datastore_types.DataStorePreparePostParam], transactional *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerRateObjectWithPosting(handler func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, rateParam *datastore_types.DataStoreRateObjectParam, postParam *datastore_types.DataStorePreparePostParam, fetchRatings *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerRateObjectsWithPosting(handler func(err error, packet nex.PacketInterface, callID uint32, targets *types.List[*datastore_types.DataStoreRatingTarget], rateParams *types.List[*datastore_types.DataStoreRateObjectParam], postParams *types.List[*datastore_types.DataStorePreparePostParam], transactional *types.PrimitiveBool, fetchRatings *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetObjectInfos(handler func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerSearchObjectLight(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerPrepareGetObjectV1 sets the handler for the PrepareGetObjectV1 method +func (protocol *Protocol) SetHandlerPrepareGetObjectV1(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePrepareGetParamV1) (*nex.RMCMessage, *nex.Error)) { + protocol.PrepareGetObjectV1 = handler +} + +// SetHandlerPreparePostObjectV1 sets the handler for the PreparePostObjectV1 method +func (protocol *Protocol) SetHandlerPreparePostObjectV1(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePreparePostParamV1) (*nex.RMCMessage, *nex.Error)) { + protocol.PreparePostObjectV1 = handler +} + +// SetHandlerCompletePostObjectV1 sets the handler for the CompletePostObjectV1 method +func (protocol *Protocol) SetHandlerCompletePostObjectV1(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreCompletePostParamV1) (*nex.RMCMessage, *nex.Error)) { + protocol.CompletePostObjectV1 = handler +} + +// SetHandlerDeleteObject sets the handler for the DeleteObject method +func (protocol *Protocol) SetHandlerDeleteObject(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreDeleteParam) (*nex.RMCMessage, *nex.Error)) { + protocol.DeleteObject = handler +} + +// SetHandlerDeleteObjects sets the handler for the DeleteObjects method +func (protocol *Protocol) SetHandlerDeleteObjects(handler func(err error, packet nex.PacketInterface, callID uint32, params *types.List[*datastore_types.DataStoreDeleteParam], transactional *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.DeleteObjects = handler +} + +// SetHandlerChangeMetaV1 sets the handler for the ChangeMetaV1 method +func (protocol *Protocol) SetHandlerChangeMetaV1(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreChangeMetaParamV1) (*nex.RMCMessage, *nex.Error)) { + protocol.ChangeMetaV1 = handler +} + +// SetHandlerChangeMetasV1 sets the handler for the ChangeMetasV1 method +func (protocol *Protocol) SetHandlerChangeMetasV1(handler func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], params *types.List[*datastore_types.DataStoreChangeMetaParamV1], transactional *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.ChangeMetasV1 = handler +} + +// SetHandlerGetMeta sets the handler for the GetMeta method +func (protocol *Protocol) SetHandlerGetMeta(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error)) { + protocol.GetMeta = handler +} + +// SetHandlerGetMetas sets the handler for the GetMetas method +func (protocol *Protocol) SetHandlerGetMetas(handler func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], param *datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error)) { + protocol.GetMetas = handler +} + +// SetHandlerPrepareUpdateObject sets the handler for the PrepareUpdateObject method +func (protocol *Protocol) SetHandlerPrepareUpdateObject(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePrepareUpdateParam) (*nex.RMCMessage, *nex.Error)) { + protocol.PrepareUpdateObject = handler +} + +// SetHandlerCompleteUpdateObject sets the handler for the CompleteUpdateObject method +func (protocol *Protocol) SetHandlerCompleteUpdateObject(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreCompleteUpdateParam) (*nex.RMCMessage, *nex.Error)) { + protocol.CompleteUpdateObject = handler +} + +// SetHandlerSearchObject sets the handler for the SearchObject method +func (protocol *Protocol) SetHandlerSearchObject(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam) (*nex.RMCMessage, *nex.Error)) { + protocol.SearchObject = handler +} + +// SetHandlerGetNotificationURL sets the handler for the GetNotificationURL method +func (protocol *Protocol) SetHandlerGetNotificationURL(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetNotificationURLParam) (*nex.RMCMessage, *nex.Error)) { + protocol.GetNotificationURL = handler +} + +// SetHandlerGetNewArrivedNotificationsV1 sets the handler for the GetNewArrivedNotificationsV1 method +func (protocol *Protocol) SetHandlerGetNewArrivedNotificationsV1(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetNewArrivedNotificationsParam) (*nex.RMCMessage, *nex.Error)) { + protocol.GetNewArrivedNotificationsV1 = handler +} + +// SetHandlerRateObject sets the handler for the RateObject method +func (protocol *Protocol) SetHandlerRateObject(handler func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, param *datastore_types.DataStoreRateObjectParam, fetchRatings *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.RateObject = handler +} + +// SetHandlerGetRating sets the handler for the GetRating method +func (protocol *Protocol) SetHandlerGetRating(handler func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, accessPassword *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.GetRating = handler +} + +// SetHandlerGetRatings sets the handler for the GetRatings method +func (protocol *Protocol) SetHandlerGetRatings(handler func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], accessPassword *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.GetRatings = handler +} + +// SetHandlerResetRating sets the handler for the ResetRating method +func (protocol *Protocol) SetHandlerResetRating(handler func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, accessPassword *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.ResetRating = handler +} + +// SetHandlerResetRatings sets the handler for the ResetRatings method +func (protocol *Protocol) SetHandlerResetRatings(handler func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, transactional *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.ResetRatings = handler +} + +// SetHandlerGetSpecificMetaV1 sets the handler for the GetSpecificMetaV1 method +func (protocol *Protocol) SetHandlerGetSpecificMetaV1(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetSpecificMetaParamV1) (*nex.RMCMessage, *nex.Error)) { + protocol.GetSpecificMetaV1 = handler +} + +// SetHandlerPostMetaBinary sets the handler for the PostMetaBinary method +func (protocol *Protocol) SetHandlerPostMetaBinary(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error)) { + protocol.PostMetaBinary = handler +} + +// SetHandlerTouchObject sets the handler for the TouchObject method +func (protocol *Protocol) SetHandlerTouchObject(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreTouchObjectParam) (*nex.RMCMessage, *nex.Error)) { + protocol.TouchObject = handler +} + +// SetHandlerGetRatingWithLog sets the handler for the GetRatingWithLog method +func (protocol *Protocol) SetHandlerGetRatingWithLog(handler func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, accessPassword *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.GetRatingWithLog = handler +} + +// SetHandlerPreparePostObject sets the handler for the PreparePostObject method +func (protocol *Protocol) SetHandlerPreparePostObject(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error)) { + protocol.PreparePostObject = handler +} + +// SetHandlerPrepareGetObject sets the handler for the PrepareGetObject method +func (protocol *Protocol) SetHandlerPrepareGetObject(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePrepareGetParam) (*nex.RMCMessage, *nex.Error)) { + protocol.PrepareGetObject = handler +} + +// SetHandlerCompletePostObject sets the handler for the CompletePostObject method +func (protocol *Protocol) SetHandlerCompletePostObject(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreCompletePostParam) (*nex.RMCMessage, *nex.Error)) { + protocol.CompletePostObject = handler +} + +// SetHandlerGetNewArrivedNotifications sets the handler for the GetNewArrivedNotifications method +func (protocol *Protocol) SetHandlerGetNewArrivedNotifications(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetNewArrivedNotificationsParam) (*nex.RMCMessage, *nex.Error)) { + protocol.GetNewArrivedNotifications = handler +} + +// SetHandlerGetSpecificMeta sets the handler for the GetSpecificMeta method +func (protocol *Protocol) SetHandlerGetSpecificMeta(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreGetSpecificMetaParam) (*nex.RMCMessage, *nex.Error)) { + protocol.GetSpecificMeta = handler +} + +// SetHandlerGetPersistenceInfo sets the handler for the GetPersistenceInfo method +func (protocol *Protocol) SetHandlerGetPersistenceInfo(handler func(err error, packet nex.PacketInterface, callID uint32, ownerID *types.PID, persistenceSlotID *types.PrimitiveU16) (*nex.RMCMessage, *nex.Error)) { + protocol.GetPersistenceInfo = handler +} + +// SetHandlerGetPersistenceInfos sets the handler for the GetPersistenceInfos method +func (protocol *Protocol) SetHandlerGetPersistenceInfos(handler func(err error, packet nex.PacketInterface, callID uint32, ownerID *types.PID, persistenceSlotIDs *types.List[*types.PrimitiveU16]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetPersistenceInfos = handler +} + +// SetHandlerPerpetuateObject sets the handler for the PerpetuateObject method +func (protocol *Protocol) SetHandlerPerpetuateObject(handler func(err error, packet nex.PacketInterface, callID uint32, persistenceSlotID *types.PrimitiveU16, dataID *types.PrimitiveU64, deleteLastObject *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.PerpetuateObject = handler +} + +// SetHandlerUnperpetuateObject sets the handler for the UnperpetuateObject method +func (protocol *Protocol) SetHandlerUnperpetuateObject(handler func(err error, packet nex.PacketInterface, callID uint32, persistenceSlotID *types.PrimitiveU16, deleteLastObject *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.UnperpetuateObject = handler +} + +// SetHandlerPrepareGetObjectOrMetaBinary sets the handler for the PrepareGetObjectOrMetaBinary method +func (protocol *Protocol) SetHandlerPrepareGetObjectOrMetaBinary(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStorePrepareGetParam) (*nex.RMCMessage, *nex.Error)) { + protocol.PrepareGetObjectOrMetaBinary = handler +} + +// SetHandlerGetPasswordInfo sets the handler for the GetPasswordInfo method +func (protocol *Protocol) SetHandlerGetPasswordInfo(handler func(err error, packet nex.PacketInterface, callID uint32, dataID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.GetPasswordInfo = handler +} + +// SetHandlerGetPasswordInfos sets the handler for the GetPasswordInfos method +func (protocol *Protocol) SetHandlerGetPasswordInfos(handler func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetPasswordInfos = handler +} + +// SetHandlerGetMetasMultipleParam sets the handler for the GetMetasMultipleParam method +func (protocol *Protocol) SetHandlerGetMetasMultipleParam(handler func(err error, packet nex.PacketInterface, callID uint32, params *types.List[*datastore_types.DataStoreGetMetaParam]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetMetasMultipleParam = handler +} + +// SetHandlerCompletePostObjects sets the handler for the CompletePostObjects method +func (protocol *Protocol) SetHandlerCompletePostObjects(handler func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error)) { + protocol.CompletePostObjects = handler +} + +// SetHandlerChangeMeta sets the handler for the ChangeMeta method +func (protocol *Protocol) SetHandlerChangeMeta(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreChangeMetaParam) (*nex.RMCMessage, *nex.Error)) { + protocol.ChangeMeta = handler +} + +// SetHandlerChangeMetas sets the handler for the ChangeMetas method +func (protocol *Protocol) SetHandlerChangeMetas(handler func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], params *types.List[*datastore_types.DataStoreChangeMetaParam], transactional *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.ChangeMetas = handler +} + +// SetHandlerRateObjects sets the handler for the RateObjects method +func (protocol *Protocol) SetHandlerRateObjects(handler func(err error, packet nex.PacketInterface, callID uint32, targets *types.List[*datastore_types.DataStoreRatingTarget], params *types.List[*datastore_types.DataStoreRateObjectParam], transactional *types.PrimitiveBool, fetchRatings *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.RateObjects = handler +} + +// SetHandlerPostMetaBinaryWithDataID sets the handler for the PostMetaBinaryWithDataID method +func (protocol *Protocol) SetHandlerPostMetaBinaryWithDataID(handler func(err error, packet nex.PacketInterface, callID uint32, dataID *types.PrimitiveU64, param *datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error)) { + protocol.PostMetaBinaryWithDataID = handler +} + +// SetHandlerPostMetaBinariesWithDataID sets the handler for the PostMetaBinariesWithDataID method +func (protocol *Protocol) SetHandlerPostMetaBinariesWithDataID(handler func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64], params *types.List[*datastore_types.DataStorePreparePostParam], transactional *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.PostMetaBinariesWithDataID = handler +} + +// SetHandlerRateObjectWithPosting sets the handler for the RateObjectWithPosting method +func (protocol *Protocol) SetHandlerRateObjectWithPosting(handler func(err error, packet nex.PacketInterface, callID uint32, target *datastore_types.DataStoreRatingTarget, rateParam *datastore_types.DataStoreRateObjectParam, postParam *datastore_types.DataStorePreparePostParam, fetchRatings *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.RateObjectWithPosting = handler +} + +// SetHandlerRateObjectsWithPosting sets the handler for the RateObjectsWithPosting method +func (protocol *Protocol) SetHandlerRateObjectsWithPosting(handler func(err error, packet nex.PacketInterface, callID uint32, targets *types.List[*datastore_types.DataStoreRatingTarget], rateParams *types.List[*datastore_types.DataStoreRateObjectParam], postParams *types.List[*datastore_types.DataStorePreparePostParam], transactional *types.PrimitiveBool, fetchRatings *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.RateObjectsWithPosting = handler +} + +// SetHandlerGetObjectInfos sets the handler for the GetObjectInfos method +func (protocol *Protocol) SetHandlerGetObjectInfos(handler func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.GetObjectInfos = handler +} + +// SetHandlerSearchObjectLight sets the handler for the SearchObjectLight method +func (protocol *Protocol) SetHandlerSearchObjectLight(handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam) (*nex.RMCMessage, *nex.Error)) { + protocol.SearchObjectLight = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodPrepareGetObjectV1: + protocol.handlePrepareGetObjectV1(packet) + case MethodPreparePostObjectV1: + protocol.handlePreparePostObjectV1(packet) + case MethodCompletePostObjectV1: + protocol.handleCompletePostObjectV1(packet) + case MethodDeleteObject: + protocol.handleDeleteObject(packet) + case MethodDeleteObjects: + protocol.handleDeleteObjects(packet) + case MethodChangeMetaV1: + protocol.handleChangeMetaV1(packet) + case MethodChangeMetasV1: + protocol.handleChangeMetasV1(packet) + case MethodGetMeta: + protocol.handleGetMeta(packet) + case MethodGetMetas: + protocol.handleGetMetas(packet) + case MethodPrepareUpdateObject: + protocol.handlePrepareUpdateObject(packet) + case MethodCompleteUpdateObject: + protocol.handleCompleteUpdateObject(packet) + case MethodSearchObject: + protocol.handleSearchObject(packet) + case MethodGetNotificationURL: + protocol.handleGetNotificationURL(packet) + case MethodGetNewArrivedNotificationsV1: + protocol.handleGetNewArrivedNotificationsV1(packet) + case MethodRateObject: + protocol.handleRateObject(packet) + case MethodGetRating: + protocol.handleGetRating(packet) + case MethodGetRatings: + protocol.handleGetRatings(packet) + case MethodResetRating: + protocol.handleResetRating(packet) + case MethodResetRatings: + protocol.handleResetRatings(packet) + case MethodGetSpecificMetaV1: + protocol.handleGetSpecificMetaV1(packet) + case MethodPostMetaBinary: + protocol.handlePostMetaBinary(packet) + case MethodTouchObject: + protocol.handleTouchObject(packet) + case MethodGetRatingWithLog: + protocol.handleGetRatingWithLog(packet) + case MethodPreparePostObject: + protocol.handlePreparePostObject(packet) + case MethodPrepareGetObject: + protocol.handlePrepareGetObject(packet) + case MethodCompletePostObject: + protocol.handleCompletePostObject(packet) + case MethodGetNewArrivedNotifications: + protocol.handleGetNewArrivedNotifications(packet) + case MethodGetSpecificMeta: + protocol.handleGetSpecificMeta(packet) + case MethodGetPersistenceInfo: + protocol.handleGetPersistenceInfo(packet) + case MethodGetPersistenceInfos: + protocol.handleGetPersistenceInfos(packet) + case MethodPerpetuateObject: + protocol.handlePerpetuateObject(packet) + case MethodUnperpetuateObject: + protocol.handleUnperpetuateObject(packet) + case MethodPrepareGetObjectOrMetaBinary: + protocol.handlePrepareGetObjectOrMetaBinary(packet) + case MethodGetPasswordInfo: + protocol.handleGetPasswordInfo(packet) + case MethodGetPasswordInfos: + protocol.handleGetPasswordInfos(packet) + case MethodGetMetasMultipleParam: + protocol.handleGetMetasMultipleParam(packet) + case MethodCompletePostObjects: + protocol.handleCompletePostObjects(packet) + case MethodChangeMeta: + protocol.handleChangeMeta(packet) + case MethodChangeMetas: + protocol.handleChangeMetas(packet) + case MethodRateObjects: + protocol.handleRateObjects(packet) + case MethodPostMetaBinaryWithDataID: + protocol.handlePostMetaBinaryWithDataID(packet) + case MethodPostMetaBinariesWithDataID: + protocol.handlePostMetaBinariesWithDataID(packet) + case MethodRateObjectWithPosting: + protocol.handleRateObjectWithPosting(packet) + case MethodRateObjectsWithPosting: + protocol.handleRateObjectsWithPosting(packet) + case MethodGetObjectInfos: + protocol.handleGetObjectInfos(packet) + case MethodSearchObjectLight: + protocol.handleSearchObjectLight(packet) + default: + errMessage := fmt.Sprintf("Unsupported DataStore method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new DataStore protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/datastore/rate_object.go b/nex-protocols-go/datastore/rate_object.go new file mode 100644 index 0000000..65ad8f3 --- /dev/null +++ b/nex-protocols-go/datastore/rate_object.go @@ -0,0 +1,72 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRateObject(packet nex.PacketInterface) { + if protocol.RateObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::RateObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + target := datastore_types.NewDataStoreRatingTarget() + param := datastore_types.NewDataStoreRateObjectParam() + fetchRatings := types.NewPrimitiveBool(false) + + var err error + + err = target.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RateObject(fmt.Errorf("Failed to read target from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RateObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = fetchRatings.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RateObject(fmt.Errorf("Failed to read fetchRatings from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RateObject(nil, packet, callID, target, param, fetchRatings) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/rate_object_with_posting.go b/nex-protocols-go/datastore/rate_object_with_posting.go new file mode 100644 index 0000000..bb9d1f4 --- /dev/null +++ b/nex-protocols-go/datastore/rate_object_with_posting.go @@ -0,0 +1,83 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRateObjectWithPosting(packet nex.PacketInterface) { + if protocol.RateObjectWithPosting == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::RateObjectWithPosting not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + target := datastore_types.NewDataStoreRatingTarget() + rateParam := datastore_types.NewDataStoreRateObjectParam() + postParam := datastore_types.NewDataStorePreparePostParam() + fetchRatings := types.NewPrimitiveBool(false) + + var err error + + err = target.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RateObjectWithPosting(fmt.Errorf("Failed to read target from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = rateParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RateObjectWithPosting(fmt.Errorf("Failed to read rateParam from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = postParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RateObjectWithPosting(fmt.Errorf("Failed to read postParam from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = fetchRatings.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RateObjectWithPosting(fmt.Errorf("Failed to read fetchRatings from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RateObjectWithPosting(nil, packet, callID, target, rateParam, postParam, fetchRatings) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/rate_objects.go b/nex-protocols-go/datastore/rate_objects.go new file mode 100644 index 0000000..f1e8654 --- /dev/null +++ b/nex-protocols-go/datastore/rate_objects.go @@ -0,0 +1,85 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRateObjects(packet nex.PacketInterface) { + if protocol.RateObjects == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::RateObjects not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + targets := types.NewList[*datastore_types.DataStoreRatingTarget]() + targets.Type = datastore_types.NewDataStoreRatingTarget() + params := types.NewList[*datastore_types.DataStoreRateObjectParam]() + params.Type = datastore_types.NewDataStoreRateObjectParam() + transactional := types.NewPrimitiveBool(false) + fetchRatings := types.NewPrimitiveBool(false) + + var err error + + err = targets.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RateObjects(fmt.Errorf("Failed to read targets from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = params.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RateObjects(fmt.Errorf("Failed to read params from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = transactional.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RateObjects(fmt.Errorf("Failed to read transactional from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = fetchRatings.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RateObjects(fmt.Errorf("Failed to read fetchRatings from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RateObjects(nil, packet, callID, targets, params, transactional, fetchRatings) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/rate_objects_with_posting.go b/nex-protocols-go/datastore/rate_objects_with_posting.go new file mode 100644 index 0000000..bb27a20 --- /dev/null +++ b/nex-protocols-go/datastore/rate_objects_with_posting.go @@ -0,0 +1,97 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRateObjectsWithPosting(packet nex.PacketInterface) { + if protocol.RateObjectsWithPosting == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::RateObjectsWithPosting not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + targets := types.NewList[*datastore_types.DataStoreRatingTarget]() + targets.Type = datastore_types.NewDataStoreRatingTarget() + rateParams := types.NewList[*datastore_types.DataStoreRateObjectParam]() + rateParams.Type = datastore_types.NewDataStoreRateObjectParam() + postParams := types.NewList[*datastore_types.DataStorePreparePostParam]() + postParams.Type = datastore_types.NewDataStorePreparePostParam() + transactional := types.NewPrimitiveBool(false) + fetchRatings := types.NewPrimitiveBool(false) + + var err error + + err = targets.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RateObjectsWithPosting(fmt.Errorf("Failed to read targets from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = rateParams.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RateObjectsWithPosting(fmt.Errorf("Failed to read rateParams from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = postParams.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RateObjectsWithPosting(fmt.Errorf("Failed to read postParams from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = transactional.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RateObjectsWithPosting(fmt.Errorf("Failed to read transactional from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = fetchRatings.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RateObjectsWithPosting(fmt.Errorf("Failed to read fetchRatings from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RateObjectsWithPosting(nil, packet, callID, targets, rateParams, postParams, transactional, fetchRatings) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/reset_rating.go b/nex-protocols-go/datastore/reset_rating.go new file mode 100644 index 0000000..e7e1aac --- /dev/null +++ b/nex-protocols-go/datastore/reset_rating.go @@ -0,0 +1,61 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleResetRating(packet nex.PacketInterface) { + if protocol.ResetRating == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::ResetRating not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + target := datastore_types.NewDataStoreRatingTarget() + accessPassword := types.NewPrimitiveU64(0) + + var err error + + err = target.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ResetRating(fmt.Errorf("Failed to read target from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = accessPassword.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ResetRating(fmt.Errorf("Failed to read accessPassword from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ResetRating(nil, packet, callID, target, accessPassword) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/reset_ratings.go b/nex-protocols-go/datastore/reset_ratings.go new file mode 100644 index 0000000..ac41487 --- /dev/null +++ b/nex-protocols-go/datastore/reset_ratings.go @@ -0,0 +1,61 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleResetRatings(packet nex.PacketInterface) { + if protocol.ResetRatings == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::ResetRatings not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + target := datastore_types.NewDataStoreRatingTarget() + transactional := types.NewPrimitiveBool(false) + + var err error + + err = target.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ResetRatings(fmt.Errorf("Failed to read target from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = transactional.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ResetRatings(fmt.Errorf("Failed to read transactional from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ResetRatings(nil, packet, callID, target, transactional) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/search_object.go b/nex-protocols-go/datastore/search_object.go new file mode 100644 index 0000000..a8407b0 --- /dev/null +++ b/nex-protocols-go/datastore/search_object.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSearchObject(packet nex.PacketInterface) { + if protocol.SearchObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::SearchObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreSearchParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SearchObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SearchObject(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/search_object_light.go b/nex-protocols-go/datastore/search_object_light.go new file mode 100644 index 0000000..83ee054 --- /dev/null +++ b/nex-protocols-go/datastore/search_object_light.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSearchObjectLight(packet nex.PacketInterface) { + if protocol.SearchObjectLight == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::SearchObjectLight not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreSearchParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SearchObjectLight(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SearchObjectLight(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/add_to_buffer_queue.go b/nex-protocols-go/datastore/super-mario-maker/add_to_buffer_queue.go new file mode 100644 index 0000000..6ae1a12 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/add_to_buffer_queue.go @@ -0,0 +1,61 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-mario-maker/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAddToBufferQueue(packet nex.PacketInterface) { + if protocol.AddToBufferQueue == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::AddToBufferQueue not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_mario_maker_types.NewBufferQueueParam() + buffer := types.NewQBuffer(nil) + + var err error + + err = param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddToBufferQueue(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = buffer.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddToBufferQueue(fmt.Errorf("Failed to read buffer from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AddToBufferQueue(nil, packet, callID, param, buffer) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/add_to_buffer_queues.go b/nex-protocols-go/datastore/super-mario-maker/add_to_buffer_queues.go new file mode 100644 index 0000000..2e75d16 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/add_to_buffer_queues.go @@ -0,0 +1,63 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-mario-maker/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAddToBufferQueues(packet nex.PacketInterface) { + if protocol.AddToBufferQueues == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::AddToBufferQueues not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + params := types.NewList[*datastore_super_mario_maker_types.BufferQueueParam]() + params.Type = datastore_super_mario_maker_types.NewBufferQueueParam() + buffers := types.NewList[*types.QBuffer]() + buffers.Type = types.NewQBuffer(nil) + + var err error + + err = params.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddToBufferQueues(fmt.Errorf("Failed to read params from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = buffers.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddToBufferQueues(fmt.Errorf("Failed to read buffers from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AddToBufferQueues(nil, packet, callID, params, buffers) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/best_score_rate_course_search_object.go b/nex-protocols-go/datastore/super-mario-maker/best_score_rate_course_search_object.go new file mode 100644 index 0000000..e4be7dc --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/best_score_rate_course_search_object.go @@ -0,0 +1,62 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleBestScoreRateCourseSearchObject(packet nex.PacketInterface) { + if protocol.BestScoreRateCourseSearchObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::BestScoreRateCourseSearchObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreSearchParam() + extraData := types.NewList[*types.String]() + extraData.Type = types.NewString("") + + var err error + + err = param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.BestScoreRateCourseSearchObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = extraData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.BestScoreRateCourseSearchObject(fmt.Errorf("Failed to read extraData from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.BestScoreRateCourseSearchObject(nil, packet, callID, param, extraData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/change_playable_platform.go b/nex-protocols-go/datastore/super-mario-maker/change_playable_platform.go new file mode 100644 index 0000000..f4721ce --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/change_playable_platform.go @@ -0,0 +1,49 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-mario-maker/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleChangePlayablePlatform(packet nex.PacketInterface) { + if protocol.ChangePlayablePlatform == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::ChangePlayablePlatform not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + params := types.NewList[*datastore_super_mario_maker_types.DataStoreChangePlayablePlatformParam]() + params.Type = datastore_super_mario_maker_types.NewDataStoreChangePlayablePlatformParam() + + err := params.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangePlayablePlatform(fmt.Errorf("Failed to read params from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ChangePlayablePlatform(nil, packet, callID, params) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/check_rate_custom_ranking_counter.go b/nex-protocols-go/datastore/super-mario-maker/check_rate_custom_ranking_counter.go new file mode 100644 index 0000000..f1da05e --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/check_rate_custom_ranking_counter.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCheckRateCustomRankingCounter(packet nex.PacketInterface) { + if protocol.CheckRateCustomRankingCounter == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::CheckRateCustomRankingCounter not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + applicationID := types.NewPrimitiveU32(0) + + err := applicationID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CheckRateCustomRankingCounter(fmt.Errorf("Failed to read applicationID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CheckRateCustomRankingCounter(nil, packet, callID, applicationID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/clear_buffer_queues.go b/nex-protocols-go/datastore/super-mario-maker/clear_buffer_queues.go new file mode 100644 index 0000000..8e01b8e --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/clear_buffer_queues.go @@ -0,0 +1,49 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-mario-maker/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleClearBufferQueues(packet nex.PacketInterface) { + if protocol.ClearBufferQueues == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::ClearBufferQueues not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + params := types.NewList[*datastore_super_mario_maker_types.BufferQueueParam]() + params.Type = datastore_super_mario_maker_types.NewBufferQueueParam() + + err := params.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ClearBufferQueues(fmt.Errorf("Failed to read params from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ClearBufferQueues(nil, packet, callID, params) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/complete_attach_file.go b/nex-protocols-go/datastore/super-mario-maker/complete_attach_file.go new file mode 100644 index 0000000..174a9a7 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/complete_attach_file.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCompleteAttachFile(packet nex.PacketInterface) { + if protocol.CompleteAttachFile == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::CompleteAttachFile not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreCompletePostParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CompleteAttachFile(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CompleteAttachFile(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/complete_attach_file_v1.go b/nex-protocols-go/datastore/super-mario-maker/complete_attach_file_v1.go new file mode 100644 index 0000000..3f89140 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/complete_attach_file_v1.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCompleteAttachFileV1(packet nex.PacketInterface) { + if protocol.CompleteAttachFileV1 == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::CompleteAttachFileV1 not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreCompletePostParamV1() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CompleteAttachFileV1(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CompleteAttachFileV1(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/complete_post_object_with_owner_id.go b/nex-protocols-go/datastore/super-mario-maker/complete_post_object_with_owner_id.go new file mode 100644 index 0000000..50c2518 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/complete_post_object_with_owner_id.go @@ -0,0 +1,61 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCompletePostObjectWithOwnerID(packet nex.PacketInterface) { + if protocol.CompletePostObjectWithOwnerID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::CompletePostObjectWithOwnerID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + ownerID := types.NewPrimitiveU32(0) + param := datastore_types.NewDataStoreCompletePostParam() + + var err error + + err = ownerID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CompletePostObjectWithOwnerID(fmt.Errorf("Failed to read ownerID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CompletePostObjectWithOwnerID(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CompletePostObjectWithOwnerID(nil, packet, callID, ownerID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/conditional_search_object.go b/nex-protocols-go/datastore/super-mario-maker/conditional_search_object.go new file mode 100644 index 0000000..098c70c --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/conditional_search_object.go @@ -0,0 +1,73 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleConditionalSearchObject(packet nex.PacketInterface) { + if protocol.ConditionalSearchObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::ConditionalSearchObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + condition := types.NewPrimitiveU32(0) + param := datastore_types.NewDataStoreSearchParam() + extraData := types.NewList[*types.String]() + extraData.Type = types.NewString("") + + var err error + + err = condition.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ConditionalSearchObject(fmt.Errorf("Failed to read condition from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ConditionalSearchObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = extraData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ConditionalSearchObject(fmt.Errorf("Failed to read extraData from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ConditionalSearchObject(nil, packet, callID, condition, param, extraData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/ctr_pick_up_course_search_object.go b/nex-protocols-go/datastore/super-mario-maker/ctr_pick_up_course_search_object.go new file mode 100644 index 0000000..b04f98b --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/ctr_pick_up_course_search_object.go @@ -0,0 +1,62 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCTRPickUpCourseSearchObject(packet nex.PacketInterface) { + if protocol.CTRPickUpCourseSearchObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::CTRPickUpCourseSearchObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreSearchParam() + extraData := types.NewList[*types.String]() + extraData.Type = types.NewString("") + + var err error + + err = param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CTRPickUpCourseSearchObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = extraData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CTRPickUpCourseSearchObject(fmt.Errorf("Failed to read extraData from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CTRPickUpCourseSearchObject(nil, packet, callID, param, extraData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/custom_search_object.go b/nex-protocols-go/datastore/super-mario-maker/custom_search_object.go new file mode 100644 index 0000000..de14fc0 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/custom_search_object.go @@ -0,0 +1,61 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCustomSearchObject(packet nex.PacketInterface) { + if protocol.CustomSearchObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::CustomSearchObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + condition := types.NewPrimitiveU32(0) + param := datastore_types.NewDataStoreSearchParam() + + var err error + + err = condition.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CustomSearchObject(fmt.Errorf("Failed to read condition from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CustomSearchObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CustomSearchObject(nil, packet, callID, condition, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/delete_application_config.go b/nex-protocols-go/datastore/super-mario-maker/delete_application_config.go new file mode 100644 index 0000000..80b299a --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/delete_application_config.go @@ -0,0 +1,60 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteApplicationConfig(packet nex.PacketInterface) { + if protocol.DeleteApplicationConfig == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::DeleteApplicationConfig not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + applicationID := types.NewPrimitiveU32(0) + key := types.NewPrimitiveU32(0) + + var err error + + err = applicationID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteApplicationConfig(fmt.Errorf("Failed to read applicationID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = key.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteApplicationConfig(fmt.Errorf("Failed to read key from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteApplicationConfig(nil, packet, callID, applicationID, key) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/delete_cached_ranking.go b/nex-protocols-go/datastore/super-mario-maker/delete_cached_ranking.go new file mode 100644 index 0000000..7b4751a --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/delete_cached_ranking.go @@ -0,0 +1,61 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteCachedRanking(packet nex.PacketInterface) { + if protocol.DeleteCachedRanking == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::DeleteCachedRanking not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + rankingType := types.NewString("") + rankingArgs := types.NewList[*types.String]() + rankingArgs.Type = types.NewString("") + + var err error + + err = rankingType.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteCachedRanking(fmt.Errorf("Failed to read rankingType from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = rankingArgs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteCachedRanking(fmt.Errorf("Failed to read rankingArgs from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteCachedRanking(nil, packet, callID, rankingType, rankingArgs) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/delete_course_record.go b/nex-protocols-go/datastore/super-mario-maker/delete_course_record.go new file mode 100644 index 0000000..a4aeaec --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/delete_course_record.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-mario-maker/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteCourseRecord(packet nex.PacketInterface) { + if protocol.DeleteCourseRecord == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::DeleteCourseRecord not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_mario_maker_types.NewDataStoreGetCourseRecordParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteCourseRecord(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteCourseRecord(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/delete_custom_ranking.go b/nex-protocols-go/datastore/super-mario-maker/delete_custom_ranking.go new file mode 100644 index 0000000..46860d1 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/delete_custom_ranking.go @@ -0,0 +1,48 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteCustomRanking(packet nex.PacketInterface) { + if protocol.DeleteCustomRanking == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::DeleteCustomRanking not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + dataIDList := types.NewList[*types.PrimitiveU64]() + dataIDList.Type = types.NewPrimitiveU64(0) + + err := dataIDList.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteCustomRanking(fmt.Errorf("Failed to read dataIDList from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteCustomRanking(nil, packet, callID, dataIDList) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/followings_latest_course_search_object.go b/nex-protocols-go/datastore/super-mario-maker/followings_latest_course_search_object.go new file mode 100644 index 0000000..7934374 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/followings_latest_course_search_object.go @@ -0,0 +1,62 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFollowingsLatestCourseSearchObject(packet nex.PacketInterface) { + if protocol.FollowingsLatestCourseSearchObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::FollowingsLatestCourseSearchObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreSearchParam() + extraData := types.NewList[*types.String]() + extraData.Type = types.NewString("") + + var err error + + err = param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FollowingsLatestCourseSearchObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = extraData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FollowingsLatestCourseSearchObject(fmt.Errorf("Failed to read extraData from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FollowingsLatestCourseSearchObject(nil, packet, callID, param, extraData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/get_application_config.go b/nex-protocols-go/datastore/super-mario-maker/get_application_config.go new file mode 100644 index 0000000..609939e --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/get_application_config.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetApplicationConfig(packet nex.PacketInterface) { + if protocol.GetApplicationConfig == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::GetApplicationConfig not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + applicationID := types.NewPrimitiveU32(0) + + err := applicationID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetApplicationConfig(fmt.Errorf("Failed to read applicationID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetApplicationConfig(nil, packet, callID, applicationID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/get_application_config_string.go b/nex-protocols-go/datastore/super-mario-maker/get_application_config_string.go new file mode 100644 index 0000000..3a03d68 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/get_application_config_string.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetApplicationConfigString(packet nex.PacketInterface) { + if protocol.GetApplicationConfigString == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::GetApplicationConfigString not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + applicationID := types.NewPrimitiveU32(0) + + err := applicationID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetApplicationConfigString(fmt.Errorf("Failed to read applicationID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetApplicationConfigString(nil, packet, callID, applicationID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/get_buffer_queue.go b/nex-protocols-go/datastore/super-mario-maker/get_buffer_queue.go new file mode 100644 index 0000000..5728043 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/get_buffer_queue.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-mario-maker/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetBufferQueue(packet nex.PacketInterface) { + if protocol.GetBufferQueue == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::GetBufferQueue not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_mario_maker_types.NewBufferQueueParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetBufferQueue(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetBufferQueue(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/get_buffer_queues.go b/nex-protocols-go/datastore/super-mario-maker/get_buffer_queues.go new file mode 100644 index 0000000..a2a3d65 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/get_buffer_queues.go @@ -0,0 +1,49 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-mario-maker/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetBufferQueues(packet nex.PacketInterface) { + if protocol.GetBufferQueues == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::GetBufferQueues not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + params := types.NewList[*datastore_super_mario_maker_types.BufferQueueParam]() + params.Type = datastore_super_mario_maker_types.NewBufferQueueParam() + + err := params.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetBufferQueues(fmt.Errorf("Failed to read params from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetBufferQueues(nil, packet, callID, params) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/get_course_record.go b/nex-protocols-go/datastore/super-mario-maker/get_course_record.go new file mode 100644 index 0000000..c29753a --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/get_course_record.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-mario-maker/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetCourseRecord(packet nex.PacketInterface) { + if protocol.GetCourseRecord == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::GetCourseRecord not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_mario_maker_types.NewDataStoreGetCourseRecordParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetCourseRecord(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetCourseRecord(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/get_custom_ranking.go b/nex-protocols-go/datastore/super-mario-maker/get_custom_ranking.go new file mode 100644 index 0000000..2f9abf2 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/get_custom_ranking.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-mario-maker/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetCustomRanking(packet nex.PacketInterface) { + if protocol.GetCustomRanking == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::GetCustomRanking not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_mario_maker_types.NewDataStoreGetCustomRankingParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetCustomRanking(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetCustomRanking(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/get_custom_ranking_by_data_id.go b/nex-protocols-go/datastore/super-mario-maker/get_custom_ranking_by_data_id.go new file mode 100644 index 0000000..0d8c999 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/get_custom_ranking_by_data_id.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-mario-maker/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetCustomRankingByDataID(packet nex.PacketInterface) { + if protocol.GetCustomRankingByDataID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::GetCustomRankingByDataID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_mario_maker_types.NewDataStoreGetCustomRankingByDataIDParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetCustomRankingByDataID(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetCustomRankingByDataID(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/get_deletion_reason.go b/nex-protocols-go/datastore/super-mario-maker/get_deletion_reason.go new file mode 100644 index 0000000..9cdff88 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/get_deletion_reason.go @@ -0,0 +1,48 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetDeletionReason(packet nex.PacketInterface) { + if protocol.GetDeletionReason == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::GetDeletionReason not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + dataIDLst := types.NewList[*types.PrimitiveU64]() + dataIDLst.Type = types.NewPrimitiveU64(0) + + err := dataIDLst.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetDeletionReason(fmt.Errorf("Failed to read dataIDLst from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetDeletionReason(nil, packet, callID, dataIDLst) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/get_meta_by_owner_id.go b/nex-protocols-go/datastore/super-mario-maker/get_meta_by_owner_id.go new file mode 100644 index 0000000..202e70f --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/get_meta_by_owner_id.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-mario-maker/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetMetaByOwnerID(packet nex.PacketInterface) { + if protocol.GetMetaByOwnerID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::GetMetaByOwnerID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_mario_maker_types.NewDataStoreGetMetaByOwnerIDParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetMetaByOwnerID(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetMetaByOwnerID(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/get_metas_with_course_record.go b/nex-protocols-go/datastore/super-mario-maker/get_metas_with_course_record.go new file mode 100644 index 0000000..79773ff --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/get_metas_with_course_record.go @@ -0,0 +1,63 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-mario-maker/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetMetasWithCourseRecord(packet nex.PacketInterface) { + if protocol.GetMetasWithCourseRecord == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::GetMetasWithCourseRecord not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + params := types.NewList[*datastore_super_mario_maker_types.DataStoreGetCourseRecordParam]() + params.Type = datastore_super_mario_maker_types.NewDataStoreGetCourseRecordParam() + metaParam := datastore_types.NewDataStoreGetMetaParam() + + var err error + + err = params.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetMetasWithCourseRecord(fmt.Errorf("Failed to read params from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = metaParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetMetasWithCourseRecord(fmt.Errorf("Failed to read metaParam from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetMetasWithCourseRecord(nil, packet, callID, params, metaParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/get_object_infos.go b/nex-protocols-go/datastore/super-mario-maker/get_object_infos.go new file mode 100644 index 0000000..4a02df8 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/get_object_infos.go @@ -0,0 +1,48 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetObjectInfos(packet nex.PacketInterface) { + if protocol.GetObjectInfos == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::GetObjectInfos not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + dataIDs := types.NewList[*types.PrimitiveU64]() + dataIDs.Type = types.NewPrimitiveU64(0) + + err := dataIDs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetObjectInfos(fmt.Errorf("Failed to read dataIDs from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetObjectInfos(nil, packet, callID, dataIDs) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/latest_course_search_object.go b/nex-protocols-go/datastore/super-mario-maker/latest_course_search_object.go new file mode 100644 index 0000000..651ceb9 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/latest_course_search_object.go @@ -0,0 +1,62 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleLatestCourseSearchObject(packet nex.PacketInterface) { + if protocol.LatestCourseSearchObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::LatestCourseSearchObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreSearchParam() + extraData := types.NewList[*types.String]() + extraData.Type = types.NewString("") + + var err error + + err = param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.LatestCourseSearchObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = extraData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.LatestCourseSearchObject(fmt.Errorf("Failed to read extraData from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.LatestCourseSearchObject(nil, packet, callID, param, extraData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/prepare_attach_file.go b/nex-protocols-go/datastore/super-mario-maker/prepare_attach_file.go new file mode 100644 index 0000000..188073e --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/prepare_attach_file.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-mario-maker/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePrepareAttachFile(packet nex.PacketInterface) { + if protocol.PrepareAttachFile == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::PrepareAttachFile not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_mario_maker_types.NewDataStoreAttachFileParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PrepareAttachFile(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PrepareAttachFile(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/prepare_post_object_with_owner_id_and_data_id.go b/nex-protocols-go/datastore/super-mario-maker/prepare_post_object_with_owner_id_and_data_id.go new file mode 100644 index 0000000..e58fb88 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/prepare_post_object_with_owner_id_and_data_id.go @@ -0,0 +1,72 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePreparePostObjectWithOwnerIDAndDataID(packet nex.PacketInterface) { + if protocol.PreparePostObjectWithOwnerIDAndDataID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::PreparePostObjectWithOwnerIDAndDataID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + ownerID := types.NewPrimitiveU32(0) + dataID := types.NewPrimitiveU64(0) + param := datastore_types.NewDataStorePreparePostParam() + + var err error + + err = ownerID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PreparePostObjectWithOwnerIDAndDataID(fmt.Errorf("Failed to read ownerID from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = dataID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PreparePostObjectWithOwnerIDAndDataID(fmt.Errorf("Failed to read dataID from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PreparePostObjectWithOwnerIDAndDataID(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PreparePostObjectWithOwnerIDAndDataID(nil, packet, callID, ownerID, dataID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/protocol.go b/nex-protocols-go/datastore/super-mario-maker/protocol.go new file mode 100644 index 0000000..98446bd --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/protocol.go @@ -0,0 +1,363 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-mario-maker/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + "golang.org/x/exp/slices" +) + +const ( + // ProtocolID is the Protocol ID for the DataStore (Super Mario Maker) protocol + ProtocolID = 0x73 + + // MethodGetObjectInfos is the method ID for the GetObjectInfos method + MethodGetObjectInfos = 0x2D + + // MethodGetMetaByOwnerID is the method ID for the GetMetaByOwnerID method + MethodGetMetaByOwnerID = 0x2E + + // MethodCustomSearchObject is the method ID for the CustomSearchObject method + MethodCustomSearchObject = 0x2F + + // MethodRateCustomRanking is the method ID for the RateCustomRanking method + MethodRateCustomRanking = 0x30 + + // MethodGetCustomRanking is the method ID for the GetCustomRanking method + MethodGetCustomRanking = 0x31 + + // MethodGetCustomRankingByDataID is the method ID for the GetCustomRankingByDataID method + MethodGetCustomRankingByDataID = 0x32 + + // MethodDeleteCustomRanking is the method ID for the DeleteCustomRanking method + MethodDeleteCustomRanking = 0x33 + + // MethodAddToBufferQueue is the method ID for the AddToBufferQueue method + MethodAddToBufferQueue = 0x34 + + // MethodAddToBufferQueues is the method ID for the AddToBufferQueues method + MethodAddToBufferQueues = 0x35 + + // MethodGetBufferQueue is the method ID for the GetBufferQueue method + MethodGetBufferQueue = 0x36 + + // MethodGetBufferQueues is the method ID for the GetBufferQueues method + MethodGetBufferQueues = 0x37 + + // MethodClearBufferQueues is the method ID for the ClearBufferQueues method + MethodClearBufferQueues = 0x38 + + // MethodCompleteAttachFile is the method ID for the CompleteAttachFile method + MethodCompleteAttachFile = 0x39 + + // MethodCompleteAttachFileV1 is the method ID for the CompleteAttachFileV1 method + MethodCompleteAttachFileV1 = 0x3A + + // MethodPrepareAttachFile is the method ID for the PrepareAttachFile method + MethodPrepareAttachFile = 0x3B + + // MethodConditionalSearchObject is the method ID for the ConditionalSearchObject method + MethodConditionalSearchObject = 0x3C + + // MethodGetApplicationConfig is the method ID for the GetApplicationConfig method + MethodGetApplicationConfig = 0x3D + + // MethodSetApplicationConfig is the method ID for the SetApplicationConfig method + MethodSetApplicationConfig = 0x3E + + // MethodDeleteApplicationConfig is the method ID for the DeleteApplicationConfig method + MethodDeleteApplicationConfig = 0x3F + + // MethodLatestCourseSearchObject is the method ID for the LatestCourseSearchObject method + MethodLatestCourseSearchObject = 0x40 + + // MethodFollowingsLatestCourseSearchObject is the method ID for the FollowingsLatestCourseSearchObject method + MethodFollowingsLatestCourseSearchObject = 0x41 + + // MethodRecommendedCourseSearchObject is the method ID for the RecommendedCourseSearchObject method + MethodRecommendedCourseSearchObject = 0x42 + + // MethodScoreRangeCascadedSearchObject is the method ID for the ScoreRangeCascadedSearchObject method + MethodScoreRangeCascadedSearchObject = 0x43 + + // MethodSuggestedCourseSearchObject is the method ID for the SuggestedCourseSearchObject method + MethodSuggestedCourseSearchObject = 0x44 + + // MethodPreparePostObjectWithOwnerIDAndDataID is the method ID for the PreparePostObjectWithOwnerIDAndDataID method + MethodPreparePostObjectWithOwnerIDAndDataID = 0x45 + + // MethodCompletePostObjectWithOwnerID is the method ID for the CompletePostObjectWithOwnerID method + MethodCompletePostObjectWithOwnerID = 0x46 + + // MethodUploadCourseRecord is the method ID for the UploadCourseRecord method + MethodUploadCourseRecord = 0x47 + + // MethodGetCourseRecord is the method ID for the GetCourseRecord method + MethodGetCourseRecord = 0x48 + + // MethodDeleteCourseRecord is the method ID for the DeleteCourseRecord method + MethodDeleteCourseRecord = 0x49 + + // MethodGetApplicationConfigString is the method ID for the GetApplicationConfigString method + MethodGetApplicationConfigString = 0x4A + + // MethodSetApplicationConfigString is the method ID for the SetApplicationConfigString method + MethodSetApplicationConfigString = 0x4B + + // MethodGetDeletionReason is the method ID for the GetDeletionReason method + MethodGetDeletionReason = 0x4C + + // MethodSetDeletionReason is the method ID for the SetDeletionReason method + MethodSetDeletionReason = 0x4D + + // MethodGetMetasWithCourseRecord is the method ID for the GetMetasWithCourseRecord method + MethodGetMetasWithCourseRecord = 0x4E + + // MethodCheckRateCustomRankingCounter is the method ID for the CheckRateCustomRankingCounter method + MethodCheckRateCustomRankingCounter = 0x4F + + // MethodResetRateCustomRankingCounter is the method ID for the ResetRateCustomRankingCounter method + MethodResetRateCustomRankingCounter = 0x50 + + // MethodBestScoreRateCourseSearchObject is the method ID for the BestScoreRateCourseSearchObject method + MethodBestScoreRateCourseSearchObject = 0x51 + + // MethodCTRPickUpCourseSearchObject is the method ID for the CTRPickUpCourseSearchObject method + MethodCTRPickUpCourseSearchObject = 0x52 + + // MethodSetCachedRanking is the method ID for the SetCachedRanking method + MethodSetCachedRanking = 0x53 + + // MethodDeleteCachedRanking is the method ID for the DeleteCachedRanking method + MethodDeleteCachedRanking = 0x54 + + // MethodChangePlayablePlatform is the method ID for the ChangePlayablePlatform method + MethodChangePlayablePlatform = 0x55 + + // MethodSearchUnknownPlatformObjects is the method ID for the SearchUnknownPlatformObjects method + MethodSearchUnknownPlatformObjects = 0x56 + + // MethodReportCourse is the method ID for the ReportCourse method + MethodReportCourse = 0x57 +) + +var patchedMethods = []uint32{ + MethodGetObjectInfos, + MethodGetMetaByOwnerID, + MethodCustomSearchObject, + MethodRateCustomRanking, + MethodGetCustomRanking, + MethodGetCustomRankingByDataID, + MethodDeleteCustomRanking, + MethodAddToBufferQueue, + MethodAddToBufferQueues, + MethodGetBufferQueue, + MethodGetBufferQueues, + MethodClearBufferQueues, + MethodCompleteAttachFile, + MethodCompleteAttachFileV1, + MethodPrepareAttachFile, + MethodConditionalSearchObject, + MethodGetApplicationConfig, + MethodSetApplicationConfig, + MethodDeleteApplicationConfig, + MethodLatestCourseSearchObject, + MethodFollowingsLatestCourseSearchObject, + MethodRecommendedCourseSearchObject, + MethodScoreRangeCascadedSearchObject, + MethodSuggestedCourseSearchObject, + MethodPreparePostObjectWithOwnerIDAndDataID, + MethodCompletePostObjectWithOwnerID, + MethodUploadCourseRecord, + MethodGetCourseRecord, + MethodDeleteCourseRecord, + MethodGetApplicationConfigString, + MethodSetApplicationConfigString, + MethodGetDeletionReason, + MethodSetDeletionReason, + MethodGetMetasWithCourseRecord, + MethodCheckRateCustomRankingCounter, + MethodResetRateCustomRankingCounter, + MethodBestScoreRateCourseSearchObject, + MethodCTRPickUpCourseSearchObject, + MethodSetCachedRanking, + MethodDeleteCachedRanking, + MethodChangePlayablePlatform, + MethodSearchUnknownPlatformObjects, + MethodReportCourse, +} + +type dataStoreProtocol = datastore.Protocol + +// Protocol stores all the RMC method handlers for the DataStore (Super Mario Maker) protocol and listens for requests +// Embeds the DataStore protocol +type Protocol struct { + endpoint nex.EndpointInterface + dataStoreProtocol + GetObjectInfos func(err error, packet nex.PacketInterface, callID uint32, dataIDs *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error) + GetMetaByOwnerID func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.DataStoreGetMetaByOwnerIDParam) (*nex.RMCMessage, *nex.Error) + CustomSearchObject func(err error, packet nex.PacketInterface, callID uint32, condition *types.PrimitiveU32, param *datastore_types.DataStoreSearchParam) (*nex.RMCMessage, *nex.Error) + RateCustomRanking func(err error, packet nex.PacketInterface, callID uint32, params *types.List[*datastore_super_mario_maker_types.DataStoreRateCustomRankingParam]) (*nex.RMCMessage, *nex.Error) + GetCustomRanking func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.DataStoreGetCustomRankingParam) (*nex.RMCMessage, *nex.Error) + GetCustomRankingByDataID func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.DataStoreGetCustomRankingByDataIDParam) (*nex.RMCMessage, *nex.Error) + DeleteCustomRanking func(err error, packet nex.PacketInterface, callID uint32, dataIDList *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error) + AddToBufferQueue func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.BufferQueueParam, buffer *types.QBuffer) (*nex.RMCMessage, *nex.Error) + AddToBufferQueues func(err error, packet nex.PacketInterface, callID uint32, params *types.List[*datastore_super_mario_maker_types.BufferQueueParam], buffers *types.List[*types.QBuffer]) (*nex.RMCMessage, *nex.Error) + GetBufferQueue func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.BufferQueueParam) (*nex.RMCMessage, *nex.Error) + GetBufferQueues func(err error, packet nex.PacketInterface, callID uint32, params *types.List[*datastore_super_mario_maker_types.BufferQueueParam]) (*nex.RMCMessage, *nex.Error) + ClearBufferQueues func(err error, packet nex.PacketInterface, callID uint32, params *types.List[*datastore_super_mario_maker_types.BufferQueueParam]) (*nex.RMCMessage, *nex.Error) + CompleteAttachFile func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreCompletePostParam) (*nex.RMCMessage, *nex.Error) + CompleteAttachFileV1 func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreCompletePostParamV1) (*nex.RMCMessage, *nex.Error) + PrepareAttachFile func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.DataStoreAttachFileParam) (*nex.RMCMessage, *nex.Error) + ConditionalSearchObject func(err error, packet nex.PacketInterface, callID uint32, condition *types.PrimitiveU32, param *datastore_types.DataStoreSearchParam, extraData *types.List[*types.String]) (*nex.RMCMessage, *nex.Error) + GetApplicationConfig func(err error, packet nex.PacketInterface, callID uint32, applicationID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + SetApplicationConfig func(err error, packet nex.PacketInterface, callID uint32, applicationID *types.PrimitiveU32, key *types.PrimitiveU32, value *types.PrimitiveS32) (*nex.RMCMessage, *nex.Error) + DeleteApplicationConfig func(err error, packet nex.PacketInterface, callID uint32, applicationID *types.PrimitiveU32, key *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + LatestCourseSearchObject func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam, extraData *types.List[*types.String]) (*nex.RMCMessage, *nex.Error) + FollowingsLatestCourseSearchObject func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam, extraData *types.List[*types.String]) (*nex.RMCMessage, *nex.Error) + RecommendedCourseSearchObject func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam, extraData *types.List[*types.String]) (*nex.RMCMessage, *nex.Error) + ScoreRangeCascadedSearchObject func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam, extraData *types.List[*types.String]) (*nex.RMCMessage, *nex.Error) + SuggestedCourseSearchObject func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam, extraData *types.List[*types.String]) (*nex.RMCMessage, *nex.Error) + PreparePostObjectWithOwnerIDAndDataID func(err error, packet nex.PacketInterface, callID uint32, ownerID *types.PrimitiveU32, dataID *types.PrimitiveU64, param *datastore_types.DataStorePreparePostParam) (*nex.RMCMessage, *nex.Error) + CompletePostObjectWithOwnerID func(err error, packet nex.PacketInterface, callID uint32, ownerID *types.PrimitiveU32, param *datastore_types.DataStoreCompletePostParam) (*nex.RMCMessage, *nex.Error) + UploadCourseRecord func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.DataStoreUploadCourseRecordParam) (*nex.RMCMessage, *nex.Error) + GetCourseRecord func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.DataStoreGetCourseRecordParam) (*nex.RMCMessage, *nex.Error) + DeleteCourseRecord func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.DataStoreGetCourseRecordParam) (*nex.RMCMessage, *nex.Error) + GetApplicationConfigString func(err error, packet nex.PacketInterface, callID uint32, applicationID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + SetApplicationConfigString func(err error, packet nex.PacketInterface, callID uint32, applicationID *types.PrimitiveU32, key *types.PrimitiveU32, value *types.String) (*nex.RMCMessage, *nex.Error) + GetDeletionReason func(err error, packet nex.PacketInterface, callID uint32, dataIDLst *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error) + SetDeletionReason func(err error, packet nex.PacketInterface, callID uint32, dataIDLst *types.List[*types.PrimitiveU64], deletionReason *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetMetasWithCourseRecord func(err error, packet nex.PacketInterface, callID uint32, params *types.List[*datastore_super_mario_maker_types.DataStoreGetCourseRecordParam], metaParam *datastore_types.DataStoreGetMetaParam) (*nex.RMCMessage, *nex.Error) + CheckRateCustomRankingCounter func(err error, packet nex.PacketInterface, callID uint32, applicationID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + ResetRateCustomRankingCounter func(err error, packet nex.PacketInterface, callID uint32, applicationID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + BestScoreRateCourseSearchObject func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam, extraData *types.List[*types.String]) (*nex.RMCMessage, *nex.Error) + CTRPickUpCourseSearchObject func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam, extraData *types.List[*types.String]) (*nex.RMCMessage, *nex.Error) + SetCachedRanking func(err error, packet nex.PacketInterface, callID uint32, rankingType *types.String, rankingArgs *types.List[*types.String], dataIDLst *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error) + DeleteCachedRanking func(err error, packet nex.PacketInterface, callID uint32, rankingType *types.String, rankingArgs *types.List[*types.String]) (*nex.RMCMessage, *nex.Error) + ChangePlayablePlatform func(err error, packet nex.PacketInterface, callID uint32, params *types.List[*datastore_super_mario_maker_types.DataStoreChangePlayablePlatformParam]) (*nex.RMCMessage, *nex.Error) + SearchUnknownPlatformObjects func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + ReportCourse func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.DataStoreReportCourseParam) (*nex.RMCMessage, *nex.Error) +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if !slices.Contains(patchedMethods, message.MethodID) { + protocol.dataStoreProtocol.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodGetObjectInfos: + protocol.handleGetObjectInfos(packet) + case MethodGetMetaByOwnerID: + protocol.handleGetMetaByOwnerID(packet) + case MethodCustomSearchObject: + protocol.handleCustomSearchObject(packet) + case MethodRateCustomRanking: + protocol.handleRateCustomRanking(packet) + case MethodGetCustomRanking: + protocol.handleGetCustomRanking(packet) + case MethodGetCustomRankingByDataID: + protocol.handleGetCustomRankingByDataID(packet) + case MethodDeleteCustomRanking: + protocol.handleDeleteCustomRanking(packet) + case MethodAddToBufferQueue: + protocol.handleAddToBufferQueue(packet) + case MethodAddToBufferQueues: + protocol.handleAddToBufferQueues(packet) + case MethodGetBufferQueue: + protocol.handleGetBufferQueue(packet) + case MethodGetBufferQueues: + protocol.handleGetBufferQueues(packet) + case MethodClearBufferQueues: + protocol.handleClearBufferQueues(packet) + case MethodCompleteAttachFile: + protocol.handleCompleteAttachFile(packet) + case MethodCompleteAttachFileV1: + protocol.handleCompleteAttachFileV1(packet) + case MethodPrepareAttachFile: + protocol.handlePrepareAttachFile(packet) + case MethodConditionalSearchObject: + protocol.handleConditionalSearchObject(packet) + case MethodGetApplicationConfig: + protocol.handleGetApplicationConfig(packet) + case MethodSetApplicationConfig: + protocol.handleSetApplicationConfig(packet) + case MethodDeleteApplicationConfig: + protocol.handleDeleteApplicationConfig(packet) + case MethodLatestCourseSearchObject: + protocol.handleLatestCourseSearchObject(packet) + case MethodFollowingsLatestCourseSearchObject: + protocol.handleFollowingsLatestCourseSearchObject(packet) + case MethodRecommendedCourseSearchObject: + protocol.handleRecommendedCourseSearchObject(packet) + case MethodScoreRangeCascadedSearchObject: + protocol.handleScoreRangeCascadedSearchObject(packet) + case MethodSuggestedCourseSearchObject: + protocol.handleSuggestedCourseSearchObject(packet) + case MethodPreparePostObjectWithOwnerIDAndDataID: + protocol.handlePreparePostObjectWithOwnerIDAndDataID(packet) + case MethodCompletePostObjectWithOwnerID: + protocol.handleCompletePostObjectWithOwnerID(packet) + case MethodUploadCourseRecord: + protocol.handleUploadCourseRecord(packet) + case MethodGetCourseRecord: + protocol.handleGetCourseRecord(packet) + case MethodDeleteCourseRecord: + protocol.handleDeleteCourseRecord(packet) + case MethodGetApplicationConfigString: + protocol.handleGetApplicationConfigString(packet) + case MethodSetApplicationConfigString: + protocol.handleSetApplicationConfigString(packet) + case MethodGetDeletionReason: + protocol.handleGetDeletionReason(packet) + case MethodSetDeletionReason: + protocol.handleSetDeletionReason(packet) + case MethodGetMetasWithCourseRecord: + protocol.handleGetMetasWithCourseRecord(packet) + case MethodCheckRateCustomRankingCounter: + protocol.handleCheckRateCustomRankingCounter(packet) + case MethodResetRateCustomRankingCounter: + protocol.handleResetRateCustomRankingCounter(packet) + case MethodBestScoreRateCourseSearchObject: + protocol.handleBestScoreRateCourseSearchObject(packet) + case MethodCTRPickUpCourseSearchObject: + protocol.handleCTRPickUpCourseSearchObject(packet) + case MethodSetCachedRanking: + protocol.handleSetCachedRanking(packet) + case MethodDeleteCachedRanking: + protocol.handleDeleteCachedRanking(packet) + case MethodChangePlayablePlatform: + protocol.handleChangePlayablePlatform(packet) + case MethodSearchUnknownPlatformObjects: + protocol.handleSearchUnknownPlatformObjects(packet) + case MethodReportCourse: + protocol.handleReportCourse(packet) + default: + errMessage := fmt.Sprintf("Unsupported DataStore (Super Mario Maker) method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new DataStoreSuperMarioMaker protocol +func NewProtocol(endpoint nex.EndpointInterface) *Protocol { + protocol := &Protocol{endpoint: endpoint} + protocol.dataStoreProtocol.SetEndpoint(endpoint) + + return protocol +} diff --git a/nex-protocols-go/datastore/super-mario-maker/rate_custom_ranking.go b/nex-protocols-go/datastore/super-mario-maker/rate_custom_ranking.go new file mode 100644 index 0000000..77ea8d2 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/rate_custom_ranking.go @@ -0,0 +1,49 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-mario-maker/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRateCustomRanking(packet nex.PacketInterface) { + if protocol.RateCustomRanking == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::RateCustomRanking not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + params := types.NewList[*datastore_super_mario_maker_types.DataStoreRateCustomRankingParam]() + params.Type = datastore_super_mario_maker_types.NewDataStoreRateCustomRankingParam() + + err := params.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RateCustomRanking(fmt.Errorf("Failed to read params from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RateCustomRanking(nil, packet, callID, params) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/recommended_course_search_object.go b/nex-protocols-go/datastore/super-mario-maker/recommended_course_search_object.go new file mode 100644 index 0000000..ef0e6a3 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/recommended_course_search_object.go @@ -0,0 +1,62 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRecommendedCourseSearchObject(packet nex.PacketInterface) { + if protocol.RecommendedCourseSearchObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::RecommendedCourseSearchObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreSearchParam() + extraData := types.NewList[*types.String]() + extraData.Type = types.NewString("") + + var err error + + err = param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RecommendedCourseSearchObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = extraData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RecommendedCourseSearchObject(fmt.Errorf("Failed to read extraData from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RecommendedCourseSearchObject(nil, packet, callID, param, extraData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/report_course.go b/nex-protocols-go/datastore/super-mario-maker/report_course.go new file mode 100644 index 0000000..f41c37b --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/report_course.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-mario-maker/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleReportCourse(packet nex.PacketInterface) { + if protocol.ReportCourse == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::ReportCourse not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_mario_maker_types.NewDataStoreReportCourseParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReportCourse(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ReportCourse(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/reset_rate_custom_ranking_counter.go b/nex-protocols-go/datastore/super-mario-maker/reset_rate_custom_ranking_counter.go new file mode 100644 index 0000000..ac91619 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/reset_rate_custom_ranking_counter.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleResetRateCustomRankingCounter(packet nex.PacketInterface) { + if protocol.ResetRateCustomRankingCounter == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::ResetRateCustomRankingCounter not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + applicationID := types.NewPrimitiveU32(0) + + err := applicationID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ResetRateCustomRankingCounter(fmt.Errorf("Failed to read applicationID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ResetRateCustomRankingCounter(nil, packet, callID, applicationID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/score_range_cascaded_search_object.go b/nex-protocols-go/datastore/super-mario-maker/score_range_cascaded_search_object.go new file mode 100644 index 0000000..e583629 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/score_range_cascaded_search_object.go @@ -0,0 +1,62 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleScoreRangeCascadedSearchObject(packet nex.PacketInterface) { + if protocol.ScoreRangeCascadedSearchObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::ScoreRangeCascadedSearchObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreSearchParam() + extraData := types.NewList[*types.String]() + extraData.Type = types.NewString("") + + var err error + + err = param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ScoreRangeCascadedSearchObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = extraData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ScoreRangeCascadedSearchObject(fmt.Errorf("Failed to read extraData from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ScoreRangeCascadedSearchObject(nil, packet, callID, param, extraData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/search_unknown_platform_objects.go b/nex-protocols-go/datastore/super-mario-maker/search_unknown_platform_objects.go new file mode 100644 index 0000000..0c6f9fd --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/search_unknown_platform_objects.go @@ -0,0 +1,31 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSearchUnknownPlatformObjects(packet nex.PacketInterface) { + if protocol.SearchUnknownPlatformObjects == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::SearchUnknownPlatformObjects not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("DataStoreSuperMarioMaker::SearchUnknownPlatformObjects STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.SearchUnknownPlatformObjects(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/set_application_config.go b/nex-protocols-go/datastore/super-mario-maker/set_application_config.go new file mode 100644 index 0000000..1d88a61 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/set_application_config.go @@ -0,0 +1,71 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSetApplicationConfig(packet nex.PacketInterface) { + if protocol.SetApplicationConfig == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::SetApplicationConfig not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + applicationID := types.NewPrimitiveU32(0) + key := types.NewPrimitiveU32(0) + value := types.NewPrimitiveS32(0) + + var err error + + err = applicationID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SetApplicationConfig(fmt.Errorf("Failed to read applicationID from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = key.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SetApplicationConfig(fmt.Errorf("Failed to read key from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = value.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SetApplicationConfig(fmt.Errorf("Failed to read value from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SetApplicationConfig(nil, packet, callID, applicationID, key, value) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/set_application_config_string.go b/nex-protocols-go/datastore/super-mario-maker/set_application_config_string.go new file mode 100644 index 0000000..0a7f4b3 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/set_application_config_string.go @@ -0,0 +1,71 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSetApplicationConfigString(packet nex.PacketInterface) { + if protocol.SetApplicationConfigString == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::SetApplicationConfigString not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + applicationID := types.NewPrimitiveU32(0) + key := types.NewPrimitiveU32(0) + value := types.NewString("") + + var err error + + err = applicationID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SetApplicationConfigString(fmt.Errorf("Failed to read applicationID from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = key.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SetApplicationConfigString(fmt.Errorf("Failed to read key from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = value.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SetApplicationConfigString(fmt.Errorf("Failed to read value from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SetApplicationConfigString(nil, packet, callID, applicationID, key, value) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/set_cached_ranking.go b/nex-protocols-go/datastore/super-mario-maker/set_cached_ranking.go new file mode 100644 index 0000000..4f47047 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/set_cached_ranking.go @@ -0,0 +1,73 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSetCachedRanking(packet nex.PacketInterface) { + if protocol.SetCachedRanking == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::SetCachedRanking not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + rankingType := types.NewString("") + rankingArgs := types.NewList[*types.String]() + rankingArgs.Type = types.NewString("") + dataIDLst := types.NewList[*types.PrimitiveU64]() + dataIDLst.Type = types.NewPrimitiveU64(0) + + var err error + + err = rankingType.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SetCachedRanking(fmt.Errorf("Failed to read rankingType from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = rankingArgs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SetCachedRanking(fmt.Errorf("Failed to read rankingArgs from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = dataIDLst.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SetCachedRanking(fmt.Errorf("Failed to read dataIDLst from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SetCachedRanking(nil, packet, callID, rankingType, rankingArgs, dataIDLst) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/set_deletion_reason.go b/nex-protocols-go/datastore/super-mario-maker/set_deletion_reason.go new file mode 100644 index 0000000..d040b66 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/set_deletion_reason.go @@ -0,0 +1,61 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSetDeletionReason(packet nex.PacketInterface) { + if protocol.SetDeletionReason == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::SetDeletionReason not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + dataIDLst := types.NewList[*types.PrimitiveU64]() + dataIDLst.Type = types.NewPrimitiveU64(0) + deletionReason := types.NewPrimitiveU32(0) + + var err error + + err = dataIDLst.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SetDeletionReason(fmt.Errorf("Failed to read dataIDLst from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = deletionReason.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SetDeletionReason(fmt.Errorf("Failed to read deletionReason from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SetDeletionReason(nil, packet, callID, dataIDLst, deletionReason) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/suggested_course_search_object.go b/nex-protocols-go/datastore/super-mario-maker/suggested_course_search_object.go new file mode 100644 index 0000000..d538d56 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/suggested_course_search_object.go @@ -0,0 +1,62 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSuggestedCourseSearchObject(packet nex.PacketInterface) { + if protocol.SuggestedCourseSearchObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::SuggestedCourseSearchObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreSearchParam() + extraData := types.NewList[*types.String]() + extraData.Type = types.NewString("") + + var err error + + err = param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SuggestedCourseSearchObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = extraData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SuggestedCourseSearchObject(fmt.Errorf("Failed to read extraData from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SuggestedCourseSearchObject(nil, packet, callID, param, extraData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-mario-maker/types/buffer_queue_param.go b/nex-protocols-go/datastore/super-mario-maker/types/buffer_queue_param.go new file mode 100644 index 0000000..622e186 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/types/buffer_queue_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// BufferQueueParam is a type within the DataStore protocol +type BufferQueueParam struct { + types.Structure + DataID *types.PrimitiveU64 + Slot *types.PrimitiveU32 +} + +// WriteTo writes the BufferQueueParam to the given writable +func (bqp *BufferQueueParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + bqp.DataID.WriteTo(contentWritable) + bqp.Slot.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + bqp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the BufferQueueParam from the given readable +func (bqp *BufferQueueParam) ExtractFrom(readable types.Readable) error { + var err error + + err = bqp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BufferQueueParam header. %s", err.Error()) + } + + err = bqp.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BufferQueueParam.DataID. %s", err.Error()) + } + + err = bqp.Slot.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BufferQueueParam.Slot. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of BufferQueueParam +func (bqp *BufferQueueParam) Copy() types.RVType { + copied := NewBufferQueueParam() + + copied.StructureVersion = bqp.StructureVersion + copied.DataID = bqp.DataID.Copy().(*types.PrimitiveU64) + copied.Slot = bqp.Slot.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given BufferQueueParam contains the same data as the current BufferQueueParam +func (bqp *BufferQueueParam) Equals(o types.RVType) bool { + if _, ok := o.(*BufferQueueParam); !ok { + return false + } + + other := o.(*BufferQueueParam) + + if bqp.StructureVersion != other.StructureVersion { + return false + } + + if !bqp.DataID.Equals(other.DataID) { + return false + } + + return bqp.Slot.Equals(other.Slot) +} + +// String returns the string representation of the BufferQueueParam +func (bqp *BufferQueueParam) String() string { + return bqp.FormatToString(0) +} + +// FormatToString pretty-prints the BufferQueueParam using the provided indentation level +func (bqp *BufferQueueParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("BufferQueueParam{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, bqp.DataID)) + b.WriteString(fmt.Sprintf("%sSlot: %s,\n", indentationValues, bqp.Slot)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewBufferQueueParam returns a new BufferQueueParam +func NewBufferQueueParam() *BufferQueueParam { + bqp := &BufferQueueParam{ + DataID: types.NewPrimitiveU64(0), + Slot: types.NewPrimitiveU32(0), + } + + return bqp +} diff --git a/nex-protocols-go/datastore/super-mario-maker/types/datastore_attach_file_param.go b/nex-protocols-go/datastore/super-mario-maker/types/datastore_attach_file_param.go new file mode 100644 index 0000000..9634c2f --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/types/datastore_attach_file_param.go @@ -0,0 +1,127 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +// DataStoreAttachFileParam is a type within the DataStore protocol +type DataStoreAttachFileParam struct { + types.Structure + PostParam *datastore_types.DataStorePreparePostParam + ReferDataID *types.PrimitiveU64 + ContentType *types.String +} + +// WriteTo writes the DataStoreAttachFileParam to the given writable +func (dsafp *DataStoreAttachFileParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsafp.PostParam.WriteTo(contentWritable) + dsafp.ReferDataID.WriteTo(contentWritable) + dsafp.ContentType.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsafp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreAttachFileParam from the given readable +func (dsafp *DataStoreAttachFileParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsafp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreAttachFileParam header. %s", err.Error()) + } + + err = dsafp.PostParam.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreAttachFileParam.PostParam. %s", err.Error()) + } + + err = dsafp.ReferDataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreAttachFileParam.ReferDataID. %s", err.Error()) + } + + err = dsafp.ContentType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreAttachFileParam.ContentType. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreAttachFileParam +func (dsafp *DataStoreAttachFileParam) Copy() types.RVType { + copied := NewDataStoreAttachFileParam() + + copied.StructureVersion = dsafp.StructureVersion + copied.PostParam = dsafp.PostParam.Copy().(*datastore_types.DataStorePreparePostParam) + copied.ReferDataID = dsafp.ReferDataID.Copy().(*types.PrimitiveU64) + copied.ContentType = dsafp.ContentType.Copy().(*types.String) + + return copied +} + +// Equals checks if the given DataStoreAttachFileParam contains the same data as the current DataStoreAttachFileParam +func (dsafp *DataStoreAttachFileParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreAttachFileParam); !ok { + return false + } + + other := o.(*DataStoreAttachFileParam) + + if dsafp.StructureVersion != other.StructureVersion { + return false + } + + if !dsafp.PostParam.Equals(other.PostParam) { + return false + } + + if !dsafp.ReferDataID.Equals(other.ReferDataID) { + return false + } + + return dsafp.ContentType.Equals(other.ContentType) +} + +// String returns the string representation of the DataStoreAttachFileParam +func (dsafp *DataStoreAttachFileParam) String() string { + return dsafp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreAttachFileParam using the provided indentation level +func (dsafp *DataStoreAttachFileParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreAttachFileParam{\n") + b.WriteString(fmt.Sprintf("%sPostParam: %s,\n", indentationValues, dsafp.PostParam.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sReferDataID: %s,\n", indentationValues, dsafp.ReferDataID)) + b.WriteString(fmt.Sprintf("%sContentType: %s,\n", indentationValues, dsafp.ContentType)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreAttachFileParam returns a new DataStoreAttachFileParam +func NewDataStoreAttachFileParam() *DataStoreAttachFileParam { + dsafp := &DataStoreAttachFileParam{ + PostParam: datastore_types.NewDataStorePreparePostParam(), + ReferDataID: types.NewPrimitiveU64(0), + ContentType: types.NewString(""), + } + + return dsafp +} diff --git a/nex-protocols-go/datastore/super-mario-maker/types/datastore_change_playable_platform_param.go b/nex-protocols-go/datastore/super-mario-maker/types/datastore_change_playable_platform_param.go new file mode 100644 index 0000000..c100404 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/types/datastore_change_playable_platform_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreChangePlayablePlatformParam is a type within the DataStore protocol +type DataStoreChangePlayablePlatformParam struct { + types.Structure + DataID *types.PrimitiveU64 + PlayablePlatform *types.PrimitiveU32 +} + +// WriteTo writes the DataStoreChangePlayablePlatformParam to the given writable +func (dscppp *DataStoreChangePlayablePlatformParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dscppp.DataID.WriteTo(contentWritable) + dscppp.PlayablePlatform.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dscppp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreChangePlayablePlatformParam from the given readable +func (dscppp *DataStoreChangePlayablePlatformParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dscppp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangePlayablePlatformParam header. %s", err.Error()) + } + + err = dscppp.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangePlayablePlatformParam.DataID. %s", err.Error()) + } + + err = dscppp.PlayablePlatform.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangePlayablePlatformParam.PlayablePlatform. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreChangePlayablePlatformParam +func (dscppp *DataStoreChangePlayablePlatformParam) Copy() types.RVType { + copied := NewDataStoreChangePlayablePlatformParam() + + copied.StructureVersion = dscppp.StructureVersion + copied.DataID = dscppp.DataID.Copy().(*types.PrimitiveU64) + copied.PlayablePlatform = dscppp.PlayablePlatform.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given DataStoreChangePlayablePlatformParam contains the same data as the current DataStoreChangePlayablePlatformParam +func (dscppp *DataStoreChangePlayablePlatformParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreChangePlayablePlatformParam); !ok { + return false + } + + other := o.(*DataStoreChangePlayablePlatformParam) + + if dscppp.StructureVersion != other.StructureVersion { + return false + } + + if !dscppp.DataID.Equals(other.DataID) { + return false + } + + return dscppp.PlayablePlatform.Equals(other.PlayablePlatform) +} + +// String returns the string representation of the DataStoreChangePlayablePlatformParam +func (dscppp *DataStoreChangePlayablePlatformParam) String() string { + return dscppp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreChangePlayablePlatformParam using the provided indentation level +func (dscppp *DataStoreChangePlayablePlatformParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreChangePlayablePlatformParam{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dscppp.DataID)) + b.WriteString(fmt.Sprintf("%sPlayablePlatform: %s,\n", indentationValues, dscppp.PlayablePlatform)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreChangePlayablePlatformParam returns a new DataStoreChangePlayablePlatformParam +func NewDataStoreChangePlayablePlatformParam() *DataStoreChangePlayablePlatformParam { + dscppp := &DataStoreChangePlayablePlatformParam{ + DataID: types.NewPrimitiveU64(0), + PlayablePlatform: types.NewPrimitiveU32(0), + } + + return dscppp +} diff --git a/nex-protocols-go/datastore/super-mario-maker/types/datastore_custom_ranking_rating_condition.go b/nex-protocols-go/datastore/super-mario-maker/types/datastore_custom_ranking_rating_condition.go new file mode 100644 index 0000000..471a30a --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/types/datastore_custom_ranking_rating_condition.go @@ -0,0 +1,164 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreCustomRankingRatingCondition is a type within the DataStore protocol +type DataStoreCustomRankingRatingCondition struct { + types.Structure + Slot *types.PrimitiveS8 + MinValue *types.PrimitiveS32 + MaxValue *types.PrimitiveS32 + MinCount *types.PrimitiveS32 // * Revision 1 + MaxCount *types.PrimitiveS32 // * Revision 1 +} + +// WriteTo writes the DataStoreCustomRankingRatingCondition to the given writable +func (dscrrc *DataStoreCustomRankingRatingCondition) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dscrrc.Slot.WriteTo(contentWritable) + dscrrc.MinValue.WriteTo(contentWritable) + dscrrc.MaxValue.WriteTo(contentWritable) + + if dscrrc.StructureVersion >= 1 { + dscrrc.MinCount.WriteTo(contentWritable) + } + + if dscrrc.StructureVersion >= 1 { + dscrrc.MaxCount.WriteTo(contentWritable) + } + + content := contentWritable.Bytes() + + dscrrc.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreCustomRankingRatingCondition from the given readable +func (dscrrc *DataStoreCustomRankingRatingCondition) ExtractFrom(readable types.Readable) error { + var err error + + err = dscrrc.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCustomRankingRatingCondition header. %s", err.Error()) + } + + err = dscrrc.Slot.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCustomRankingRatingCondition.Slot. %s", err.Error()) + } + + err = dscrrc.MinValue.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCustomRankingRatingCondition.MinValue. %s", err.Error()) + } + + err = dscrrc.MaxValue.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCustomRankingRatingCondition.MaxValue. %s", err.Error()) + } + + if dscrrc.StructureVersion >= 1 { + err = dscrrc.MinCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCustomRankingRatingCondition.MinCount. %s", err.Error()) + } + } + + if dscrrc.StructureVersion >= 1 { + err = dscrrc.MaxCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCustomRankingRatingCondition.MaxCount. %s", err.Error()) + } + } + + return nil +} + +// Copy returns a new copied instance of DataStoreCustomRankingRatingCondition +func (dscrrc *DataStoreCustomRankingRatingCondition) Copy() types.RVType { + copied := NewDataStoreCustomRankingRatingCondition() + + copied.StructureVersion = dscrrc.StructureVersion + copied.Slot = dscrrc.Slot.Copy().(*types.PrimitiveS8) + copied.MinValue = dscrrc.MinValue.Copy().(*types.PrimitiveS32) + copied.MaxValue = dscrrc.MaxValue.Copy().(*types.PrimitiveS32) + copied.MinCount = dscrrc.MinCount.Copy().(*types.PrimitiveS32) + copied.MaxCount = dscrrc.MaxCount.Copy().(*types.PrimitiveS32) + + return copied +} + +// Equals checks if the given DataStoreCustomRankingRatingCondition contains the same data as the current DataStoreCustomRankingRatingCondition +func (dscrrc *DataStoreCustomRankingRatingCondition) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreCustomRankingRatingCondition); !ok { + return false + } + + other := o.(*DataStoreCustomRankingRatingCondition) + + if dscrrc.StructureVersion != other.StructureVersion { + return false + } + + if !dscrrc.Slot.Equals(other.Slot) { + return false + } + + if !dscrrc.MinValue.Equals(other.MinValue) { + return false + } + + if !dscrrc.MaxValue.Equals(other.MaxValue) { + return false + } + + if !dscrrc.MinCount.Equals(other.MinCount) { + return false + } + + return dscrrc.MaxCount.Equals(other.MaxCount) +} + +// String returns the string representation of the DataStoreCustomRankingRatingCondition +func (dscrrc *DataStoreCustomRankingRatingCondition) String() string { + return dscrrc.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreCustomRankingRatingCondition using the provided indentation level +func (dscrrc *DataStoreCustomRankingRatingCondition) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreCustomRankingRatingCondition{\n") + b.WriteString(fmt.Sprintf("%sSlot: %s,\n", indentationValues, dscrrc.Slot)) + b.WriteString(fmt.Sprintf("%sMinValue: %s,\n", indentationValues, dscrrc.MinValue)) + b.WriteString(fmt.Sprintf("%sMaxValue: %s,\n", indentationValues, dscrrc.MaxValue)) + b.WriteString(fmt.Sprintf("%sMinCount: %s,\n", indentationValues, dscrrc.MinCount)) + b.WriteString(fmt.Sprintf("%sMaxCount: %s,\n", indentationValues, dscrrc.MaxCount)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreCustomRankingRatingCondition returns a new DataStoreCustomRankingRatingCondition +func NewDataStoreCustomRankingRatingCondition() *DataStoreCustomRankingRatingCondition { + dscrrc := &DataStoreCustomRankingRatingCondition{ + Slot: types.NewPrimitiveS8(0), + MinValue: types.NewPrimitiveS32(0), + MaxValue: types.NewPrimitiveS32(0), + MinCount: types.NewPrimitiveS32(0), + MaxCount: types.NewPrimitiveS32(0), + } + + return dscrrc +} diff --git a/nex-protocols-go/datastore/super-mario-maker/types/datastore_custom_ranking_result.go b/nex-protocols-go/datastore/super-mario-maker/types/datastore_custom_ranking_result.go new file mode 100644 index 0000000..cf56a18 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/types/datastore_custom_ranking_result.go @@ -0,0 +1,127 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +// DataStoreCustomRankingResult is a type within the DataStore protocol +type DataStoreCustomRankingResult struct { + types.Structure + Order *types.PrimitiveU32 + Score *types.PrimitiveU32 + MetaInfo *datastore_types.DataStoreMetaInfo +} + +// WriteTo writes the DataStoreCustomRankingResult to the given writable +func (dscrr *DataStoreCustomRankingResult) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dscrr.Order.WriteTo(contentWritable) + dscrr.Score.WriteTo(contentWritable) + dscrr.MetaInfo.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dscrr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreCustomRankingResult from the given readable +func (dscrr *DataStoreCustomRankingResult) ExtractFrom(readable types.Readable) error { + var err error + + err = dscrr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCustomRankingResult header. %s", err.Error()) + } + + err = dscrr.Order.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCustomRankingResult.Order. %s", err.Error()) + } + + err = dscrr.Score.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCustomRankingResult.Score. %s", err.Error()) + } + + err = dscrr.MetaInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCustomRankingResult.MetaInfo. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreCustomRankingResult +func (dscrr *DataStoreCustomRankingResult) Copy() types.RVType { + copied := NewDataStoreCustomRankingResult() + + copied.StructureVersion = dscrr.StructureVersion + copied.Order = dscrr.Order.Copy().(*types.PrimitiveU32) + copied.Score = dscrr.Score.Copy().(*types.PrimitiveU32) + copied.MetaInfo = dscrr.MetaInfo.Copy().(*datastore_types.DataStoreMetaInfo) + + return copied +} + +// Equals checks if the given DataStoreCustomRankingResult contains the same data as the current DataStoreCustomRankingResult +func (dscrr *DataStoreCustomRankingResult) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreCustomRankingResult); !ok { + return false + } + + other := o.(*DataStoreCustomRankingResult) + + if dscrr.StructureVersion != other.StructureVersion { + return false + } + + if !dscrr.Order.Equals(other.Order) { + return false + } + + if !dscrr.Score.Equals(other.Score) { + return false + } + + return dscrr.MetaInfo.Equals(other.MetaInfo) +} + +// String returns the string representation of the DataStoreCustomRankingResult +func (dscrr *DataStoreCustomRankingResult) String() string { + return dscrr.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreCustomRankingResult using the provided indentation level +func (dscrr *DataStoreCustomRankingResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreCustomRankingResult{\n") + b.WriteString(fmt.Sprintf("%sOrder: %s,\n", indentationValues, dscrr.Order)) + b.WriteString(fmt.Sprintf("%sScore: %s,\n", indentationValues, dscrr.Score)) + b.WriteString(fmt.Sprintf("%sMetaInfo: %s,\n", indentationValues, dscrr.MetaInfo.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreCustomRankingResult returns a new DataStoreCustomRankingResult +func NewDataStoreCustomRankingResult() *DataStoreCustomRankingResult { + dscrr := &DataStoreCustomRankingResult{ + Order: types.NewPrimitiveU32(0), + Score: types.NewPrimitiveU32(0), + MetaInfo: datastore_types.NewDataStoreMetaInfo(), + } + + return dscrr +} diff --git a/nex-protocols-go/datastore/super-mario-maker/types/datastore_file_server_object_info.go b/nex-protocols-go/datastore/super-mario-maker/types/datastore_file_server_object_info.go new file mode 100644 index 0000000..95be0e7 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/types/datastore_file_server_object_info.go @@ -0,0 +1,113 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +// DataStoreFileServerObjectInfo is a type within the DataStore protocol +type DataStoreFileServerObjectInfo struct { + types.Structure + DataID *types.PrimitiveU64 + GetInfo *datastore_types.DataStoreReqGetInfo +} + +// WriteTo writes the DataStoreFileServerObjectInfo to the given writable +func (dsfsoi *DataStoreFileServerObjectInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsfsoi.DataID.WriteTo(contentWritable) + dsfsoi.GetInfo.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsfsoi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreFileServerObjectInfo from the given readable +func (dsfsoi *DataStoreFileServerObjectInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = dsfsoi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreFileServerObjectInfo header. %s", err.Error()) + } + + err = dsfsoi.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreFileServerObjectInfo.DataID. %s", err.Error()) + } + + err = dsfsoi.GetInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreFileServerObjectInfo.GetInfo. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreFileServerObjectInfo +func (dsfsoi *DataStoreFileServerObjectInfo) Copy() types.RVType { + copied := NewDataStoreFileServerObjectInfo() + + copied.StructureVersion = dsfsoi.StructureVersion + copied.DataID = dsfsoi.DataID.Copy().(*types.PrimitiveU64) + copied.GetInfo = dsfsoi.GetInfo.Copy().(*datastore_types.DataStoreReqGetInfo) + + return copied +} + +// Equals checks if the given DataStoreFileServerObjectInfo contains the same data as the current DataStoreFileServerObjectInfo +func (dsfsoi *DataStoreFileServerObjectInfo) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreFileServerObjectInfo); !ok { + return false + } + + other := o.(*DataStoreFileServerObjectInfo) + + if dsfsoi.StructureVersion != other.StructureVersion { + return false + } + + if !dsfsoi.DataID.Equals(other.DataID) { + return false + } + + return dsfsoi.GetInfo.Equals(other.GetInfo) +} + +// String returns the string representation of the DataStoreFileServerObjectInfo +func (dsfsoi *DataStoreFileServerObjectInfo) String() string { + return dsfsoi.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreFileServerObjectInfo using the provided indentation level +func (dsfsoi *DataStoreFileServerObjectInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreFileServerObjectInfo{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dsfsoi.DataID)) + b.WriteString(fmt.Sprintf("%sGetInfo: %s,\n", indentationValues, dsfsoi.GetInfo.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreFileServerObjectInfo returns a new DataStoreFileServerObjectInfo +func NewDataStoreFileServerObjectInfo() *DataStoreFileServerObjectInfo { + dsfsoi := &DataStoreFileServerObjectInfo{ + DataID: types.NewPrimitiveU64(0), + GetInfo: datastore_types.NewDataStoreReqGetInfo(), + } + + return dsfsoi +} diff --git a/nex-protocols-go/datastore/super-mario-maker/types/datastore_get_course_record_param.go b/nex-protocols-go/datastore/super-mario-maker/types/datastore_get_course_record_param.go new file mode 100644 index 0000000..ece0a64 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/types/datastore_get_course_record_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreGetCourseRecordParam is a type within the DataStore protocol +type DataStoreGetCourseRecordParam struct { + types.Structure + DataID *types.PrimitiveU64 + Slot *types.PrimitiveU8 +} + +// WriteTo writes the DataStoreGetCourseRecordParam to the given writable +func (dsgcrp *DataStoreGetCourseRecordParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsgcrp.DataID.WriteTo(contentWritable) + dsgcrp.Slot.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsgcrp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreGetCourseRecordParam from the given readable +func (dsgcrp *DataStoreGetCourseRecordParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsgcrp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCourseRecordParam header. %s", err.Error()) + } + + err = dsgcrp.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCourseRecordParam.DataID. %s", err.Error()) + } + + err = dsgcrp.Slot.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCourseRecordParam.Slot. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreGetCourseRecordParam +func (dsgcrp *DataStoreGetCourseRecordParam) Copy() types.RVType { + copied := NewDataStoreGetCourseRecordParam() + + copied.StructureVersion = dsgcrp.StructureVersion + copied.DataID = dsgcrp.DataID.Copy().(*types.PrimitiveU64) + copied.Slot = dsgcrp.Slot.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given DataStoreGetCourseRecordParam contains the same data as the current DataStoreGetCourseRecordParam +func (dsgcrp *DataStoreGetCourseRecordParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreGetCourseRecordParam); !ok { + return false + } + + other := o.(*DataStoreGetCourseRecordParam) + + if dsgcrp.StructureVersion != other.StructureVersion { + return false + } + + if !dsgcrp.DataID.Equals(other.DataID) { + return false + } + + return dsgcrp.Slot.Equals(other.Slot) +} + +// String returns the string representation of the DataStoreGetCourseRecordParam +func (dsgcrp *DataStoreGetCourseRecordParam) String() string { + return dsgcrp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreGetCourseRecordParam using the provided indentation level +func (dsgcrp *DataStoreGetCourseRecordParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreGetCourseRecordParam{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dsgcrp.DataID)) + b.WriteString(fmt.Sprintf("%sSlot: %s,\n", indentationValues, dsgcrp.Slot)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreGetCourseRecordParam returns a new DataStoreGetCourseRecordParam +func NewDataStoreGetCourseRecordParam() *DataStoreGetCourseRecordParam { + dsgcrp := &DataStoreGetCourseRecordParam{ + DataID: types.NewPrimitiveU64(0), + Slot: types.NewPrimitiveU8(0), + } + + return dsgcrp +} diff --git a/nex-protocols-go/datastore/super-mario-maker/types/datastore_get_course_record_result.go b/nex-protocols-go/datastore/super-mario-maker/types/datastore_get_course_record_result.go new file mode 100644 index 0000000..1c72f03 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/types/datastore_get_course_record_result.go @@ -0,0 +1,182 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreGetCourseRecordResult is a type within the DataStore protocol +type DataStoreGetCourseRecordResult struct { + types.Structure + DataID *types.PrimitiveU64 + Slot *types.PrimitiveU8 + FirstPID *types.PID + BestPID *types.PID + BestScore *types.PrimitiveS32 + CreatedTime *types.DateTime + UpdatedTime *types.DateTime +} + +// WriteTo writes the DataStoreGetCourseRecordResult to the given writable +func (dsgcrr *DataStoreGetCourseRecordResult) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsgcrr.DataID.WriteTo(contentWritable) + dsgcrr.Slot.WriteTo(contentWritable) + dsgcrr.FirstPID.WriteTo(contentWritable) + dsgcrr.BestPID.WriteTo(contentWritable) + dsgcrr.BestScore.WriteTo(contentWritable) + dsgcrr.CreatedTime.WriteTo(contentWritable) + dsgcrr.UpdatedTime.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsgcrr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreGetCourseRecordResult from the given readable +func (dsgcrr *DataStoreGetCourseRecordResult) ExtractFrom(readable types.Readable) error { + var err error + + err = dsgcrr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCourseRecordResult header. %s", err.Error()) + } + + err = dsgcrr.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCourseRecordResult.DataID. %s", err.Error()) + } + + err = dsgcrr.Slot.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCourseRecordResult.Slot. %s", err.Error()) + } + + err = dsgcrr.FirstPID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCourseRecordResult.FirstPID. %s", err.Error()) + } + + err = dsgcrr.BestPID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCourseRecordResult.BestPID. %s", err.Error()) + } + + err = dsgcrr.BestScore.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCourseRecordResult.BestScore. %s", err.Error()) + } + + err = dsgcrr.CreatedTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCourseRecordResult.CreatedTime. %s", err.Error()) + } + + err = dsgcrr.UpdatedTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCourseRecordResult.UpdatedTime. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreGetCourseRecordResult +func (dsgcrr *DataStoreGetCourseRecordResult) Copy() types.RVType { + copied := NewDataStoreGetCourseRecordResult() + + copied.StructureVersion = dsgcrr.StructureVersion + copied.DataID = dsgcrr.DataID.Copy().(*types.PrimitiveU64) + copied.Slot = dsgcrr.Slot.Copy().(*types.PrimitiveU8) + copied.FirstPID = dsgcrr.FirstPID.Copy().(*types.PID) + copied.BestPID = dsgcrr.BestPID.Copy().(*types.PID) + copied.BestScore = dsgcrr.BestScore.Copy().(*types.PrimitiveS32) + copied.CreatedTime = dsgcrr.CreatedTime.Copy().(*types.DateTime) + copied.UpdatedTime = dsgcrr.UpdatedTime.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given DataStoreGetCourseRecordResult contains the same data as the current DataStoreGetCourseRecordResult +func (dsgcrr *DataStoreGetCourseRecordResult) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreGetCourseRecordResult); !ok { + return false + } + + other := o.(*DataStoreGetCourseRecordResult) + + if dsgcrr.StructureVersion != other.StructureVersion { + return false + } + + if !dsgcrr.DataID.Equals(other.DataID) { + return false + } + + if !dsgcrr.Slot.Equals(other.Slot) { + return false + } + + if !dsgcrr.FirstPID.Equals(other.FirstPID) { + return false + } + + if !dsgcrr.BestPID.Equals(other.BestPID) { + return false + } + + if !dsgcrr.BestScore.Equals(other.BestScore) { + return false + } + + if !dsgcrr.CreatedTime.Equals(other.CreatedTime) { + return false + } + + return dsgcrr.UpdatedTime.Equals(other.UpdatedTime) +} + +// String returns the string representation of the DataStoreGetCourseRecordResult +func (dsgcrr *DataStoreGetCourseRecordResult) String() string { + return dsgcrr.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreGetCourseRecordResult using the provided indentation level +func (dsgcrr *DataStoreGetCourseRecordResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreGetCourseRecordResult{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dsgcrr.DataID)) + b.WriteString(fmt.Sprintf("%sSlot: %s,\n", indentationValues, dsgcrr.Slot)) + b.WriteString(fmt.Sprintf("%sFirstPID: %s,\n", indentationValues, dsgcrr.FirstPID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sBestPID: %s,\n", indentationValues, dsgcrr.BestPID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sBestScore: %s,\n", indentationValues, dsgcrr.BestScore)) + b.WriteString(fmt.Sprintf("%sCreatedTime: %s,\n", indentationValues, dsgcrr.CreatedTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUpdatedTime: %s,\n", indentationValues, dsgcrr.UpdatedTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreGetCourseRecordResult returns a new DataStoreGetCourseRecordResult +func NewDataStoreGetCourseRecordResult() *DataStoreGetCourseRecordResult { + dsgcrr := &DataStoreGetCourseRecordResult{ + DataID: types.NewPrimitiveU64(0), + Slot: types.NewPrimitiveU8(0), + FirstPID: types.NewPID(0), + BestPID: types.NewPID(0), + BestScore: types.NewPrimitiveS32(0), + CreatedTime: types.NewDateTime(0), + UpdatedTime: types.NewDateTime(0), + } + + return dsgcrr +} diff --git a/nex-protocols-go/datastore/super-mario-maker/types/datastore_get_custom_ranking_by_data_id_param.go b/nex-protocols-go/datastore/super-mario-maker/types/datastore_get_custom_ranking_by_data_id_param.go new file mode 100644 index 0000000..72cfd01 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/types/datastore_get_custom_ranking_by_data_id_param.go @@ -0,0 +1,128 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreGetCustomRankingByDataIDParam is a type within the DataStore protocol +type DataStoreGetCustomRankingByDataIDParam struct { + types.Structure + ApplicationID *types.PrimitiveU32 + DataIDList *types.List[*types.PrimitiveU64] + ResultOption *types.PrimitiveU8 +} + +// WriteTo writes the DataStoreGetCustomRankingByDataIDParam to the given writable +func (dsgcrbdidp *DataStoreGetCustomRankingByDataIDParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsgcrbdidp.ApplicationID.WriteTo(contentWritable) + dsgcrbdidp.DataIDList.WriteTo(contentWritable) + dsgcrbdidp.ResultOption.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsgcrbdidp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreGetCustomRankingByDataIDParam from the given readable +func (dsgcrbdidp *DataStoreGetCustomRankingByDataIDParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsgcrbdidp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCustomRankingByDataIDParam header. %s", err.Error()) + } + + err = dsgcrbdidp.ApplicationID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCustomRankingByDataIDParam.ApplicationID. %s", err.Error()) + } + + err = dsgcrbdidp.DataIDList.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCustomRankingByDataIDParam.DataIDList. %s", err.Error()) + } + + err = dsgcrbdidp.ResultOption.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCustomRankingByDataIDParam.ResultOption. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreGetCustomRankingByDataIDParam +func (dsgcrbdidp *DataStoreGetCustomRankingByDataIDParam) Copy() types.RVType { + copied := NewDataStoreGetCustomRankingByDataIDParam() + + copied.StructureVersion = dsgcrbdidp.StructureVersion + copied.ApplicationID = dsgcrbdidp.ApplicationID.Copy().(*types.PrimitiveU32) + copied.DataIDList = dsgcrbdidp.DataIDList.Copy().(*types.List[*types.PrimitiveU64]) + copied.ResultOption = dsgcrbdidp.ResultOption.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given DataStoreGetCustomRankingByDataIDParam contains the same data as the current DataStoreGetCustomRankingByDataIDParam +func (dsgcrbdidp *DataStoreGetCustomRankingByDataIDParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreGetCustomRankingByDataIDParam); !ok { + return false + } + + other := o.(*DataStoreGetCustomRankingByDataIDParam) + + if dsgcrbdidp.StructureVersion != other.StructureVersion { + return false + } + + if !dsgcrbdidp.ApplicationID.Equals(other.ApplicationID) { + return false + } + + if !dsgcrbdidp.DataIDList.Equals(other.DataIDList) { + return false + } + + return dsgcrbdidp.ResultOption.Equals(other.ResultOption) +} + +// String returns the string representation of the DataStoreGetCustomRankingByDataIDParam +func (dsgcrbdidp *DataStoreGetCustomRankingByDataIDParam) String() string { + return dsgcrbdidp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreGetCustomRankingByDataIDParam using the provided indentation level +func (dsgcrbdidp *DataStoreGetCustomRankingByDataIDParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreGetCustomRankingByDataIDParam{\n") + b.WriteString(fmt.Sprintf("%sApplicationID: %s,\n", indentationValues, dsgcrbdidp.ApplicationID)) + b.WriteString(fmt.Sprintf("%sDataIDList: %s,\n", indentationValues, dsgcrbdidp.DataIDList)) + b.WriteString(fmt.Sprintf("%sResultOption: %s,\n", indentationValues, dsgcrbdidp.ResultOption)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreGetCustomRankingByDataIDParam returns a new DataStoreGetCustomRankingByDataIDParam +func NewDataStoreGetCustomRankingByDataIDParam() *DataStoreGetCustomRankingByDataIDParam { + dsgcrbdidp := &DataStoreGetCustomRankingByDataIDParam{ + ApplicationID: types.NewPrimitiveU32(0), + DataIDList: types.NewList[*types.PrimitiveU64](), + ResultOption: types.NewPrimitiveU8(0), + } + + dsgcrbdidp.DataIDList.Type = types.NewPrimitiveU64(0) + + return dsgcrbdidp +} diff --git a/nex-protocols-go/datastore/super-mario-maker/types/datastore_get_custom_ranking_param.go b/nex-protocols-go/datastore/super-mario-maker/types/datastore_get_custom_ranking_param.go new file mode 100644 index 0000000..3f4bb1e --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/types/datastore_get_custom_ranking_param.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreGetCustomRankingParam is a type within the DataStore protocol +type DataStoreGetCustomRankingParam struct { + types.Structure + ApplicationID *types.PrimitiveU32 + Condition *DataStoreCustomRankingRatingCondition + ResultOption *types.PrimitiveU8 + ResultRange *types.ResultRange +} + +// WriteTo writes the DataStoreGetCustomRankingParam to the given writable +func (dsgcrp *DataStoreGetCustomRankingParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsgcrp.ApplicationID.WriteTo(contentWritable) + dsgcrp.Condition.WriteTo(contentWritable) + dsgcrp.ResultOption.WriteTo(contentWritable) + dsgcrp.ResultRange.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsgcrp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreGetCustomRankingParam from the given readable +func (dsgcrp *DataStoreGetCustomRankingParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsgcrp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCustomRankingParam header. %s", err.Error()) + } + + err = dsgcrp.ApplicationID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCustomRankingParam.ApplicationID. %s", err.Error()) + } + + err = dsgcrp.Condition.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCustomRankingParam.Condition. %s", err.Error()) + } + + err = dsgcrp.ResultOption.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCustomRankingParam.ResultOption. %s", err.Error()) + } + + err = dsgcrp.ResultRange.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetCustomRankingParam.ResultRange. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreGetCustomRankingParam +func (dsgcrp *DataStoreGetCustomRankingParam) Copy() types.RVType { + copied := NewDataStoreGetCustomRankingParam() + + copied.StructureVersion = dsgcrp.StructureVersion + copied.ApplicationID = dsgcrp.ApplicationID.Copy().(*types.PrimitiveU32) + copied.Condition = dsgcrp.Condition.Copy().(*DataStoreCustomRankingRatingCondition) + copied.ResultOption = dsgcrp.ResultOption.Copy().(*types.PrimitiveU8) + copied.ResultRange = dsgcrp.ResultRange.Copy().(*types.ResultRange) + + return copied +} + +// Equals checks if the given DataStoreGetCustomRankingParam contains the same data as the current DataStoreGetCustomRankingParam +func (dsgcrp *DataStoreGetCustomRankingParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreGetCustomRankingParam); !ok { + return false + } + + other := o.(*DataStoreGetCustomRankingParam) + + if dsgcrp.StructureVersion != other.StructureVersion { + return false + } + + if !dsgcrp.ApplicationID.Equals(other.ApplicationID) { + return false + } + + if !dsgcrp.Condition.Equals(other.Condition) { + return false + } + + if !dsgcrp.ResultOption.Equals(other.ResultOption) { + return false + } + + return dsgcrp.ResultRange.Equals(other.ResultRange) +} + +// String returns the string representation of the DataStoreGetCustomRankingParam +func (dsgcrp *DataStoreGetCustomRankingParam) String() string { + return dsgcrp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreGetCustomRankingParam using the provided indentation level +func (dsgcrp *DataStoreGetCustomRankingParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreGetCustomRankingParam{\n") + b.WriteString(fmt.Sprintf("%sApplicationID: %s,\n", indentationValues, dsgcrp.ApplicationID)) + b.WriteString(fmt.Sprintf("%sCondition: %s,\n", indentationValues, dsgcrp.Condition.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sResultOption: %s,\n", indentationValues, dsgcrp.ResultOption)) + b.WriteString(fmt.Sprintf("%sResultRange: %s,\n", indentationValues, dsgcrp.ResultRange.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreGetCustomRankingParam returns a new DataStoreGetCustomRankingParam +func NewDataStoreGetCustomRankingParam() *DataStoreGetCustomRankingParam { + dsgcrp := &DataStoreGetCustomRankingParam{ + ApplicationID: types.NewPrimitiveU32(0), + Condition: NewDataStoreCustomRankingRatingCondition(), + ResultOption: types.NewPrimitiveU8(0), + ResultRange: types.NewResultRange(), + } + + return dsgcrp +} diff --git a/nex-protocols-go/datastore/super-mario-maker/types/datastore_get_meta_by_owner_id_param.go b/nex-protocols-go/datastore/super-mario-maker/types/datastore_get_meta_by_owner_id_param.go new file mode 100644 index 0000000..9d89d92 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/types/datastore_get_meta_by_owner_id_param.go @@ -0,0 +1,143 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreGetMetaByOwnerIDParam is a type within the DataStore protocol +type DataStoreGetMetaByOwnerIDParam struct { + types.Structure + OwnerIDs *types.List[*types.PrimitiveU32] + DataTypes *types.List[*types.PrimitiveU16] + ResultOption *types.PrimitiveU8 + ResultRange *types.ResultRange +} + +// WriteTo writes the DataStoreGetMetaByOwnerIDParam to the given writable +func (dsgmboidp *DataStoreGetMetaByOwnerIDParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsgmboidp.OwnerIDs.WriteTo(contentWritable) + dsgmboidp.DataTypes.WriteTo(contentWritable) + dsgmboidp.ResultOption.WriteTo(contentWritable) + dsgmboidp.ResultRange.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsgmboidp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreGetMetaByOwnerIDParam from the given readable +func (dsgmboidp *DataStoreGetMetaByOwnerIDParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsgmboidp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetMetaByOwnerIDParam header. %s", err.Error()) + } + + err = dsgmboidp.OwnerIDs.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetMetaByOwnerIDParam.OwnerIDs. %s", err.Error()) + } + + err = dsgmboidp.DataTypes.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetMetaByOwnerIDParam.DataTypes. %s", err.Error()) + } + + err = dsgmboidp.ResultOption.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetMetaByOwnerIDParam.ResultOption. %s", err.Error()) + } + + err = dsgmboidp.ResultRange.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetMetaByOwnerIDParam.ResultRange. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreGetMetaByOwnerIDParam +func (dsgmboidp *DataStoreGetMetaByOwnerIDParam) Copy() types.RVType { + copied := NewDataStoreGetMetaByOwnerIDParam() + + copied.StructureVersion = dsgmboidp.StructureVersion + copied.OwnerIDs = dsgmboidp.OwnerIDs.Copy().(*types.List[*types.PrimitiveU32]) + copied.DataTypes = dsgmboidp.DataTypes.Copy().(*types.List[*types.PrimitiveU16]) + copied.ResultOption = dsgmboidp.ResultOption.Copy().(*types.PrimitiveU8) + copied.ResultRange = dsgmboidp.ResultRange.Copy().(*types.ResultRange) + + return copied +} + +// Equals checks if the given DataStoreGetMetaByOwnerIDParam contains the same data as the current DataStoreGetMetaByOwnerIDParam +func (dsgmboidp *DataStoreGetMetaByOwnerIDParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreGetMetaByOwnerIDParam); !ok { + return false + } + + other := o.(*DataStoreGetMetaByOwnerIDParam) + + if dsgmboidp.StructureVersion != other.StructureVersion { + return false + } + + if !dsgmboidp.OwnerIDs.Equals(other.OwnerIDs) { + return false + } + + if !dsgmboidp.DataTypes.Equals(other.DataTypes) { + return false + } + + if !dsgmboidp.ResultOption.Equals(other.ResultOption) { + return false + } + + return dsgmboidp.ResultRange.Equals(other.ResultRange) +} + +// String returns the string representation of the DataStoreGetMetaByOwnerIDParam +func (dsgmboidp *DataStoreGetMetaByOwnerIDParam) String() string { + return dsgmboidp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreGetMetaByOwnerIDParam using the provided indentation level +func (dsgmboidp *DataStoreGetMetaByOwnerIDParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreGetMetaByOwnerIDParam{\n") + b.WriteString(fmt.Sprintf("%sOwnerIDs: %s,\n", indentationValues, dsgmboidp.OwnerIDs)) + b.WriteString(fmt.Sprintf("%sDataTypes: %s,\n", indentationValues, dsgmboidp.DataTypes)) + b.WriteString(fmt.Sprintf("%sResultOption: %s,\n", indentationValues, dsgmboidp.ResultOption)) + b.WriteString(fmt.Sprintf("%sResultRange: %s,\n", indentationValues, dsgmboidp.ResultRange.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreGetMetaByOwnerIDParam returns a new DataStoreGetMetaByOwnerIDParam +func NewDataStoreGetMetaByOwnerIDParam() *DataStoreGetMetaByOwnerIDParam { + dsgmboidp := &DataStoreGetMetaByOwnerIDParam{ + OwnerIDs: types.NewList[*types.PrimitiveU32](), + DataTypes: types.NewList[*types.PrimitiveU16](), + ResultOption: types.NewPrimitiveU8(0), + ResultRange: types.NewResultRange(), + } + + dsgmboidp.OwnerIDs.Type = types.NewPrimitiveU32(0) + dsgmboidp.DataTypes.Type = types.NewPrimitiveU16(0) + + return dsgmboidp +} diff --git a/nex-protocols-go/datastore/super-mario-maker/types/datastore_rate_custom_ranking_param.go b/nex-protocols-go/datastore/super-mario-maker/types/datastore_rate_custom_ranking_param.go new file mode 100644 index 0000000..9253688 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/types/datastore_rate_custom_ranking_param.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreRateCustomRankingParam is a type within the DataStore protocol +type DataStoreRateCustomRankingParam struct { + types.Structure + DataID *types.PrimitiveU64 + ApplicationID *types.PrimitiveU32 + Score *types.PrimitiveU32 + Period *types.PrimitiveU16 +} + +// WriteTo writes the DataStoreRateCustomRankingParam to the given writable +func (dsrcrp *DataStoreRateCustomRankingParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsrcrp.DataID.WriteTo(contentWritable) + dsrcrp.ApplicationID.WriteTo(contentWritable) + dsrcrp.Score.WriteTo(contentWritable) + dsrcrp.Period.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsrcrp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreRateCustomRankingParam from the given readable +func (dsrcrp *DataStoreRateCustomRankingParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsrcrp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRateCustomRankingParam header. %s", err.Error()) + } + + err = dsrcrp.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRateCustomRankingParam.DataID. %s", err.Error()) + } + + err = dsrcrp.ApplicationID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRateCustomRankingParam.ApplicationID. %s", err.Error()) + } + + err = dsrcrp.Score.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRateCustomRankingParam.Score. %s", err.Error()) + } + + err = dsrcrp.Period.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRateCustomRankingParam.Period. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreRateCustomRankingParam +func (dsrcrp *DataStoreRateCustomRankingParam) Copy() types.RVType { + copied := NewDataStoreRateCustomRankingParam() + + copied.StructureVersion = dsrcrp.StructureVersion + copied.DataID = dsrcrp.DataID.Copy().(*types.PrimitiveU64) + copied.ApplicationID = dsrcrp.ApplicationID.Copy().(*types.PrimitiveU32) + copied.Score = dsrcrp.Score.Copy().(*types.PrimitiveU32) + copied.Period = dsrcrp.Period.Copy().(*types.PrimitiveU16) + + return copied +} + +// Equals checks if the given DataStoreRateCustomRankingParam contains the same data as the current DataStoreRateCustomRankingParam +func (dsrcrp *DataStoreRateCustomRankingParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreRateCustomRankingParam); !ok { + return false + } + + other := o.(*DataStoreRateCustomRankingParam) + + if dsrcrp.StructureVersion != other.StructureVersion { + return false + } + + if !dsrcrp.DataID.Equals(other.DataID) { + return false + } + + if !dsrcrp.ApplicationID.Equals(other.ApplicationID) { + return false + } + + if !dsrcrp.Score.Equals(other.Score) { + return false + } + + return dsrcrp.Period.Equals(other.Period) +} + +// String returns the string representation of the DataStoreRateCustomRankingParam +func (dsrcrp *DataStoreRateCustomRankingParam) String() string { + return dsrcrp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreRateCustomRankingParam using the provided indentation level +func (dsrcrp *DataStoreRateCustomRankingParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreRateCustomRankingParam{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dsrcrp.DataID)) + b.WriteString(fmt.Sprintf("%sApplicationID: %s,\n", indentationValues, dsrcrp.ApplicationID)) + b.WriteString(fmt.Sprintf("%sScore: %s,\n", indentationValues, dsrcrp.Score)) + b.WriteString(fmt.Sprintf("%sPeriod: %s,\n", indentationValues, dsrcrp.Period)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreRateCustomRankingParam returns a new DataStoreRateCustomRankingParam +func NewDataStoreRateCustomRankingParam() *DataStoreRateCustomRankingParam { + dsrcrp := &DataStoreRateCustomRankingParam{ + DataID: types.NewPrimitiveU64(0), + ApplicationID: types.NewPrimitiveU32(0), + Score: types.NewPrimitiveU32(0), + Period: types.NewPrimitiveU16(0), + } + + return dsrcrp +} diff --git a/nex-protocols-go/datastore/super-mario-maker/types/datastore_report_course_param.go b/nex-protocols-go/datastore/super-mario-maker/types/datastore_report_course_param.go new file mode 100644 index 0000000..5a1d488 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/types/datastore_report_course_param.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreReportCourseParam is a type within the DataStore protocol +type DataStoreReportCourseParam struct { + types.Structure + DataID *types.PrimitiveU64 + MiiName *types.String + ReportCategory *types.PrimitiveU8 + ReportReason *types.String +} + +// WriteTo writes the DataStoreReportCourseParam to the given writable +func (dsrcp *DataStoreReportCourseParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsrcp.DataID.WriteTo(contentWritable) + dsrcp.MiiName.WriteTo(contentWritable) + dsrcp.ReportCategory.WriteTo(contentWritable) + dsrcp.ReportReason.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsrcp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreReportCourseParam from the given readable +func (dsrcp *DataStoreReportCourseParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsrcp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReportCourseParam header. %s", err.Error()) + } + + err = dsrcp.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReportCourseParam.DataID. %s", err.Error()) + } + + err = dsrcp.MiiName.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReportCourseParam.MiiName. %s", err.Error()) + } + + err = dsrcp.ReportCategory.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReportCourseParam.ReportCategory. %s", err.Error()) + } + + err = dsrcp.ReportReason.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReportCourseParam.ReportReason. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreReportCourseParam +func (dsrcp *DataStoreReportCourseParam) Copy() types.RVType { + copied := NewDataStoreReportCourseParam() + + copied.StructureVersion = dsrcp.StructureVersion + copied.DataID = dsrcp.DataID.Copy().(*types.PrimitiveU64) + copied.MiiName = dsrcp.MiiName.Copy().(*types.String) + copied.ReportCategory = dsrcp.ReportCategory.Copy().(*types.PrimitiveU8) + copied.ReportReason = dsrcp.ReportReason.Copy().(*types.String) + + return copied +} + +// Equals checks if the given DataStoreReportCourseParam contains the same data as the current DataStoreReportCourseParam +func (dsrcp *DataStoreReportCourseParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreReportCourseParam); !ok { + return false + } + + other := o.(*DataStoreReportCourseParam) + + if dsrcp.StructureVersion != other.StructureVersion { + return false + } + + if !dsrcp.DataID.Equals(other.DataID) { + return false + } + + if !dsrcp.MiiName.Equals(other.MiiName) { + return false + } + + if !dsrcp.ReportCategory.Equals(other.ReportCategory) { + return false + } + + return dsrcp.ReportReason.Equals(other.ReportReason) +} + +// String returns the string representation of the DataStoreReportCourseParam +func (dsrcp *DataStoreReportCourseParam) String() string { + return dsrcp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreReportCourseParam using the provided indentation level +func (dsrcp *DataStoreReportCourseParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreReportCourseParam{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dsrcp.DataID)) + b.WriteString(fmt.Sprintf("%sMiiName: %s,\n", indentationValues, dsrcp.MiiName)) + b.WriteString(fmt.Sprintf("%sReportCategory: %s,\n", indentationValues, dsrcp.ReportCategory)) + b.WriteString(fmt.Sprintf("%sReportReason: %s,\n", indentationValues, dsrcp.ReportReason)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreReportCourseParam returns a new DataStoreReportCourseParam +func NewDataStoreReportCourseParam() *DataStoreReportCourseParam { + dsrcp := &DataStoreReportCourseParam{ + DataID: types.NewPrimitiveU64(0), + MiiName: types.NewString(""), + ReportCategory: types.NewPrimitiveU8(0), + ReportReason: types.NewString(""), + } + + return dsrcp +} diff --git a/nex-protocols-go/datastore/super-mario-maker/types/datastore_upload_course_record_param.go b/nex-protocols-go/datastore/super-mario-maker/types/datastore_upload_course_record_param.go new file mode 100644 index 0000000..34aad56 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/types/datastore_upload_course_record_param.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreUploadCourseRecordParam is a type within the DataStore protocol +type DataStoreUploadCourseRecordParam struct { + types.Structure + DataID *types.PrimitiveU64 + Slot *types.PrimitiveU8 + Score *types.PrimitiveS32 +} + +// WriteTo writes the DataStoreUploadCourseRecordParam to the given writable +func (dsucrp *DataStoreUploadCourseRecordParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsucrp.DataID.WriteTo(contentWritable) + dsucrp.Slot.WriteTo(contentWritable) + dsucrp.Score.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsucrp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreUploadCourseRecordParam from the given readable +func (dsucrp *DataStoreUploadCourseRecordParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsucrp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreUploadCourseRecordParam header. %s", err.Error()) + } + + err = dsucrp.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreUploadCourseRecordParam.DataID. %s", err.Error()) + } + + err = dsucrp.Slot.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreUploadCourseRecordParam.Slot. %s", err.Error()) + } + + err = dsucrp.Score.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreUploadCourseRecordParam.Score. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreUploadCourseRecordParam +func (dsucrp *DataStoreUploadCourseRecordParam) Copy() types.RVType { + copied := NewDataStoreUploadCourseRecordParam() + + copied.StructureVersion = dsucrp.StructureVersion + copied.DataID = dsucrp.DataID.Copy().(*types.PrimitiveU64) + copied.Slot = dsucrp.Slot.Copy().(*types.PrimitiveU8) + copied.Score = dsucrp.Score.Copy().(*types.PrimitiveS32) + + return copied +} + +// Equals checks if the given DataStoreUploadCourseRecordParam contains the same data as the current DataStoreUploadCourseRecordParam +func (dsucrp *DataStoreUploadCourseRecordParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreUploadCourseRecordParam); !ok { + return false + } + + other := o.(*DataStoreUploadCourseRecordParam) + + if dsucrp.StructureVersion != other.StructureVersion { + return false + } + + if !dsucrp.DataID.Equals(other.DataID) { + return false + } + + if !dsucrp.Slot.Equals(other.Slot) { + return false + } + + return dsucrp.Score.Equals(other.Score) +} + +// String returns the string representation of the DataStoreUploadCourseRecordParam +func (dsucrp *DataStoreUploadCourseRecordParam) String() string { + return dsucrp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreUploadCourseRecordParam using the provided indentation level +func (dsucrp *DataStoreUploadCourseRecordParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreUploadCourseRecordParam{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dsucrp.DataID)) + b.WriteString(fmt.Sprintf("%sSlot: %s,\n", indentationValues, dsucrp.Slot)) + b.WriteString(fmt.Sprintf("%sScore: %s,\n", indentationValues, dsucrp.Score)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreUploadCourseRecordParam returns a new DataStoreUploadCourseRecordParam +func NewDataStoreUploadCourseRecordParam() *DataStoreUploadCourseRecordParam { + dsucrp := &DataStoreUploadCourseRecordParam{ + DataID: types.NewPrimitiveU64(0), + Slot: types.NewPrimitiveU8(0), + Score: types.NewPrimitiveS32(0), + } + + return dsucrp +} diff --git a/nex-protocols-go/datastore/super-mario-maker/upload_course_record.go b/nex-protocols-go/datastore/super-mario-maker/upload_course_record.go new file mode 100644 index 0000000..7facca3 --- /dev/null +++ b/nex-protocols-go/datastore/super-mario-maker/upload_course_record.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStoreSuperMarioMaker protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-mario-maker/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUploadCourseRecord(packet nex.PacketInterface) { + if protocol.UploadCourseRecord == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperMarioMaker::UploadCourseRecord not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_mario_maker_types.NewDataStoreUploadCourseRecordParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UploadCourseRecord(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UploadCourseRecord(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/check_post_replay.go b/nex-protocols-go/datastore/super-smash-bros-4/check_post_replay.go new file mode 100644 index 0000000..e0192ed --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/check_post_replay.go @@ -0,0 +1,47 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_smash_bros_4_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-smash-bros-4/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCheckPostReplay(packet nex.PacketInterface) { + if protocol.CheckPostReplay == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::CheckPostReplay not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_smash_bros_4_types.NewDataStorePreparePostReplayParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CheckPostReplay(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CheckPostReplay(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/complete_post_replay.go b/nex-protocols-go/datastore/super-smash-bros-4/complete_post_replay.go new file mode 100644 index 0000000..50e9fcf --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/complete_post_replay.go @@ -0,0 +1,47 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_smash_bros_4_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-smash-bros-4/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCompletePostReplay(packet nex.PacketInterface) { + if protocol.CompletePostReplay == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::CompletePostReplay not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_smash_bros_4_types.NewDataStoreCompletePostReplayParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CompletePostReplay(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CompletePostReplay(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/complete_post_shared_data.go b/nex-protocols-go/datastore/super-smash-bros-4/complete_post_shared_data.go new file mode 100644 index 0000000..6bb7923 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/complete_post_shared_data.go @@ -0,0 +1,47 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_smash_bros_4_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-smash-bros-4/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCompletePostSharedData(packet nex.PacketInterface) { + if protocol.CompletePostSharedData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::CompletePostSharedData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_smash_bros_4_types.NewDataStoreCompletePostSharedDataParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CompletePostSharedData(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CompletePostSharedData(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/get_application_config.go b/nex-protocols-go/datastore/super-smash-bros-4/get_application_config.go new file mode 100644 index 0000000..a217205 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/get_application_config.go @@ -0,0 +1,47 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetApplicationConfig(packet nex.PacketInterface) { + if protocol.GetApplicationConfig == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::GetApplicationConfig not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + applicationID := types.NewPrimitiveU32(0) + + err := applicationID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetApplicationConfig(fmt.Errorf("Failed to read applicationID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetApplicationConfig(nil, packet, callID, applicationID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/get_fighting_power_chart.go b/nex-protocols-go/datastore/super-smash-bros-4/get_fighting_power_chart.go new file mode 100644 index 0000000..b907ff6 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/get_fighting_power_chart.go @@ -0,0 +1,47 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetFightingPowerChart(packet nex.PacketInterface) { + if protocol.GetFightingPowerChart == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::GetFightingPowerChart not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + mode := types.NewPrimitiveU8(0) + + err := mode.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetFightingPowerChart(fmt.Errorf("Failed to read mode from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetFightingPowerChart(nil, packet, callID, mode) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/get_fighting_power_chart_all.go b/nex-protocols-go/datastore/super-smash-bros-4/get_fighting_power_chart_all.go new file mode 100644 index 0000000..ddd5963 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/get_fighting_power_chart_all.go @@ -0,0 +1,29 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetFightingPowerChartAll(packet nex.PacketInterface) { + if protocol.GetFightingPowerChartAll == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::GetFightingPowerChartAll not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetFightingPowerChartAll(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/get_next_replay.go b/nex-protocols-go/datastore/super-smash-bros-4/get_next_replay.go new file mode 100644 index 0000000..0b8a9db --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/get_next_replay.go @@ -0,0 +1,29 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetNextReplay(packet nex.PacketInterface) { + if protocol.GetNextReplay == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::GetNextReplay not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetNextReplay(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/get_profiles.go b/nex-protocols-go/datastore/super-smash-bros-4/get_profiles.go new file mode 100644 index 0000000..f86885a --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/get_profiles.go @@ -0,0 +1,48 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetProfiles(packet nex.PacketInterface) { + if protocol.GetProfiles == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::GetProfiles not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pidList := types.NewList[*types.PID]() + pidList.Type = types.NewPID(0) + + err := pidList.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetProfiles(fmt.Errorf("Failed to read pidList from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetProfiles(nil, packet, callID, pidList) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/get_replay_meta.go b/nex-protocols-go/datastore/super-smash-bros-4/get_replay_meta.go new file mode 100644 index 0000000..e231da1 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/get_replay_meta.go @@ -0,0 +1,47 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_smash_bros_4_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-smash-bros-4/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetReplayMeta(packet nex.PacketInterface) { + if protocol.GetReplayMeta == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::GetReplayMeta not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_smash_bros_4_types.NewDataStoreGetReplayMetaParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetReplayMeta(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetReplayMeta(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/get_shared_data_meta.go b/nex-protocols-go/datastore/super-smash-bros-4/get_shared_data_meta.go new file mode 100644 index 0000000..1354d98 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/get_shared_data_meta.go @@ -0,0 +1,31 @@ +// Package protocol implements the DataStoreSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetSharedDataMeta(packet nex.PacketInterface) { + if protocol.GetSharedDataMeta == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::GetSharedDataMeta not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("DataStoreSuperSmashBros4::GetSharedDataMeta STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetSharedDataMeta(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/get_world_play_report.go b/nex-protocols-go/datastore/super-smash-bros-4/get_world_play_report.go new file mode 100644 index 0000000..9899dce --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/get_world_play_report.go @@ -0,0 +1,29 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetWorldPlayReport(packet nex.PacketInterface) { + if protocol.GetWorldPlayReport == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::GetWorldPlayReport not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetWorldPlayReport(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/post_fighting_power_score.go b/nex-protocols-go/datastore/super-smash-bros-4/post_fighting_power_score.go new file mode 100644 index 0000000..c6fa697 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/post_fighting_power_score.go @@ -0,0 +1,49 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_super_smash_bros_4_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-smash-bros-4/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePostFightingPowerScore(packet nex.PacketInterface) { + if protocol.PostFightingPowerScore == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::PostFightingPowerScore not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + params := types.NewList[*datastore_super_smash_bros_4_types.DataStorePostFightingPowerScoreParam]() + params.Type = datastore_super_smash_bros_4_types.NewDataStorePostFightingPowerScoreParam() + + err := params.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PostFightingPowerScore(fmt.Errorf("Failed to read params from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PostFightingPowerScore(nil, packet, callID, params) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/post_profile.go b/nex-protocols-go/datastore/super-smash-bros-4/post_profile.go new file mode 100644 index 0000000..fc74663 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/post_profile.go @@ -0,0 +1,47 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_smash_bros_4_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-smash-bros-4/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePostProfile(packet nex.PacketInterface) { + if protocol.PostProfile == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::PostProfile not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_smash_bros_4_types.NewDataStorePostProfileParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PostProfile(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PostProfile(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/prepare_get_replay.go b/nex-protocols-go/datastore/super-smash-bros-4/prepare_get_replay.go new file mode 100644 index 0000000..c0365f6 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/prepare_get_replay.go @@ -0,0 +1,47 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_smash_bros_4_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-smash-bros-4/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePrepareGetReplay(packet nex.PacketInterface) { + if protocol.PrepareGetReplay == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::PrepareGetReplay not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_smash_bros_4_types.NewDataStorePrepareGetReplayParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PrepareGetReplay(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PrepareGetReplay(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/prepare_post_replay.go b/nex-protocols-go/datastore/super-smash-bros-4/prepare_post_replay.go new file mode 100644 index 0000000..b699f5a --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/prepare_post_replay.go @@ -0,0 +1,47 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_smash_bros_4_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-smash-bros-4/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePreparePostReplay(packet nex.PacketInterface) { + if protocol.PreparePostReplay == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::PreparePostReplay not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_smash_bros_4_types.NewDataStorePreparePostReplayParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PreparePostReplay(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PreparePostReplay(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/prepare_post_shared_data.go b/nex-protocols-go/datastore/super-smash-bros-4/prepare_post_shared_data.go new file mode 100644 index 0000000..d1f916d --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/prepare_post_shared_data.go @@ -0,0 +1,47 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_smash_bros_4_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-smash-bros-4/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePreparePostSharedData(packet nex.PacketInterface) { + if protocol.PreparePostSharedData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::PreparePostSharedData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_smash_bros_4_types.NewDataStorePreparePostSharedDataParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PreparePostSharedData(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PreparePostSharedData(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/protocol.go b/nex-protocols-go/datastore/super-smash-bros-4/protocol.go new file mode 100644 index 0000000..fc7f5fe --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/protocol.go @@ -0,0 +1,200 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + datastore_super_smash_bros_4_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-smash-bros-4/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + "golang.org/x/exp/slices" +) + +const ( + // ProtocolID is the protocol ID for the DataStore (Super Smash Bros 4) protocol. ID is the same as the DataStore protocol + ProtocolID = 0x73 + + // MethodPostProfile is the method ID for the method PostProfile + MethodPostProfile = 0x2D + + // MethodGetProfiles is the method ID for the method GetProfiles + MethodGetProfiles = 0x2E + + // MethodSendPlayReport is the method ID for the method SendPlayReport + MethodSendPlayReport = 0x2F + + // MethodGetWorldPlayReport is the method ID for the method GetWorldPlayReport + MethodGetWorldPlayReport = 0x30 + + // MethodGetReplayMeta is the method ID for the method GetReplayMeta + MethodGetReplayMeta = 0x31 + + // MethodPrepareGetReplay is the method ID for the method PrepareGetReplay + MethodPrepareGetReplay = 0x32 + + // MethodPreparePostReplay is the method ID for the method PreparePostReplay + MethodPreparePostReplay = 0x33 + + // MethodCompletePostReplay is the method ID for the method CompletePostReplay + MethodCompletePostReplay = 0x34 + + // MethodCheckPostReplay is the method ID for the method CheckPostReplay + MethodCheckPostReplay = 0x35 + + // MethodGetNextReplay is the method ID for the method GetNextReplay + MethodGetNextReplay = 0x36 + + // MethodPreparePostSharedData is the method ID for the method PreparePostSharedData + MethodPreparePostSharedData = 0x37 + + // MethodCompletePostSharedData is the method ID for the method CompletePostSharedData + MethodCompletePostSharedData = 0x38 + + // MethodSearchSharedData is the method ID for the method SearchSharedData + MethodSearchSharedData = 0x39 + + // MethodGetApplicationConfig is the method ID for the method GetApplicationConfig + MethodGetApplicationConfig = 0x3A + + // MethodSearchReplay is the method ID for the method SearchReplay + MethodSearchReplay = 0x3B + + // MethodPostFightingPowerScore is the method ID for the method PostFightingPowerScore + MethodPostFightingPowerScore = 0x3C + + // MethodGetFightingPowerChart is the method ID for the method GetFightingPowerChart + MethodGetFightingPowerChart = 0x3D + + // MethodGetFightingPowerChartAll is the method ID for the method GetFightingPowerChartAll + MethodGetFightingPowerChartAll = 0x3E + + // MethodReportSharedData is the method ID for the method ReportSharedData + MethodReportSharedData = 0x3F + + // MethodGetSharedDataMeta is the method ID for the method GetSharedDataMeta + MethodGetSharedDataMeta = 0x40 +) + +var patchedMethods = []uint32{ + MethodPostProfile, + MethodGetProfiles, + MethodSendPlayReport, + MethodGetWorldPlayReport, + MethodGetReplayMeta, + MethodPrepareGetReplay, + MethodPreparePostReplay, + MethodCompletePostReplay, + MethodCheckPostReplay, + MethodGetNextReplay, + MethodPreparePostSharedData, + MethodCompletePostSharedData, + MethodSearchSharedData, + MethodGetApplicationConfig, + MethodSearchReplay, + MethodPostFightingPowerScore, + MethodGetFightingPowerChart, + MethodGetFightingPowerChartAll, + MethodReportSharedData, +} + +type dataStoreProtocol = datastore.Protocol + +// Protocol stores all the RMC method handlers for the DataStore (Super Smash Bros 4) protocol and listens for requests +// Embeds the DataStore protocol +type Protocol struct { + endpoint nex.EndpointInterface + dataStoreProtocol + PostProfile func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_smash_bros_4_types.DataStorePostProfileParam) (*nex.RMCMessage, *nex.Error) + GetProfiles func(err error, packet nex.PacketInterface, callID uint32, pidList *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error) + SendPlayReport func(err error, packet nex.PacketInterface, callID uint32, playReport *types.List[*types.PrimitiveS32]) (*nex.RMCMessage, *nex.Error) + GetWorldPlayReport func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + GetReplayMeta func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_smash_bros_4_types.DataStoreGetReplayMetaParam) (*nex.RMCMessage, *nex.Error) + PrepareGetReplay func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_smash_bros_4_types.DataStorePrepareGetReplayParam) (*nex.RMCMessage, *nex.Error) + PreparePostReplay func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_smash_bros_4_types.DataStorePreparePostReplayParam) (*nex.RMCMessage, *nex.Error) + CompletePostReplay func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_smash_bros_4_types.DataStoreCompletePostReplayParam) (*nex.RMCMessage, *nex.Error) + CheckPostReplay func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_smash_bros_4_types.DataStorePreparePostReplayParam) (*nex.RMCMessage, *nex.Error) + GetNextReplay func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + PreparePostSharedData func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_smash_bros_4_types.DataStorePreparePostSharedDataParam) (*nex.RMCMessage, *nex.Error) + CompletePostSharedData func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_smash_bros_4_types.DataStoreCompletePostSharedDataParam) (*nex.RMCMessage, *nex.Error) + SearchSharedData func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_smash_bros_4_types.DataStoreSearchSharedDataParam) (*nex.RMCMessage, *nex.Error) + GetApplicationConfig func(err error, packet nex.PacketInterface, callID uint32, applicationID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + SearchReplay func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_smash_bros_4_types.DataStoreSearchReplayParam) (*nex.RMCMessage, *nex.Error) + PostFightingPowerScore func(err error, packet nex.PacketInterface, callID uint32, params *types.List[*datastore_super_smash_bros_4_types.DataStorePostFightingPowerScoreParam]) (*nex.RMCMessage, *nex.Error) + GetFightingPowerChart func(err error, packet nex.PacketInterface, callID uint32, mode *types.PrimitiveU8) (*nex.RMCMessage, *nex.Error) + GetFightingPowerChartAll func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + ReportSharedData func(err error, packet nex.PacketInterface, callID uint32, dataID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + GetSharedDataMeta func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if !slices.Contains(patchedMethods, message.MethodID) { + protocol.dataStoreProtocol.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodPostProfile: + protocol.handlePostProfile(packet) + case MethodGetProfiles: + protocol.handleGetProfiles(packet) + case MethodSendPlayReport: + protocol.handleSendPlayReport(packet) + case MethodGetWorldPlayReport: + protocol.handleGetWorldPlayReport(packet) + case MethodGetReplayMeta: + protocol.handleGetReplayMeta(packet) + case MethodPrepareGetReplay: + protocol.handlePrepareGetReplay(packet) + case MethodPreparePostReplay: + protocol.handlePreparePostReplay(packet) + case MethodCompletePostReplay: + protocol.handleCompletePostReplay(packet) + case MethodCheckPostReplay: + protocol.handleCheckPostReplay(packet) + case MethodGetNextReplay: + protocol.handleGetNextReplay(packet) + case MethodPreparePostSharedData: + protocol.handlePreparePostSharedData(packet) + case MethodCompletePostSharedData: + protocol.handleCompletePostSharedData(packet) + case MethodSearchSharedData: + protocol.handleSearchSharedData(packet) + case MethodGetApplicationConfig: + protocol.handleGetApplicationConfig(packet) + case MethodSearchReplay: + protocol.handleSearchReplay(packet) + case MethodPostFightingPowerScore: + protocol.handlePostFightingPowerScore(packet) + case MethodGetFightingPowerChart: + protocol.handleGetFightingPowerChart(packet) + case MethodGetFightingPowerChartAll: + protocol.handleGetFightingPowerChartAll(packet) + case MethodReportSharedData: + protocol.handleReportSharedData(packet) + case MethodGetSharedDataMeta: + protocol.handleGetSharedDataMeta(packet) + default: + errMessage := fmt.Sprintf("Unsupported DataStoreSuperSmashBros4 method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new DataStore (Super Smash Bros 4) protocol +func NewProtocol(endpoint nex.EndpointInterface) *Protocol { + protocol := &Protocol{endpoint: endpoint} + protocol.dataStoreProtocol.SetEndpoint(endpoint) + + return protocol +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/report_shared_data.go b/nex-protocols-go/datastore/super-smash-bros-4/report_shared_data.go new file mode 100644 index 0000000..8ac4e8a --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/report_shared_data.go @@ -0,0 +1,47 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleReportSharedData(packet nex.PacketInterface) { + if protocol.ReportSharedData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::ReportSharedData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + dataID := types.NewPrimitiveU64(0) + + err := dataID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReportSharedData(fmt.Errorf("Failed to read dataID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ReportSharedData(nil, packet, callID, dataID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/search_replay.go b/nex-protocols-go/datastore/super-smash-bros-4/search_replay.go new file mode 100644 index 0000000..4efbbdc --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/search_replay.go @@ -0,0 +1,47 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_smash_bros_4_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-smash-bros-4/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSearchReplay(packet nex.PacketInterface) { + if protocol.SearchReplay == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::SearchReplay not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_smash_bros_4_types.NewDataStoreSearchReplayParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SearchReplay(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SearchReplay(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/search_shared_data.go b/nex-protocols-go/datastore/super-smash-bros-4/search_shared_data.go new file mode 100644 index 0000000..bf690ae --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/search_shared_data.go @@ -0,0 +1,47 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_super_smash_bros_4_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/super-smash-bros-4/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSearchSharedData(packet nex.PacketInterface) { + if protocol.SearchSharedData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::SearchSharedData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_super_smash_bros_4_types.NewDataStoreSearchSharedDataParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SearchSharedData(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SearchSharedData(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/send_play_report.go b/nex-protocols-go/datastore/super-smash-bros-4/send_play_report.go new file mode 100644 index 0000000..6e86ca7 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/send_play_report.go @@ -0,0 +1,48 @@ +// Package protocol implements the Super Smash Bros. 4 DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSendPlayReport(packet nex.PacketInterface) { + if protocol.SendPlayReport == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStoreSuperSmashBros4::SendPlayReport not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + playReport := types.NewList[*types.PrimitiveS32]() + playReport.Type = types.NewPrimitiveS32(0) + + err := playReport.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SendPlayReport(fmt.Errorf("Failed to read playReport from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SendPlayReport(nil, packet, callID, playReport) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_complete_post_replay_param.go b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_complete_post_replay_param.go new file mode 100644 index 0000000..45fb791 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_complete_post_replay_param.go @@ -0,0 +1,127 @@ +// Package types implements all the types used by the DataStoreSuperSmashBros.4 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +// DataStoreCompletePostReplayParam is a type within the DataStoreSuperSmashBros.4 protocol +type DataStoreCompletePostReplayParam struct { + types.Structure + ReplayID *types.PrimitiveU64 + CompleteParam *datastore_types.DataStoreCompletePostParam + PrepareParam *DataStorePreparePostReplayParam +} + +// WriteTo writes the DataStoreCompletePostReplayParam to the given writable +func (dscprp *DataStoreCompletePostReplayParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dscprp.ReplayID.WriteTo(contentWritable) + dscprp.CompleteParam.WriteTo(contentWritable) + dscprp.PrepareParam.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dscprp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreCompletePostReplayParam from the given readable +func (dscprp *DataStoreCompletePostReplayParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dscprp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompletePostReplayParam header. %s", err.Error()) + } + + err = dscprp.ReplayID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompletePostReplayParam.ReplayID. %s", err.Error()) + } + + err = dscprp.CompleteParam.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompletePostReplayParam.CompleteParam. %s", err.Error()) + } + + err = dscprp.PrepareParam.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompletePostReplayParam.PrepareParam. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreCompletePostReplayParam +func (dscprp *DataStoreCompletePostReplayParam) Copy() types.RVType { + copied := NewDataStoreCompletePostReplayParam() + + copied.StructureVersion = dscprp.StructureVersion + copied.ReplayID = dscprp.ReplayID.Copy().(*types.PrimitiveU64) + copied.CompleteParam = dscprp.CompleteParam.Copy().(*datastore_types.DataStoreCompletePostParam) + copied.PrepareParam = dscprp.PrepareParam.Copy().(*DataStorePreparePostReplayParam) + + return copied +} + +// Equals checks if the given DataStoreCompletePostReplayParam contains the same data as the current DataStoreCompletePostReplayParam +func (dscprp *DataStoreCompletePostReplayParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreCompletePostReplayParam); !ok { + return false + } + + other := o.(*DataStoreCompletePostReplayParam) + + if dscprp.StructureVersion != other.StructureVersion { + return false + } + + if !dscprp.ReplayID.Equals(other.ReplayID) { + return false + } + + if !dscprp.CompleteParam.Equals(other.CompleteParam) { + return false + } + + return dscprp.PrepareParam.Equals(other.PrepareParam) +} + +// String returns the string representation of the DataStoreCompletePostReplayParam +func (dscprp *DataStoreCompletePostReplayParam) String() string { + return dscprp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreCompletePostReplayParam using the provided indentation level +func (dscprp *DataStoreCompletePostReplayParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreCompletePostReplayParam{\n") + b.WriteString(fmt.Sprintf("%sReplayID: %s,\n", indentationValues, dscprp.ReplayID)) + b.WriteString(fmt.Sprintf("%sCompleteParam: %s,\n", indentationValues, dscprp.CompleteParam.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPrepareParam: %s,\n", indentationValues, dscprp.PrepareParam.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreCompletePostReplayParam returns a new DataStoreCompletePostReplayParam +func NewDataStoreCompletePostReplayParam() *DataStoreCompletePostReplayParam { + dscprp := &DataStoreCompletePostReplayParam{ + ReplayID: types.NewPrimitiveU64(0), + CompleteParam: datastore_types.NewDataStoreCompletePostParam(), + PrepareParam: NewDataStorePreparePostReplayParam(), + } + + return dscprp +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_complete_post_shared_data_param.go b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_complete_post_shared_data_param.go new file mode 100644 index 0000000..4e1ff46 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_complete_post_shared_data_param.go @@ -0,0 +1,127 @@ +// Package types implements all the types used by the DataStoreSuperSmashBros.4 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +// DataStoreCompletePostSharedDataParam is a type within the DataStoreSuperSmashBros.4 protocol +type DataStoreCompletePostSharedDataParam struct { + types.Structure + DataID *types.PrimitiveU64 + CompleteParam *datastore_types.DataStoreCompletePostParam + PrepareParam *DataStorePreparePostSharedDataParam +} + +// WriteTo writes the DataStoreCompletePostSharedDataParam to the given writable +func (dscpsdp *DataStoreCompletePostSharedDataParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dscpsdp.DataID.WriteTo(contentWritable) + dscpsdp.CompleteParam.WriteTo(contentWritable) + dscpsdp.PrepareParam.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dscpsdp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreCompletePostSharedDataParam from the given readable +func (dscpsdp *DataStoreCompletePostSharedDataParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dscpsdp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompletePostSharedDataParam header. %s", err.Error()) + } + + err = dscpsdp.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompletePostSharedDataParam.DataID. %s", err.Error()) + } + + err = dscpsdp.CompleteParam.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompletePostSharedDataParam.CompleteParam. %s", err.Error()) + } + + err = dscpsdp.PrepareParam.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompletePostSharedDataParam.PrepareParam. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreCompletePostSharedDataParam +func (dscpsdp *DataStoreCompletePostSharedDataParam) Copy() types.RVType { + copied := NewDataStoreCompletePostSharedDataParam() + + copied.StructureVersion = dscpsdp.StructureVersion + copied.DataID = dscpsdp.DataID.Copy().(*types.PrimitiveU64) + copied.CompleteParam = dscpsdp.CompleteParam.Copy().(*datastore_types.DataStoreCompletePostParam) + copied.PrepareParam = dscpsdp.PrepareParam.Copy().(*DataStorePreparePostSharedDataParam) + + return copied +} + +// Equals checks if the given DataStoreCompletePostSharedDataParam contains the same data as the current DataStoreCompletePostSharedDataParam +func (dscpsdp *DataStoreCompletePostSharedDataParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreCompletePostSharedDataParam); !ok { + return false + } + + other := o.(*DataStoreCompletePostSharedDataParam) + + if dscpsdp.StructureVersion != other.StructureVersion { + return false + } + + if !dscpsdp.DataID.Equals(other.DataID) { + return false + } + + if !dscpsdp.CompleteParam.Equals(other.CompleteParam) { + return false + } + + return dscpsdp.PrepareParam.Equals(other.PrepareParam) +} + +// String returns the string representation of the DataStoreCompletePostSharedDataParam +func (dscpsdp *DataStoreCompletePostSharedDataParam) String() string { + return dscpsdp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreCompletePostSharedDataParam using the provided indentation level +func (dscpsdp *DataStoreCompletePostSharedDataParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreCompletePostSharedDataParam{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dscpsdp.DataID)) + b.WriteString(fmt.Sprintf("%sCompleteParam: %s,\n", indentationValues, dscpsdp.CompleteParam.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPrepareParam: %s,\n", indentationValues, dscpsdp.PrepareParam.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreCompletePostSharedDataParam returns a new DataStoreCompletePostSharedDataParam +func NewDataStoreCompletePostSharedDataParam() *DataStoreCompletePostSharedDataParam { + dscpsdp := &DataStoreCompletePostSharedDataParam{ + DataID: types.NewPrimitiveU64(0), + CompleteParam: datastore_types.NewDataStoreCompletePostParam(), + PrepareParam: NewDataStorePreparePostSharedDataParam(), + } + + return dscpsdp +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_fighting_power_chart.go b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_fighting_power_chart.go new file mode 100644 index 0000000..f226edf --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_fighting_power_chart.go @@ -0,0 +1,114 @@ +// Package types implements all the types used by the DataStoreSuperSmashBros.4 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreFightingPowerChart is a type within the DataStoreSuperSmashBros.4 protocol +type DataStoreFightingPowerChart struct { + types.Structure + UserNum *types.PrimitiveU32 + Chart *types.List[*DataStoreFightingPowerScore] +} + +// WriteTo writes the DataStoreFightingPowerChart to the given writable +func (dsfpc *DataStoreFightingPowerChart) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsfpc.UserNum.WriteTo(contentWritable) + dsfpc.Chart.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsfpc.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreFightingPowerChart from the given readable +func (dsfpc *DataStoreFightingPowerChart) ExtractFrom(readable types.Readable) error { + var err error + + err = dsfpc.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreFightingPowerChart header. %s", err.Error()) + } + + err = dsfpc.UserNum.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreFightingPowerChart.UserNum. %s", err.Error()) + } + + err = dsfpc.Chart.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreFightingPowerChart.Chart. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreFightingPowerChart +func (dsfpc *DataStoreFightingPowerChart) Copy() types.RVType { + copied := NewDataStoreFightingPowerChart() + + copied.StructureVersion = dsfpc.StructureVersion + copied.UserNum = dsfpc.UserNum.Copy().(*types.PrimitiveU32) + copied.Chart = dsfpc.Chart.Copy().(*types.List[*DataStoreFightingPowerScore]) + + return copied +} + +// Equals checks if the given DataStoreFightingPowerChart contains the same data as the current DataStoreFightingPowerChart +func (dsfpc *DataStoreFightingPowerChart) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreFightingPowerChart); !ok { + return false + } + + other := o.(*DataStoreFightingPowerChart) + + if dsfpc.StructureVersion != other.StructureVersion { + return false + } + + if !dsfpc.UserNum.Equals(other.UserNum) { + return false + } + + return dsfpc.Chart.Equals(other.Chart) +} + +// String returns the string representation of the DataStoreFightingPowerChart +func (dsfpc *DataStoreFightingPowerChart) String() string { + return dsfpc.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreFightingPowerChart using the provided indentation level +func (dsfpc *DataStoreFightingPowerChart) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreFightingPowerChart{\n") + b.WriteString(fmt.Sprintf("%sUserNum: %s,\n", indentationValues, dsfpc.UserNum)) + b.WriteString(fmt.Sprintf("%sChart: %s,\n", indentationValues, dsfpc.Chart)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreFightingPowerChart returns a new DataStoreFightingPowerChart +func NewDataStoreFightingPowerChart() *DataStoreFightingPowerChart { + dsfpc := &DataStoreFightingPowerChart{ + UserNum: types.NewPrimitiveU32(0), + Chart: types.NewList[*DataStoreFightingPowerScore](), + } + + dsfpc.Chart.Type = NewDataStoreFightingPowerScore() + + return dsfpc +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_fighting_power_score.go b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_fighting_power_score.go new file mode 100644 index 0000000..486925d --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_fighting_power_score.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStoreSuperSmashBros.4 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreFightingPowerScore is a type within the DataStoreSuperSmashBros.4 protocol +type DataStoreFightingPowerScore struct { + types.Structure + Score *types.PrimitiveU32 + Rank *types.PrimitiveU32 +} + +// WriteTo writes the DataStoreFightingPowerScore to the given writable +func (dsfps *DataStoreFightingPowerScore) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsfps.Score.WriteTo(contentWritable) + dsfps.Rank.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsfps.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreFightingPowerScore from the given readable +func (dsfps *DataStoreFightingPowerScore) ExtractFrom(readable types.Readable) error { + var err error + + err = dsfps.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreFightingPowerScore header. %s", err.Error()) + } + + err = dsfps.Score.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreFightingPowerScore.Score. %s", err.Error()) + } + + err = dsfps.Rank.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreFightingPowerScore.Rank. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreFightingPowerScore +func (dsfps *DataStoreFightingPowerScore) Copy() types.RVType { + copied := NewDataStoreFightingPowerScore() + + copied.StructureVersion = dsfps.StructureVersion + copied.Score = dsfps.Score.Copy().(*types.PrimitiveU32) + copied.Rank = dsfps.Rank.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given DataStoreFightingPowerScore contains the same data as the current DataStoreFightingPowerScore +func (dsfps *DataStoreFightingPowerScore) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreFightingPowerScore); !ok { + return false + } + + other := o.(*DataStoreFightingPowerScore) + + if dsfps.StructureVersion != other.StructureVersion { + return false + } + + if !dsfps.Score.Equals(other.Score) { + return false + } + + return dsfps.Rank.Equals(other.Rank) +} + +// String returns the string representation of the DataStoreFightingPowerScore +func (dsfps *DataStoreFightingPowerScore) String() string { + return dsfps.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreFightingPowerScore using the provided indentation level +func (dsfps *DataStoreFightingPowerScore) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreFightingPowerScore{\n") + b.WriteString(fmt.Sprintf("%sScore: %s,\n", indentationValues, dsfps.Score)) + b.WriteString(fmt.Sprintf("%sRank: %s,\n", indentationValues, dsfps.Rank)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreFightingPowerScore returns a new DataStoreFightingPowerScore +func NewDataStoreFightingPowerScore() *DataStoreFightingPowerScore { + dsfps := &DataStoreFightingPowerScore{ + Score: types.NewPrimitiveU32(0), + Rank: types.NewPrimitiveU32(0), + } + + return dsfps +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_file_object_server_info.go b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_file_object_server_info.go new file mode 100644 index 0000000..a11ea74 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_file_object_server_info.go @@ -0,0 +1,113 @@ +// Package types implements all the types used by the DataStoreSuperSmashBros.4 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" +) + +// DataStoreFileServerObjectInfo is a type within the DataStoreSuperSmashBros.4 protocol +type DataStoreFileServerObjectInfo struct { + types.Structure + DataID *types.PrimitiveU64 + GetInfo *datastore_types.DataStoreReqGetInfo +} + +// WriteTo writes the DataStoreFileServerObjectInfo to the given writable +func (dsfsoi *DataStoreFileServerObjectInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsfsoi.DataID.WriteTo(contentWritable) + dsfsoi.GetInfo.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsfsoi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreFileServerObjectInfo from the given readable +func (dsfsoi *DataStoreFileServerObjectInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = dsfsoi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreFileServerObjectInfo header. %s", err.Error()) + } + + err = dsfsoi.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreFileServerObjectInfo.DataID. %s", err.Error()) + } + + err = dsfsoi.GetInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreFileServerObjectInfo.GetInfo. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreFileServerObjectInfo +func (dsfsoi *DataStoreFileServerObjectInfo) Copy() types.RVType { + copied := NewDataStoreFileServerObjectInfo() + + copied.StructureVersion = dsfsoi.StructureVersion + copied.DataID = dsfsoi.DataID.Copy().(*types.PrimitiveU64) + copied.GetInfo = dsfsoi.GetInfo.Copy().(*datastore_types.DataStoreReqGetInfo) + + return copied +} + +// Equals checks if the given DataStoreFileServerObjectInfo contains the same data as the current DataStoreFileServerObjectInfo +func (dsfsoi *DataStoreFileServerObjectInfo) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreFileServerObjectInfo); !ok { + return false + } + + other := o.(*DataStoreFileServerObjectInfo) + + if dsfsoi.StructureVersion != other.StructureVersion { + return false + } + + if !dsfsoi.DataID.Equals(other.DataID) { + return false + } + + return dsfsoi.GetInfo.Equals(other.GetInfo) +} + +// String returns the string representation of the DataStoreFileServerObjectInfo +func (dsfsoi *DataStoreFileServerObjectInfo) String() string { + return dsfsoi.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreFileServerObjectInfo using the provided indentation level +func (dsfsoi *DataStoreFileServerObjectInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreFileServerObjectInfo{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dsfsoi.DataID)) + b.WriteString(fmt.Sprintf("%sGetInfo: %s,\n", indentationValues, dsfsoi.GetInfo.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreFileServerObjectInfo returns a new DataStoreFileServerObjectInfo +func NewDataStoreFileServerObjectInfo() *DataStoreFileServerObjectInfo { + dsfsoi := &DataStoreFileServerObjectInfo{ + DataID: types.NewPrimitiveU64(0), + GetInfo: datastore_types.NewDataStoreReqGetInfo(), + } + + return dsfsoi +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_get_replay_meta_param.go b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_get_replay_meta_param.go new file mode 100644 index 0000000..87c36e3 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_get_replay_meta_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStoreSuperSmashBros.4 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreGetReplayMetaParam is a type within the DataStoreSuperSmashBros.4 protocol +type DataStoreGetReplayMetaParam struct { + types.Structure + ReplayID *types.PrimitiveU64 + MetaType *types.PrimitiveU8 +} + +// WriteTo writes the DataStoreGetReplayMetaParam to the given writable +func (dsgrmp *DataStoreGetReplayMetaParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsgrmp.ReplayID.WriteTo(contentWritable) + dsgrmp.MetaType.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsgrmp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreGetReplayMetaParam from the given readable +func (dsgrmp *DataStoreGetReplayMetaParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsgrmp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetReplayMetaParam header. %s", err.Error()) + } + + err = dsgrmp.ReplayID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetReplayMetaParam.ReplayID. %s", err.Error()) + } + + err = dsgrmp.MetaType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetReplayMetaParam.MetaType. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreGetReplayMetaParam +func (dsgrmp *DataStoreGetReplayMetaParam) Copy() types.RVType { + copied := NewDataStoreGetReplayMetaParam() + + copied.StructureVersion = dsgrmp.StructureVersion + copied.ReplayID = dsgrmp.ReplayID.Copy().(*types.PrimitiveU64) + copied.MetaType = dsgrmp.MetaType.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given DataStoreGetReplayMetaParam contains the same data as the current DataStoreGetReplayMetaParam +func (dsgrmp *DataStoreGetReplayMetaParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreGetReplayMetaParam); !ok { + return false + } + + other := o.(*DataStoreGetReplayMetaParam) + + if dsgrmp.StructureVersion != other.StructureVersion { + return false + } + + if !dsgrmp.ReplayID.Equals(other.ReplayID) { + return false + } + + return dsgrmp.MetaType.Equals(other.MetaType) +} + +// String returns the string representation of the DataStoreGetReplayMetaParam +func (dsgrmp *DataStoreGetReplayMetaParam) String() string { + return dsgrmp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreGetReplayMetaParam using the provided indentation level +func (dsgrmp *DataStoreGetReplayMetaParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreGetReplayMetaParam{\n") + b.WriteString(fmt.Sprintf("%sReplayID: %s,\n", indentationValues, dsgrmp.ReplayID)) + b.WriteString(fmt.Sprintf("%sMetaType: %s,\n", indentationValues, dsgrmp.MetaType)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreGetReplayMetaParam returns a new DataStoreGetReplayMetaParam +func NewDataStoreGetReplayMetaParam() *DataStoreGetReplayMetaParam { + dsgrmp := &DataStoreGetReplayMetaParam{ + ReplayID: types.NewPrimitiveU64(0), + MetaType: types.NewPrimitiveU8(0), + } + + return dsgrmp +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_post_fighting_power_score_param.go b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_post_fighting_power_score_param.go new file mode 100644 index 0000000..a257fe3 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_post_fighting_power_score_param.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the DataStoreSuperSmashBros.4 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStorePostFightingPowerScoreParam is a type within the DataStoreSuperSmashBros.4 protocol +type DataStorePostFightingPowerScoreParam struct { + types.Structure + Mode *types.PrimitiveU8 + Score *types.PrimitiveU32 + IsWorldHighScore *types.PrimitiveBool +} + +// WriteTo writes the DataStorePostFightingPowerScoreParam to the given writable +func (dspfpsp *DataStorePostFightingPowerScoreParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dspfpsp.Mode.WriteTo(contentWritable) + dspfpsp.Score.WriteTo(contentWritable) + dspfpsp.IsWorldHighScore.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dspfpsp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStorePostFightingPowerScoreParam from the given readable +func (dspfpsp *DataStorePostFightingPowerScoreParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dspfpsp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePostFightingPowerScoreParam header. %s", err.Error()) + } + + err = dspfpsp.Mode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePostFightingPowerScoreParam.Mode. %s", err.Error()) + } + + err = dspfpsp.Score.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePostFightingPowerScoreParam.Score. %s", err.Error()) + } + + err = dspfpsp.IsWorldHighScore.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePostFightingPowerScoreParam.IsWorldHighScore. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStorePostFightingPowerScoreParam +func (dspfpsp *DataStorePostFightingPowerScoreParam) Copy() types.RVType { + copied := NewDataStorePostFightingPowerScoreParam() + + copied.StructureVersion = dspfpsp.StructureVersion + copied.Mode = dspfpsp.Mode.Copy().(*types.PrimitiveU8) + copied.Score = dspfpsp.Score.Copy().(*types.PrimitiveU32) + copied.IsWorldHighScore = dspfpsp.IsWorldHighScore.Copy().(*types.PrimitiveBool) + + return copied +} + +// Equals checks if the given DataStorePostFightingPowerScoreParam contains the same data as the current DataStorePostFightingPowerScoreParam +func (dspfpsp *DataStorePostFightingPowerScoreParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStorePostFightingPowerScoreParam); !ok { + return false + } + + other := o.(*DataStorePostFightingPowerScoreParam) + + if dspfpsp.StructureVersion != other.StructureVersion { + return false + } + + if !dspfpsp.Mode.Equals(other.Mode) { + return false + } + + if !dspfpsp.Score.Equals(other.Score) { + return false + } + + return dspfpsp.IsWorldHighScore.Equals(other.IsWorldHighScore) +} + +// String returns the string representation of the DataStorePostFightingPowerScoreParam +func (dspfpsp *DataStorePostFightingPowerScoreParam) String() string { + return dspfpsp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStorePostFightingPowerScoreParam using the provided indentation level +func (dspfpsp *DataStorePostFightingPowerScoreParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStorePostFightingPowerScoreParam{\n") + b.WriteString(fmt.Sprintf("%sMode: %s,\n", indentationValues, dspfpsp.Mode)) + b.WriteString(fmt.Sprintf("%sScore: %s,\n", indentationValues, dspfpsp.Score)) + b.WriteString(fmt.Sprintf("%sIsWorldHighScore: %s,\n", indentationValues, dspfpsp.IsWorldHighScore)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStorePostFightingPowerScoreParam returns a new DataStorePostFightingPowerScoreParam +func NewDataStorePostFightingPowerScoreParam() *DataStorePostFightingPowerScoreParam { + dspfpsp := &DataStorePostFightingPowerScoreParam{ + Mode: types.NewPrimitiveU8(0), + Score: types.NewPrimitiveU32(0), + IsWorldHighScore: types.NewPrimitiveBool(false), + } + + return dspfpsp +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_post_profile_param.go b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_post_profile_param.go new file mode 100644 index 0000000..aa71e48 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_post_profile_param.go @@ -0,0 +1,98 @@ +// Package types implements all the types used by the DataStoreSuperSmashBros.4 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStorePostProfileParam is a type within the DataStoreSuperSmashBros.4 protocol +type DataStorePostProfileParam struct { + types.Structure + Profile *types.QBuffer +} + +// WriteTo writes the DataStorePostProfileParam to the given writable +func (dsppp *DataStorePostProfileParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsppp.Profile.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsppp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStorePostProfileParam from the given readable +func (dsppp *DataStorePostProfileParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsppp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePostProfileParam header. %s", err.Error()) + } + + err = dsppp.Profile.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePostProfileParam.Profile. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStorePostProfileParam +func (dsppp *DataStorePostProfileParam) Copy() types.RVType { + copied := NewDataStorePostProfileParam() + + copied.StructureVersion = dsppp.StructureVersion + copied.Profile = dsppp.Profile.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given DataStorePostProfileParam contains the same data as the current DataStorePostProfileParam +func (dsppp *DataStorePostProfileParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStorePostProfileParam); !ok { + return false + } + + other := o.(*DataStorePostProfileParam) + + if dsppp.StructureVersion != other.StructureVersion { + return false + } + + return dsppp.Profile.Equals(other.Profile) +} + +// String returns the string representation of the DataStorePostProfileParam +func (dsppp *DataStorePostProfileParam) String() string { + return dsppp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStorePostProfileParam using the provided indentation level +func (dsppp *DataStorePostProfileParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStorePostProfileParam{\n") + b.WriteString(fmt.Sprintf("%sProfile: %s,\n", indentationValues, dsppp.Profile)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStorePostProfileParam returns a new DataStorePostProfileParam +func NewDataStorePostProfileParam() *DataStorePostProfileParam { + dsppp := &DataStorePostProfileParam{ + Profile: types.NewQBuffer(nil), + } + + return dsppp +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_prepare_get_replay_param.go b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_prepare_get_replay_param.go new file mode 100644 index 0000000..b3859a5 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_prepare_get_replay_param.go @@ -0,0 +1,114 @@ +// Package types implements all the types used by the DataStoreSuperSmashBros.4 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStorePrepareGetReplayParam is a type within the DataStoreSuperSmashBros.4 protocol +type DataStorePrepareGetReplayParam struct { + types.Structure + ReplayID *types.PrimitiveU64 + ExtraData *types.List[*types.String] +} + +// WriteTo writes the DataStorePrepareGetReplayParam to the given writable +func (dspgrp *DataStorePrepareGetReplayParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dspgrp.ReplayID.WriteTo(contentWritable) + dspgrp.ExtraData.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dspgrp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStorePrepareGetReplayParam from the given readable +func (dspgrp *DataStorePrepareGetReplayParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dspgrp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePrepareGetReplayParam header. %s", err.Error()) + } + + err = dspgrp.ReplayID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePrepareGetReplayParam.ReplayID. %s", err.Error()) + } + + err = dspgrp.ExtraData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePrepareGetReplayParam.ExtraData. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStorePrepareGetReplayParam +func (dspgrp *DataStorePrepareGetReplayParam) Copy() types.RVType { + copied := NewDataStorePrepareGetReplayParam() + + copied.StructureVersion = dspgrp.StructureVersion + copied.ReplayID = dspgrp.ReplayID.Copy().(*types.PrimitiveU64) + copied.ExtraData = dspgrp.ExtraData.Copy().(*types.List[*types.String]) + + return copied +} + +// Equals checks if the given DataStorePrepareGetReplayParam contains the same data as the current DataStorePrepareGetReplayParam +func (dspgrp *DataStorePrepareGetReplayParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStorePrepareGetReplayParam); !ok { + return false + } + + other := o.(*DataStorePrepareGetReplayParam) + + if dspgrp.StructureVersion != other.StructureVersion { + return false + } + + if !dspgrp.ReplayID.Equals(other.ReplayID) { + return false + } + + return dspgrp.ExtraData.Equals(other.ExtraData) +} + +// String returns the string representation of the DataStorePrepareGetReplayParam +func (dspgrp *DataStorePrepareGetReplayParam) String() string { + return dspgrp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStorePrepareGetReplayParam using the provided indentation level +func (dspgrp *DataStorePrepareGetReplayParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStorePrepareGetReplayParam{\n") + b.WriteString(fmt.Sprintf("%sReplayID: %s,\n", indentationValues, dspgrp.ReplayID)) + b.WriteString(fmt.Sprintf("%sExtraData: %s,\n", indentationValues, dspgrp.ExtraData)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStorePrepareGetReplayParam returns a new DataStorePrepareGetReplayParam +func NewDataStorePrepareGetReplayParam() *DataStorePrepareGetReplayParam { + dspgrp := &DataStorePrepareGetReplayParam{ + ReplayID: types.NewPrimitiveU64(0), + ExtraData: types.NewList[*types.String](), + } + + dspgrp.ExtraData.Type = types.NewString("") + + return dspgrp +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_prepare_post_replay_param.go b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_prepare_post_replay_param.go new file mode 100644 index 0000000..50a358b --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_prepare_post_replay_param.go @@ -0,0 +1,256 @@ +// Package types implements all the types used by the DataStoreSuperSmashBros.4 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStorePreparePostReplayParam is a type within the DataStoreSuperSmashBros.4 protocol +type DataStorePreparePostReplayParam struct { + types.Structure + Size *types.PrimitiveU32 + Mode *types.PrimitiveU8 + Style *types.PrimitiveU8 + Rule *types.PrimitiveU8 + Stage *types.PrimitiveU8 + ReplayType *types.PrimitiveU8 + CompetitionID *types.PrimitiveU64 + Score *types.PrimitiveS32 + Players *types.List[*DataStoreReplayPlayer] + Winners *types.List[*types.PrimitiveU32] + KeyVersion *types.PrimitiveU16 + ExtraData *types.List[*types.String] +} + +// WriteTo writes the DataStorePreparePostReplayParam to the given writable +func (dspprp *DataStorePreparePostReplayParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dspprp.Size.WriteTo(contentWritable) + dspprp.Mode.WriteTo(contentWritable) + dspprp.Style.WriteTo(contentWritable) + dspprp.Rule.WriteTo(contentWritable) + dspprp.Stage.WriteTo(contentWritable) + dspprp.ReplayType.WriteTo(contentWritable) + dspprp.CompetitionID.WriteTo(contentWritable) + dspprp.Score.WriteTo(contentWritable) + dspprp.Players.WriteTo(contentWritable) + dspprp.Winners.WriteTo(contentWritable) + dspprp.KeyVersion.WriteTo(contentWritable) + dspprp.ExtraData.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dspprp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStorePreparePostReplayParam from the given readable +func (dspprp *DataStorePreparePostReplayParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dspprp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostReplayParam header. %s", err.Error()) + } + + err = dspprp.Size.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostReplayParam.Size. %s", err.Error()) + } + + err = dspprp.Mode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostReplayParam.Mode. %s", err.Error()) + } + + err = dspprp.Style.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostReplayParam.Style. %s", err.Error()) + } + + err = dspprp.Rule.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostReplayParam.Rule. %s", err.Error()) + } + + err = dspprp.Stage.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostReplayParam.Stage. %s", err.Error()) + } + + err = dspprp.ReplayType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostReplayParam.ReplayType. %s", err.Error()) + } + + err = dspprp.CompetitionID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostReplayParam.CompetitionID. %s", err.Error()) + } + + err = dspprp.Score.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostReplayParam.Score. %s", err.Error()) + } + + err = dspprp.Players.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostReplayParam.Players. %s", err.Error()) + } + + err = dspprp.Winners.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostReplayParam.Winners. %s", err.Error()) + } + + err = dspprp.KeyVersion.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostReplayParam.KeyVersion. %s", err.Error()) + } + + err = dspprp.ExtraData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostReplayParam.ExtraData. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStorePreparePostReplayParam +func (dspprp *DataStorePreparePostReplayParam) Copy() types.RVType { + copied := NewDataStorePreparePostReplayParam() + + copied.StructureVersion = dspprp.StructureVersion + copied.Size = dspprp.Size.Copy().(*types.PrimitiveU32) + copied.Mode = dspprp.Mode.Copy().(*types.PrimitiveU8) + copied.Style = dspprp.Style.Copy().(*types.PrimitiveU8) + copied.Rule = dspprp.Rule.Copy().(*types.PrimitiveU8) + copied.Stage = dspprp.Stage.Copy().(*types.PrimitiveU8) + copied.ReplayType = dspprp.ReplayType.Copy().(*types.PrimitiveU8) + copied.CompetitionID = dspprp.CompetitionID.Copy().(*types.PrimitiveU64) + copied.Score = dspprp.Score.Copy().(*types.PrimitiveS32) + copied.Players = dspprp.Players.Copy().(*types.List[*DataStoreReplayPlayer]) + copied.Winners = dspprp.Winners.Copy().(*types.List[*types.PrimitiveU32]) + copied.KeyVersion = dspprp.KeyVersion.Copy().(*types.PrimitiveU16) + copied.ExtraData = dspprp.ExtraData.Copy().(*types.List[*types.String]) + + return copied +} + +// Equals checks if the given DataStorePreparePostReplayParam contains the same data as the current DataStorePreparePostReplayParam +func (dspprp *DataStorePreparePostReplayParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStorePreparePostReplayParam); !ok { + return false + } + + other := o.(*DataStorePreparePostReplayParam) + + if dspprp.StructureVersion != other.StructureVersion { + return false + } + + if !dspprp.Size.Equals(other.Size) { + return false + } + + if !dspprp.Mode.Equals(other.Mode) { + return false + } + + if !dspprp.Style.Equals(other.Style) { + return false + } + + if !dspprp.Rule.Equals(other.Rule) { + return false + } + + if !dspprp.Stage.Equals(other.Stage) { + return false + } + + if !dspprp.ReplayType.Equals(other.ReplayType) { + return false + } + + if !dspprp.CompetitionID.Equals(other.CompetitionID) { + return false + } + + if !dspprp.Score.Equals(other.Score) { + return false + } + + if !dspprp.Players.Equals(other.Players) { + return false + } + + if !dspprp.Winners.Equals(other.Winners) { + return false + } + + if !dspprp.KeyVersion.Equals(other.KeyVersion) { + return false + } + + return dspprp.ExtraData.Equals(other.ExtraData) +} + +// String returns the string representation of the DataStorePreparePostReplayParam +func (dspprp *DataStorePreparePostReplayParam) String() string { + return dspprp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStorePreparePostReplayParam using the provided indentation level +func (dspprp *DataStorePreparePostReplayParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStorePreparePostReplayParam{\n") + b.WriteString(fmt.Sprintf("%sSize: %s,\n", indentationValues, dspprp.Size)) + b.WriteString(fmt.Sprintf("%sMode: %s,\n", indentationValues, dspprp.Mode)) + b.WriteString(fmt.Sprintf("%sStyle: %s,\n", indentationValues, dspprp.Style)) + b.WriteString(fmt.Sprintf("%sRule: %s,\n", indentationValues, dspprp.Rule)) + b.WriteString(fmt.Sprintf("%sStage: %s,\n", indentationValues, dspprp.Stage)) + b.WriteString(fmt.Sprintf("%sReplayType: %s,\n", indentationValues, dspprp.ReplayType)) + b.WriteString(fmt.Sprintf("%sCompetitionID: %s,\n", indentationValues, dspprp.CompetitionID)) + b.WriteString(fmt.Sprintf("%sScore: %s,\n", indentationValues, dspprp.Score)) + b.WriteString(fmt.Sprintf("%sPlayers: %s,\n", indentationValues, dspprp.Players)) + b.WriteString(fmt.Sprintf("%sWinners: %s,\n", indentationValues, dspprp.Winners)) + b.WriteString(fmt.Sprintf("%sKeyVersion: %s,\n", indentationValues, dspprp.KeyVersion)) + b.WriteString(fmt.Sprintf("%sExtraData: %s,\n", indentationValues, dspprp.ExtraData)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStorePreparePostReplayParam returns a new DataStorePreparePostReplayParam +func NewDataStorePreparePostReplayParam() *DataStorePreparePostReplayParam { + dspprp := &DataStorePreparePostReplayParam{ + Size: types.NewPrimitiveU32(0), + Mode: types.NewPrimitiveU8(0), + Style: types.NewPrimitiveU8(0), + Rule: types.NewPrimitiveU8(0), + Stage: types.NewPrimitiveU8(0), + ReplayType: types.NewPrimitiveU8(0), + CompetitionID: types.NewPrimitiveU64(0), + Score: types.NewPrimitiveS32(0), + Players: types.NewList[*DataStoreReplayPlayer](), + Winners: types.NewList[*types.PrimitiveU32](), + KeyVersion: types.NewPrimitiveU16(0), + ExtraData: types.NewList[*types.String](), + } + + dspprp.Players.Type = NewDataStoreReplayPlayer() + dspprp.Winners.Type = types.NewPrimitiveU32(0) + dspprp.ExtraData.Type = types.NewString("") + + return dspprp +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_prepare_post_shared_data_param.go b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_prepare_post_shared_data_param.go new file mode 100644 index 0000000..0fe6b98 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_prepare_post_shared_data_param.go @@ -0,0 +1,212 @@ +// Package types implements all the types used by the DataStoreSuperSmashBros.4 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStorePreparePostSharedDataParam is a type within the DataStoreSuperSmashBros.4 protocol +type DataStorePreparePostSharedDataParam struct { + types.Structure + DataType *types.PrimitiveU8 + Region *types.PrimitiveU8 + Attribute1 *types.PrimitiveU8 + Attribute2 *types.PrimitiveU8 + Fighter *types.Buffer + Size *types.PrimitiveU32 + Comment *types.String + MetaBinary *types.QBuffer + ExtraData *types.List[*types.String] +} + +// WriteTo writes the DataStorePreparePostSharedDataParam to the given writable +func (dsppsdp *DataStorePreparePostSharedDataParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsppsdp.DataType.WriteTo(contentWritable) + dsppsdp.Region.WriteTo(contentWritable) + dsppsdp.Attribute1.WriteTo(contentWritable) + dsppsdp.Attribute2.WriteTo(contentWritable) + dsppsdp.Fighter.WriteTo(contentWritable) + dsppsdp.Size.WriteTo(contentWritable) + dsppsdp.Comment.WriteTo(contentWritable) + dsppsdp.MetaBinary.WriteTo(contentWritable) + dsppsdp.ExtraData.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsppsdp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStorePreparePostSharedDataParam from the given readable +func (dsppsdp *DataStorePreparePostSharedDataParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsppsdp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostSharedDataParam header. %s", err.Error()) + } + + err = dsppsdp.DataType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostSharedDataParam.DataType. %s", err.Error()) + } + + err = dsppsdp.Region.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostSharedDataParam.Region. %s", err.Error()) + } + + err = dsppsdp.Attribute1.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostSharedDataParam.Attribute1. %s", err.Error()) + } + + err = dsppsdp.Attribute2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostSharedDataParam.Attribute2. %s", err.Error()) + } + + err = dsppsdp.Fighter.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostSharedDataParam.Fighter. %s", err.Error()) + } + + err = dsppsdp.Size.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostSharedDataParam.Size. %s", err.Error()) + } + + err = dsppsdp.Comment.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostSharedDataParam.Comment. %s", err.Error()) + } + + err = dsppsdp.MetaBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostSharedDataParam.MetaBinary. %s", err.Error()) + } + + err = dsppsdp.ExtraData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostSharedDataParam.ExtraData. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStorePreparePostSharedDataParam +func (dsppsdp *DataStorePreparePostSharedDataParam) Copy() types.RVType { + copied := NewDataStorePreparePostSharedDataParam() + + copied.StructureVersion = dsppsdp.StructureVersion + copied.DataType = dsppsdp.DataType.Copy().(*types.PrimitiveU8) + copied.Region = dsppsdp.Region.Copy().(*types.PrimitiveU8) + copied.Attribute1 = dsppsdp.Attribute1.Copy().(*types.PrimitiveU8) + copied.Attribute2 = dsppsdp.Attribute2.Copy().(*types.PrimitiveU8) + copied.Fighter = dsppsdp.Fighter.Copy().(*types.Buffer) + copied.Size = dsppsdp.Size.Copy().(*types.PrimitiveU32) + copied.Comment = dsppsdp.Comment.Copy().(*types.String) + copied.MetaBinary = dsppsdp.MetaBinary.Copy().(*types.QBuffer) + copied.ExtraData = dsppsdp.ExtraData.Copy().(*types.List[*types.String]) + + return copied +} + +// Equals checks if the given DataStorePreparePostSharedDataParam contains the same data as the current DataStorePreparePostSharedDataParam +func (dsppsdp *DataStorePreparePostSharedDataParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStorePreparePostSharedDataParam); !ok { + return false + } + + other := o.(*DataStorePreparePostSharedDataParam) + + if dsppsdp.StructureVersion != other.StructureVersion { + return false + } + + if !dsppsdp.DataType.Equals(other.DataType) { + return false + } + + if !dsppsdp.Region.Equals(other.Region) { + return false + } + + if !dsppsdp.Attribute1.Equals(other.Attribute1) { + return false + } + + if !dsppsdp.Attribute2.Equals(other.Attribute2) { + return false + } + + if !dsppsdp.Fighter.Equals(other.Fighter) { + return false + } + + if !dsppsdp.Size.Equals(other.Size) { + return false + } + + if !dsppsdp.Comment.Equals(other.Comment) { + return false + } + + if !dsppsdp.MetaBinary.Equals(other.MetaBinary) { + return false + } + + return dsppsdp.ExtraData.Equals(other.ExtraData) +} + +// String returns the string representation of the DataStorePreparePostSharedDataParam +func (dsppsdp *DataStorePreparePostSharedDataParam) String() string { + return dsppsdp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStorePreparePostSharedDataParam using the provided indentation level +func (dsppsdp *DataStorePreparePostSharedDataParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStorePreparePostSharedDataParam{\n") + b.WriteString(fmt.Sprintf("%sDataType: %s,\n", indentationValues, dsppsdp.DataType)) + b.WriteString(fmt.Sprintf("%sRegion: %s,\n", indentationValues, dsppsdp.Region)) + b.WriteString(fmt.Sprintf("%sAttribute1: %s,\n", indentationValues, dsppsdp.Attribute1)) + b.WriteString(fmt.Sprintf("%sAttribute2: %s,\n", indentationValues, dsppsdp.Attribute2)) + b.WriteString(fmt.Sprintf("%sFighter: %s,\n", indentationValues, dsppsdp.Fighter)) + b.WriteString(fmt.Sprintf("%sSize: %s,\n", indentationValues, dsppsdp.Size)) + b.WriteString(fmt.Sprintf("%sComment: %s,\n", indentationValues, dsppsdp.Comment)) + b.WriteString(fmt.Sprintf("%sMetaBinary: %s,\n", indentationValues, dsppsdp.MetaBinary)) + b.WriteString(fmt.Sprintf("%sExtraData: %s,\n", indentationValues, dsppsdp.ExtraData)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStorePreparePostSharedDataParam returns a new DataStorePreparePostSharedDataParam +func NewDataStorePreparePostSharedDataParam() *DataStorePreparePostSharedDataParam { + dsppsdp := &DataStorePreparePostSharedDataParam{ + DataType: types.NewPrimitiveU8(0), + Region: types.NewPrimitiveU8(0), + Attribute1: types.NewPrimitiveU8(0), + Attribute2: types.NewPrimitiveU8(0), + Fighter: types.NewBuffer(nil), + Size: types.NewPrimitiveU32(0), + Comment: types.NewString(""), + MetaBinary: types.NewQBuffer(nil), + ExtraData: types.NewList[*types.String](), + } + + dsppsdp.ExtraData.Type = types.NewString("") + + return dsppsdp +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_profile_info.go b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_profile_info.go new file mode 100644 index 0000000..a8fd8d1 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_profile_info.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStoreSuperSmashBros.4 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreProfileInfo is a type within the DataStoreSuperSmashBros.4 protocol +type DataStoreProfileInfo struct { + types.Structure + PID *types.PID + Profile *types.QBuffer +} + +// WriteTo writes the DataStoreProfileInfo to the given writable +func (dspi *DataStoreProfileInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dspi.PID.WriteTo(contentWritable) + dspi.Profile.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dspi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreProfileInfo from the given readable +func (dspi *DataStoreProfileInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = dspi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreProfileInfo header. %s", err.Error()) + } + + err = dspi.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreProfileInfo.PID. %s", err.Error()) + } + + err = dspi.Profile.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreProfileInfo.Profile. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreProfileInfo +func (dspi *DataStoreProfileInfo) Copy() types.RVType { + copied := NewDataStoreProfileInfo() + + copied.StructureVersion = dspi.StructureVersion + copied.PID = dspi.PID.Copy().(*types.PID) + copied.Profile = dspi.Profile.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given DataStoreProfileInfo contains the same data as the current DataStoreProfileInfo +func (dspi *DataStoreProfileInfo) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreProfileInfo); !ok { + return false + } + + other := o.(*DataStoreProfileInfo) + + if dspi.StructureVersion != other.StructureVersion { + return false + } + + if !dspi.PID.Equals(other.PID) { + return false + } + + return dspi.Profile.Equals(other.Profile) +} + +// String returns the string representation of the DataStoreProfileInfo +func (dspi *DataStoreProfileInfo) String() string { + return dspi.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreProfileInfo using the provided indentation level +func (dspi *DataStoreProfileInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreProfileInfo{\n") + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, dspi.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sProfile: %s,\n", indentationValues, dspi.Profile)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreProfileInfo returns a new DataStoreProfileInfo +func NewDataStoreProfileInfo() *DataStoreProfileInfo { + dspi := &DataStoreProfileInfo{ + PID: types.NewPID(0), + Profile: types.NewQBuffer(nil), + } + + return dspi +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_replay_meta_info.go b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_replay_meta_info.go new file mode 100644 index 0000000..8120412 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_replay_meta_info.go @@ -0,0 +1,213 @@ +// Package types implements all the types used by the DataStoreSuperSmashBros.4 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreReplayMetaInfo is a type within the DataStoreSuperSmashBros.4 protocol +type DataStoreReplayMetaInfo struct { + types.Structure + ReplayID *types.PrimitiveU64 + Size *types.PrimitiveU32 + Mode *types.PrimitiveU8 + Style *types.PrimitiveU8 + Rule *types.PrimitiveU8 + Stage *types.PrimitiveU8 + ReplayType *types.PrimitiveU8 + Players *types.List[*DataStoreReplayPlayer] + Winners *types.List[*types.PrimitiveU32] +} + +// WriteTo writes the DataStoreReplayMetaInfo to the given writable +func (dsrmi *DataStoreReplayMetaInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsrmi.ReplayID.WriteTo(contentWritable) + dsrmi.Size.WriteTo(contentWritable) + dsrmi.Mode.WriteTo(contentWritable) + dsrmi.Style.WriteTo(contentWritable) + dsrmi.Rule.WriteTo(contentWritable) + dsrmi.Stage.WriteTo(contentWritable) + dsrmi.ReplayType.WriteTo(contentWritable) + dsrmi.Players.WriteTo(contentWritable) + dsrmi.Winners.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsrmi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreReplayMetaInfo from the given readable +func (dsrmi *DataStoreReplayMetaInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = dsrmi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayMetaInfo header. %s", err.Error()) + } + + err = dsrmi.ReplayID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayMetaInfo.ReplayID. %s", err.Error()) + } + + err = dsrmi.Size.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayMetaInfo.Size. %s", err.Error()) + } + + err = dsrmi.Mode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayMetaInfo.Mode. %s", err.Error()) + } + + err = dsrmi.Style.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayMetaInfo.Style. %s", err.Error()) + } + + err = dsrmi.Rule.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayMetaInfo.Rule. %s", err.Error()) + } + + err = dsrmi.Stage.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayMetaInfo.Stage. %s", err.Error()) + } + + err = dsrmi.ReplayType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayMetaInfo.ReplayType. %s", err.Error()) + } + + err = dsrmi.Players.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayMetaInfo.Players. %s", err.Error()) + } + + err = dsrmi.Winners.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayMetaInfo.Winners. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreReplayMetaInfo +func (dsrmi *DataStoreReplayMetaInfo) Copy() types.RVType { + copied := NewDataStoreReplayMetaInfo() + + copied.StructureVersion = dsrmi.StructureVersion + copied.ReplayID = dsrmi.ReplayID.Copy().(*types.PrimitiveU64) + copied.Size = dsrmi.Size.Copy().(*types.PrimitiveU32) + copied.Mode = dsrmi.Mode.Copy().(*types.PrimitiveU8) + copied.Style = dsrmi.Style.Copy().(*types.PrimitiveU8) + copied.Rule = dsrmi.Rule.Copy().(*types.PrimitiveU8) + copied.Stage = dsrmi.Stage.Copy().(*types.PrimitiveU8) + copied.ReplayType = dsrmi.ReplayType.Copy().(*types.PrimitiveU8) + copied.Players = dsrmi.Players.Copy().(*types.List[*DataStoreReplayPlayer]) + copied.Winners = dsrmi.Winners.Copy().(*types.List[*types.PrimitiveU32]) + + return copied +} + +// Equals checks if the given DataStoreReplayMetaInfo contains the same data as the current DataStoreReplayMetaInfo +func (dsrmi *DataStoreReplayMetaInfo) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreReplayMetaInfo); !ok { + return false + } + + other := o.(*DataStoreReplayMetaInfo) + + if dsrmi.StructureVersion != other.StructureVersion { + return false + } + + if !dsrmi.ReplayID.Equals(other.ReplayID) { + return false + } + + if !dsrmi.Size.Equals(other.Size) { + return false + } + + if !dsrmi.Mode.Equals(other.Mode) { + return false + } + + if !dsrmi.Style.Equals(other.Style) { + return false + } + + if !dsrmi.Rule.Equals(other.Rule) { + return false + } + + if !dsrmi.Stage.Equals(other.Stage) { + return false + } + + if !dsrmi.ReplayType.Equals(other.ReplayType) { + return false + } + + if !dsrmi.Players.Equals(other.Players) { + return false + } + + return dsrmi.Winners.Equals(other.Winners) +} + +// String returns the string representation of the DataStoreReplayMetaInfo +func (dsrmi *DataStoreReplayMetaInfo) String() string { + return dsrmi.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreReplayMetaInfo using the provided indentation level +func (dsrmi *DataStoreReplayMetaInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreReplayMetaInfo{\n") + b.WriteString(fmt.Sprintf("%sReplayID: %s,\n", indentationValues, dsrmi.ReplayID)) + b.WriteString(fmt.Sprintf("%sSize: %s,\n", indentationValues, dsrmi.Size)) + b.WriteString(fmt.Sprintf("%sMode: %s,\n", indentationValues, dsrmi.Mode)) + b.WriteString(fmt.Sprintf("%sStyle: %s,\n", indentationValues, dsrmi.Style)) + b.WriteString(fmt.Sprintf("%sRule: %s,\n", indentationValues, dsrmi.Rule)) + b.WriteString(fmt.Sprintf("%sStage: %s,\n", indentationValues, dsrmi.Stage)) + b.WriteString(fmt.Sprintf("%sReplayType: %s,\n", indentationValues, dsrmi.ReplayType)) + b.WriteString(fmt.Sprintf("%sPlayers: %s,\n", indentationValues, dsrmi.Players)) + b.WriteString(fmt.Sprintf("%sWinners: %s,\n", indentationValues, dsrmi.Winners)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreReplayMetaInfo returns a new DataStoreReplayMetaInfo +func NewDataStoreReplayMetaInfo() *DataStoreReplayMetaInfo { + dsrmi := &DataStoreReplayMetaInfo{ + ReplayID: types.NewPrimitiveU64(0), + Size: types.NewPrimitiveU32(0), + Mode: types.NewPrimitiveU8(0), + Style: types.NewPrimitiveU8(0), + Rule: types.NewPrimitiveU8(0), + Stage: types.NewPrimitiveU8(0), + ReplayType: types.NewPrimitiveU8(0), + Players: types.NewList[*DataStoreReplayPlayer](), + Winners: types.NewList[*types.PrimitiveU32](), + } + + dsrmi.Players.Type = NewDataStoreReplayPlayer() + dsrmi.Winners.Type = types.NewPrimitiveU32(0) + + return dsrmi +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_replay_player.go b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_replay_player.go new file mode 100644 index 0000000..e103fde --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_replay_player.go @@ -0,0 +1,210 @@ +// Package types implements all the types used by the DataStoreSuperSmashBros.4 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreReplayPlayer is a type within the DataStoreSuperSmashBros.4 protocol +type DataStoreReplayPlayer struct { + types.Structure + Fighter *types.PrimitiveU8 + Health *types.PrimitiveU8 + WinningRate *types.PrimitiveU16 + Color *types.PrimitiveU8 + Color2 *types.PrimitiveU8 + PrincipalID *types.PrimitiveU32 + Country *types.PrimitiveU32 + Region *types.PrimitiveU8 + Number *types.PrimitiveU8 +} + +// WriteTo writes the DataStoreReplayPlayer to the given writable +func (dsrp *DataStoreReplayPlayer) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsrp.Fighter.WriteTo(contentWritable) + dsrp.Health.WriteTo(contentWritable) + dsrp.WinningRate.WriteTo(contentWritable) + dsrp.Color.WriteTo(contentWritable) + dsrp.Color2.WriteTo(contentWritable) + dsrp.PrincipalID.WriteTo(contentWritable) + dsrp.Country.WriteTo(contentWritable) + dsrp.Region.WriteTo(contentWritable) + dsrp.Number.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsrp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreReplayPlayer from the given readable +func (dsrp *DataStoreReplayPlayer) ExtractFrom(readable types.Readable) error { + var err error + + err = dsrp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayPlayer header. %s", err.Error()) + } + + err = dsrp.Fighter.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayPlayer.Fighter. %s", err.Error()) + } + + err = dsrp.Health.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayPlayer.Health. %s", err.Error()) + } + + err = dsrp.WinningRate.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayPlayer.WinningRate. %s", err.Error()) + } + + err = dsrp.Color.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayPlayer.Color. %s", err.Error()) + } + + err = dsrp.Color2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayPlayer.Color2. %s", err.Error()) + } + + err = dsrp.PrincipalID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayPlayer.PrincipalID. %s", err.Error()) + } + + err = dsrp.Country.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayPlayer.Country. %s", err.Error()) + } + + err = dsrp.Region.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayPlayer.Region. %s", err.Error()) + } + + err = dsrp.Number.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReplayPlayer.Number. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreReplayPlayer +func (dsrp *DataStoreReplayPlayer) Copy() types.RVType { + copied := NewDataStoreReplayPlayer() + + copied.StructureVersion = dsrp.StructureVersion + copied.Fighter = dsrp.Fighter.Copy().(*types.PrimitiveU8) + copied.Health = dsrp.Health.Copy().(*types.PrimitiveU8) + copied.WinningRate = dsrp.WinningRate.Copy().(*types.PrimitiveU16) + copied.Color = dsrp.Color.Copy().(*types.PrimitiveU8) + copied.Color2 = dsrp.Color2.Copy().(*types.PrimitiveU8) + copied.PrincipalID = dsrp.PrincipalID.Copy().(*types.PrimitiveU32) + copied.Country = dsrp.Country.Copy().(*types.PrimitiveU32) + copied.Region = dsrp.Region.Copy().(*types.PrimitiveU8) + copied.Number = dsrp.Number.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given DataStoreReplayPlayer contains the same data as the current DataStoreReplayPlayer +func (dsrp *DataStoreReplayPlayer) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreReplayPlayer); !ok { + return false + } + + other := o.(*DataStoreReplayPlayer) + + if dsrp.StructureVersion != other.StructureVersion { + return false + } + + if !dsrp.Fighter.Equals(other.Fighter) { + return false + } + + if !dsrp.Health.Equals(other.Health) { + return false + } + + if !dsrp.WinningRate.Equals(other.WinningRate) { + return false + } + + if !dsrp.Color.Equals(other.Color) { + return false + } + + if !dsrp.Color2.Equals(other.Color2) { + return false + } + + if !dsrp.PrincipalID.Equals(other.PrincipalID) { + return false + } + + if !dsrp.Country.Equals(other.Country) { + return false + } + + if !dsrp.Region.Equals(other.Region) { + return false + } + + return dsrp.Number.Equals(other.Number) +} + +// String returns the string representation of the DataStoreReplayPlayer +func (dsrp *DataStoreReplayPlayer) String() string { + return dsrp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreReplayPlayer using the provided indentation level +func (dsrp *DataStoreReplayPlayer) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreReplayPlayer{\n") + b.WriteString(fmt.Sprintf("%sFighter: %s,\n", indentationValues, dsrp.Fighter)) + b.WriteString(fmt.Sprintf("%sHealth: %s,\n", indentationValues, dsrp.Health)) + b.WriteString(fmt.Sprintf("%sWinningRate: %s,\n", indentationValues, dsrp.WinningRate)) + b.WriteString(fmt.Sprintf("%sColor: %s,\n", indentationValues, dsrp.Color)) + b.WriteString(fmt.Sprintf("%sColor2: %s,\n", indentationValues, dsrp.Color2)) + b.WriteString(fmt.Sprintf("%sPrincipalID: %s,\n", indentationValues, dsrp.PrincipalID)) + b.WriteString(fmt.Sprintf("%sCountry: %s,\n", indentationValues, dsrp.Country)) + b.WriteString(fmt.Sprintf("%sRegion: %s,\n", indentationValues, dsrp.Region)) + b.WriteString(fmt.Sprintf("%sNumber: %s,\n", indentationValues, dsrp.Number)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreReplayPlayer returns a new DataStoreReplayPlayer +func NewDataStoreReplayPlayer() *DataStoreReplayPlayer { + dsrp := &DataStoreReplayPlayer{ + Fighter: types.NewPrimitiveU8(0), + Health: types.NewPrimitiveU8(0), + WinningRate: types.NewPrimitiveU16(0), + Color: types.NewPrimitiveU8(0), + Color2: types.NewPrimitiveU8(0), + PrincipalID: types.NewPrimitiveU32(0), + Country: types.NewPrimitiveU32(0), + Region: types.NewPrimitiveU8(0), + Number: types.NewPrimitiveU8(0), + } + + return dsrp +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_search_replay_param.go b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_search_replay_param.go new file mode 100644 index 0000000..725d709 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_search_replay_param.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the DataStoreSuperSmashBros.4 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreSearchReplayParam is a type within the DataStoreSuperSmashBros.4 protocol +type DataStoreSearchReplayParam struct { + types.Structure + Mode *types.PrimitiveU8 + Style *types.PrimitiveU8 + Fighter *types.PrimitiveU8 + ResultRange *types.ResultRange +} + +// WriteTo writes the DataStoreSearchReplayParam to the given writable +func (dssrp *DataStoreSearchReplayParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dssrp.Mode.WriteTo(contentWritable) + dssrp.Style.WriteTo(contentWritable) + dssrp.Fighter.WriteTo(contentWritable) + dssrp.ResultRange.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dssrp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreSearchReplayParam from the given readable +func (dssrp *DataStoreSearchReplayParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dssrp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchReplayParam header. %s", err.Error()) + } + + err = dssrp.Mode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchReplayParam.Mode. %s", err.Error()) + } + + err = dssrp.Style.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchReplayParam.Style. %s", err.Error()) + } + + err = dssrp.Fighter.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchReplayParam.Fighter. %s", err.Error()) + } + + err = dssrp.ResultRange.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchReplayParam.ResultRange. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreSearchReplayParam +func (dssrp *DataStoreSearchReplayParam) Copy() types.RVType { + copied := NewDataStoreSearchReplayParam() + + copied.StructureVersion = dssrp.StructureVersion + copied.Mode = dssrp.Mode.Copy().(*types.PrimitiveU8) + copied.Style = dssrp.Style.Copy().(*types.PrimitiveU8) + copied.Fighter = dssrp.Fighter.Copy().(*types.PrimitiveU8) + copied.ResultRange = dssrp.ResultRange.Copy().(*types.ResultRange) + + return copied +} + +// Equals checks if the given DataStoreSearchReplayParam contains the same data as the current DataStoreSearchReplayParam +func (dssrp *DataStoreSearchReplayParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreSearchReplayParam); !ok { + return false + } + + other := o.(*DataStoreSearchReplayParam) + + if dssrp.StructureVersion != other.StructureVersion { + return false + } + + if !dssrp.Mode.Equals(other.Mode) { + return false + } + + if !dssrp.Style.Equals(other.Style) { + return false + } + + if !dssrp.Fighter.Equals(other.Fighter) { + return false + } + + return dssrp.ResultRange.Equals(other.ResultRange) +} + +// String returns the string representation of the DataStoreSearchReplayParam +func (dssrp *DataStoreSearchReplayParam) String() string { + return dssrp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreSearchReplayParam using the provided indentation level +func (dssrp *DataStoreSearchReplayParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreSearchReplayParam{\n") + b.WriteString(fmt.Sprintf("%sMode: %s,\n", indentationValues, dssrp.Mode)) + b.WriteString(fmt.Sprintf("%sStyle: %s,\n", indentationValues, dssrp.Style)) + b.WriteString(fmt.Sprintf("%sFighter: %s,\n", indentationValues, dssrp.Fighter)) + b.WriteString(fmt.Sprintf("%sResultRange: %s,\n", indentationValues, dssrp.ResultRange.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreSearchReplayParam returns a new DataStoreSearchReplayParam +func NewDataStoreSearchReplayParam() *DataStoreSearchReplayParam { + dssrp := &DataStoreSearchReplayParam{ + Mode: types.NewPrimitiveU8(0), + Style: types.NewPrimitiveU8(0), + Fighter: types.NewPrimitiveU8(0), + ResultRange: types.NewResultRange(), + } + + return dssrp +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_search_shared_data_param.go b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_search_shared_data_param.go new file mode 100644 index 0000000..ab1e963 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_search_shared_data_param.go @@ -0,0 +1,182 @@ +// Package types implements all the types used by the DataStoreSuperSmashBros.4 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreSearchSharedDataParam is a type within the DataStoreSuperSmashBros.4 protocol +type DataStoreSearchSharedDataParam struct { + types.Structure + DataType *types.PrimitiveU8 + Owner *types.PrimitiveU32 + Region *types.PrimitiveU8 + Attribute1 *types.PrimitiveU8 + Attribute2 *types.PrimitiveU8 + Fighter *types.PrimitiveU8 + ResultRange *types.ResultRange +} + +// WriteTo writes the DataStoreSearchSharedDataParam to the given writable +func (dsssdp *DataStoreSearchSharedDataParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsssdp.DataType.WriteTo(contentWritable) + dsssdp.Owner.WriteTo(contentWritable) + dsssdp.Region.WriteTo(contentWritable) + dsssdp.Attribute1.WriteTo(contentWritable) + dsssdp.Attribute2.WriteTo(contentWritable) + dsssdp.Fighter.WriteTo(contentWritable) + dsssdp.ResultRange.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsssdp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreSearchSharedDataParam from the given readable +func (dsssdp *DataStoreSearchSharedDataParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsssdp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchSharedDataParam header. %s", err.Error()) + } + + err = dsssdp.DataType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchSharedDataParam.DataType. %s", err.Error()) + } + + err = dsssdp.Owner.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchSharedDataParam.Owner. %s", err.Error()) + } + + err = dsssdp.Region.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchSharedDataParam.Region. %s", err.Error()) + } + + err = dsssdp.Attribute1.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchSharedDataParam.Attribute1. %s", err.Error()) + } + + err = dsssdp.Attribute2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchSharedDataParam.Attribute2. %s", err.Error()) + } + + err = dsssdp.Fighter.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchSharedDataParam.Fighter. %s", err.Error()) + } + + err = dsssdp.ResultRange.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchSharedDataParam.ResultRange. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreSearchSharedDataParam +func (dsssdp *DataStoreSearchSharedDataParam) Copy() types.RVType { + copied := NewDataStoreSearchSharedDataParam() + + copied.StructureVersion = dsssdp.StructureVersion + copied.DataType = dsssdp.DataType.Copy().(*types.PrimitiveU8) + copied.Owner = dsssdp.Owner.Copy().(*types.PrimitiveU32) + copied.Region = dsssdp.Region.Copy().(*types.PrimitiveU8) + copied.Attribute1 = dsssdp.Attribute1.Copy().(*types.PrimitiveU8) + copied.Attribute2 = dsssdp.Attribute2.Copy().(*types.PrimitiveU8) + copied.Fighter = dsssdp.Fighter.Copy().(*types.PrimitiveU8) + copied.ResultRange = dsssdp.ResultRange.Copy().(*types.ResultRange) + + return copied +} + +// Equals checks if the given DataStoreSearchSharedDataParam contains the same data as the current DataStoreSearchSharedDataParam +func (dsssdp *DataStoreSearchSharedDataParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreSearchSharedDataParam); !ok { + return false + } + + other := o.(*DataStoreSearchSharedDataParam) + + if dsssdp.StructureVersion != other.StructureVersion { + return false + } + + if !dsssdp.DataType.Equals(other.DataType) { + return false + } + + if !dsssdp.Owner.Equals(other.Owner) { + return false + } + + if !dsssdp.Region.Equals(other.Region) { + return false + } + + if !dsssdp.Attribute1.Equals(other.Attribute1) { + return false + } + + if !dsssdp.Attribute2.Equals(other.Attribute2) { + return false + } + + if !dsssdp.Fighter.Equals(other.Fighter) { + return false + } + + return dsssdp.ResultRange.Equals(other.ResultRange) +} + +// String returns the string representation of the DataStoreSearchSharedDataParam +func (dsssdp *DataStoreSearchSharedDataParam) String() string { + return dsssdp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreSearchSharedDataParam using the provided indentation level +func (dsssdp *DataStoreSearchSharedDataParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreSearchSharedDataParam{\n") + b.WriteString(fmt.Sprintf("%sDataType: %s,\n", indentationValues, dsssdp.DataType)) + b.WriteString(fmt.Sprintf("%sOwner: %s,\n", indentationValues, dsssdp.Owner)) + b.WriteString(fmt.Sprintf("%sRegion: %s,\n", indentationValues, dsssdp.Region)) + b.WriteString(fmt.Sprintf("%sAttribute1: %s,\n", indentationValues, dsssdp.Attribute1)) + b.WriteString(fmt.Sprintf("%sAttribute2: %s,\n", indentationValues, dsssdp.Attribute2)) + b.WriteString(fmt.Sprintf("%sFighter: %s,\n", indentationValues, dsssdp.Fighter)) + b.WriteString(fmt.Sprintf("%sResultRange: %s,\n", indentationValues, dsssdp.ResultRange.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreSearchSharedDataParam returns a new DataStoreSearchSharedDataParam +func NewDataStoreSearchSharedDataParam() *DataStoreSearchSharedDataParam { + dsssdp := &DataStoreSearchSharedDataParam{ + DataType: types.NewPrimitiveU8(0), + Owner: types.NewPrimitiveU32(0), + Region: types.NewPrimitiveU8(0), + Attribute1: types.NewPrimitiveU8(0), + Attribute2: types.NewPrimitiveU8(0), + Fighter: types.NewPrimitiveU8(0), + ResultRange: types.NewResultRange(), + } + + return dsssdp +} diff --git a/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_shared_data_info.go b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_shared_data_info.go new file mode 100644 index 0000000..4c0e7a9 --- /dev/null +++ b/nex-protocols-go/datastore/super-smash-bros-4/types/datastore_shared_data_info.go @@ -0,0 +1,210 @@ +// Package types implements all the types used by the DataStoreSuperSmashBros.4 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreSharedDataInfo is a type within the DataStoreSuperSmashBros.4 protocol +type DataStoreSharedDataInfo struct { + types.Structure + DataID *types.PrimitiveU64 + OwnerID *types.PrimitiveU32 + DataType *types.PrimitiveU8 + Comment *types.String + MetaBinary *types.QBuffer + Profile *types.QBuffer + Rating *types.PrimitiveS64 + CreatedTime *types.DateTime + Info *DataStoreFileServerObjectInfo +} + +// WriteTo writes the DataStoreSharedDataInfo to the given writable +func (dssdi *DataStoreSharedDataInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dssdi.DataID.WriteTo(contentWritable) + dssdi.OwnerID.WriteTo(contentWritable) + dssdi.DataType.WriteTo(contentWritable) + dssdi.Comment.WriteTo(contentWritable) + dssdi.MetaBinary.WriteTo(contentWritable) + dssdi.Profile.WriteTo(contentWritable) + dssdi.Rating.WriteTo(contentWritable) + dssdi.CreatedTime.WriteTo(contentWritable) + dssdi.Info.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dssdi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreSharedDataInfo from the given readable +func (dssdi *DataStoreSharedDataInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = dssdi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSharedDataInfo header. %s", err.Error()) + } + + err = dssdi.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSharedDataInfo.DataID. %s", err.Error()) + } + + err = dssdi.OwnerID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSharedDataInfo.OwnerID. %s", err.Error()) + } + + err = dssdi.DataType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSharedDataInfo.DataType. %s", err.Error()) + } + + err = dssdi.Comment.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSharedDataInfo.Comment. %s", err.Error()) + } + + err = dssdi.MetaBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSharedDataInfo.MetaBinary. %s", err.Error()) + } + + err = dssdi.Profile.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSharedDataInfo.Profile. %s", err.Error()) + } + + err = dssdi.Rating.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSharedDataInfo.Rating. %s", err.Error()) + } + + err = dssdi.CreatedTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSharedDataInfo.CreatedTime. %s", err.Error()) + } + + err = dssdi.Info.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSharedDataInfo.Info. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreSharedDataInfo +func (dssdi *DataStoreSharedDataInfo) Copy() types.RVType { + copied := NewDataStoreSharedDataInfo() + + copied.StructureVersion = dssdi.StructureVersion + copied.DataID = dssdi.DataID.Copy().(*types.PrimitiveU64) + copied.OwnerID = dssdi.OwnerID.Copy().(*types.PrimitiveU32) + copied.DataType = dssdi.DataType.Copy().(*types.PrimitiveU8) + copied.Comment = dssdi.Comment.Copy().(*types.String) + copied.MetaBinary = dssdi.MetaBinary.Copy().(*types.QBuffer) + copied.Profile = dssdi.Profile.Copy().(*types.QBuffer) + copied.Rating = dssdi.Rating.Copy().(*types.PrimitiveS64) + copied.CreatedTime = dssdi.CreatedTime.Copy().(*types.DateTime) + copied.Info = dssdi.Info.Copy().(*DataStoreFileServerObjectInfo) + + return copied +} + +// Equals checks if the given DataStoreSharedDataInfo contains the same data as the current DataStoreSharedDataInfo +func (dssdi *DataStoreSharedDataInfo) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreSharedDataInfo); !ok { + return false + } + + other := o.(*DataStoreSharedDataInfo) + + if dssdi.StructureVersion != other.StructureVersion { + return false + } + + if !dssdi.DataID.Equals(other.DataID) { + return false + } + + if !dssdi.OwnerID.Equals(other.OwnerID) { + return false + } + + if !dssdi.DataType.Equals(other.DataType) { + return false + } + + if !dssdi.Comment.Equals(other.Comment) { + return false + } + + if !dssdi.MetaBinary.Equals(other.MetaBinary) { + return false + } + + if !dssdi.Profile.Equals(other.Profile) { + return false + } + + if !dssdi.Rating.Equals(other.Rating) { + return false + } + + if !dssdi.CreatedTime.Equals(other.CreatedTime) { + return false + } + + return dssdi.Info.Equals(other.Info) +} + +// String returns the string representation of the DataStoreSharedDataInfo +func (dssdi *DataStoreSharedDataInfo) String() string { + return dssdi.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreSharedDataInfo using the provided indentation level +func (dssdi *DataStoreSharedDataInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreSharedDataInfo{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dssdi.DataID)) + b.WriteString(fmt.Sprintf("%sOwnerID: %s,\n", indentationValues, dssdi.OwnerID)) + b.WriteString(fmt.Sprintf("%sDataType: %s,\n", indentationValues, dssdi.DataType)) + b.WriteString(fmt.Sprintf("%sComment: %s,\n", indentationValues, dssdi.Comment)) + b.WriteString(fmt.Sprintf("%sMetaBinary: %s,\n", indentationValues, dssdi.MetaBinary)) + b.WriteString(fmt.Sprintf("%sProfile: %s,\n", indentationValues, dssdi.Profile)) + b.WriteString(fmt.Sprintf("%sRating: %s,\n", indentationValues, dssdi.Rating)) + b.WriteString(fmt.Sprintf("%sCreatedTime: %s,\n", indentationValues, dssdi.CreatedTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sInfo: %s,\n", indentationValues, dssdi.Info.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreSharedDataInfo returns a new DataStoreSharedDataInfo +func NewDataStoreSharedDataInfo() *DataStoreSharedDataInfo { + dssdi := &DataStoreSharedDataInfo{ + DataID: types.NewPrimitiveU64(0), + OwnerID: types.NewPrimitiveU32(0), + DataType: types.NewPrimitiveU8(0), + Comment: types.NewString(""), + MetaBinary: types.NewQBuffer(nil), + Profile: types.NewQBuffer(nil), + Rating: types.NewPrimitiveS64(0), + CreatedTime: types.NewDateTime(0), + Info: NewDataStoreFileServerObjectInfo(), + } + + return dssdi +} diff --git a/nex-protocols-go/datastore/touch_object.go b/nex-protocols-go/datastore/touch_object.go new file mode 100644 index 0000000..49037b9 --- /dev/null +++ b/nex-protocols-go/datastore/touch_object.go @@ -0,0 +1,47 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + datastore_types "github.com/PretendoNetwork/nex-protocols-go/v2/datastore/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleTouchObject(packet nex.PacketInterface) { + if protocol.TouchObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::TouchObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := datastore_types.NewDataStoreTouchObjectParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.TouchObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.TouchObject(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/datastore/types/datastore_change_meta_compare_param.go b/nex-protocols-go/datastore/types/datastore_change_meta_compare_param.go new file mode 100644 index 0000000..6b2db11 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_change_meta_compare_param.go @@ -0,0 +1,226 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreChangeMetaCompareParam is a type within the DataStore protocol +type DataStoreChangeMetaCompareParam struct { + types.Structure + ComparisonFlag *types.PrimitiveU32 + Name *types.String + Permission *DataStorePermission + DelPermission *DataStorePermission + Period *types.PrimitiveU16 + MetaBinary *types.QBuffer + Tags *types.List[*types.String] + ReferredCnt *types.PrimitiveU32 + DataType *types.PrimitiveU16 + Status *types.PrimitiveU8 +} + +// WriteTo writes the DataStoreChangeMetaCompareParam to the given writable +func (dscmcp *DataStoreChangeMetaCompareParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dscmcp.ComparisonFlag.WriteTo(contentWritable) + dscmcp.Name.WriteTo(contentWritable) + dscmcp.Permission.WriteTo(contentWritable) + dscmcp.DelPermission.WriteTo(contentWritable) + dscmcp.Period.WriteTo(contentWritable) + dscmcp.MetaBinary.WriteTo(contentWritable) + dscmcp.Tags.WriteTo(contentWritable) + dscmcp.ReferredCnt.WriteTo(contentWritable) + dscmcp.DataType.WriteTo(contentWritable) + dscmcp.Status.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dscmcp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreChangeMetaCompareParam from the given readable +func (dscmcp *DataStoreChangeMetaCompareParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dscmcp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaCompareParam header. %s", err.Error()) + } + + err = dscmcp.ComparisonFlag.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaCompareParam.ComparisonFlag. %s", err.Error()) + } + + err = dscmcp.Name.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaCompareParam.Name. %s", err.Error()) + } + + err = dscmcp.Permission.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaCompareParam.Permission. %s", err.Error()) + } + + err = dscmcp.DelPermission.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaCompareParam.DelPermission. %s", err.Error()) + } + + err = dscmcp.Period.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaCompareParam.Period. %s", err.Error()) + } + + err = dscmcp.MetaBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaCompareParam.MetaBinary. %s", err.Error()) + } + + err = dscmcp.Tags.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaCompareParam.Tags. %s", err.Error()) + } + + err = dscmcp.ReferredCnt.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaCompareParam.ReferredCnt. %s", err.Error()) + } + + err = dscmcp.DataType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaCompareParam.DataType. %s", err.Error()) + } + + err = dscmcp.Status.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaCompareParam.Status. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreChangeMetaCompareParam +func (dscmcp *DataStoreChangeMetaCompareParam) Copy() types.RVType { + copied := NewDataStoreChangeMetaCompareParam() + + copied.StructureVersion = dscmcp.StructureVersion + copied.ComparisonFlag = dscmcp.ComparisonFlag.Copy().(*types.PrimitiveU32) + copied.Name = dscmcp.Name.Copy().(*types.String) + copied.Permission = dscmcp.Permission.Copy().(*DataStorePermission) + copied.DelPermission = dscmcp.DelPermission.Copy().(*DataStorePermission) + copied.Period = dscmcp.Period.Copy().(*types.PrimitiveU16) + copied.MetaBinary = dscmcp.MetaBinary.Copy().(*types.QBuffer) + copied.Tags = dscmcp.Tags.Copy().(*types.List[*types.String]) + copied.ReferredCnt = dscmcp.ReferredCnt.Copy().(*types.PrimitiveU32) + copied.DataType = dscmcp.DataType.Copy().(*types.PrimitiveU16) + copied.Status = dscmcp.Status.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given DataStoreChangeMetaCompareParam contains the same data as the current DataStoreChangeMetaCompareParam +func (dscmcp *DataStoreChangeMetaCompareParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreChangeMetaCompareParam); !ok { + return false + } + + other := o.(*DataStoreChangeMetaCompareParam) + + if dscmcp.StructureVersion != other.StructureVersion { + return false + } + + if !dscmcp.ComparisonFlag.Equals(other.ComparisonFlag) { + return false + } + + if !dscmcp.Name.Equals(other.Name) { + return false + } + + if !dscmcp.Permission.Equals(other.Permission) { + return false + } + + if !dscmcp.DelPermission.Equals(other.DelPermission) { + return false + } + + if !dscmcp.Period.Equals(other.Period) { + return false + } + + if !dscmcp.MetaBinary.Equals(other.MetaBinary) { + return false + } + + if !dscmcp.Tags.Equals(other.Tags) { + return false + } + + if !dscmcp.ReferredCnt.Equals(other.ReferredCnt) { + return false + } + + if !dscmcp.DataType.Equals(other.DataType) { + return false + } + + return dscmcp.Status.Equals(other.Status) +} + +// String returns the string representation of the DataStoreChangeMetaCompareParam +func (dscmcp *DataStoreChangeMetaCompareParam) String() string { + return dscmcp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreChangeMetaCompareParam using the provided indentation level +func (dscmcp *DataStoreChangeMetaCompareParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreChangeMetaCompareParam{\n") + b.WriteString(fmt.Sprintf("%sComparisonFlag: %s,\n", indentationValues, dscmcp.ComparisonFlag)) + b.WriteString(fmt.Sprintf("%sName: %s,\n", indentationValues, dscmcp.Name)) + b.WriteString(fmt.Sprintf("%sPermission: %s,\n", indentationValues, dscmcp.Permission.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sDelPermission: %s,\n", indentationValues, dscmcp.DelPermission.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPeriod: %s,\n", indentationValues, dscmcp.Period)) + b.WriteString(fmt.Sprintf("%sMetaBinary: %s,\n", indentationValues, dscmcp.MetaBinary)) + b.WriteString(fmt.Sprintf("%sTags: %s,\n", indentationValues, dscmcp.Tags)) + b.WriteString(fmt.Sprintf("%sReferredCnt: %s,\n", indentationValues, dscmcp.ReferredCnt)) + b.WriteString(fmt.Sprintf("%sDataType: %s,\n", indentationValues, dscmcp.DataType)) + b.WriteString(fmt.Sprintf("%sStatus: %s,\n", indentationValues, dscmcp.Status)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreChangeMetaCompareParam returns a new DataStoreChangeMetaCompareParam +func NewDataStoreChangeMetaCompareParam() *DataStoreChangeMetaCompareParam { + dscmcp := &DataStoreChangeMetaCompareParam{ + ComparisonFlag: types.NewPrimitiveU32(0), + Name: types.NewString(""), + Permission: NewDataStorePermission(), + DelPermission: NewDataStorePermission(), + Period: types.NewPrimitiveU16(0), + MetaBinary: types.NewQBuffer(nil), + Tags: types.NewList[*types.String](), + ReferredCnt: types.NewPrimitiveU32(0), + DataType: types.NewPrimitiveU16(0), + Status: types.NewPrimitiveU8(0), + } + + dscmcp.Tags.Type = types.NewString("") + + return dscmcp +} diff --git a/nex-protocols-go/datastore/types/datastore_change_meta_param.go b/nex-protocols-go/datastore/types/datastore_change_meta_param.go new file mode 100644 index 0000000..cac10c0 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_change_meta_param.go @@ -0,0 +1,282 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreChangeMetaParam is a type within the DataStore protocol +type DataStoreChangeMetaParam struct { + types.Structure + DataID *types.PrimitiveU64 + ModifiesFlag *types.PrimitiveU32 + Name *types.String + Permission *DataStorePermission + DelPermission *DataStorePermission + Period *types.PrimitiveU16 + MetaBinary *types.QBuffer + Tags *types.List[*types.String] + UpdatePassword *types.PrimitiveU64 + ReferredCnt *types.PrimitiveU32 + DataType *types.PrimitiveU16 + Status *types.PrimitiveU8 + CompareParam *DataStoreChangeMetaCompareParam + PersistenceTarget *DataStorePersistenceTarget +} + +// WriteTo writes the DataStoreChangeMetaParam to the given writable +func (dscmp *DataStoreChangeMetaParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dscmp.DataID.WriteTo(contentWritable) + dscmp.ModifiesFlag.WriteTo(contentWritable) + dscmp.Name.WriteTo(contentWritable) + dscmp.Permission.WriteTo(contentWritable) + dscmp.DelPermission.WriteTo(contentWritable) + dscmp.Period.WriteTo(contentWritable) + dscmp.MetaBinary.WriteTo(contentWritable) + dscmp.Tags.WriteTo(contentWritable) + dscmp.UpdatePassword.WriteTo(contentWritable) + dscmp.ReferredCnt.WriteTo(contentWritable) + dscmp.DataType.WriteTo(contentWritable) + dscmp.Status.WriteTo(contentWritable) + dscmp.CompareParam.WriteTo(contentWritable) + dscmp.PersistenceTarget.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dscmp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreChangeMetaParam from the given readable +func (dscmp *DataStoreChangeMetaParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dscmp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParam header. %s", err.Error()) + } + + err = dscmp.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParam.DataID. %s", err.Error()) + } + + err = dscmp.ModifiesFlag.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParam.ModifiesFlag. %s", err.Error()) + } + + err = dscmp.Name.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParam.Name. %s", err.Error()) + } + + err = dscmp.Permission.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParam.Permission. %s", err.Error()) + } + + err = dscmp.DelPermission.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParam.DelPermission. %s", err.Error()) + } + + err = dscmp.Period.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParam.Period. %s", err.Error()) + } + + err = dscmp.MetaBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParam.MetaBinary. %s", err.Error()) + } + + err = dscmp.Tags.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParam.Tags. %s", err.Error()) + } + + err = dscmp.UpdatePassword.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParam.UpdatePassword. %s", err.Error()) + } + + err = dscmp.ReferredCnt.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParam.ReferredCnt. %s", err.Error()) + } + + err = dscmp.DataType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParam.DataType. %s", err.Error()) + } + + err = dscmp.Status.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParam.Status. %s", err.Error()) + } + + err = dscmp.CompareParam.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParam.CompareParam. %s", err.Error()) + } + + err = dscmp.PersistenceTarget.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParam.PersistenceTarget. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreChangeMetaParam +func (dscmp *DataStoreChangeMetaParam) Copy() types.RVType { + copied := NewDataStoreChangeMetaParam() + + copied.StructureVersion = dscmp.StructureVersion + copied.DataID = dscmp.DataID.Copy().(*types.PrimitiveU64) + copied.ModifiesFlag = dscmp.ModifiesFlag.Copy().(*types.PrimitiveU32) + copied.Name = dscmp.Name.Copy().(*types.String) + copied.Permission = dscmp.Permission.Copy().(*DataStorePermission) + copied.DelPermission = dscmp.DelPermission.Copy().(*DataStorePermission) + copied.Period = dscmp.Period.Copy().(*types.PrimitiveU16) + copied.MetaBinary = dscmp.MetaBinary.Copy().(*types.QBuffer) + copied.Tags = dscmp.Tags.Copy().(*types.List[*types.String]) + copied.UpdatePassword = dscmp.UpdatePassword.Copy().(*types.PrimitiveU64) + copied.ReferredCnt = dscmp.ReferredCnt.Copy().(*types.PrimitiveU32) + copied.DataType = dscmp.DataType.Copy().(*types.PrimitiveU16) + copied.Status = dscmp.Status.Copy().(*types.PrimitiveU8) + copied.CompareParam = dscmp.CompareParam.Copy().(*DataStoreChangeMetaCompareParam) + copied.PersistenceTarget = dscmp.PersistenceTarget.Copy().(*DataStorePersistenceTarget) + + return copied +} + +// Equals checks if the given DataStoreChangeMetaParam contains the same data as the current DataStoreChangeMetaParam +func (dscmp *DataStoreChangeMetaParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreChangeMetaParam); !ok { + return false + } + + other := o.(*DataStoreChangeMetaParam) + + if dscmp.StructureVersion != other.StructureVersion { + return false + } + + if !dscmp.DataID.Equals(other.DataID) { + return false + } + + if !dscmp.ModifiesFlag.Equals(other.ModifiesFlag) { + return false + } + + if !dscmp.Name.Equals(other.Name) { + return false + } + + if !dscmp.Permission.Equals(other.Permission) { + return false + } + + if !dscmp.DelPermission.Equals(other.DelPermission) { + return false + } + + if !dscmp.Period.Equals(other.Period) { + return false + } + + if !dscmp.MetaBinary.Equals(other.MetaBinary) { + return false + } + + if !dscmp.Tags.Equals(other.Tags) { + return false + } + + if !dscmp.UpdatePassword.Equals(other.UpdatePassword) { + return false + } + + if !dscmp.ReferredCnt.Equals(other.ReferredCnt) { + return false + } + + if !dscmp.DataType.Equals(other.DataType) { + return false + } + + if !dscmp.Status.Equals(other.Status) { + return false + } + + if !dscmp.CompareParam.Equals(other.CompareParam) { + return false + } + + return dscmp.PersistenceTarget.Equals(other.PersistenceTarget) +} + +// String returns the string representation of the DataStoreChangeMetaParam +func (dscmp *DataStoreChangeMetaParam) String() string { + return dscmp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreChangeMetaParam using the provided indentation level +func (dscmp *DataStoreChangeMetaParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreChangeMetaParam{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dscmp.DataID)) + b.WriteString(fmt.Sprintf("%sModifiesFlag: %s,\n", indentationValues, dscmp.ModifiesFlag)) + b.WriteString(fmt.Sprintf("%sName: %s,\n", indentationValues, dscmp.Name)) + b.WriteString(fmt.Sprintf("%sPermission: %s,\n", indentationValues, dscmp.Permission.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sDelPermission: %s,\n", indentationValues, dscmp.DelPermission.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPeriod: %s,\n", indentationValues, dscmp.Period)) + b.WriteString(fmt.Sprintf("%sMetaBinary: %s,\n", indentationValues, dscmp.MetaBinary)) + b.WriteString(fmt.Sprintf("%sTags: %s,\n", indentationValues, dscmp.Tags)) + b.WriteString(fmt.Sprintf("%sUpdatePassword: %s,\n", indentationValues, dscmp.UpdatePassword)) + b.WriteString(fmt.Sprintf("%sReferredCnt: %s,\n", indentationValues, dscmp.ReferredCnt)) + b.WriteString(fmt.Sprintf("%sDataType: %s,\n", indentationValues, dscmp.DataType)) + b.WriteString(fmt.Sprintf("%sStatus: %s,\n", indentationValues, dscmp.Status)) + b.WriteString(fmt.Sprintf("%sCompareParam: %s,\n", indentationValues, dscmp.CompareParam.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPersistenceTarget: %s,\n", indentationValues, dscmp.PersistenceTarget.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreChangeMetaParam returns a new DataStoreChangeMetaParam +func NewDataStoreChangeMetaParam() *DataStoreChangeMetaParam { + dscmp := &DataStoreChangeMetaParam{ + DataID: types.NewPrimitiveU64(0), + ModifiesFlag: types.NewPrimitiveU32(0), + Name: types.NewString(""), + Permission: NewDataStorePermission(), + DelPermission: NewDataStorePermission(), + Period: types.NewPrimitiveU16(0), + MetaBinary: types.NewQBuffer(nil), + Tags: types.NewList[*types.String](), + UpdatePassword: types.NewPrimitiveU64(0), + ReferredCnt: types.NewPrimitiveU32(0), + DataType: types.NewPrimitiveU16(0), + Status: types.NewPrimitiveU8(0), + CompareParam: NewDataStoreChangeMetaCompareParam(), + PersistenceTarget: NewDataStorePersistenceTarget(), + } + + dscmp.Tags.Type = types.NewString("") + + return dscmp +} diff --git a/nex-protocols-go/datastore/types/datastore_change_meta_param_v1.go b/nex-protocols-go/datastore/types/datastore_change_meta_param_v1.go new file mode 100644 index 0000000..05777ba --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_change_meta_param_v1.go @@ -0,0 +1,212 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreChangeMetaParamV1 is a type within the DataStore protocol +type DataStoreChangeMetaParamV1 struct { + types.Structure + DataID *types.PrimitiveU64 + ModifiesFlag *types.PrimitiveU32 + Name *types.String + Permission *DataStorePermission + DelPermission *DataStorePermission + Period *types.PrimitiveU16 + MetaBinary *types.QBuffer + Tags *types.List[*types.String] + UpdatePassword *types.PrimitiveU64 +} + +// WriteTo writes the DataStoreChangeMetaParamV1 to the given writable +func (dscmpv *DataStoreChangeMetaParamV1) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dscmpv.DataID.WriteTo(contentWritable) + dscmpv.ModifiesFlag.WriteTo(contentWritable) + dscmpv.Name.WriteTo(contentWritable) + dscmpv.Permission.WriteTo(contentWritable) + dscmpv.DelPermission.WriteTo(contentWritable) + dscmpv.Period.WriteTo(contentWritable) + dscmpv.MetaBinary.WriteTo(contentWritable) + dscmpv.Tags.WriteTo(contentWritable) + dscmpv.UpdatePassword.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dscmpv.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreChangeMetaParamV1 from the given readable +func (dscmpv *DataStoreChangeMetaParamV1) ExtractFrom(readable types.Readable) error { + var err error + + err = dscmpv.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParamV1 header. %s", err.Error()) + } + + err = dscmpv.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParamV1.DataID. %s", err.Error()) + } + + err = dscmpv.ModifiesFlag.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParamV1.ModifiesFlag. %s", err.Error()) + } + + err = dscmpv.Name.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParamV1.Name. %s", err.Error()) + } + + err = dscmpv.Permission.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParamV1.Permission. %s", err.Error()) + } + + err = dscmpv.DelPermission.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParamV1.DelPermission. %s", err.Error()) + } + + err = dscmpv.Period.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParamV1.Period. %s", err.Error()) + } + + err = dscmpv.MetaBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParamV1.MetaBinary. %s", err.Error()) + } + + err = dscmpv.Tags.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParamV1.Tags. %s", err.Error()) + } + + err = dscmpv.UpdatePassword.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreChangeMetaParamV1.UpdatePassword. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreChangeMetaParamV1 +func (dscmpv *DataStoreChangeMetaParamV1) Copy() types.RVType { + copied := NewDataStoreChangeMetaParamV1() + + copied.StructureVersion = dscmpv.StructureVersion + copied.DataID = dscmpv.DataID.Copy().(*types.PrimitiveU64) + copied.ModifiesFlag = dscmpv.ModifiesFlag.Copy().(*types.PrimitiveU32) + copied.Name = dscmpv.Name.Copy().(*types.String) + copied.Permission = dscmpv.Permission.Copy().(*DataStorePermission) + copied.DelPermission = dscmpv.DelPermission.Copy().(*DataStorePermission) + copied.Period = dscmpv.Period.Copy().(*types.PrimitiveU16) + copied.MetaBinary = dscmpv.MetaBinary.Copy().(*types.QBuffer) + copied.Tags = dscmpv.Tags.Copy().(*types.List[*types.String]) + copied.UpdatePassword = dscmpv.UpdatePassword.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given DataStoreChangeMetaParamV1 contains the same data as the current DataStoreChangeMetaParamV1 +func (dscmpv *DataStoreChangeMetaParamV1) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreChangeMetaParamV1); !ok { + return false + } + + other := o.(*DataStoreChangeMetaParamV1) + + if dscmpv.StructureVersion != other.StructureVersion { + return false + } + + if !dscmpv.DataID.Equals(other.DataID) { + return false + } + + if !dscmpv.ModifiesFlag.Equals(other.ModifiesFlag) { + return false + } + + if !dscmpv.Name.Equals(other.Name) { + return false + } + + if !dscmpv.Permission.Equals(other.Permission) { + return false + } + + if !dscmpv.DelPermission.Equals(other.DelPermission) { + return false + } + + if !dscmpv.Period.Equals(other.Period) { + return false + } + + if !dscmpv.MetaBinary.Equals(other.MetaBinary) { + return false + } + + if !dscmpv.Tags.Equals(other.Tags) { + return false + } + + return dscmpv.UpdatePassword.Equals(other.UpdatePassword) +} + +// String returns the string representation of the DataStoreChangeMetaParamV1 +func (dscmpv *DataStoreChangeMetaParamV1) String() string { + return dscmpv.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreChangeMetaParamV1 using the provided indentation level +func (dscmpv *DataStoreChangeMetaParamV1) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreChangeMetaParamV1{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dscmpv.DataID)) + b.WriteString(fmt.Sprintf("%sModifiesFlag: %s,\n", indentationValues, dscmpv.ModifiesFlag)) + b.WriteString(fmt.Sprintf("%sName: %s,\n", indentationValues, dscmpv.Name)) + b.WriteString(fmt.Sprintf("%sPermission: %s,\n", indentationValues, dscmpv.Permission.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sDelPermission: %s,\n", indentationValues, dscmpv.DelPermission.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPeriod: %s,\n", indentationValues, dscmpv.Period)) + b.WriteString(fmt.Sprintf("%sMetaBinary: %s,\n", indentationValues, dscmpv.MetaBinary)) + b.WriteString(fmt.Sprintf("%sTags: %s,\n", indentationValues, dscmpv.Tags)) + b.WriteString(fmt.Sprintf("%sUpdatePassword: %s,\n", indentationValues, dscmpv.UpdatePassword)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreChangeMetaParamV1 returns a new DataStoreChangeMetaParamV1 +func NewDataStoreChangeMetaParamV1() *DataStoreChangeMetaParamV1 { + dscmpv := &DataStoreChangeMetaParamV1{ + DataID: types.NewPrimitiveU64(0), + ModifiesFlag: types.NewPrimitiveU32(0), + Name: types.NewString(""), + Permission: NewDataStorePermission(), + DelPermission: NewDataStorePermission(), + Period: types.NewPrimitiveU16(0), + MetaBinary: types.NewQBuffer(nil), + Tags: types.NewList[*types.String](), + UpdatePassword: types.NewPrimitiveU64(0), + } + + dscmpv.Tags.Type = types.NewString("") + + return dscmpv +} diff --git a/nex-protocols-go/datastore/types/datastore_complete_post_param.go b/nex-protocols-go/datastore/types/datastore_complete_post_param.go new file mode 100644 index 0000000..d8fbc9c --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_complete_post_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreCompletePostParam is a type within the DataStore protocol +type DataStoreCompletePostParam struct { + types.Structure + DataID *types.PrimitiveU64 + IsSuccess *types.PrimitiveBool +} + +// WriteTo writes the DataStoreCompletePostParam to the given writable +func (dscpp *DataStoreCompletePostParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dscpp.DataID.WriteTo(contentWritable) + dscpp.IsSuccess.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dscpp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreCompletePostParam from the given readable +func (dscpp *DataStoreCompletePostParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dscpp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompletePostParam header. %s", err.Error()) + } + + err = dscpp.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompletePostParam.DataID. %s", err.Error()) + } + + err = dscpp.IsSuccess.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompletePostParam.IsSuccess. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreCompletePostParam +func (dscpp *DataStoreCompletePostParam) Copy() types.RVType { + copied := NewDataStoreCompletePostParam() + + copied.StructureVersion = dscpp.StructureVersion + copied.DataID = dscpp.DataID.Copy().(*types.PrimitiveU64) + copied.IsSuccess = dscpp.IsSuccess.Copy().(*types.PrimitiveBool) + + return copied +} + +// Equals checks if the given DataStoreCompletePostParam contains the same data as the current DataStoreCompletePostParam +func (dscpp *DataStoreCompletePostParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreCompletePostParam); !ok { + return false + } + + other := o.(*DataStoreCompletePostParam) + + if dscpp.StructureVersion != other.StructureVersion { + return false + } + + if !dscpp.DataID.Equals(other.DataID) { + return false + } + + return dscpp.IsSuccess.Equals(other.IsSuccess) +} + +// String returns the string representation of the DataStoreCompletePostParam +func (dscpp *DataStoreCompletePostParam) String() string { + return dscpp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreCompletePostParam using the provided indentation level +func (dscpp *DataStoreCompletePostParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreCompletePostParam{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dscpp.DataID)) + b.WriteString(fmt.Sprintf("%sIsSuccess: %s,\n", indentationValues, dscpp.IsSuccess)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreCompletePostParam returns a new DataStoreCompletePostParam +func NewDataStoreCompletePostParam() *DataStoreCompletePostParam { + dscpp := &DataStoreCompletePostParam{ + DataID: types.NewPrimitiveU64(0), + IsSuccess: types.NewPrimitiveBool(false), + } + + return dscpp +} diff --git a/nex-protocols-go/datastore/types/datastore_complete_post_param_v1.go b/nex-protocols-go/datastore/types/datastore_complete_post_param_v1.go new file mode 100644 index 0000000..dd3c942 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_complete_post_param_v1.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreCompletePostParamV1 is a type within the DataStore protocol +type DataStoreCompletePostParamV1 struct { + types.Structure + DataID *types.PrimitiveU32 + IsSuccess *types.PrimitiveBool +} + +// WriteTo writes the DataStoreCompletePostParamV1 to the given writable +func (dscppv *DataStoreCompletePostParamV1) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dscppv.DataID.WriteTo(contentWritable) + dscppv.IsSuccess.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dscppv.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreCompletePostParamV1 from the given readable +func (dscppv *DataStoreCompletePostParamV1) ExtractFrom(readable types.Readable) error { + var err error + + err = dscppv.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompletePostParamV1 header. %s", err.Error()) + } + + err = dscppv.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompletePostParamV1.DataID. %s", err.Error()) + } + + err = dscppv.IsSuccess.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompletePostParamV1.IsSuccess. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreCompletePostParamV1 +func (dscppv *DataStoreCompletePostParamV1) Copy() types.RVType { + copied := NewDataStoreCompletePostParamV1() + + copied.StructureVersion = dscppv.StructureVersion + copied.DataID = dscppv.DataID.Copy().(*types.PrimitiveU32) + copied.IsSuccess = dscppv.IsSuccess.Copy().(*types.PrimitiveBool) + + return copied +} + +// Equals checks if the given DataStoreCompletePostParamV1 contains the same data as the current DataStoreCompletePostParamV1 +func (dscppv *DataStoreCompletePostParamV1) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreCompletePostParamV1); !ok { + return false + } + + other := o.(*DataStoreCompletePostParamV1) + + if dscppv.StructureVersion != other.StructureVersion { + return false + } + + if !dscppv.DataID.Equals(other.DataID) { + return false + } + + return dscppv.IsSuccess.Equals(other.IsSuccess) +} + +// String returns the string representation of the DataStoreCompletePostParamV1 +func (dscppv *DataStoreCompletePostParamV1) String() string { + return dscppv.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreCompletePostParamV1 using the provided indentation level +func (dscppv *DataStoreCompletePostParamV1) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreCompletePostParamV1{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dscppv.DataID)) + b.WriteString(fmt.Sprintf("%sIsSuccess: %s,\n", indentationValues, dscppv.IsSuccess)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreCompletePostParamV1 returns a new DataStoreCompletePostParamV1 +func NewDataStoreCompletePostParamV1() *DataStoreCompletePostParamV1 { + dscppv := &DataStoreCompletePostParamV1{ + DataID: types.NewPrimitiveU32(0), + IsSuccess: types.NewPrimitiveBool(false), + } + + return dscppv +} diff --git a/nex-protocols-go/datastore/types/datastore_complete_update_param.go b/nex-protocols-go/datastore/types/datastore_complete_update_param.go new file mode 100644 index 0000000..31b1edc --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_complete_update_param.go @@ -0,0 +1,161 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreCompleteUpdateParam is a type within the DataStore protocol +type DataStoreCompleteUpdateParam struct { + types.Structure + DataID *types.PrimitiveU64 + Version *types.PrimitiveU32 + IsSuccess *types.PrimitiveBool +} + +// WriteTo writes the DataStoreCompleteUpdateParam to the given writable +func (dscup *DataStoreCompleteUpdateParam) WriteTo(writable types.Writable) { + stream := writable.(*nex.ByteStreamOut) + libraryVersion := stream.LibraryVersions.DataStore + + contentWritable := writable.CopyNew() + + if libraryVersion.GreaterOrEqual("3.0.0") { + dscup.DataID.WriteTo(contentWritable) + } else { + contentWritable.WritePrimitiveUInt32LE(uint32(dscup.DataID.Value)) + } + + if libraryVersion.GreaterOrEqual("3.0.0") { + dscup.Version.WriteTo(contentWritable) + } else { + contentWritable.WritePrimitiveUInt16LE(uint16(dscup.Version.Value)) + } + + dscup.IsSuccess.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dscup.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreCompleteUpdateParam from the given readable +func (dscup *DataStoreCompleteUpdateParam) ExtractFrom(readable types.Readable) error { + stream := readable.(*nex.ByteStreamIn) + libraryVersion := stream.LibraryVersions.DataStore + + var err error + + err = dscup.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompleteUpdateParam header. %s", err.Error()) + } + + if libraryVersion.GreaterOrEqual("3.0.0") { + err = dscup.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompleteUpdateParam.DataID. %s", err.Error()) + } + } else { + dataID, err := readable.ReadPrimitiveUInt32LE() + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompleteUpdateParam.DataID. %s", err.Error()) + } + + dscup.DataID.Value = uint64(dataID) + } + + if libraryVersion.GreaterOrEqual("3.0.0") { + err = dscup.Version.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompleteUpdateParam.Version. %s", err.Error()) + } + } else { + version, err := readable.ReadPrimitiveUInt16LE() + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompleteUpdateParam.Version. %s", err.Error()) + } + + dscup.Version.Value = uint32(version) + } + + err = dscup.IsSuccess.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompleteUpdateParam.IsSuccess. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreCompleteUpdateParam +func (dscup *DataStoreCompleteUpdateParam) Copy() types.RVType { + copied := NewDataStoreCompleteUpdateParam() + + copied.StructureVersion = dscup.StructureVersion + copied.DataID = dscup.DataID.Copy().(*types.PrimitiveU64) + copied.Version = dscup.Version.Copy().(*types.PrimitiveU32) + copied.IsSuccess = dscup.IsSuccess.Copy().(*types.PrimitiveBool) + + return copied +} + +// Equals checks if the given DataStoreCompleteUpdateParam contains the same data as the current DataStoreCompleteUpdateParam +func (dscup *DataStoreCompleteUpdateParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreCompleteUpdateParam); !ok { + return false + } + + other := o.(*DataStoreCompleteUpdateParam) + + if dscup.StructureVersion != other.StructureVersion { + return false + } + + if !dscup.DataID.Equals(other.DataID) { + return false + } + + if !dscup.Version.Equals(other.Version) { + return false + } + + return dscup.IsSuccess.Equals(other.IsSuccess) +} + +// String returns the string representation of the DataStoreCompleteUpdateParam +func (dscup *DataStoreCompleteUpdateParam) String() string { + return dscup.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreCompleteUpdateParam using the provided indentation level +func (dscup *DataStoreCompleteUpdateParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreCompleteUpdateParam{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dscup.DataID)) + b.WriteString(fmt.Sprintf("%sVersion: %s,\n", indentationValues, dscup.Version)) + b.WriteString(fmt.Sprintf("%sIsSuccess: %s,\n", indentationValues, dscup.IsSuccess)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreCompleteUpdateParam returns a new DataStoreCompleteUpdateParam +func NewDataStoreCompleteUpdateParam() *DataStoreCompleteUpdateParam { + dscup := &DataStoreCompleteUpdateParam{ + DataID: types.NewPrimitiveU64(0), + Version: types.NewPrimitiveU32(0), + IsSuccess: types.NewPrimitiveBool(false), + } + + return dscup +} diff --git a/nex-protocols-go/datastore/types/datastore_delete_param.go b/nex-protocols-go/datastore/types/datastore_delete_param.go new file mode 100644 index 0000000..def3550 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_delete_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreDeleteParam is a type within the DataStore protocol +type DataStoreDeleteParam struct { + types.Structure + DataID *types.PrimitiveU64 + UpdatePassword *types.PrimitiveU64 +} + +// WriteTo writes the DataStoreDeleteParam to the given writable +func (dsdp *DataStoreDeleteParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsdp.DataID.WriteTo(contentWritable) + dsdp.UpdatePassword.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsdp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreDeleteParam from the given readable +func (dsdp *DataStoreDeleteParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsdp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreDeleteParam header. %s", err.Error()) + } + + err = dsdp.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreDeleteParam.DataID. %s", err.Error()) + } + + err = dsdp.UpdatePassword.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreDeleteParam.UpdatePassword. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreDeleteParam +func (dsdp *DataStoreDeleteParam) Copy() types.RVType { + copied := NewDataStoreDeleteParam() + + copied.StructureVersion = dsdp.StructureVersion + copied.DataID = dsdp.DataID.Copy().(*types.PrimitiveU64) + copied.UpdatePassword = dsdp.UpdatePassword.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given DataStoreDeleteParam contains the same data as the current DataStoreDeleteParam +func (dsdp *DataStoreDeleteParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreDeleteParam); !ok { + return false + } + + other := o.(*DataStoreDeleteParam) + + if dsdp.StructureVersion != other.StructureVersion { + return false + } + + if !dsdp.DataID.Equals(other.DataID) { + return false + } + + return dsdp.UpdatePassword.Equals(other.UpdatePassword) +} + +// String returns the string representation of the DataStoreDeleteParam +func (dsdp *DataStoreDeleteParam) String() string { + return dsdp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreDeleteParam using the provided indentation level +func (dsdp *DataStoreDeleteParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreDeleteParam{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dsdp.DataID)) + b.WriteString(fmt.Sprintf("%sUpdatePassword: %s,\n", indentationValues, dsdp.UpdatePassword)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreDeleteParam returns a new DataStoreDeleteParam +func NewDataStoreDeleteParam() *DataStoreDeleteParam { + dsdp := &DataStoreDeleteParam{ + DataID: types.NewPrimitiveU64(0), + UpdatePassword: types.NewPrimitiveU64(0), + } + + return dsdp +} diff --git a/nex-protocols-go/datastore/types/datastore_get_meta_param.go b/nex-protocols-go/datastore/types/datastore_get_meta_param.go new file mode 100644 index 0000000..31b9fa5 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_get_meta_param.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreGetMetaParam is a type within the DataStore protocol +type DataStoreGetMetaParam struct { + types.Structure + DataID *types.PrimitiveU64 + PersistenceTarget *DataStorePersistenceTarget + ResultOption *types.PrimitiveU8 + AccessPassword *types.PrimitiveU64 +} + +// WriteTo writes the DataStoreGetMetaParam to the given writable +func (dsgmp *DataStoreGetMetaParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsgmp.DataID.WriteTo(contentWritable) + dsgmp.PersistenceTarget.WriteTo(contentWritable) + dsgmp.ResultOption.WriteTo(contentWritable) + dsgmp.AccessPassword.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsgmp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreGetMetaParam from the given readable +func (dsgmp *DataStoreGetMetaParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsgmp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetMetaParam header. %s", err.Error()) + } + + err = dsgmp.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetMetaParam.DataID. %s", err.Error()) + } + + err = dsgmp.PersistenceTarget.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetMetaParam.PersistenceTarget. %s", err.Error()) + } + + err = dsgmp.ResultOption.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetMetaParam.ResultOption. %s", err.Error()) + } + + err = dsgmp.AccessPassword.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetMetaParam.AccessPassword. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreGetMetaParam +func (dsgmp *DataStoreGetMetaParam) Copy() types.RVType { + copied := NewDataStoreGetMetaParam() + + copied.StructureVersion = dsgmp.StructureVersion + copied.DataID = dsgmp.DataID.Copy().(*types.PrimitiveU64) + copied.PersistenceTarget = dsgmp.PersistenceTarget.Copy().(*DataStorePersistenceTarget) + copied.ResultOption = dsgmp.ResultOption.Copy().(*types.PrimitiveU8) + copied.AccessPassword = dsgmp.AccessPassword.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given DataStoreGetMetaParam contains the same data as the current DataStoreGetMetaParam +func (dsgmp *DataStoreGetMetaParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreGetMetaParam); !ok { + return false + } + + other := o.(*DataStoreGetMetaParam) + + if dsgmp.StructureVersion != other.StructureVersion { + return false + } + + if !dsgmp.DataID.Equals(other.DataID) { + return false + } + + if !dsgmp.PersistenceTarget.Equals(other.PersistenceTarget) { + return false + } + + if !dsgmp.ResultOption.Equals(other.ResultOption) { + return false + } + + return dsgmp.AccessPassword.Equals(other.AccessPassword) +} + +// String returns the string representation of the DataStoreGetMetaParam +func (dsgmp *DataStoreGetMetaParam) String() string { + return dsgmp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreGetMetaParam using the provided indentation level +func (dsgmp *DataStoreGetMetaParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreGetMetaParam{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dsgmp.DataID)) + b.WriteString(fmt.Sprintf("%sPersistenceTarget: %s,\n", indentationValues, dsgmp.PersistenceTarget.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sResultOption: %s,\n", indentationValues, dsgmp.ResultOption)) + b.WriteString(fmt.Sprintf("%sAccessPassword: %s,\n", indentationValues, dsgmp.AccessPassword)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreGetMetaParam returns a new DataStoreGetMetaParam +func NewDataStoreGetMetaParam() *DataStoreGetMetaParam { + dsgmp := &DataStoreGetMetaParam{ + DataID: types.NewPrimitiveU64(0), + PersistenceTarget: NewDataStorePersistenceTarget(), + ResultOption: types.NewPrimitiveU8(0), + AccessPassword: types.NewPrimitiveU64(0), + } + + return dsgmp +} diff --git a/nex-protocols-go/datastore/types/datastore_get_new_arrived_notifications_param.go b/nex-protocols-go/datastore/types/datastore_get_new_arrived_notifications_param.go new file mode 100644 index 0000000..08928a5 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_get_new_arrived_notifications_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreGetNewArrivedNotificationsParam is a type within the DataStore protocol +type DataStoreGetNewArrivedNotificationsParam struct { + types.Structure + LastNotificationID *types.PrimitiveU64 + Limit *types.PrimitiveU16 +} + +// WriteTo writes the DataStoreGetNewArrivedNotificationsParam to the given writable +func (dsgnanp *DataStoreGetNewArrivedNotificationsParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsgnanp.LastNotificationID.WriteTo(contentWritable) + dsgnanp.Limit.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsgnanp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreGetNewArrivedNotificationsParam from the given readable +func (dsgnanp *DataStoreGetNewArrivedNotificationsParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsgnanp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetNewArrivedNotificationsParam header. %s", err.Error()) + } + + err = dsgnanp.LastNotificationID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetNewArrivedNotificationsParam.LastNotificationID. %s", err.Error()) + } + + err = dsgnanp.Limit.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetNewArrivedNotificationsParam.Limit. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreGetNewArrivedNotificationsParam +func (dsgnanp *DataStoreGetNewArrivedNotificationsParam) Copy() types.RVType { + copied := NewDataStoreGetNewArrivedNotificationsParam() + + copied.StructureVersion = dsgnanp.StructureVersion + copied.LastNotificationID = dsgnanp.LastNotificationID.Copy().(*types.PrimitiveU64) + copied.Limit = dsgnanp.Limit.Copy().(*types.PrimitiveU16) + + return copied +} + +// Equals checks if the given DataStoreGetNewArrivedNotificationsParam contains the same data as the current DataStoreGetNewArrivedNotificationsParam +func (dsgnanp *DataStoreGetNewArrivedNotificationsParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreGetNewArrivedNotificationsParam); !ok { + return false + } + + other := o.(*DataStoreGetNewArrivedNotificationsParam) + + if dsgnanp.StructureVersion != other.StructureVersion { + return false + } + + if !dsgnanp.LastNotificationID.Equals(other.LastNotificationID) { + return false + } + + return dsgnanp.Limit.Equals(other.Limit) +} + +// String returns the string representation of the DataStoreGetNewArrivedNotificationsParam +func (dsgnanp *DataStoreGetNewArrivedNotificationsParam) String() string { + return dsgnanp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreGetNewArrivedNotificationsParam using the provided indentation level +func (dsgnanp *DataStoreGetNewArrivedNotificationsParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreGetNewArrivedNotificationsParam{\n") + b.WriteString(fmt.Sprintf("%sLastNotificationID: %s,\n", indentationValues, dsgnanp.LastNotificationID)) + b.WriteString(fmt.Sprintf("%sLimit: %s,\n", indentationValues, dsgnanp.Limit)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreGetNewArrivedNotificationsParam returns a new DataStoreGetNewArrivedNotificationsParam +func NewDataStoreGetNewArrivedNotificationsParam() *DataStoreGetNewArrivedNotificationsParam { + dsgnanp := &DataStoreGetNewArrivedNotificationsParam{ + LastNotificationID: types.NewPrimitiveU64(0), + Limit: types.NewPrimitiveU16(0), + } + + return dsgnanp +} diff --git a/nex-protocols-go/datastore/types/datastore_get_notification_url_param.go b/nex-protocols-go/datastore/types/datastore_get_notification_url_param.go new file mode 100644 index 0000000..7b69b60 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_get_notification_url_param.go @@ -0,0 +1,98 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreGetNotificationURLParam is a type within the DataStore protocol +type DataStoreGetNotificationURLParam struct { + types.Structure + PreviousURL *types.String +} + +// WriteTo writes the DataStoreGetNotificationURLParam to the given writable +func (dsgnurlp *DataStoreGetNotificationURLParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsgnurlp.PreviousURL.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsgnurlp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreGetNotificationURLParam from the given readable +func (dsgnurlp *DataStoreGetNotificationURLParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsgnurlp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetNotificationURLParam header. %s", err.Error()) + } + + err = dsgnurlp.PreviousURL.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetNotificationURLParam.PreviousURL. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreGetNotificationURLParam +func (dsgnurlp *DataStoreGetNotificationURLParam) Copy() types.RVType { + copied := NewDataStoreGetNotificationURLParam() + + copied.StructureVersion = dsgnurlp.StructureVersion + copied.PreviousURL = dsgnurlp.PreviousURL.Copy().(*types.String) + + return copied +} + +// Equals checks if the given DataStoreGetNotificationURLParam contains the same data as the current DataStoreGetNotificationURLParam +func (dsgnurlp *DataStoreGetNotificationURLParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreGetNotificationURLParam); !ok { + return false + } + + other := o.(*DataStoreGetNotificationURLParam) + + if dsgnurlp.StructureVersion != other.StructureVersion { + return false + } + + return dsgnurlp.PreviousURL.Equals(other.PreviousURL) +} + +// String returns the string representation of the DataStoreGetNotificationURLParam +func (dsgnurlp *DataStoreGetNotificationURLParam) String() string { + return dsgnurlp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreGetNotificationURLParam using the provided indentation level +func (dsgnurlp *DataStoreGetNotificationURLParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreGetNotificationURLParam{\n") + b.WriteString(fmt.Sprintf("%sPreviousURL: %s,\n", indentationValues, dsgnurlp.PreviousURL)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreGetNotificationURLParam returns a new DataStoreGetNotificationURLParam +func NewDataStoreGetNotificationURLParam() *DataStoreGetNotificationURLParam { + dsgnurlp := &DataStoreGetNotificationURLParam{ + PreviousURL: types.NewString(""), + } + + return dsgnurlp +} diff --git a/nex-protocols-go/datastore/types/datastore_get_specific_meta_param.go b/nex-protocols-go/datastore/types/datastore_get_specific_meta_param.go new file mode 100644 index 0000000..785261e --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_get_specific_meta_param.go @@ -0,0 +1,100 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreGetSpecificMetaParam is a type within the DataStore protocol +type DataStoreGetSpecificMetaParam struct { + types.Structure + DataIDs *types.List[*types.PrimitiveU64] +} + +// WriteTo writes the DataStoreGetSpecificMetaParam to the given writable +func (dsgsmp *DataStoreGetSpecificMetaParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsgsmp.DataIDs.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsgsmp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreGetSpecificMetaParam from the given readable +func (dsgsmp *DataStoreGetSpecificMetaParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsgsmp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetSpecificMetaParam header. %s", err.Error()) + } + + err = dsgsmp.DataIDs.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetSpecificMetaParam.DataIDs. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreGetSpecificMetaParam +func (dsgsmp *DataStoreGetSpecificMetaParam) Copy() types.RVType { + copied := NewDataStoreGetSpecificMetaParam() + + copied.StructureVersion = dsgsmp.StructureVersion + copied.DataIDs = dsgsmp.DataIDs.Copy().(*types.List[*types.PrimitiveU64]) + + return copied +} + +// Equals checks if the given DataStoreGetSpecificMetaParam contains the same data as the current DataStoreGetSpecificMetaParam +func (dsgsmp *DataStoreGetSpecificMetaParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreGetSpecificMetaParam); !ok { + return false + } + + other := o.(*DataStoreGetSpecificMetaParam) + + if dsgsmp.StructureVersion != other.StructureVersion { + return false + } + + return dsgsmp.DataIDs.Equals(other.DataIDs) +} + +// String returns the string representation of the DataStoreGetSpecificMetaParam +func (dsgsmp *DataStoreGetSpecificMetaParam) String() string { + return dsgsmp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreGetSpecificMetaParam using the provided indentation level +func (dsgsmp *DataStoreGetSpecificMetaParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreGetSpecificMetaParam{\n") + b.WriteString(fmt.Sprintf("%sDataIDs: %s,\n", indentationValues, dsgsmp.DataIDs)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreGetSpecificMetaParam returns a new DataStoreGetSpecificMetaParam +func NewDataStoreGetSpecificMetaParam() *DataStoreGetSpecificMetaParam { + dsgsmp := &DataStoreGetSpecificMetaParam{ + DataIDs: types.NewList[*types.PrimitiveU64](), + } + + dsgsmp.DataIDs.Type = types.NewPrimitiveU64(0) + + return dsgsmp +} diff --git a/nex-protocols-go/datastore/types/datastore_get_specific_meta_param_v1.go b/nex-protocols-go/datastore/types/datastore_get_specific_meta_param_v1.go new file mode 100644 index 0000000..2fd164f --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_get_specific_meta_param_v1.go @@ -0,0 +1,100 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreGetSpecificMetaParamV1 is a type within the DataStore protocol +type DataStoreGetSpecificMetaParamV1 struct { + types.Structure + DataIDs *types.List[*types.PrimitiveU32] +} + +// WriteTo writes the DataStoreGetSpecificMetaParamV1 to the given writable +func (dsgsmpv *DataStoreGetSpecificMetaParamV1) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsgsmpv.DataIDs.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsgsmpv.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreGetSpecificMetaParamV1 from the given readable +func (dsgsmpv *DataStoreGetSpecificMetaParamV1) ExtractFrom(readable types.Readable) error { + var err error + + err = dsgsmpv.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetSpecificMetaParamV1 header. %s", err.Error()) + } + + err = dsgsmpv.DataIDs.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreGetSpecificMetaParamV1.DataIDs. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreGetSpecificMetaParamV1 +func (dsgsmpv *DataStoreGetSpecificMetaParamV1) Copy() types.RVType { + copied := NewDataStoreGetSpecificMetaParamV1() + + copied.StructureVersion = dsgsmpv.StructureVersion + copied.DataIDs = dsgsmpv.DataIDs.Copy().(*types.List[*types.PrimitiveU32]) + + return copied +} + +// Equals checks if the given DataStoreGetSpecificMetaParamV1 contains the same data as the current DataStoreGetSpecificMetaParamV1 +func (dsgsmpv *DataStoreGetSpecificMetaParamV1) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreGetSpecificMetaParamV1); !ok { + return false + } + + other := o.(*DataStoreGetSpecificMetaParamV1) + + if dsgsmpv.StructureVersion != other.StructureVersion { + return false + } + + return dsgsmpv.DataIDs.Equals(other.DataIDs) +} + +// String returns the string representation of the DataStoreGetSpecificMetaParamV1 +func (dsgsmpv *DataStoreGetSpecificMetaParamV1) String() string { + return dsgsmpv.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreGetSpecificMetaParamV1 using the provided indentation level +func (dsgsmpv *DataStoreGetSpecificMetaParamV1) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreGetSpecificMetaParamV1{\n") + b.WriteString(fmt.Sprintf("%sDataIDs: %s,\n", indentationValues, dsgsmpv.DataIDs)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreGetSpecificMetaParamV1 returns a new DataStoreGetSpecificMetaParamV1 +func NewDataStoreGetSpecificMetaParamV1() *DataStoreGetSpecificMetaParamV1 { + dsgsmpv := &DataStoreGetSpecificMetaParamV1{ + DataIDs: types.NewList[*types.PrimitiveU32](), + } + + dsgsmpv.DataIDs.Type = types.NewPrimitiveU32(0) + + return dsgsmpv +} diff --git a/nex-protocols-go/datastore/types/datastore_key_value.go b/nex-protocols-go/datastore/types/datastore_key_value.go new file mode 100644 index 0000000..16df8a6 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_key_value.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreKeyValue is a type within the DataStore protocol +type DataStoreKeyValue struct { + types.Structure + Key *types.String + Value *types.String +} + +// WriteTo writes the DataStoreKeyValue to the given writable +func (dskv *DataStoreKeyValue) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dskv.Key.WriteTo(contentWritable) + dskv.Value.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dskv.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreKeyValue from the given readable +func (dskv *DataStoreKeyValue) ExtractFrom(readable types.Readable) error { + var err error + + err = dskv.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreKeyValue header. %s", err.Error()) + } + + err = dskv.Key.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreKeyValue.Key. %s", err.Error()) + } + + err = dskv.Value.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreKeyValue.Value. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreKeyValue +func (dskv *DataStoreKeyValue) Copy() types.RVType { + copied := NewDataStoreKeyValue() + + copied.StructureVersion = dskv.StructureVersion + copied.Key = dskv.Key.Copy().(*types.String) + copied.Value = dskv.Value.Copy().(*types.String) + + return copied +} + +// Equals checks if the given DataStoreKeyValue contains the same data as the current DataStoreKeyValue +func (dskv *DataStoreKeyValue) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreKeyValue); !ok { + return false + } + + other := o.(*DataStoreKeyValue) + + if dskv.StructureVersion != other.StructureVersion { + return false + } + + if !dskv.Key.Equals(other.Key) { + return false + } + + return dskv.Value.Equals(other.Value) +} + +// String returns the string representation of the DataStoreKeyValue +func (dskv *DataStoreKeyValue) String() string { + return dskv.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreKeyValue using the provided indentation level +func (dskv *DataStoreKeyValue) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreKeyValue{\n") + b.WriteString(fmt.Sprintf("%sKey: %s,\n", indentationValues, dskv.Key)) + b.WriteString(fmt.Sprintf("%sValue: %s,\n", indentationValues, dskv.Value)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreKeyValue returns a new DataStoreKeyValue +func NewDataStoreKeyValue() *DataStoreKeyValue { + dskv := &DataStoreKeyValue{ + Key: types.NewString(""), + Value: types.NewString(""), + } + + return dskv +} diff --git a/nex-protocols-go/datastore/types/datastore_meta_info.go b/nex-protocols-go/datastore/types/datastore_meta_info.go new file mode 100644 index 0000000..0d60858 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_meta_info.go @@ -0,0 +1,379 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreMetaInfo is a type within the DataStore protocol +type DataStoreMetaInfo struct { + types.Structure + DataID *types.PrimitiveU64 + OwnerID *types.PID + Size *types.PrimitiveU32 + DataType *types.PrimitiveU16 + Name *types.String + MetaBinary *types.QBuffer + Permission *DataStorePermission + DelPermission *DataStorePermission + CreatedTime *types.DateTime + UpdatedTime *types.DateTime + Period *types.PrimitiveU16 + Status *types.PrimitiveU8 + ReferredCnt *types.PrimitiveU32 + ReferDataID *types.PrimitiveU32 + Flag *types.PrimitiveU32 + ReferredTime *types.DateTime + ExpireTime *types.DateTime + Tags *types.List[*types.String] + Ratings *types.List[*DataStoreRatingInfoWithSlot] +} + +// WriteTo writes the DataStoreMetaInfo to the given writable +func (dsmi *DataStoreMetaInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsmi.DataID.WriteTo(contentWritable) + dsmi.OwnerID.WriteTo(contentWritable) + dsmi.Size.WriteTo(contentWritable) + dsmi.DataType.WriteTo(contentWritable) + dsmi.Name.WriteTo(contentWritable) + dsmi.MetaBinary.WriteTo(contentWritable) + dsmi.Permission.WriteTo(contentWritable) + dsmi.DelPermission.WriteTo(contentWritable) + dsmi.CreatedTime.WriteTo(contentWritable) + dsmi.UpdatedTime.WriteTo(contentWritable) + dsmi.Period.WriteTo(contentWritable) + dsmi.Status.WriteTo(contentWritable) + dsmi.ReferredCnt.WriteTo(contentWritable) + dsmi.ReferDataID.WriteTo(contentWritable) + dsmi.Flag.WriteTo(contentWritable) + dsmi.ReferredTime.WriteTo(contentWritable) + dsmi.ExpireTime.WriteTo(contentWritable) + dsmi.Tags.WriteTo(contentWritable) + dsmi.Ratings.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsmi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreMetaInfo from the given readable +func (dsmi *DataStoreMetaInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = dsmi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo header. %s", err.Error()) + } + + err = dsmi.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.DataID. %s", err.Error()) + } + + err = dsmi.OwnerID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.OwnerID. %s", err.Error()) + } + + err = dsmi.Size.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.Size. %s", err.Error()) + } + + err = dsmi.DataType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.DataType. %s", err.Error()) + } + + err = dsmi.Name.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.Name. %s", err.Error()) + } + + err = dsmi.MetaBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.MetaBinary. %s", err.Error()) + } + + err = dsmi.Permission.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.Permission. %s", err.Error()) + } + + err = dsmi.DelPermission.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.DelPermission. %s", err.Error()) + } + + err = dsmi.CreatedTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.CreatedTime. %s", err.Error()) + } + + err = dsmi.UpdatedTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.UpdatedTime. %s", err.Error()) + } + + err = dsmi.Period.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.Period. %s", err.Error()) + } + + err = dsmi.Status.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.Status. %s", err.Error()) + } + + err = dsmi.ReferredCnt.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.ReferredCnt. %s", err.Error()) + } + + err = dsmi.ReferDataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.ReferDataID. %s", err.Error()) + } + + err = dsmi.Flag.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.Flag. %s", err.Error()) + } + + err = dsmi.ReferredTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.ReferredTime. %s", err.Error()) + } + + err = dsmi.ExpireTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.ExpireTime. %s", err.Error()) + } + + err = dsmi.Tags.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.Tags. %s", err.Error()) + } + + err = dsmi.Ratings.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreMetaInfo.Ratings. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreMetaInfo +func (dsmi *DataStoreMetaInfo) Copy() types.RVType { + copied := NewDataStoreMetaInfo() + + copied.StructureVersion = dsmi.StructureVersion + copied.DataID = dsmi.DataID.Copy().(*types.PrimitiveU64) + copied.OwnerID = dsmi.OwnerID.Copy().(*types.PID) + copied.Size = dsmi.Size.Copy().(*types.PrimitiveU32) + copied.DataType = dsmi.DataType.Copy().(*types.PrimitiveU16) + copied.Name = dsmi.Name.Copy().(*types.String) + copied.MetaBinary = dsmi.MetaBinary.Copy().(*types.QBuffer) + copied.Permission = dsmi.Permission.Copy().(*DataStorePermission) + copied.DelPermission = dsmi.DelPermission.Copy().(*DataStorePermission) + copied.CreatedTime = dsmi.CreatedTime.Copy().(*types.DateTime) + copied.UpdatedTime = dsmi.UpdatedTime.Copy().(*types.DateTime) + copied.Period = dsmi.Period.Copy().(*types.PrimitiveU16) + copied.Status = dsmi.Status.Copy().(*types.PrimitiveU8) + copied.ReferredCnt = dsmi.ReferredCnt.Copy().(*types.PrimitiveU32) + copied.ReferDataID = dsmi.ReferDataID.Copy().(*types.PrimitiveU32) + copied.Flag = dsmi.Flag.Copy().(*types.PrimitiveU32) + copied.ReferredTime = dsmi.ReferredTime.Copy().(*types.DateTime) + copied.ExpireTime = dsmi.ExpireTime.Copy().(*types.DateTime) + copied.Tags = dsmi.Tags.Copy().(*types.List[*types.String]) + copied.Ratings = dsmi.Ratings.Copy().(*types.List[*DataStoreRatingInfoWithSlot]) + + return copied +} + +// Equals checks if the given DataStoreMetaInfo contains the same data as the current DataStoreMetaInfo +func (dsmi *DataStoreMetaInfo) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreMetaInfo); !ok { + return false + } + + other := o.(*DataStoreMetaInfo) + + if dsmi.StructureVersion != other.StructureVersion { + return false + } + + if !dsmi.DataID.Equals(other.DataID) { + return false + } + + if !dsmi.OwnerID.Equals(other.OwnerID) { + return false + } + + if !dsmi.Size.Equals(other.Size) { + return false + } + + if !dsmi.DataType.Equals(other.DataType) { + return false + } + + if !dsmi.Name.Equals(other.Name) { + return false + } + + if !dsmi.MetaBinary.Equals(other.MetaBinary) { + return false + } + + if !dsmi.Permission.Equals(other.Permission) { + return false + } + + if !dsmi.DelPermission.Equals(other.DelPermission) { + return false + } + + if !dsmi.CreatedTime.Equals(other.CreatedTime) { + return false + } + + if !dsmi.UpdatedTime.Equals(other.UpdatedTime) { + return false + } + + if !dsmi.Period.Equals(other.Period) { + return false + } + + if !dsmi.Status.Equals(other.Status) { + return false + } + + if !dsmi.ReferredCnt.Equals(other.ReferredCnt) { + return false + } + + if !dsmi.ReferDataID.Equals(other.ReferDataID) { + return false + } + + if !dsmi.Flag.Equals(other.Flag) { + return false + } + + if !dsmi.ReferredTime.Equals(other.ReferredTime) { + return false + } + + if !dsmi.ExpireTime.Equals(other.ExpireTime) { + return false + } + + if !dsmi.Tags.Equals(other.Tags) { + return false + } + + return dsmi.Ratings.Equals(other.Ratings) +} + +// String returns the string representation of the DataStoreMetaInfo +func (dsmi *DataStoreMetaInfo) String() string { + return dsmi.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreMetaInfo using the provided indentation level +func (dsmi *DataStoreMetaInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreMetaInfo{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dsmi.DataID)) + b.WriteString(fmt.Sprintf("%sOwnerID: %s,\n", indentationValues, dsmi.OwnerID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sSize: %s,\n", indentationValues, dsmi.Size)) + b.WriteString(fmt.Sprintf("%sDataType: %s,\n", indentationValues, dsmi.DataType)) + b.WriteString(fmt.Sprintf("%sName: %s,\n", indentationValues, dsmi.Name)) + b.WriteString(fmt.Sprintf("%sMetaBinary: %s,\n", indentationValues, dsmi.MetaBinary)) + b.WriteString(fmt.Sprintf("%sPermission: %s,\n", indentationValues, dsmi.Permission.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sDelPermission: %s,\n", indentationValues, dsmi.DelPermission.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sCreatedTime: %s,\n", indentationValues, dsmi.CreatedTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUpdatedTime: %s,\n", indentationValues, dsmi.UpdatedTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPeriod: %s,\n", indentationValues, dsmi.Period)) + b.WriteString(fmt.Sprintf("%sStatus: %s,\n", indentationValues, dsmi.Status)) + b.WriteString(fmt.Sprintf("%sReferredCnt: %s,\n", indentationValues, dsmi.ReferredCnt)) + b.WriteString(fmt.Sprintf("%sReferDataID: %s,\n", indentationValues, dsmi.ReferDataID)) + b.WriteString(fmt.Sprintf("%sFlag: %s,\n", indentationValues, dsmi.Flag)) + b.WriteString(fmt.Sprintf("%sReferredTime: %s,\n", indentationValues, dsmi.ReferredTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sExpireTime: %s,\n", indentationValues, dsmi.ExpireTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sTags: %s,\n", indentationValues, dsmi.Tags)) + b.WriteString(fmt.Sprintf("%sRatings: %s,\n", indentationValues, dsmi.Ratings)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// FilterPropertiesByResultOption zeroes out certain struct properties based on the input flags +func (dsmi *DataStoreMetaInfo) FilterPropertiesByResultOption(resultOption *types.PrimitiveU8) { + // * This is kind of backwards + // * + // * This method assumes all struct data exists + // * by default. This is done in order to simplify + // * database calls by just querying for all fields + // * at once. Therefore, instead of the ResultOption + // * flags being used to conditionally ADD properties, + // * it's used to conditionally REMOVE them + + if resultOption.PAND(0x1) == 0 { + dsmi.Tags = types.NewList[*types.String]() + dsmi.Tags.Type = types.NewString("") + } + + if resultOption.PAND(0x2) == 0 { + dsmi.Ratings = types.NewList[*DataStoreRatingInfoWithSlot]() + dsmi.Ratings.Type = NewDataStoreRatingInfoWithSlot() + } + + if resultOption.PAND(0x4) == 0 { + dsmi.MetaBinary = types.NewQBuffer(nil) + } +} + +// NewDataStoreMetaInfo returns a new DataStoreMetaInfo +func NewDataStoreMetaInfo() *DataStoreMetaInfo { + dsmi := &DataStoreMetaInfo{ + DataID: types.NewPrimitiveU64(0), + OwnerID: types.NewPID(0), + Size: types.NewPrimitiveU32(0), + DataType: types.NewPrimitiveU16(0), + Name: types.NewString(""), + MetaBinary: types.NewQBuffer(nil), + Permission: NewDataStorePermission(), + DelPermission: NewDataStorePermission(), + CreatedTime: types.NewDateTime(0), + UpdatedTime: types.NewDateTime(0), + Period: types.NewPrimitiveU16(0), + Status: types.NewPrimitiveU8(0), + ReferredCnt: types.NewPrimitiveU32(0), + ReferDataID: types.NewPrimitiveU32(0), + Flag: types.NewPrimitiveU32(0), + ReferredTime: types.NewDateTime(0), + ExpireTime: types.NewDateTime(0), + Tags: types.NewList[*types.String](), + Ratings: types.NewList[*DataStoreRatingInfoWithSlot](), + } + + dsmi.Tags.Type = types.NewString("") + dsmi.Ratings.Type = NewDataStoreRatingInfoWithSlot() + + return dsmi +} diff --git a/nex-protocols-go/datastore/types/datastore_notification.go b/nex-protocols-go/datastore/types/datastore_notification.go new file mode 100644 index 0000000..03b77d8 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_notification.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreNotification is a type within the DataStore protocol +type DataStoreNotification struct { + types.Structure + NotificationID *types.PrimitiveU64 + DataID *types.PrimitiveU64 +} + +// WriteTo writes the DataStoreNotification to the given writable +func (dsn *DataStoreNotification) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsn.NotificationID.WriteTo(contentWritable) + dsn.DataID.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsn.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreNotification from the given readable +func (dsn *DataStoreNotification) ExtractFrom(readable types.Readable) error { + var err error + + err = dsn.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreNotification header. %s", err.Error()) + } + + err = dsn.NotificationID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreNotification.NotificationID. %s", err.Error()) + } + + err = dsn.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreNotification.DataID. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreNotification +func (dsn *DataStoreNotification) Copy() types.RVType { + copied := NewDataStoreNotification() + + copied.StructureVersion = dsn.StructureVersion + copied.NotificationID = dsn.NotificationID.Copy().(*types.PrimitiveU64) + copied.DataID = dsn.DataID.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given DataStoreNotification contains the same data as the current DataStoreNotification +func (dsn *DataStoreNotification) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreNotification); !ok { + return false + } + + other := o.(*DataStoreNotification) + + if dsn.StructureVersion != other.StructureVersion { + return false + } + + if !dsn.NotificationID.Equals(other.NotificationID) { + return false + } + + return dsn.DataID.Equals(other.DataID) +} + +// String returns the string representation of the DataStoreNotification +func (dsn *DataStoreNotification) String() string { + return dsn.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreNotification using the provided indentation level +func (dsn *DataStoreNotification) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreNotification{\n") + b.WriteString(fmt.Sprintf("%sNotificationID: %s,\n", indentationValues, dsn.NotificationID)) + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dsn.DataID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreNotification returns a new DataStoreNotification +func NewDataStoreNotification() *DataStoreNotification { + dsn := &DataStoreNotification{ + NotificationID: types.NewPrimitiveU64(0), + DataID: types.NewPrimitiveU64(0), + } + + return dsn +} diff --git a/nex-protocols-go/datastore/types/datastore_notification_v1.go b/nex-protocols-go/datastore/types/datastore_notification_v1.go new file mode 100644 index 0000000..70ff2bf --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_notification_v1.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreNotificationV1 is a type within the DataStore protocol +type DataStoreNotificationV1 struct { + types.Structure + NotificationID *types.PrimitiveU64 + DataID *types.PrimitiveU32 +} + +// WriteTo writes the DataStoreNotificationV1 to the given writable +func (dsnv *DataStoreNotificationV1) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsnv.NotificationID.WriteTo(contentWritable) + dsnv.DataID.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsnv.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreNotificationV1 from the given readable +func (dsnv *DataStoreNotificationV1) ExtractFrom(readable types.Readable) error { + var err error + + err = dsnv.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreNotificationV1 header. %s", err.Error()) + } + + err = dsnv.NotificationID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreNotificationV1.NotificationID. %s", err.Error()) + } + + err = dsnv.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreNotificationV1.DataID. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreNotificationV1 +func (dsnv *DataStoreNotificationV1) Copy() types.RVType { + copied := NewDataStoreNotificationV1() + + copied.StructureVersion = dsnv.StructureVersion + copied.NotificationID = dsnv.NotificationID.Copy().(*types.PrimitiveU64) + copied.DataID = dsnv.DataID.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given DataStoreNotificationV1 contains the same data as the current DataStoreNotificationV1 +func (dsnv *DataStoreNotificationV1) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreNotificationV1); !ok { + return false + } + + other := o.(*DataStoreNotificationV1) + + if dsnv.StructureVersion != other.StructureVersion { + return false + } + + if !dsnv.NotificationID.Equals(other.NotificationID) { + return false + } + + return dsnv.DataID.Equals(other.DataID) +} + +// String returns the string representation of the DataStoreNotificationV1 +func (dsnv *DataStoreNotificationV1) String() string { + return dsnv.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreNotificationV1 using the provided indentation level +func (dsnv *DataStoreNotificationV1) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreNotificationV1{\n") + b.WriteString(fmt.Sprintf("%sNotificationID: %s,\n", indentationValues, dsnv.NotificationID)) + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dsnv.DataID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreNotificationV1 returns a new DataStoreNotificationV1 +func NewDataStoreNotificationV1() *DataStoreNotificationV1 { + dsnv := &DataStoreNotificationV1{ + NotificationID: types.NewPrimitiveU64(0), + DataID: types.NewPrimitiveU32(0), + } + + return dsnv +} diff --git a/nex-protocols-go/datastore/types/datastore_password_info.go b/nex-protocols-go/datastore/types/datastore_password_info.go new file mode 100644 index 0000000..d38203c --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_password_info.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStorePasswordInfo is a type within the DataStore protocol +type DataStorePasswordInfo struct { + types.Structure + DataID *types.PrimitiveU64 + AccessPassword *types.PrimitiveU64 + UpdatePassword *types.PrimitiveU64 +} + +// WriteTo writes the DataStorePasswordInfo to the given writable +func (dspi *DataStorePasswordInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dspi.DataID.WriteTo(contentWritable) + dspi.AccessPassword.WriteTo(contentWritable) + dspi.UpdatePassword.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dspi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStorePasswordInfo from the given readable +func (dspi *DataStorePasswordInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = dspi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePasswordInfo header. %s", err.Error()) + } + + err = dspi.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePasswordInfo.DataID. %s", err.Error()) + } + + err = dspi.AccessPassword.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePasswordInfo.AccessPassword. %s", err.Error()) + } + + err = dspi.UpdatePassword.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePasswordInfo.UpdatePassword. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStorePasswordInfo +func (dspi *DataStorePasswordInfo) Copy() types.RVType { + copied := NewDataStorePasswordInfo() + + copied.StructureVersion = dspi.StructureVersion + copied.DataID = dspi.DataID.Copy().(*types.PrimitiveU64) + copied.AccessPassword = dspi.AccessPassword.Copy().(*types.PrimitiveU64) + copied.UpdatePassword = dspi.UpdatePassword.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given DataStorePasswordInfo contains the same data as the current DataStorePasswordInfo +func (dspi *DataStorePasswordInfo) Equals(o types.RVType) bool { + if _, ok := o.(*DataStorePasswordInfo); !ok { + return false + } + + other := o.(*DataStorePasswordInfo) + + if dspi.StructureVersion != other.StructureVersion { + return false + } + + if !dspi.DataID.Equals(other.DataID) { + return false + } + + if !dspi.AccessPassword.Equals(other.AccessPassword) { + return false + } + + return dspi.UpdatePassword.Equals(other.UpdatePassword) +} + +// String returns the string representation of the DataStorePasswordInfo +func (dspi *DataStorePasswordInfo) String() string { + return dspi.FormatToString(0) +} + +// FormatToString pretty-prints the DataStorePasswordInfo using the provided indentation level +func (dspi *DataStorePasswordInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStorePasswordInfo{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dspi.DataID)) + b.WriteString(fmt.Sprintf("%sAccessPassword: %s,\n", indentationValues, dspi.AccessPassword)) + b.WriteString(fmt.Sprintf("%sUpdatePassword: %s,\n", indentationValues, dspi.UpdatePassword)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStorePasswordInfo returns a new DataStorePasswordInfo +func NewDataStorePasswordInfo() *DataStorePasswordInfo { + dspi := &DataStorePasswordInfo{ + DataID: types.NewPrimitiveU64(0), + AccessPassword: types.NewPrimitiveU64(0), + UpdatePassword: types.NewPrimitiveU64(0), + } + + return dspi +} diff --git a/nex-protocols-go/datastore/types/datastore_permission.go b/nex-protocols-go/datastore/types/datastore_permission.go new file mode 100644 index 0000000..ab61f0a --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_permission.go @@ -0,0 +1,114 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStorePermission is a type within the DataStore protocol +type DataStorePermission struct { + types.Structure + Permission *types.PrimitiveU8 + RecipientIDs *types.List[*types.PID] +} + +// WriteTo writes the DataStorePermission to the given writable +func (dsp *DataStorePermission) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsp.Permission.WriteTo(contentWritable) + dsp.RecipientIDs.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStorePermission from the given readable +func (dsp *DataStorePermission) ExtractFrom(readable types.Readable) error { + var err error + + err = dsp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePermission header. %s", err.Error()) + } + + err = dsp.Permission.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePermission.Permission. %s", err.Error()) + } + + err = dsp.RecipientIDs.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePermission.RecipientIDs. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStorePermission +func (dsp *DataStorePermission) Copy() types.RVType { + copied := NewDataStorePermission() + + copied.StructureVersion = dsp.StructureVersion + copied.Permission = dsp.Permission.Copy().(*types.PrimitiveU8) + copied.RecipientIDs = dsp.RecipientIDs.Copy().(*types.List[*types.PID]) + + return copied +} + +// Equals checks if the given DataStorePermission contains the same data as the current DataStorePermission +func (dsp *DataStorePermission) Equals(o types.RVType) bool { + if _, ok := o.(*DataStorePermission); !ok { + return false + } + + other := o.(*DataStorePermission) + + if dsp.StructureVersion != other.StructureVersion { + return false + } + + if !dsp.Permission.Equals(other.Permission) { + return false + } + + return dsp.RecipientIDs.Equals(other.RecipientIDs) +} + +// String returns the string representation of the DataStorePermission +func (dsp *DataStorePermission) String() string { + return dsp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStorePermission using the provided indentation level +func (dsp *DataStorePermission) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStorePermission{\n") + b.WriteString(fmt.Sprintf("%sPermission: %s,\n", indentationValues, dsp.Permission)) + b.WriteString(fmt.Sprintf("%sRecipientIDs: %s,\n", indentationValues, dsp.RecipientIDs)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStorePermission returns a new DataStorePermission +func NewDataStorePermission() *DataStorePermission { + dsp := &DataStorePermission{ + Permission: types.NewPrimitiveU8(0), + RecipientIDs: types.NewList[*types.PID](), + } + + dsp.RecipientIDs.Type = types.NewPID(0) + + return dsp +} diff --git a/nex-protocols-go/datastore/types/datastore_persistence_info.go b/nex-protocols-go/datastore/types/datastore_persistence_info.go new file mode 100644 index 0000000..2510773 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_persistence_info.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStorePersistenceInfo is a type within the DataStore protocol +type DataStorePersistenceInfo struct { + types.Structure + OwnerID *types.PID + PersistenceSlotID *types.PrimitiveU16 + DataID *types.PrimitiveU64 +} + +// WriteTo writes the DataStorePersistenceInfo to the given writable +func (dspi *DataStorePersistenceInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dspi.OwnerID.WriteTo(contentWritable) + dspi.PersistenceSlotID.WriteTo(contentWritable) + dspi.DataID.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dspi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStorePersistenceInfo from the given readable +func (dspi *DataStorePersistenceInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = dspi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePersistenceInfo header. %s", err.Error()) + } + + err = dspi.OwnerID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePersistenceInfo.OwnerID. %s", err.Error()) + } + + err = dspi.PersistenceSlotID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePersistenceInfo.PersistenceSlotID. %s", err.Error()) + } + + err = dspi.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePersistenceInfo.DataID. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStorePersistenceInfo +func (dspi *DataStorePersistenceInfo) Copy() types.RVType { + copied := NewDataStorePersistenceInfo() + + copied.StructureVersion = dspi.StructureVersion + copied.OwnerID = dspi.OwnerID.Copy().(*types.PID) + copied.PersistenceSlotID = dspi.PersistenceSlotID.Copy().(*types.PrimitiveU16) + copied.DataID = dspi.DataID.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given DataStorePersistenceInfo contains the same data as the current DataStorePersistenceInfo +func (dspi *DataStorePersistenceInfo) Equals(o types.RVType) bool { + if _, ok := o.(*DataStorePersistenceInfo); !ok { + return false + } + + other := o.(*DataStorePersistenceInfo) + + if dspi.StructureVersion != other.StructureVersion { + return false + } + + if !dspi.OwnerID.Equals(other.OwnerID) { + return false + } + + if !dspi.PersistenceSlotID.Equals(other.PersistenceSlotID) { + return false + } + + return dspi.DataID.Equals(other.DataID) +} + +// String returns the string representation of the DataStorePersistenceInfo +func (dspi *DataStorePersistenceInfo) String() string { + return dspi.FormatToString(0) +} + +// FormatToString pretty-prints the DataStorePersistenceInfo using the provided indentation level +func (dspi *DataStorePersistenceInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStorePersistenceInfo{\n") + b.WriteString(fmt.Sprintf("%sOwnerID: %s,\n", indentationValues, dspi.OwnerID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPersistenceSlotID: %s,\n", indentationValues, dspi.PersistenceSlotID)) + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dspi.DataID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStorePersistenceInfo returns a new DataStorePersistenceInfo +func NewDataStorePersistenceInfo() *DataStorePersistenceInfo { + dspi := &DataStorePersistenceInfo{ + OwnerID: types.NewPID(0), + PersistenceSlotID: types.NewPrimitiveU16(0), + DataID: types.NewPrimitiveU64(0), + } + + return dspi +} diff --git a/nex-protocols-go/datastore/types/datastore_persistence_init_param.go b/nex-protocols-go/datastore/types/datastore_persistence_init_param.go new file mode 100644 index 0000000..a6c1672 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_persistence_init_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStorePersistenceInitParam is a type within the DataStore protocol +type DataStorePersistenceInitParam struct { + types.Structure + PersistenceSlotID *types.PrimitiveU16 + DeleteLastObject *types.PrimitiveBool +} + +// WriteTo writes the DataStorePersistenceInitParam to the given writable +func (dspip *DataStorePersistenceInitParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dspip.PersistenceSlotID.WriteTo(contentWritable) + dspip.DeleteLastObject.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dspip.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStorePersistenceInitParam from the given readable +func (dspip *DataStorePersistenceInitParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dspip.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePersistenceInitParam header. %s", err.Error()) + } + + err = dspip.PersistenceSlotID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePersistenceInitParam.PersistenceSlotID. %s", err.Error()) + } + + err = dspip.DeleteLastObject.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePersistenceInitParam.DeleteLastObject. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStorePersistenceInitParam +func (dspip *DataStorePersistenceInitParam) Copy() types.RVType { + copied := NewDataStorePersistenceInitParam() + + copied.StructureVersion = dspip.StructureVersion + copied.PersistenceSlotID = dspip.PersistenceSlotID.Copy().(*types.PrimitiveU16) + copied.DeleteLastObject = dspip.DeleteLastObject.Copy().(*types.PrimitiveBool) + + return copied +} + +// Equals checks if the given DataStorePersistenceInitParam contains the same data as the current DataStorePersistenceInitParam +func (dspip *DataStorePersistenceInitParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStorePersistenceInitParam); !ok { + return false + } + + other := o.(*DataStorePersistenceInitParam) + + if dspip.StructureVersion != other.StructureVersion { + return false + } + + if !dspip.PersistenceSlotID.Equals(other.PersistenceSlotID) { + return false + } + + return dspip.DeleteLastObject.Equals(other.DeleteLastObject) +} + +// String returns the string representation of the DataStorePersistenceInitParam +func (dspip *DataStorePersistenceInitParam) String() string { + return dspip.FormatToString(0) +} + +// FormatToString pretty-prints the DataStorePersistenceInitParam using the provided indentation level +func (dspip *DataStorePersistenceInitParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStorePersistenceInitParam{\n") + b.WriteString(fmt.Sprintf("%sPersistenceSlotID: %s,\n", indentationValues, dspip.PersistenceSlotID)) + b.WriteString(fmt.Sprintf("%sDeleteLastObject: %s,\n", indentationValues, dspip.DeleteLastObject)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStorePersistenceInitParam returns a new DataStorePersistenceInitParam +func NewDataStorePersistenceInitParam() *DataStorePersistenceInitParam { + dspip := &DataStorePersistenceInitParam{ + PersistenceSlotID: types.NewPrimitiveU16(0), + DeleteLastObject: types.NewPrimitiveBool(false), + } + + return dspip +} diff --git a/nex-protocols-go/datastore/types/datastore_persistence_target.go b/nex-protocols-go/datastore/types/datastore_persistence_target.go new file mode 100644 index 0000000..30901e9 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_persistence_target.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStorePersistenceTarget is a type within the DataStore protocol +type DataStorePersistenceTarget struct { + types.Structure + OwnerID *types.PID + PersistenceSlotID *types.PrimitiveU16 +} + +// WriteTo writes the DataStorePersistenceTarget to the given writable +func (dspt *DataStorePersistenceTarget) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dspt.OwnerID.WriteTo(contentWritable) + dspt.PersistenceSlotID.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dspt.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStorePersistenceTarget from the given readable +func (dspt *DataStorePersistenceTarget) ExtractFrom(readable types.Readable) error { + var err error + + err = dspt.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePersistenceTarget header. %s", err.Error()) + } + + err = dspt.OwnerID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePersistenceTarget.OwnerID. %s", err.Error()) + } + + err = dspt.PersistenceSlotID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePersistenceTarget.PersistenceSlotID. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStorePersistenceTarget +func (dspt *DataStorePersistenceTarget) Copy() types.RVType { + copied := NewDataStorePersistenceTarget() + + copied.StructureVersion = dspt.StructureVersion + copied.OwnerID = dspt.OwnerID.Copy().(*types.PID) + copied.PersistenceSlotID = dspt.PersistenceSlotID.Copy().(*types.PrimitiveU16) + + return copied +} + +// Equals checks if the given DataStorePersistenceTarget contains the same data as the current DataStorePersistenceTarget +func (dspt *DataStorePersistenceTarget) Equals(o types.RVType) bool { + if _, ok := o.(*DataStorePersistenceTarget); !ok { + return false + } + + other := o.(*DataStorePersistenceTarget) + + if dspt.StructureVersion != other.StructureVersion { + return false + } + + if !dspt.OwnerID.Equals(other.OwnerID) { + return false + } + + return dspt.PersistenceSlotID.Equals(other.PersistenceSlotID) +} + +// String returns the string representation of the DataStorePersistenceTarget +func (dspt *DataStorePersistenceTarget) String() string { + return dspt.FormatToString(0) +} + +// FormatToString pretty-prints the DataStorePersistenceTarget using the provided indentation level +func (dspt *DataStorePersistenceTarget) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStorePersistenceTarget{\n") + b.WriteString(fmt.Sprintf("%sOwnerID: %s,\n", indentationValues, dspt.OwnerID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPersistenceSlotID: %s,\n", indentationValues, dspt.PersistenceSlotID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStorePersistenceTarget returns a new DataStorePersistenceTarget +func NewDataStorePersistenceTarget() *DataStorePersistenceTarget { + dspt := &DataStorePersistenceTarget{ + OwnerID: types.NewPID(0), + PersistenceSlotID: types.NewPrimitiveU16(0), + } + + return dspt +} diff --git a/nex-protocols-go/datastore/types/datastore_prepare_get_param.go b/nex-protocols-go/datastore/types/datastore_prepare_get_param.go new file mode 100644 index 0000000..e5efebc --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_prepare_get_param.go @@ -0,0 +1,168 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStorePrepareGetParam is a type within the DataStore protocol +type DataStorePrepareGetParam struct { + types.Structure + DataID *types.PrimitiveU64 + LockID *types.PrimitiveU32 + PersistenceTarget *DataStorePersistenceTarget + AccessPassword *types.PrimitiveU64 + ExtraData *types.List[*types.String] // * NEX v3.5.0 +} + +// WriteTo writes the DataStorePrepareGetParam to the given writable +func (dspgp *DataStorePrepareGetParam) WriteTo(writable types.Writable) { + stream := writable.(*nex.ByteStreamOut) + libraryVersion := stream.LibraryVersions.DataStore + + contentWritable := writable.CopyNew() + + dspgp.DataID.WriteTo(contentWritable) + dspgp.LockID.WriteTo(contentWritable) + dspgp.PersistenceTarget.WriteTo(contentWritable) + dspgp.AccessPassword.WriteTo(contentWritable) + + if libraryVersion.GreaterOrEqual("3.5.0") { + dspgp.ExtraData.WriteTo(contentWritable) + } + + content := contentWritable.Bytes() + + dspgp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStorePrepareGetParam from the given readable +func (dspgp *DataStorePrepareGetParam) ExtractFrom(readable types.Readable) error { + stream := readable.(*nex.ByteStreamIn) + libraryVersion := stream.LibraryVersions.DataStore + + var err error + + err = dspgp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePrepareGetParam header. %s", err.Error()) + } + + err = dspgp.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePrepareGetParam.DataID. %s", err.Error()) + } + + err = dspgp.LockID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePrepareGetParam.LockID. %s", err.Error()) + } + + err = dspgp.PersistenceTarget.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePrepareGetParam.PersistenceTarget. %s", err.Error()) + } + + err = dspgp.AccessPassword.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePrepareGetParam.AccessPassword. %s", err.Error()) + } + + if libraryVersion.GreaterOrEqual("3.5.0") { + err = dspgp.ExtraData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePrepareGetParam.ExtraData. %s", err.Error()) + } + } + + return nil +} + +// Copy returns a new copied instance of DataStorePrepareGetParam +func (dspgp *DataStorePrepareGetParam) Copy() types.RVType { + copied := NewDataStorePrepareGetParam() + + copied.StructureVersion = dspgp.StructureVersion + copied.DataID = dspgp.DataID.Copy().(*types.PrimitiveU64) + copied.LockID = dspgp.LockID.Copy().(*types.PrimitiveU32) + copied.PersistenceTarget = dspgp.PersistenceTarget.Copy().(*DataStorePersistenceTarget) + copied.AccessPassword = dspgp.AccessPassword.Copy().(*types.PrimitiveU64) + copied.ExtraData = dspgp.ExtraData.Copy().(*types.List[*types.String]) + + return copied +} + +// Equals checks if the given DataStorePrepareGetParam contains the same data as the current DataStorePrepareGetParam +func (dspgp *DataStorePrepareGetParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStorePrepareGetParam); !ok { + return false + } + + other := o.(*DataStorePrepareGetParam) + + if dspgp.StructureVersion != other.StructureVersion { + return false + } + + if !dspgp.DataID.Equals(other.DataID) { + return false + } + + if !dspgp.LockID.Equals(other.LockID) { + return false + } + + if !dspgp.PersistenceTarget.Equals(other.PersistenceTarget) { + return false + } + + if !dspgp.AccessPassword.Equals(other.AccessPassword) { + return false + } + + return dspgp.ExtraData.Equals(other.ExtraData) +} + +// String returns the string representation of the DataStorePrepareGetParam +func (dspgp *DataStorePrepareGetParam) String() string { + return dspgp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStorePrepareGetParam using the provided indentation level +func (dspgp *DataStorePrepareGetParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStorePrepareGetParam{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dspgp.DataID)) + b.WriteString(fmt.Sprintf("%sLockID: %s,\n", indentationValues, dspgp.LockID)) + b.WriteString(fmt.Sprintf("%sPersistenceTarget: %s,\n", indentationValues, dspgp.PersistenceTarget.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sAccessPassword: %s,\n", indentationValues, dspgp.AccessPassword)) + b.WriteString(fmt.Sprintf("%sExtraData: %s,\n", indentationValues, dspgp.ExtraData)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStorePrepareGetParam returns a new DataStorePrepareGetParam +func NewDataStorePrepareGetParam() *DataStorePrepareGetParam { + dspgp := &DataStorePrepareGetParam{ + DataID: types.NewPrimitiveU64(0), + LockID: types.NewPrimitiveU32(0), + PersistenceTarget: NewDataStorePersistenceTarget(), + AccessPassword: types.NewPrimitiveU64(0), + ExtraData: types.NewList[*types.String](), + } + + dspgp.ExtraData.Type = types.NewString("") + + return dspgp +} diff --git a/nex-protocols-go/datastore/types/datastore_prepare_get_param_v1.go b/nex-protocols-go/datastore/types/datastore_prepare_get_param_v1.go new file mode 100644 index 0000000..4b27c05 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_prepare_get_param_v1.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStorePrepareGetParamV1 is a type within the DataStore protocol +type DataStorePrepareGetParamV1 struct { + types.Structure + DataID *types.PrimitiveU32 + LockID *types.PrimitiveU32 +} + +// WriteTo writes the DataStorePrepareGetParamV1 to the given writable +func (dspgpv *DataStorePrepareGetParamV1) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dspgpv.DataID.WriteTo(contentWritable) + dspgpv.LockID.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dspgpv.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStorePrepareGetParamV1 from the given readable +func (dspgpv *DataStorePrepareGetParamV1) ExtractFrom(readable types.Readable) error { + var err error + + err = dspgpv.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePrepareGetParamV1 header. %s", err.Error()) + } + + err = dspgpv.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePrepareGetParamV1.DataID. %s", err.Error()) + } + + err = dspgpv.LockID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePrepareGetParamV1.LockID. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStorePrepareGetParamV1 +func (dspgpv *DataStorePrepareGetParamV1) Copy() types.RVType { + copied := NewDataStorePrepareGetParamV1() + + copied.StructureVersion = dspgpv.StructureVersion + copied.DataID = dspgpv.DataID.Copy().(*types.PrimitiveU32) + copied.LockID = dspgpv.LockID.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given DataStorePrepareGetParamV1 contains the same data as the current DataStorePrepareGetParamV1 +func (dspgpv *DataStorePrepareGetParamV1) Equals(o types.RVType) bool { + if _, ok := o.(*DataStorePrepareGetParamV1); !ok { + return false + } + + other := o.(*DataStorePrepareGetParamV1) + + if dspgpv.StructureVersion != other.StructureVersion { + return false + } + + if !dspgpv.DataID.Equals(other.DataID) { + return false + } + + return dspgpv.LockID.Equals(other.LockID) +} + +// String returns the string representation of the DataStorePrepareGetParamV1 +func (dspgpv *DataStorePrepareGetParamV1) String() string { + return dspgpv.FormatToString(0) +} + +// FormatToString pretty-prints the DataStorePrepareGetParamV1 using the provided indentation level +func (dspgpv *DataStorePrepareGetParamV1) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStorePrepareGetParamV1{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dspgpv.DataID)) + b.WriteString(fmt.Sprintf("%sLockID: %s,\n", indentationValues, dspgpv.LockID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStorePrepareGetParamV1 returns a new DataStorePrepareGetParamV1 +func NewDataStorePrepareGetParamV1() *DataStorePrepareGetParamV1 { + dspgpv := &DataStorePrepareGetParamV1{ + DataID: types.NewPrimitiveU32(0), + LockID: types.NewPrimitiveU32(0), + } + + return dspgpv +} diff --git a/nex-protocols-go/datastore/types/datastore_prepare_post_param.go b/nex-protocols-go/datastore/types/datastore_prepare_post_param.go new file mode 100644 index 0000000..2c1f1ad --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_prepare_post_param.go @@ -0,0 +1,282 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStorePreparePostParam is a type within the DataStore protocol +type DataStorePreparePostParam struct { + types.Structure + Size *types.PrimitiveU32 + Name *types.String + DataType *types.PrimitiveU16 + MetaBinary *types.QBuffer + Permission *DataStorePermission + DelPermission *DataStorePermission + Flag *types.PrimitiveU32 + Period *types.PrimitiveU16 + ReferDataID *types.PrimitiveU32 + Tags *types.List[*types.String] + RatingInitParams *types.List[*DataStoreRatingInitParamWithSlot] + PersistenceInitParam *DataStorePersistenceInitParam + ExtraData *types.List[*types.String] // * NEX v3.5.0 +} + +// WriteTo writes the DataStorePreparePostParam to the given writable +func (dsppp *DataStorePreparePostParam) WriteTo(writable types.Writable) { + stream := writable.(*nex.ByteStreamOut) + libraryVersion := stream.LibraryVersions.DataStore + + contentWritable := writable.CopyNew() + + dsppp.Size.WriteTo(contentWritable) + dsppp.Name.WriteTo(contentWritable) + dsppp.DataType.WriteTo(contentWritable) + dsppp.MetaBinary.WriteTo(contentWritable) + dsppp.Permission.WriteTo(contentWritable) + dsppp.DelPermission.WriteTo(contentWritable) + dsppp.Flag.WriteTo(contentWritable) + dsppp.Period.WriteTo(contentWritable) + dsppp.ReferDataID.WriteTo(contentWritable) + dsppp.Tags.WriteTo(contentWritable) + dsppp.RatingInitParams.WriteTo(contentWritable) + dsppp.PersistenceInitParam.WriteTo(contentWritable) + + if libraryVersion.GreaterOrEqual("3.5.0") { + dsppp.ExtraData.WriteTo(contentWritable) + } + + content := contentWritable.Bytes() + + dsppp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStorePreparePostParam from the given readable +func (dsppp *DataStorePreparePostParam) ExtractFrom(readable types.Readable) error { + stream := readable.(*nex.ByteStreamIn) + libraryVersion := stream.LibraryVersions.DataStore + + var err error + + err = dsppp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParam header. %s", err.Error()) + } + + err = dsppp.Size.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParam.Size. %s", err.Error()) + } + + err = dsppp.Name.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParam.Name. %s", err.Error()) + } + + err = dsppp.DataType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParam.DataType. %s", err.Error()) + } + + err = dsppp.MetaBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParam.MetaBinary. %s", err.Error()) + } + + err = dsppp.Permission.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParam.Permission. %s", err.Error()) + } + + err = dsppp.DelPermission.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParam.DelPermission. %s", err.Error()) + } + + err = dsppp.Flag.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParam.Flag. %s", err.Error()) + } + + err = dsppp.Period.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParam.Period. %s", err.Error()) + } + + err = dsppp.ReferDataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParam.ReferDataID. %s", err.Error()) + } + + err = dsppp.Tags.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParam.Tags. %s", err.Error()) + } + + err = dsppp.RatingInitParams.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParam.RatingInitParams. %s", err.Error()) + } + + err = dsppp.PersistenceInitParam.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParam.PersistenceInitParam. %s", err.Error()) + } + + if libraryVersion.GreaterOrEqual("3.5.0") { + err = dsppp.ExtraData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParam.ExtraData. %s", err.Error()) + } + } + + return nil +} + +// Copy returns a new copied instance of DataStorePreparePostParam +func (dsppp *DataStorePreparePostParam) Copy() types.RVType { + copied := NewDataStorePreparePostParam() + + copied.StructureVersion = dsppp.StructureVersion + copied.Size = dsppp.Size.Copy().(*types.PrimitiveU32) + copied.Name = dsppp.Name.Copy().(*types.String) + copied.DataType = dsppp.DataType.Copy().(*types.PrimitiveU16) + copied.MetaBinary = dsppp.MetaBinary.Copy().(*types.QBuffer) + copied.Permission = dsppp.Permission.Copy().(*DataStorePermission) + copied.DelPermission = dsppp.DelPermission.Copy().(*DataStorePermission) + copied.Flag = dsppp.Flag.Copy().(*types.PrimitiveU32) + copied.Period = dsppp.Period.Copy().(*types.PrimitiveU16) + copied.ReferDataID = dsppp.ReferDataID.Copy().(*types.PrimitiveU32) + copied.Tags = dsppp.Tags.Copy().(*types.List[*types.String]) + copied.RatingInitParams = dsppp.RatingInitParams.Copy().(*types.List[*DataStoreRatingInitParamWithSlot]) + copied.PersistenceInitParam = dsppp.PersistenceInitParam.Copy().(*DataStorePersistenceInitParam) + copied.ExtraData = dsppp.ExtraData.Copy().(*types.List[*types.String]) + + return copied +} + +// Equals checks if the given DataStorePreparePostParam contains the same data as the current DataStorePreparePostParam +func (dsppp *DataStorePreparePostParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStorePreparePostParam); !ok { + return false + } + + other := o.(*DataStorePreparePostParam) + + if dsppp.StructureVersion != other.StructureVersion { + return false + } + + if !dsppp.Size.Equals(other.Size) { + return false + } + + if !dsppp.Name.Equals(other.Name) { + return false + } + + if !dsppp.DataType.Equals(other.DataType) { + return false + } + + if !dsppp.MetaBinary.Equals(other.MetaBinary) { + return false + } + + if !dsppp.Permission.Equals(other.Permission) { + return false + } + + if !dsppp.DelPermission.Equals(other.DelPermission) { + return false + } + + if !dsppp.Flag.Equals(other.Flag) { + return false + } + + if !dsppp.Period.Equals(other.Period) { + return false + } + + if !dsppp.ReferDataID.Equals(other.ReferDataID) { + return false + } + + if !dsppp.Tags.Equals(other.Tags) { + return false + } + + if !dsppp.RatingInitParams.Equals(other.RatingInitParams) { + return false + } + + if !dsppp.PersistenceInitParam.Equals(other.PersistenceInitParam) { + return false + } + + return dsppp.ExtraData.Equals(other.ExtraData) +} + +// String returns the string representation of the DataStorePreparePostParam +func (dsppp *DataStorePreparePostParam) String() string { + return dsppp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStorePreparePostParam using the provided indentation level +func (dsppp *DataStorePreparePostParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStorePreparePostParam{\n") + b.WriteString(fmt.Sprintf("%sSize: %s,\n", indentationValues, dsppp.Size)) + b.WriteString(fmt.Sprintf("%sName: %s,\n", indentationValues, dsppp.Name)) + b.WriteString(fmt.Sprintf("%sDataType: %s,\n", indentationValues, dsppp.DataType)) + b.WriteString(fmt.Sprintf("%sMetaBinary: %s,\n", indentationValues, dsppp.MetaBinary)) + b.WriteString(fmt.Sprintf("%sPermission: %s,\n", indentationValues, dsppp.Permission.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sDelPermission: %s,\n", indentationValues, dsppp.DelPermission.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sFlag: %s,\n", indentationValues, dsppp.Flag)) + b.WriteString(fmt.Sprintf("%sPeriod: %s,\n", indentationValues, dsppp.Period)) + b.WriteString(fmt.Sprintf("%sReferDataID: %s,\n", indentationValues, dsppp.ReferDataID)) + b.WriteString(fmt.Sprintf("%sTags: %s,\n", indentationValues, dsppp.Tags)) + b.WriteString(fmt.Sprintf("%sRatingInitParams: %s,\n", indentationValues, dsppp.RatingInitParams)) + b.WriteString(fmt.Sprintf("%sPersistenceInitParam: %s,\n", indentationValues, dsppp.PersistenceInitParam.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sExtraData: %s,\n", indentationValues, dsppp.ExtraData)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStorePreparePostParam returns a new DataStorePreparePostParam +func NewDataStorePreparePostParam() *DataStorePreparePostParam { + dsppp := &DataStorePreparePostParam{ + Size: types.NewPrimitiveU32(0), + Name: types.NewString(""), + DataType: types.NewPrimitiveU16(0), + MetaBinary: types.NewQBuffer(nil), + Permission: NewDataStorePermission(), + DelPermission: NewDataStorePermission(), + Flag: types.NewPrimitiveU32(0), + Period: types.NewPrimitiveU16(0), + ReferDataID: types.NewPrimitiveU32(0), + Tags: types.NewList[*types.String](), + RatingInitParams: types.NewList[*DataStoreRatingInitParamWithSlot](), + PersistenceInitParam: NewDataStorePersistenceInitParam(), + ExtraData: types.NewList[*types.String](), + } + + dsppp.Tags.Type = types.NewString("") + dsppp.RatingInitParams.Type = NewDataStoreRatingInitParamWithSlot() + dsppp.ExtraData.Type = types.NewString("") + + return dsppp +} diff --git a/nex-protocols-go/datastore/types/datastore_prepare_post_param_v1.go b/nex-protocols-go/datastore/types/datastore_prepare_post_param_v1.go new file mode 100644 index 0000000..edc3a16 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_prepare_post_param_v1.go @@ -0,0 +1,241 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStorePreparePostParamV1 is a type within the DataStore protocol +type DataStorePreparePostParamV1 struct { + types.Structure + Size *types.PrimitiveU32 + Name *types.String + DataType *types.PrimitiveU16 + MetaBinary *types.QBuffer + Permission *DataStorePermission + DelPermission *DataStorePermission + Flag *types.PrimitiveU32 + Period *types.PrimitiveU16 + ReferDataID *types.PrimitiveU32 + Tags *types.List[*types.String] + RatingInitParams *types.List[*DataStoreRatingInitParamWithSlot] +} + +// WriteTo writes the DataStorePreparePostParamV1 to the given writable +func (dspppv *DataStorePreparePostParamV1) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dspppv.Size.WriteTo(contentWritable) + dspppv.Name.WriteTo(contentWritable) + dspppv.DataType.WriteTo(contentWritable) + dspppv.MetaBinary.WriteTo(contentWritable) + dspppv.Permission.WriteTo(contentWritable) + dspppv.DelPermission.WriteTo(contentWritable) + dspppv.Flag.WriteTo(contentWritable) + dspppv.Period.WriteTo(contentWritable) + dspppv.ReferDataID.WriteTo(contentWritable) + dspppv.Tags.WriteTo(contentWritable) + dspppv.RatingInitParams.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dspppv.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStorePreparePostParamV1 from the given readable +func (dspppv *DataStorePreparePostParamV1) ExtractFrom(readable types.Readable) error { + var err error + + err = dspppv.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParamV1 header. %s", err.Error()) + } + + err = dspppv.Size.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParamV1.Size. %s", err.Error()) + } + + err = dspppv.Name.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParamV1.Name. %s", err.Error()) + } + + err = dspppv.DataType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParamV1.DataType. %s", err.Error()) + } + + err = dspppv.MetaBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParamV1.MetaBinary. %s", err.Error()) + } + + err = dspppv.Permission.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParamV1.Permission. %s", err.Error()) + } + + err = dspppv.DelPermission.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParamV1.DelPermission. %s", err.Error()) + } + + err = dspppv.Flag.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParamV1.Flag. %s", err.Error()) + } + + err = dspppv.Period.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParamV1.Period. %s", err.Error()) + } + + err = dspppv.ReferDataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParamV1.ReferDataID. %s", err.Error()) + } + + err = dspppv.Tags.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParamV1.Tags. %s", err.Error()) + } + + err = dspppv.RatingInitParams.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePreparePostParamV1.RatingInitParams. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStorePreparePostParamV1 +func (dspppv *DataStorePreparePostParamV1) Copy() types.RVType { + copied := NewDataStorePreparePostParamV1() + + copied.StructureVersion = dspppv.StructureVersion + copied.Size = dspppv.Size.Copy().(*types.PrimitiveU32) + copied.Name = dspppv.Name.Copy().(*types.String) + copied.DataType = dspppv.DataType.Copy().(*types.PrimitiveU16) + copied.MetaBinary = dspppv.MetaBinary.Copy().(*types.QBuffer) + copied.Permission = dspppv.Permission.Copy().(*DataStorePermission) + copied.DelPermission = dspppv.DelPermission.Copy().(*DataStorePermission) + copied.Flag = dspppv.Flag.Copy().(*types.PrimitiveU32) + copied.Period = dspppv.Period.Copy().(*types.PrimitiveU16) + copied.ReferDataID = dspppv.ReferDataID.Copy().(*types.PrimitiveU32) + copied.Tags = dspppv.Tags.Copy().(*types.List[*types.String]) + copied.RatingInitParams = dspppv.RatingInitParams.Copy().(*types.List[*DataStoreRatingInitParamWithSlot]) + + return copied +} + +// Equals checks if the given DataStorePreparePostParamV1 contains the same data as the current DataStorePreparePostParamV1 +func (dspppv *DataStorePreparePostParamV1) Equals(o types.RVType) bool { + if _, ok := o.(*DataStorePreparePostParamV1); !ok { + return false + } + + other := o.(*DataStorePreparePostParamV1) + + if dspppv.StructureVersion != other.StructureVersion { + return false + } + + if !dspppv.Size.Equals(other.Size) { + return false + } + + if !dspppv.Name.Equals(other.Name) { + return false + } + + if !dspppv.DataType.Equals(other.DataType) { + return false + } + + if !dspppv.MetaBinary.Equals(other.MetaBinary) { + return false + } + + if !dspppv.Permission.Equals(other.Permission) { + return false + } + + if !dspppv.DelPermission.Equals(other.DelPermission) { + return false + } + + if !dspppv.Flag.Equals(other.Flag) { + return false + } + + if !dspppv.Period.Equals(other.Period) { + return false + } + + if !dspppv.ReferDataID.Equals(other.ReferDataID) { + return false + } + + if !dspppv.Tags.Equals(other.Tags) { + return false + } + + return dspppv.RatingInitParams.Equals(other.RatingInitParams) +} + +// String returns the string representation of the DataStorePreparePostParamV1 +func (dspppv *DataStorePreparePostParamV1) String() string { + return dspppv.FormatToString(0) +} + +// FormatToString pretty-prints the DataStorePreparePostParamV1 using the provided indentation level +func (dspppv *DataStorePreparePostParamV1) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStorePreparePostParamV1{\n") + b.WriteString(fmt.Sprintf("%sSize: %s,\n", indentationValues, dspppv.Size)) + b.WriteString(fmt.Sprintf("%sName: %s,\n", indentationValues, dspppv.Name)) + b.WriteString(fmt.Sprintf("%sDataType: %s,\n", indentationValues, dspppv.DataType)) + b.WriteString(fmt.Sprintf("%sMetaBinary: %s,\n", indentationValues, dspppv.MetaBinary)) + b.WriteString(fmt.Sprintf("%sPermission: %s,\n", indentationValues, dspppv.Permission.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sDelPermission: %s,\n", indentationValues, dspppv.DelPermission.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sFlag: %s,\n", indentationValues, dspppv.Flag)) + b.WriteString(fmt.Sprintf("%sPeriod: %s,\n", indentationValues, dspppv.Period)) + b.WriteString(fmt.Sprintf("%sReferDataID: %s,\n", indentationValues, dspppv.ReferDataID)) + b.WriteString(fmt.Sprintf("%sTags: %s,\n", indentationValues, dspppv.Tags)) + b.WriteString(fmt.Sprintf("%sRatingInitParams: %s,\n", indentationValues, dspppv.RatingInitParams)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStorePreparePostParamV1 returns a new DataStorePreparePostParamV1 +func NewDataStorePreparePostParamV1() *DataStorePreparePostParamV1 { + dspppv := &DataStorePreparePostParamV1{ + Size: types.NewPrimitiveU32(0), + Name: types.NewString(""), + DataType: types.NewPrimitiveU16(0), + MetaBinary: types.NewQBuffer(nil), + Permission: NewDataStorePermission(), + DelPermission: NewDataStorePermission(), + Flag: types.NewPrimitiveU32(0), + Period: types.NewPrimitiveU16(0), + ReferDataID: types.NewPrimitiveU32(0), + Tags: types.NewList[*types.String](), + RatingInitParams: types.NewList[*DataStoreRatingInitParamWithSlot](), + } + + dspppv.Tags.Type = types.NewString("") + dspppv.RatingInitParams.Type = NewDataStoreRatingInitParamWithSlot() + + return dspppv +} diff --git a/nex-protocols-go/datastore/types/datastore_prepare_update_param.go b/nex-protocols-go/datastore/types/datastore_prepare_update_param.go new file mode 100644 index 0000000..55922ce --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_prepare_update_param.go @@ -0,0 +1,173 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStorePrepareUpdateParam is a type within the DataStore protocol +type DataStorePrepareUpdateParam struct { + types.Structure + DataID *types.PrimitiveU64 + Size *types.PrimitiveU32 + UpdatePassword *types.PrimitiveU64 // * NEX v3.0.0 + ExtraData *types.List[*types.String] // * NEX v3.5.0 +} + +// WriteTo writes the DataStorePrepareUpdateParam to the given writable +func (dspup *DataStorePrepareUpdateParam) WriteTo(writable types.Writable) { + stream := writable.(*nex.ByteStreamOut) + libraryVersion := stream.LibraryVersions.DataStore + + contentWritable := writable.CopyNew() + + if libraryVersion.GreaterOrEqual("3.0.0") { + dspup.DataID.WriteTo(contentWritable) + } else { + contentWritable.WritePrimitiveUInt32LE(uint32(dspup.DataID.Value)) + } + + dspup.Size.WriteTo(contentWritable) + + if libraryVersion.GreaterOrEqual("3.0.0") { + dspup.UpdatePassword.WriteTo(contentWritable) + } + + if libraryVersion.GreaterOrEqual("3.5.0") { + dspup.ExtraData.WriteTo(contentWritable) + } + + content := contentWritable.Bytes() + + dspup.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStorePrepareUpdateParam from the given readable +func (dspup *DataStorePrepareUpdateParam) ExtractFrom(readable types.Readable) error { + stream := readable.(*nex.ByteStreamIn) + libraryVersion := stream.LibraryVersions.DataStore + + var err error + + err = dspup.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePrepareUpdateParam header. %s", err.Error()) + } + + if libraryVersion.GreaterOrEqual("3.0.0") { + err = dspup.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompleteUpdateParam.DataID. %s", err.Error()) + } + } else { + dataID, err := readable.ReadPrimitiveUInt32LE() + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompleteUpdateParam.DataID. %s", err.Error()) + } + + dspup.DataID.Value = uint64(dataID) + } + + err = dspup.Size.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePrepareUpdateParam.Size. %s", err.Error()) + } + + if libraryVersion.GreaterOrEqual("3.0.0") { + err = dspup.UpdatePassword.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePrepareUpdateParam.UpdatePassword. %s", err.Error()) + } + } + + if libraryVersion.GreaterOrEqual("3.5.0") { + err = dspup.ExtraData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStorePrepareUpdateParam.ExtraData. %s", err.Error()) + } + } + + return nil +} + +// Copy returns a new copied instance of DataStorePrepareUpdateParam +func (dspup *DataStorePrepareUpdateParam) Copy() types.RVType { + copied := NewDataStorePrepareUpdateParam() + + copied.StructureVersion = dspup.StructureVersion + copied.DataID = dspup.DataID.Copy().(*types.PrimitiveU64) + copied.Size = dspup.Size.Copy().(*types.PrimitiveU32) + copied.UpdatePassword = dspup.UpdatePassword.Copy().(*types.PrimitiveU64) + copied.ExtraData = dspup.ExtraData.Copy().(*types.List[*types.String]) + + return copied +} + +// Equals checks if the given DataStorePrepareUpdateParam contains the same data as the current DataStorePrepareUpdateParam +func (dspup *DataStorePrepareUpdateParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStorePrepareUpdateParam); !ok { + return false + } + + other := o.(*DataStorePrepareUpdateParam) + + if dspup.StructureVersion != other.StructureVersion { + return false + } + + if !dspup.DataID.Equals(other.DataID) { + return false + } + + if !dspup.Size.Equals(other.Size) { + return false + } + + if !dspup.UpdatePassword.Equals(other.UpdatePassword) { + return false + } + + return dspup.ExtraData.Equals(other.ExtraData) +} + +// String returns the string representation of the DataStorePrepareUpdateParam +func (dspup *DataStorePrepareUpdateParam) String() string { + return dspup.FormatToString(0) +} + +// FormatToString pretty-prints the DataStorePrepareUpdateParam using the provided indentation level +func (dspup *DataStorePrepareUpdateParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStorePrepareUpdateParam{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dspup.DataID)) + b.WriteString(fmt.Sprintf("%sSize: %s,\n", indentationValues, dspup.Size)) + b.WriteString(fmt.Sprintf("%sUpdatePassword: %s,\n", indentationValues, dspup.UpdatePassword)) + b.WriteString(fmt.Sprintf("%sExtraData: %s,\n", indentationValues, dspup.ExtraData)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStorePrepareUpdateParam returns a new DataStorePrepareUpdateParam +func NewDataStorePrepareUpdateParam() *DataStorePrepareUpdateParam { + dspup := &DataStorePrepareUpdateParam{ + DataID: types.NewPrimitiveU64(0), + Size: types.NewPrimitiveU32(0), + UpdatePassword: types.NewPrimitiveU64(0), + ExtraData: types.NewList[*types.String](), + } + + dspup.ExtraData.Type = types.NewString("") + + return dspup +} diff --git a/nex-protocols-go/datastore/types/datastore_rate_object_param.go b/nex-protocols-go/datastore/types/datastore_rate_object_param.go new file mode 100644 index 0000000..0e5eb76 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_rate_object_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreRateObjectParam is a type within the DataStore protocol +type DataStoreRateObjectParam struct { + types.Structure + RatingValue *types.PrimitiveS32 + AccessPassword *types.PrimitiveU64 +} + +// WriteTo writes the DataStoreRateObjectParam to the given writable +func (dsrop *DataStoreRateObjectParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsrop.RatingValue.WriteTo(contentWritable) + dsrop.AccessPassword.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsrop.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreRateObjectParam from the given readable +func (dsrop *DataStoreRateObjectParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsrop.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRateObjectParam header. %s", err.Error()) + } + + err = dsrop.RatingValue.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRateObjectParam.RatingValue. %s", err.Error()) + } + + err = dsrop.AccessPassword.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRateObjectParam.AccessPassword. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreRateObjectParam +func (dsrop *DataStoreRateObjectParam) Copy() types.RVType { + copied := NewDataStoreRateObjectParam() + + copied.StructureVersion = dsrop.StructureVersion + copied.RatingValue = dsrop.RatingValue.Copy().(*types.PrimitiveS32) + copied.AccessPassword = dsrop.AccessPassword.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given DataStoreRateObjectParam contains the same data as the current DataStoreRateObjectParam +func (dsrop *DataStoreRateObjectParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreRateObjectParam); !ok { + return false + } + + other := o.(*DataStoreRateObjectParam) + + if dsrop.StructureVersion != other.StructureVersion { + return false + } + + if !dsrop.RatingValue.Equals(other.RatingValue) { + return false + } + + return dsrop.AccessPassword.Equals(other.AccessPassword) +} + +// String returns the string representation of the DataStoreRateObjectParam +func (dsrop *DataStoreRateObjectParam) String() string { + return dsrop.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreRateObjectParam using the provided indentation level +func (dsrop *DataStoreRateObjectParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreRateObjectParam{\n") + b.WriteString(fmt.Sprintf("%sRatingValue: %s,\n", indentationValues, dsrop.RatingValue)) + b.WriteString(fmt.Sprintf("%sAccessPassword: %s,\n", indentationValues, dsrop.AccessPassword)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreRateObjectParam returns a new DataStoreRateObjectParam +func NewDataStoreRateObjectParam() *DataStoreRateObjectParam { + dsrop := &DataStoreRateObjectParam{ + RatingValue: types.NewPrimitiveS32(0), + AccessPassword: types.NewPrimitiveU64(0), + } + + return dsrop +} diff --git a/nex-protocols-go/datastore/types/datastore_rating_info.go b/nex-protocols-go/datastore/types/datastore_rating_info.go new file mode 100644 index 0000000..2157a98 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_rating_info.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreRatingInfo is a type within the DataStore protocol +type DataStoreRatingInfo struct { + types.Structure + TotalValue *types.PrimitiveS64 + Count *types.PrimitiveU32 + InitialValue *types.PrimitiveS64 +} + +// WriteTo writes the DataStoreRatingInfo to the given writable +func (dsri *DataStoreRatingInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsri.TotalValue.WriteTo(contentWritable) + dsri.Count.WriteTo(contentWritable) + dsri.InitialValue.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsri.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreRatingInfo from the given readable +func (dsri *DataStoreRatingInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = dsri.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInfo header. %s", err.Error()) + } + + err = dsri.TotalValue.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInfo.TotalValue. %s", err.Error()) + } + + err = dsri.Count.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInfo.Count. %s", err.Error()) + } + + err = dsri.InitialValue.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInfo.InitialValue. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreRatingInfo +func (dsri *DataStoreRatingInfo) Copy() types.RVType { + copied := NewDataStoreRatingInfo() + + copied.StructureVersion = dsri.StructureVersion + copied.TotalValue = dsri.TotalValue.Copy().(*types.PrimitiveS64) + copied.Count = dsri.Count.Copy().(*types.PrimitiveU32) + copied.InitialValue = dsri.InitialValue.Copy().(*types.PrimitiveS64) + + return copied +} + +// Equals checks if the given DataStoreRatingInfo contains the same data as the current DataStoreRatingInfo +func (dsri *DataStoreRatingInfo) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreRatingInfo); !ok { + return false + } + + other := o.(*DataStoreRatingInfo) + + if dsri.StructureVersion != other.StructureVersion { + return false + } + + if !dsri.TotalValue.Equals(other.TotalValue) { + return false + } + + if !dsri.Count.Equals(other.Count) { + return false + } + + return dsri.InitialValue.Equals(other.InitialValue) +} + +// String returns the string representation of the DataStoreRatingInfo +func (dsri *DataStoreRatingInfo) String() string { + return dsri.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreRatingInfo using the provided indentation level +func (dsri *DataStoreRatingInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreRatingInfo{\n") + b.WriteString(fmt.Sprintf("%sTotalValue: %s,\n", indentationValues, dsri.TotalValue)) + b.WriteString(fmt.Sprintf("%sCount: %s,\n", indentationValues, dsri.Count)) + b.WriteString(fmt.Sprintf("%sInitialValue: %s,\n", indentationValues, dsri.InitialValue)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreRatingInfo returns a new DataStoreRatingInfo +func NewDataStoreRatingInfo() *DataStoreRatingInfo { + dsri := &DataStoreRatingInfo{ + TotalValue: types.NewPrimitiveS64(0), + Count: types.NewPrimitiveU32(0), + InitialValue: types.NewPrimitiveS64(0), + } + + return dsri +} diff --git a/nex-protocols-go/datastore/types/datastore_rating_info_with_slot.go b/nex-protocols-go/datastore/types/datastore_rating_info_with_slot.go new file mode 100644 index 0000000..bbf6700 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_rating_info_with_slot.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreRatingInfoWithSlot is a type within the DataStore protocol +type DataStoreRatingInfoWithSlot struct { + types.Structure + Slot *types.PrimitiveS8 + Rating *DataStoreRatingInfo +} + +// WriteTo writes the DataStoreRatingInfoWithSlot to the given writable +func (dsriws *DataStoreRatingInfoWithSlot) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsriws.Slot.WriteTo(contentWritable) + dsriws.Rating.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsriws.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreRatingInfoWithSlot from the given readable +func (dsriws *DataStoreRatingInfoWithSlot) ExtractFrom(readable types.Readable) error { + var err error + + err = dsriws.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInfoWithSlot header. %s", err.Error()) + } + + err = dsriws.Slot.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInfoWithSlot.Slot. %s", err.Error()) + } + + err = dsriws.Rating.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInfoWithSlot.Rating. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreRatingInfoWithSlot +func (dsriws *DataStoreRatingInfoWithSlot) Copy() types.RVType { + copied := NewDataStoreRatingInfoWithSlot() + + copied.StructureVersion = dsriws.StructureVersion + copied.Slot = dsriws.Slot.Copy().(*types.PrimitiveS8) + copied.Rating = dsriws.Rating.Copy().(*DataStoreRatingInfo) + + return copied +} + +// Equals checks if the given DataStoreRatingInfoWithSlot contains the same data as the current DataStoreRatingInfoWithSlot +func (dsriws *DataStoreRatingInfoWithSlot) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreRatingInfoWithSlot); !ok { + return false + } + + other := o.(*DataStoreRatingInfoWithSlot) + + if dsriws.StructureVersion != other.StructureVersion { + return false + } + + if !dsriws.Slot.Equals(other.Slot) { + return false + } + + return dsriws.Rating.Equals(other.Rating) +} + +// String returns the string representation of the DataStoreRatingInfoWithSlot +func (dsriws *DataStoreRatingInfoWithSlot) String() string { + return dsriws.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreRatingInfoWithSlot using the provided indentation level +func (dsriws *DataStoreRatingInfoWithSlot) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreRatingInfoWithSlot{\n") + b.WriteString(fmt.Sprintf("%sSlot: %s,\n", indentationValues, dsriws.Slot)) + b.WriteString(fmt.Sprintf("%sRating: %s,\n", indentationValues, dsriws.Rating.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreRatingInfoWithSlot returns a new DataStoreRatingInfoWithSlot +func NewDataStoreRatingInfoWithSlot() *DataStoreRatingInfoWithSlot { + dsriws := &DataStoreRatingInfoWithSlot{ + Slot: types.NewPrimitiveS8(0), + Rating: NewDataStoreRatingInfo(), + } + + return dsriws +} diff --git a/nex-protocols-go/datastore/types/datastore_rating_init_param.go b/nex-protocols-go/datastore/types/datastore_rating_init_param.go new file mode 100644 index 0000000..32f02bc --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_rating_init_param.go @@ -0,0 +1,196 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreRatingInitParam is a type within the DataStore protocol +type DataStoreRatingInitParam struct { + types.Structure + Flag *types.PrimitiveU8 + InternalFlag *types.PrimitiveU8 + LockType *types.PrimitiveU8 + InitialValue *types.PrimitiveS64 + RangeMin *types.PrimitiveS32 + RangeMax *types.PrimitiveS32 + PeriodHour *types.PrimitiveS8 + PeriodDuration *types.PrimitiveS16 +} + +// WriteTo writes the DataStoreRatingInitParam to the given writable +func (dsrip *DataStoreRatingInitParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsrip.Flag.WriteTo(contentWritable) + dsrip.InternalFlag.WriteTo(contentWritable) + dsrip.LockType.WriteTo(contentWritable) + dsrip.InitialValue.WriteTo(contentWritable) + dsrip.RangeMin.WriteTo(contentWritable) + dsrip.RangeMax.WriteTo(contentWritable) + dsrip.PeriodHour.WriteTo(contentWritable) + dsrip.PeriodDuration.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsrip.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreRatingInitParam from the given readable +func (dsrip *DataStoreRatingInitParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dsrip.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInitParam header. %s", err.Error()) + } + + err = dsrip.Flag.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInitParam.Flag. %s", err.Error()) + } + + err = dsrip.InternalFlag.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInitParam.InternalFlag. %s", err.Error()) + } + + err = dsrip.LockType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInitParam.LockType. %s", err.Error()) + } + + err = dsrip.InitialValue.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInitParam.InitialValue. %s", err.Error()) + } + + err = dsrip.RangeMin.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInitParam.RangeMin. %s", err.Error()) + } + + err = dsrip.RangeMax.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInitParam.RangeMax. %s", err.Error()) + } + + err = dsrip.PeriodHour.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInitParam.PeriodHour. %s", err.Error()) + } + + err = dsrip.PeriodDuration.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInitParam.PeriodDuration. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreRatingInitParam +func (dsrip *DataStoreRatingInitParam) Copy() types.RVType { + copied := NewDataStoreRatingInitParam() + + copied.StructureVersion = dsrip.StructureVersion + copied.Flag = dsrip.Flag.Copy().(*types.PrimitiveU8) + copied.InternalFlag = dsrip.InternalFlag.Copy().(*types.PrimitiveU8) + copied.LockType = dsrip.LockType.Copy().(*types.PrimitiveU8) + copied.InitialValue = dsrip.InitialValue.Copy().(*types.PrimitiveS64) + copied.RangeMin = dsrip.RangeMin.Copy().(*types.PrimitiveS32) + copied.RangeMax = dsrip.RangeMax.Copy().(*types.PrimitiveS32) + copied.PeriodHour = dsrip.PeriodHour.Copy().(*types.PrimitiveS8) + copied.PeriodDuration = dsrip.PeriodDuration.Copy().(*types.PrimitiveS16) + + return copied +} + +// Equals checks if the given DataStoreRatingInitParam contains the same data as the current DataStoreRatingInitParam +func (dsrip *DataStoreRatingInitParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreRatingInitParam); !ok { + return false + } + + other := o.(*DataStoreRatingInitParam) + + if dsrip.StructureVersion != other.StructureVersion { + return false + } + + if !dsrip.Flag.Equals(other.Flag) { + return false + } + + if !dsrip.InternalFlag.Equals(other.InternalFlag) { + return false + } + + if !dsrip.LockType.Equals(other.LockType) { + return false + } + + if !dsrip.InitialValue.Equals(other.InitialValue) { + return false + } + + if !dsrip.RangeMin.Equals(other.RangeMin) { + return false + } + + if !dsrip.RangeMax.Equals(other.RangeMax) { + return false + } + + if !dsrip.PeriodHour.Equals(other.PeriodHour) { + return false + } + + return dsrip.PeriodDuration.Equals(other.PeriodDuration) +} + +// String returns the string representation of the DataStoreRatingInitParam +func (dsrip *DataStoreRatingInitParam) String() string { + return dsrip.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreRatingInitParam using the provided indentation level +func (dsrip *DataStoreRatingInitParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreRatingInitParam{\n") + b.WriteString(fmt.Sprintf("%sFlag: %s,\n", indentationValues, dsrip.Flag)) + b.WriteString(fmt.Sprintf("%sInternalFlag: %s,\n", indentationValues, dsrip.InternalFlag)) + b.WriteString(fmt.Sprintf("%sLockType: %s,\n", indentationValues, dsrip.LockType)) + b.WriteString(fmt.Sprintf("%sInitialValue: %s,\n", indentationValues, dsrip.InitialValue)) + b.WriteString(fmt.Sprintf("%sRangeMin: %s,\n", indentationValues, dsrip.RangeMin)) + b.WriteString(fmt.Sprintf("%sRangeMax: %s,\n", indentationValues, dsrip.RangeMax)) + b.WriteString(fmt.Sprintf("%sPeriodHour: %s,\n", indentationValues, dsrip.PeriodHour)) + b.WriteString(fmt.Sprintf("%sPeriodDuration: %s,\n", indentationValues, dsrip.PeriodDuration)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreRatingInitParam returns a new DataStoreRatingInitParam +func NewDataStoreRatingInitParam() *DataStoreRatingInitParam { + dsrip := &DataStoreRatingInitParam{ + Flag: types.NewPrimitiveU8(0), + InternalFlag: types.NewPrimitiveU8(0), + LockType: types.NewPrimitiveU8(0), + InitialValue: types.NewPrimitiveS64(0), + RangeMin: types.NewPrimitiveS32(0), + RangeMax: types.NewPrimitiveS32(0), + PeriodHour: types.NewPrimitiveS8(0), + PeriodDuration: types.NewPrimitiveS16(0), + } + + return dsrip +} diff --git a/nex-protocols-go/datastore/types/datastore_rating_init_param_with_slot.go b/nex-protocols-go/datastore/types/datastore_rating_init_param_with_slot.go new file mode 100644 index 0000000..87c3757 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_rating_init_param_with_slot.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreRatingInitParamWithSlot is a type within the DataStore protocol +type DataStoreRatingInitParamWithSlot struct { + types.Structure + Slot *types.PrimitiveS8 + Param *DataStoreRatingInitParam +} + +// WriteTo writes the DataStoreRatingInitParamWithSlot to the given writable +func (dsripws *DataStoreRatingInitParamWithSlot) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsripws.Slot.WriteTo(contentWritable) + dsripws.Param.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsripws.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreRatingInitParamWithSlot from the given readable +func (dsripws *DataStoreRatingInitParamWithSlot) ExtractFrom(readable types.Readable) error { + var err error + + err = dsripws.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInitParamWithSlot header. %s", err.Error()) + } + + err = dsripws.Slot.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInitParamWithSlot.Slot. %s", err.Error()) + } + + err = dsripws.Param.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingInitParamWithSlot.Param. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreRatingInitParamWithSlot +func (dsripws *DataStoreRatingInitParamWithSlot) Copy() types.RVType { + copied := NewDataStoreRatingInitParamWithSlot() + + copied.StructureVersion = dsripws.StructureVersion + copied.Slot = dsripws.Slot.Copy().(*types.PrimitiveS8) + copied.Param = dsripws.Param.Copy().(*DataStoreRatingInitParam) + + return copied +} + +// Equals checks if the given DataStoreRatingInitParamWithSlot contains the same data as the current DataStoreRatingInitParamWithSlot +func (dsripws *DataStoreRatingInitParamWithSlot) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreRatingInitParamWithSlot); !ok { + return false + } + + other := o.(*DataStoreRatingInitParamWithSlot) + + if dsripws.StructureVersion != other.StructureVersion { + return false + } + + if !dsripws.Slot.Equals(other.Slot) { + return false + } + + return dsripws.Param.Equals(other.Param) +} + +// String returns the string representation of the DataStoreRatingInitParamWithSlot +func (dsripws *DataStoreRatingInitParamWithSlot) String() string { + return dsripws.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreRatingInitParamWithSlot using the provided indentation level +func (dsripws *DataStoreRatingInitParamWithSlot) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreRatingInitParamWithSlot{\n") + b.WriteString(fmt.Sprintf("%sSlot: %s,\n", indentationValues, dsripws.Slot)) + b.WriteString(fmt.Sprintf("%sParam: %s,\n", indentationValues, dsripws.Param.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreRatingInitParamWithSlot returns a new DataStoreRatingInitParamWithSlot +func NewDataStoreRatingInitParamWithSlot() *DataStoreRatingInitParamWithSlot { + dsripws := &DataStoreRatingInitParamWithSlot{ + Slot: types.NewPrimitiveS8(0), + Param: NewDataStoreRatingInitParam(), + } + + return dsripws +} diff --git a/nex-protocols-go/datastore/types/datastore_rating_log.go b/nex-protocols-go/datastore/types/datastore_rating_log.go new file mode 100644 index 0000000..53bb90e --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_rating_log.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreRatingLog is a type within the DataStore protocol +type DataStoreRatingLog struct { + types.Structure + IsRated *types.PrimitiveBool + PID *types.PID + RatingValue *types.PrimitiveS32 + LockExpirationTime *types.DateTime +} + +// WriteTo writes the DataStoreRatingLog to the given writable +func (dsrl *DataStoreRatingLog) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsrl.IsRated.WriteTo(contentWritable) + dsrl.PID.WriteTo(contentWritable) + dsrl.RatingValue.WriteTo(contentWritable) + dsrl.LockExpirationTime.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsrl.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreRatingLog from the given readable +func (dsrl *DataStoreRatingLog) ExtractFrom(readable types.Readable) error { + var err error + + err = dsrl.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingLog header. %s", err.Error()) + } + + err = dsrl.IsRated.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingLog.IsRated. %s", err.Error()) + } + + err = dsrl.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingLog.PID. %s", err.Error()) + } + + err = dsrl.RatingValue.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingLog.RatingValue. %s", err.Error()) + } + + err = dsrl.LockExpirationTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingLog.LockExpirationTime. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreRatingLog +func (dsrl *DataStoreRatingLog) Copy() types.RVType { + copied := NewDataStoreRatingLog() + + copied.StructureVersion = dsrl.StructureVersion + copied.IsRated = dsrl.IsRated.Copy().(*types.PrimitiveBool) + copied.PID = dsrl.PID.Copy().(*types.PID) + copied.RatingValue = dsrl.RatingValue.Copy().(*types.PrimitiveS32) + copied.LockExpirationTime = dsrl.LockExpirationTime.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given DataStoreRatingLog contains the same data as the current DataStoreRatingLog +func (dsrl *DataStoreRatingLog) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreRatingLog); !ok { + return false + } + + other := o.(*DataStoreRatingLog) + + if dsrl.StructureVersion != other.StructureVersion { + return false + } + + if !dsrl.IsRated.Equals(other.IsRated) { + return false + } + + if !dsrl.PID.Equals(other.PID) { + return false + } + + if !dsrl.RatingValue.Equals(other.RatingValue) { + return false + } + + return dsrl.LockExpirationTime.Equals(other.LockExpirationTime) +} + +// String returns the string representation of the DataStoreRatingLog +func (dsrl *DataStoreRatingLog) String() string { + return dsrl.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreRatingLog using the provided indentation level +func (dsrl *DataStoreRatingLog) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreRatingLog{\n") + b.WriteString(fmt.Sprintf("%sIsRated: %s,\n", indentationValues, dsrl.IsRated)) + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, dsrl.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sRatingValue: %s,\n", indentationValues, dsrl.RatingValue)) + b.WriteString(fmt.Sprintf("%sLockExpirationTime: %s,\n", indentationValues, dsrl.LockExpirationTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreRatingLog returns a new DataStoreRatingLog +func NewDataStoreRatingLog() *DataStoreRatingLog { + dsrl := &DataStoreRatingLog{ + IsRated: types.NewPrimitiveBool(false), + PID: types.NewPID(0), + RatingValue: types.NewPrimitiveS32(0), + LockExpirationTime: types.NewDateTime(0), + } + + return dsrl +} diff --git a/nex-protocols-go/datastore/types/datastore_rating_target.go b/nex-protocols-go/datastore/types/datastore_rating_target.go new file mode 100644 index 0000000..ad8040f --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_rating_target.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreRatingTarget is a type within the DataStore protocol +type DataStoreRatingTarget struct { + types.Structure + DataID *types.PrimitiveU64 + Slot *types.PrimitiveU8 +} + +// WriteTo writes the DataStoreRatingTarget to the given writable +func (dsrt *DataStoreRatingTarget) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsrt.DataID.WriteTo(contentWritable) + dsrt.Slot.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsrt.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreRatingTarget from the given readable +func (dsrt *DataStoreRatingTarget) ExtractFrom(readable types.Readable) error { + var err error + + err = dsrt.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingTarget header. %s", err.Error()) + } + + err = dsrt.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingTarget.DataID. %s", err.Error()) + } + + err = dsrt.Slot.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreRatingTarget.Slot. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreRatingTarget +func (dsrt *DataStoreRatingTarget) Copy() types.RVType { + copied := NewDataStoreRatingTarget() + + copied.StructureVersion = dsrt.StructureVersion + copied.DataID = dsrt.DataID.Copy().(*types.PrimitiveU64) + copied.Slot = dsrt.Slot.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given DataStoreRatingTarget contains the same data as the current DataStoreRatingTarget +func (dsrt *DataStoreRatingTarget) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreRatingTarget); !ok { + return false + } + + other := o.(*DataStoreRatingTarget) + + if dsrt.StructureVersion != other.StructureVersion { + return false + } + + if !dsrt.DataID.Equals(other.DataID) { + return false + } + + return dsrt.Slot.Equals(other.Slot) +} + +// String returns the string representation of the DataStoreRatingTarget +func (dsrt *DataStoreRatingTarget) String() string { + return dsrt.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreRatingTarget using the provided indentation level +func (dsrt *DataStoreRatingTarget) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreRatingTarget{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dsrt.DataID)) + b.WriteString(fmt.Sprintf("%sSlot: %s,\n", indentationValues, dsrt.Slot)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreRatingTarget returns a new DataStoreRatingTarget +func NewDataStoreRatingTarget() *DataStoreRatingTarget { + dsrt := &DataStoreRatingTarget{ + DataID: types.NewPrimitiveU64(0), + Slot: types.NewPrimitiveU8(0), + } + + return dsrt +} diff --git a/nex-protocols-go/datastore/types/datastore_req_get_additional_meta.go b/nex-protocols-go/datastore/types/datastore_req_get_additional_meta.go new file mode 100644 index 0000000..d471767 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_req_get_additional_meta.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreReqGetAdditionalMeta is a type within the DataStore protocol +type DataStoreReqGetAdditionalMeta struct { + types.Structure + OwnerID *types.PID + DataType *types.PrimitiveU16 + Version *types.PrimitiveU16 + MetaBinary *types.QBuffer +} + +// WriteTo writes the DataStoreReqGetAdditionalMeta to the given writable +func (dsrgam *DataStoreReqGetAdditionalMeta) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsrgam.OwnerID.WriteTo(contentWritable) + dsrgam.DataType.WriteTo(contentWritable) + dsrgam.Version.WriteTo(contentWritable) + dsrgam.MetaBinary.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsrgam.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreReqGetAdditionalMeta from the given readable +func (dsrgam *DataStoreReqGetAdditionalMeta) ExtractFrom(readable types.Readable) error { + var err error + + err = dsrgam.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetAdditionalMeta header. %s", err.Error()) + } + + err = dsrgam.OwnerID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetAdditionalMeta.OwnerID. %s", err.Error()) + } + + err = dsrgam.DataType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetAdditionalMeta.DataType. %s", err.Error()) + } + + err = dsrgam.Version.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetAdditionalMeta.Version. %s", err.Error()) + } + + err = dsrgam.MetaBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetAdditionalMeta.MetaBinary. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreReqGetAdditionalMeta +func (dsrgam *DataStoreReqGetAdditionalMeta) Copy() types.RVType { + copied := NewDataStoreReqGetAdditionalMeta() + + copied.StructureVersion = dsrgam.StructureVersion + copied.OwnerID = dsrgam.OwnerID.Copy().(*types.PID) + copied.DataType = dsrgam.DataType.Copy().(*types.PrimitiveU16) + copied.Version = dsrgam.Version.Copy().(*types.PrimitiveU16) + copied.MetaBinary = dsrgam.MetaBinary.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given DataStoreReqGetAdditionalMeta contains the same data as the current DataStoreReqGetAdditionalMeta +func (dsrgam *DataStoreReqGetAdditionalMeta) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreReqGetAdditionalMeta); !ok { + return false + } + + other := o.(*DataStoreReqGetAdditionalMeta) + + if dsrgam.StructureVersion != other.StructureVersion { + return false + } + + if !dsrgam.OwnerID.Equals(other.OwnerID) { + return false + } + + if !dsrgam.DataType.Equals(other.DataType) { + return false + } + + if !dsrgam.Version.Equals(other.Version) { + return false + } + + return dsrgam.MetaBinary.Equals(other.MetaBinary) +} + +// String returns the string representation of the DataStoreReqGetAdditionalMeta +func (dsrgam *DataStoreReqGetAdditionalMeta) String() string { + return dsrgam.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreReqGetAdditionalMeta using the provided indentation level +func (dsrgam *DataStoreReqGetAdditionalMeta) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreReqGetAdditionalMeta{\n") + b.WriteString(fmt.Sprintf("%sOwnerID: %s,\n", indentationValues, dsrgam.OwnerID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sDataType: %s,\n", indentationValues, dsrgam.DataType)) + b.WriteString(fmt.Sprintf("%sVersion: %s,\n", indentationValues, dsrgam.Version)) + b.WriteString(fmt.Sprintf("%sMetaBinary: %s,\n", indentationValues, dsrgam.MetaBinary)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreReqGetAdditionalMeta returns a new DataStoreReqGetAdditionalMeta +func NewDataStoreReqGetAdditionalMeta() *DataStoreReqGetAdditionalMeta { + dsrgam := &DataStoreReqGetAdditionalMeta{ + OwnerID: types.NewPID(0), + DataType: types.NewPrimitiveU16(0), + Version: types.NewPrimitiveU16(0), + MetaBinary: types.NewQBuffer(nil), + } + + return dsrgam +} diff --git a/nex-protocols-go/datastore/types/datastore_req_get_info.go b/nex-protocols-go/datastore/types/datastore_req_get_info.go new file mode 100644 index 0000000..78e1be6 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_req_get_info.go @@ -0,0 +1,168 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreReqGetInfo is a type within the DataStore protocol +type DataStoreReqGetInfo struct { + types.Structure + URL *types.String + RequestHeaders *types.List[*DataStoreKeyValue] + Size *types.PrimitiveU32 + RootCACert *types.Buffer + DataID *types.PrimitiveU64 // * NEX v3.5.0 +} + +// WriteTo writes the DataStoreReqGetInfo to the given writable +func (dsrgi *DataStoreReqGetInfo) WriteTo(writable types.Writable) { + stream := writable.(*nex.ByteStreamOut) + libraryVersion := stream.LibraryVersions.DataStore + + contentWritable := writable.CopyNew() + + dsrgi.URL.WriteTo(contentWritable) + dsrgi.RequestHeaders.WriteTo(contentWritable) + dsrgi.Size.WriteTo(contentWritable) + dsrgi.RootCACert.WriteTo(contentWritable) + + if libraryVersion.GreaterOrEqual("3.5.0") { + dsrgi.DataID.WriteTo(contentWritable) + } + + content := contentWritable.Bytes() + + dsrgi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreReqGetInfo from the given readable +func (dsrgi *DataStoreReqGetInfo) ExtractFrom(readable types.Readable) error { + stream := readable.(*nex.ByteStreamIn) + libraryVersion := stream.LibraryVersions.DataStore + + var err error + + err = dsrgi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetInfo header. %s", err.Error()) + } + + err = dsrgi.URL.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetInfo.URL. %s", err.Error()) + } + + err = dsrgi.RequestHeaders.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetInfo.RequestHeaders. %s", err.Error()) + } + + err = dsrgi.Size.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetInfo.Size. %s", err.Error()) + } + + err = dsrgi.RootCACert.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetInfo.RootCACert. %s", err.Error()) + } + + if libraryVersion.GreaterOrEqual("3.5.0") { + err = dsrgi.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetInfo.DataID. %s", err.Error()) + } + } + + return nil +} + +// Copy returns a new copied instance of DataStoreReqGetInfo +func (dsrgi *DataStoreReqGetInfo) Copy() types.RVType { + copied := NewDataStoreReqGetInfo() + + copied.StructureVersion = dsrgi.StructureVersion + copied.URL = dsrgi.URL.Copy().(*types.String) + copied.RequestHeaders = dsrgi.RequestHeaders.Copy().(*types.List[*DataStoreKeyValue]) + copied.Size = dsrgi.Size.Copy().(*types.PrimitiveU32) + copied.RootCACert = dsrgi.RootCACert.Copy().(*types.Buffer) + copied.DataID = dsrgi.DataID.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given DataStoreReqGetInfo contains the same data as the current DataStoreReqGetInfo +func (dsrgi *DataStoreReqGetInfo) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreReqGetInfo); !ok { + return false + } + + other := o.(*DataStoreReqGetInfo) + + if dsrgi.StructureVersion != other.StructureVersion { + return false + } + + if !dsrgi.URL.Equals(other.URL) { + return false + } + + if !dsrgi.RequestHeaders.Equals(other.RequestHeaders) { + return false + } + + if !dsrgi.Size.Equals(other.Size) { + return false + } + + if !dsrgi.RootCACert.Equals(other.RootCACert) { + return false + } + + return dsrgi.DataID.Equals(other.DataID) +} + +// String returns the string representation of the DataStoreReqGetInfo +func (dsrgi *DataStoreReqGetInfo) String() string { + return dsrgi.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreReqGetInfo using the provided indentation level +func (dsrgi *DataStoreReqGetInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreReqGetInfo{\n") + b.WriteString(fmt.Sprintf("%sURL: %s,\n", indentationValues, dsrgi.URL)) + b.WriteString(fmt.Sprintf("%sRequestHeaders: %s,\n", indentationValues, dsrgi.RequestHeaders)) + b.WriteString(fmt.Sprintf("%sSize: %s,\n", indentationValues, dsrgi.Size)) + b.WriteString(fmt.Sprintf("%sRootCACert: %s,\n", indentationValues, dsrgi.RootCACert)) + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dsrgi.DataID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreReqGetInfo returns a new DataStoreReqGetInfo +func NewDataStoreReqGetInfo() *DataStoreReqGetInfo { + dsrgi := &DataStoreReqGetInfo{ + URL: types.NewString(""), + RequestHeaders: types.NewList[*DataStoreKeyValue](), + Size: types.NewPrimitiveU32(0), + RootCACert: types.NewBuffer(nil), + DataID: types.NewPrimitiveU64(0), + } + + dsrgi.RequestHeaders.Type = NewDataStoreKeyValue() + + return dsrgi +} diff --git a/nex-protocols-go/datastore/types/datastore_req_get_info_v1.go b/nex-protocols-go/datastore/types/datastore_req_get_info_v1.go new file mode 100644 index 0000000..8391b64 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_req_get_info_v1.go @@ -0,0 +1,142 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreReqGetInfoV1 is a type within the DataStore protocol +type DataStoreReqGetInfoV1 struct { + types.Structure + URL *types.String + RequestHeaders *types.List[*DataStoreKeyValue] + Size *types.PrimitiveU32 + RootCACert *types.Buffer +} + +// WriteTo writes the DataStoreReqGetInfoV1 to the given writable +func (dsrgiv *DataStoreReqGetInfoV1) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsrgiv.URL.WriteTo(contentWritable) + dsrgiv.RequestHeaders.WriteTo(contentWritable) + dsrgiv.Size.WriteTo(contentWritable) + dsrgiv.RootCACert.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsrgiv.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreReqGetInfoV1 from the given readable +func (dsrgiv *DataStoreReqGetInfoV1) ExtractFrom(readable types.Readable) error { + var err error + + err = dsrgiv.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetInfoV1 header. %s", err.Error()) + } + + err = dsrgiv.URL.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetInfoV1.URL. %s", err.Error()) + } + + err = dsrgiv.RequestHeaders.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetInfoV1.RequestHeaders. %s", err.Error()) + } + + err = dsrgiv.Size.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetInfoV1.Size. %s", err.Error()) + } + + err = dsrgiv.RootCACert.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetInfoV1.RootCACert. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreReqGetInfoV1 +func (dsrgiv *DataStoreReqGetInfoV1) Copy() types.RVType { + copied := NewDataStoreReqGetInfoV1() + + copied.StructureVersion = dsrgiv.StructureVersion + copied.URL = dsrgiv.URL.Copy().(*types.String) + copied.RequestHeaders = dsrgiv.RequestHeaders.Copy().(*types.List[*DataStoreKeyValue]) + copied.Size = dsrgiv.Size.Copy().(*types.PrimitiveU32) + copied.RootCACert = dsrgiv.RootCACert.Copy().(*types.Buffer) + + return copied +} + +// Equals checks if the given DataStoreReqGetInfoV1 contains the same data as the current DataStoreReqGetInfoV1 +func (dsrgiv *DataStoreReqGetInfoV1) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreReqGetInfoV1); !ok { + return false + } + + other := o.(*DataStoreReqGetInfoV1) + + if dsrgiv.StructureVersion != other.StructureVersion { + return false + } + + if !dsrgiv.URL.Equals(other.URL) { + return false + } + + if !dsrgiv.RequestHeaders.Equals(other.RequestHeaders) { + return false + } + + if !dsrgiv.Size.Equals(other.Size) { + return false + } + + return dsrgiv.RootCACert.Equals(other.RootCACert) +} + +// String returns the string representation of the DataStoreReqGetInfoV1 +func (dsrgiv *DataStoreReqGetInfoV1) String() string { + return dsrgiv.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreReqGetInfoV1 using the provided indentation level +func (dsrgiv *DataStoreReqGetInfoV1) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreReqGetInfoV1{\n") + b.WriteString(fmt.Sprintf("%sURL: %s,\n", indentationValues, dsrgiv.URL)) + b.WriteString(fmt.Sprintf("%sRequestHeaders: %s,\n", indentationValues, dsrgiv.RequestHeaders)) + b.WriteString(fmt.Sprintf("%sSize: %s,\n", indentationValues, dsrgiv.Size)) + b.WriteString(fmt.Sprintf("%sRootCACert: %s,\n", indentationValues, dsrgiv.RootCACert)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreReqGetInfoV1 returns a new DataStoreReqGetInfoV1 +func NewDataStoreReqGetInfoV1() *DataStoreReqGetInfoV1 { + dsrgiv := &DataStoreReqGetInfoV1{ + URL: types.NewString(""), + RequestHeaders: types.NewList[*DataStoreKeyValue](), + Size: types.NewPrimitiveU32(0), + RootCACert: types.NewBuffer(nil), + } + + dsrgiv.RequestHeaders.Type = NewDataStoreKeyValue() + + return dsrgiv +} diff --git a/nex-protocols-go/datastore/types/datastore_req_get_notification_url_info.go b/nex-protocols-go/datastore/types/datastore_req_get_notification_url_info.go new file mode 100644 index 0000000..9188bd4 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_req_get_notification_url_info.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreReqGetNotificationURLInfo is a type within the DataStore protocol +type DataStoreReqGetNotificationURLInfo struct { + types.Structure + URL *types.String + Key *types.String + Query *types.String + RootCACert *types.Buffer +} + +// WriteTo writes the DataStoreReqGetNotificationURLInfo to the given writable +func (dsrgnurli *DataStoreReqGetNotificationURLInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsrgnurli.URL.WriteTo(contentWritable) + dsrgnurli.Key.WriteTo(contentWritable) + dsrgnurli.Query.WriteTo(contentWritable) + dsrgnurli.RootCACert.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsrgnurli.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreReqGetNotificationURLInfo from the given readable +func (dsrgnurli *DataStoreReqGetNotificationURLInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = dsrgnurli.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetNotificationURLInfo header. %s", err.Error()) + } + + err = dsrgnurli.URL.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetNotificationURLInfo.URL. %s", err.Error()) + } + + err = dsrgnurli.Key.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetNotificationURLInfo.Key. %s", err.Error()) + } + + err = dsrgnurli.Query.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetNotificationURLInfo.Query. %s", err.Error()) + } + + err = dsrgnurli.RootCACert.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqGetNotificationURLInfo.RootCACert. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreReqGetNotificationURLInfo +func (dsrgnurli *DataStoreReqGetNotificationURLInfo) Copy() types.RVType { + copied := NewDataStoreReqGetNotificationURLInfo() + + copied.StructureVersion = dsrgnurli.StructureVersion + copied.URL = dsrgnurli.URL.Copy().(*types.String) + copied.Key = dsrgnurli.Key.Copy().(*types.String) + copied.Query = dsrgnurli.Query.Copy().(*types.String) + copied.RootCACert = dsrgnurli.RootCACert.Copy().(*types.Buffer) + + return copied +} + +// Equals checks if the given DataStoreReqGetNotificationURLInfo contains the same data as the current DataStoreReqGetNotificationURLInfo +func (dsrgnurli *DataStoreReqGetNotificationURLInfo) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreReqGetNotificationURLInfo); !ok { + return false + } + + other := o.(*DataStoreReqGetNotificationURLInfo) + + if dsrgnurli.StructureVersion != other.StructureVersion { + return false + } + + if !dsrgnurli.URL.Equals(other.URL) { + return false + } + + if !dsrgnurli.Key.Equals(other.Key) { + return false + } + + if !dsrgnurli.Query.Equals(other.Query) { + return false + } + + return dsrgnurli.RootCACert.Equals(other.RootCACert) +} + +// String returns the string representation of the DataStoreReqGetNotificationURLInfo +func (dsrgnurli *DataStoreReqGetNotificationURLInfo) String() string { + return dsrgnurli.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreReqGetNotificationURLInfo using the provided indentation level +func (dsrgnurli *DataStoreReqGetNotificationURLInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreReqGetNotificationURLInfo{\n") + b.WriteString(fmt.Sprintf("%sURL: %s,\n", indentationValues, dsrgnurli.URL)) + b.WriteString(fmt.Sprintf("%sKey: %s,\n", indentationValues, dsrgnurli.Key)) + b.WriteString(fmt.Sprintf("%sQuery: %s,\n", indentationValues, dsrgnurli.Query)) + b.WriteString(fmt.Sprintf("%sRootCACert: %s,\n", indentationValues, dsrgnurli.RootCACert)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreReqGetNotificationURLInfo returns a new DataStoreReqGetNotificationURLInfo +func NewDataStoreReqGetNotificationURLInfo() *DataStoreReqGetNotificationURLInfo { + dsrgnurli := &DataStoreReqGetNotificationURLInfo{ + URL: types.NewString(""), + Key: types.NewString(""), + Query: types.NewString(""), + RootCACert: types.NewBuffer(nil), + } + + return dsrgnurli +} diff --git a/nex-protocols-go/datastore/types/datastore_req_post_info.go b/nex-protocols-go/datastore/types/datastore_req_post_info.go new file mode 100644 index 0000000..af6105b --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_req_post_info.go @@ -0,0 +1,157 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreReqPostInfo is a type within the DataStore protocol +type DataStoreReqPostInfo struct { + types.Structure + DataID *types.PrimitiveU64 + URL *types.String + RequestHeaders *types.List[*DataStoreKeyValue] + FormFields *types.List[*DataStoreKeyValue] + RootCACert *types.Buffer +} + +// WriteTo writes the DataStoreReqPostInfo to the given writable +func (dsrpi *DataStoreReqPostInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsrpi.DataID.WriteTo(contentWritable) + dsrpi.URL.WriteTo(contentWritable) + dsrpi.RequestHeaders.WriteTo(contentWritable) + dsrpi.FormFields.WriteTo(contentWritable) + dsrpi.RootCACert.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsrpi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreReqPostInfo from the given readable +func (dsrpi *DataStoreReqPostInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = dsrpi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqPostInfo header. %s", err.Error()) + } + + err = dsrpi.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqPostInfo.DataID. %s", err.Error()) + } + + err = dsrpi.URL.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqPostInfo.URL. %s", err.Error()) + } + + err = dsrpi.RequestHeaders.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqPostInfo.RequestHeaders. %s", err.Error()) + } + + err = dsrpi.FormFields.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqPostInfo.FormFields. %s", err.Error()) + } + + err = dsrpi.RootCACert.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqPostInfo.RootCACert. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreReqPostInfo +func (dsrpi *DataStoreReqPostInfo) Copy() types.RVType { + copied := NewDataStoreReqPostInfo() + + copied.StructureVersion = dsrpi.StructureVersion + copied.DataID = dsrpi.DataID.Copy().(*types.PrimitiveU64) + copied.URL = dsrpi.URL.Copy().(*types.String) + copied.RequestHeaders = dsrpi.RequestHeaders.Copy().(*types.List[*DataStoreKeyValue]) + copied.FormFields = dsrpi.FormFields.Copy().(*types.List[*DataStoreKeyValue]) + copied.RootCACert = dsrpi.RootCACert.Copy().(*types.Buffer) + + return copied +} + +// Equals checks if the given DataStoreReqPostInfo contains the same data as the current DataStoreReqPostInfo +func (dsrpi *DataStoreReqPostInfo) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreReqPostInfo); !ok { + return false + } + + other := o.(*DataStoreReqPostInfo) + + if dsrpi.StructureVersion != other.StructureVersion { + return false + } + + if !dsrpi.DataID.Equals(other.DataID) { + return false + } + + if !dsrpi.URL.Equals(other.URL) { + return false + } + + if !dsrpi.RequestHeaders.Equals(other.RequestHeaders) { + return false + } + + if !dsrpi.FormFields.Equals(other.FormFields) { + return false + } + + return dsrpi.RootCACert.Equals(other.RootCACert) +} + +// String returns the string representation of the DataStoreReqPostInfo +func (dsrpi *DataStoreReqPostInfo) String() string { + return dsrpi.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreReqPostInfo using the provided indentation level +func (dsrpi *DataStoreReqPostInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreReqPostInfo{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dsrpi.DataID)) + b.WriteString(fmt.Sprintf("%sURL: %s,\n", indentationValues, dsrpi.URL)) + b.WriteString(fmt.Sprintf("%sRequestHeaders: %s,\n", indentationValues, dsrpi.RequestHeaders)) + b.WriteString(fmt.Sprintf("%sFormFields: %s,\n", indentationValues, dsrpi.FormFields)) + b.WriteString(fmt.Sprintf("%sRootCACert: %s,\n", indentationValues, dsrpi.RootCACert)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreReqPostInfo returns a new DataStoreReqPostInfo +func NewDataStoreReqPostInfo() *DataStoreReqPostInfo { + dsrpi := &DataStoreReqPostInfo{ + DataID: types.NewPrimitiveU64(0), + URL: types.NewString(""), + RequestHeaders: types.NewList[*DataStoreKeyValue](), + FormFields: types.NewList[*DataStoreKeyValue](), + RootCACert: types.NewBuffer(nil), + } + + dsrpi.RequestHeaders.Type = NewDataStoreKeyValue() + dsrpi.FormFields.Type = NewDataStoreKeyValue() + + return dsrpi +} diff --git a/nex-protocols-go/datastore/types/datastore_req_post_info_v1.go b/nex-protocols-go/datastore/types/datastore_req_post_info_v1.go new file mode 100644 index 0000000..ddb2494 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_req_post_info_v1.go @@ -0,0 +1,157 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreReqPostInfoV1 is a type within the DataStore protocol +type DataStoreReqPostInfoV1 struct { + types.Structure + DataID *types.PrimitiveU32 + URL *types.String + RequestHeaders *types.List[*DataStoreKeyValue] + FormFields *types.List[*DataStoreKeyValue] + RootCACert *types.Buffer +} + +// WriteTo writes the DataStoreReqPostInfoV1 to the given writable +func (dsrpiv *DataStoreReqPostInfoV1) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dsrpiv.DataID.WriteTo(contentWritable) + dsrpiv.URL.WriteTo(contentWritable) + dsrpiv.RequestHeaders.WriteTo(contentWritable) + dsrpiv.FormFields.WriteTo(contentWritable) + dsrpiv.RootCACert.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsrpiv.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreReqPostInfoV1 from the given readable +func (dsrpiv *DataStoreReqPostInfoV1) ExtractFrom(readable types.Readable) error { + var err error + + err = dsrpiv.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqPostInfoV1 header. %s", err.Error()) + } + + err = dsrpiv.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqPostInfoV1.DataID. %s", err.Error()) + } + + err = dsrpiv.URL.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqPostInfoV1.URL. %s", err.Error()) + } + + err = dsrpiv.RequestHeaders.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqPostInfoV1.RequestHeaders. %s", err.Error()) + } + + err = dsrpiv.FormFields.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqPostInfoV1.FormFields. %s", err.Error()) + } + + err = dsrpiv.RootCACert.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqPostInfoV1.RootCACert. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreReqPostInfoV1 +func (dsrpiv *DataStoreReqPostInfoV1) Copy() types.RVType { + copied := NewDataStoreReqPostInfoV1() + + copied.StructureVersion = dsrpiv.StructureVersion + copied.DataID = dsrpiv.DataID.Copy().(*types.PrimitiveU32) + copied.URL = dsrpiv.URL.Copy().(*types.String) + copied.RequestHeaders = dsrpiv.RequestHeaders.Copy().(*types.List[*DataStoreKeyValue]) + copied.FormFields = dsrpiv.FormFields.Copy().(*types.List[*DataStoreKeyValue]) + copied.RootCACert = dsrpiv.RootCACert.Copy().(*types.Buffer) + + return copied +} + +// Equals checks if the given DataStoreReqPostInfoV1 contains the same data as the current DataStoreReqPostInfoV1 +func (dsrpiv *DataStoreReqPostInfoV1) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreReqPostInfoV1); !ok { + return false + } + + other := o.(*DataStoreReqPostInfoV1) + + if dsrpiv.StructureVersion != other.StructureVersion { + return false + } + + if !dsrpiv.DataID.Equals(other.DataID) { + return false + } + + if !dsrpiv.URL.Equals(other.URL) { + return false + } + + if !dsrpiv.RequestHeaders.Equals(other.RequestHeaders) { + return false + } + + if !dsrpiv.FormFields.Equals(other.FormFields) { + return false + } + + return dsrpiv.RootCACert.Equals(other.RootCACert) +} + +// String returns the string representation of the DataStoreReqPostInfoV1 +func (dsrpiv *DataStoreReqPostInfoV1) String() string { + return dsrpiv.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreReqPostInfoV1 using the provided indentation level +func (dsrpiv *DataStoreReqPostInfoV1) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreReqPostInfoV1{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dsrpiv.DataID)) + b.WriteString(fmt.Sprintf("%sURL: %s,\n", indentationValues, dsrpiv.URL)) + b.WriteString(fmt.Sprintf("%sRequestHeaders: %s,\n", indentationValues, dsrpiv.RequestHeaders)) + b.WriteString(fmt.Sprintf("%sFormFields: %s,\n", indentationValues, dsrpiv.FormFields)) + b.WriteString(fmt.Sprintf("%sRootCACert: %s,\n", indentationValues, dsrpiv.RootCACert)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreReqPostInfoV1 returns a new DataStoreReqPostInfoV1 +func NewDataStoreReqPostInfoV1() *DataStoreReqPostInfoV1 { + dsrpiv := &DataStoreReqPostInfoV1{ + DataID: types.NewPrimitiveU32(0), + URL: types.NewString(""), + RequestHeaders: types.NewList[*DataStoreKeyValue](), + FormFields: types.NewList[*DataStoreKeyValue](), + RootCACert: types.NewBuffer(nil), + } + + dsrpiv.RequestHeaders.Type = NewDataStoreKeyValue() + dsrpiv.FormFields.Type = NewDataStoreKeyValue() + + return dsrpiv +} diff --git a/nex-protocols-go/datastore/types/datastore_req_update_info.go b/nex-protocols-go/datastore/types/datastore_req_update_info.go new file mode 100644 index 0000000..ca5668d --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_req_update_info.go @@ -0,0 +1,178 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreReqUpdateInfo is a type within the DataStore protocol +type DataStoreReqUpdateInfo struct { + types.Structure + Version *types.PrimitiveU32 + URL *types.String + RequestHeaders *types.List[*DataStoreKeyValue] + FormFields *types.List[*DataStoreKeyValue] + RootCACert *types.Buffer +} + +// WriteTo writes the DataStoreReqUpdateInfo to the given writable +func (dsrui *DataStoreReqUpdateInfo) WriteTo(writable types.Writable) { + stream := writable.(*nex.ByteStreamOut) + libraryVersion := stream.LibraryVersions.DataStore + + contentWritable := writable.CopyNew() + + if libraryVersion.GreaterOrEqual("3.0.0") { + dsrui.Version.WriteTo(contentWritable) + } else { + contentWritable.WritePrimitiveUInt16LE(uint16(dsrui.Version.Value)) + } + + dsrui.URL.WriteTo(contentWritable) + dsrui.RequestHeaders.WriteTo(contentWritable) + dsrui.FormFields.WriteTo(contentWritable) + dsrui.RootCACert.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dsrui.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreReqUpdateInfo from the given readable +func (dsrui *DataStoreReqUpdateInfo) ExtractFrom(readable types.Readable) error { + stream := readable.(*nex.ByteStreamIn) + libraryVersion := stream.LibraryVersions.DataStore + + var err error + + err = dsrui.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqUpdateInfo header. %s", err.Error()) + } + + if libraryVersion.GreaterOrEqual("3.0.0") { + err = dsrui.Version.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompleteUpdateParam.Version. %s", err.Error()) + } + } else { + version, err := readable.ReadPrimitiveUInt16LE() + if err != nil { + return fmt.Errorf("Failed to extract DataStoreCompleteUpdateParam.Version. %s", err.Error()) + } + + dsrui.Version.Value = uint32(version) + } + + err = dsrui.URL.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqUpdateInfo.URL. %s", err.Error()) + } + + err = dsrui.RequestHeaders.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqUpdateInfo.RequestHeaders. %s", err.Error()) + } + + err = dsrui.FormFields.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqUpdateInfo.FormFields. %s", err.Error()) + } + + err = dsrui.RootCACert.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreReqUpdateInfo.RootCACert. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreReqUpdateInfo +func (dsrui *DataStoreReqUpdateInfo) Copy() types.RVType { + copied := NewDataStoreReqUpdateInfo() + + copied.StructureVersion = dsrui.StructureVersion + copied.Version = dsrui.Version.Copy().(*types.PrimitiveU32) + copied.URL = dsrui.URL.Copy().(*types.String) + copied.RequestHeaders = dsrui.RequestHeaders.Copy().(*types.List[*DataStoreKeyValue]) + copied.FormFields = dsrui.FormFields.Copy().(*types.List[*DataStoreKeyValue]) + copied.RootCACert = dsrui.RootCACert.Copy().(*types.Buffer) + + return copied +} + +// Equals checks if the given DataStoreReqUpdateInfo contains the same data as the current DataStoreReqUpdateInfo +func (dsrui *DataStoreReqUpdateInfo) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreReqUpdateInfo); !ok { + return false + } + + other := o.(*DataStoreReqUpdateInfo) + + if dsrui.StructureVersion != other.StructureVersion { + return false + } + + if !dsrui.Version.Equals(other.Version) { + return false + } + + if !dsrui.URL.Equals(other.URL) { + return false + } + + if !dsrui.RequestHeaders.Equals(other.RequestHeaders) { + return false + } + + if !dsrui.FormFields.Equals(other.FormFields) { + return false + } + + return dsrui.RootCACert.Equals(other.RootCACert) +} + +// String returns the string representation of the DataStoreReqUpdateInfo +func (dsrui *DataStoreReqUpdateInfo) String() string { + return dsrui.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreReqUpdateInfo using the provided indentation level +func (dsrui *DataStoreReqUpdateInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreReqUpdateInfo{\n") + b.WriteString(fmt.Sprintf("%sVersion: %s,\n", indentationValues, dsrui.Version)) + b.WriteString(fmt.Sprintf("%sURL: %s,\n", indentationValues, dsrui.URL)) + b.WriteString(fmt.Sprintf("%sRequestHeaders: %s,\n", indentationValues, dsrui.RequestHeaders)) + b.WriteString(fmt.Sprintf("%sFormFields: %s,\n", indentationValues, dsrui.FormFields)) + b.WriteString(fmt.Sprintf("%sRootCACert: %s,\n", indentationValues, dsrui.RootCACert)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreReqUpdateInfo returns a new DataStoreReqUpdateInfo +func NewDataStoreReqUpdateInfo() *DataStoreReqUpdateInfo { + dsrui := &DataStoreReqUpdateInfo{ + Version: types.NewPrimitiveU32(0), + URL: types.NewString(""), + RequestHeaders: types.NewList[*DataStoreKeyValue](), + FormFields: types.NewList[*DataStoreKeyValue](), + RootCACert: types.NewBuffer(nil), + } + + dsrui.RequestHeaders.Type = NewDataStoreKeyValue() + dsrui.FormFields.Type = NewDataStoreKeyValue() + + return dsrui +} diff --git a/nex-protocols-go/datastore/types/datastore_search_param.go b/nex-protocols-go/datastore/types/datastore_search_param.go new file mode 100644 index 0000000..1f58451 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_search_param.go @@ -0,0 +1,355 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreSearchParam is a type within the DataStore protocol +type DataStoreSearchParam struct { + types.Structure + SearchTarget *types.PrimitiveU8 + OwnerIDs *types.List[*types.PID] + OwnerType *types.PrimitiveU8 + DestinationIDs *types.List[*types.PID] + DataType *types.PrimitiveU16 + CreatedAfter *types.DateTime + CreatedBefore *types.DateTime + UpdatedAfter *types.DateTime + UpdatedBefore *types.DateTime + ReferDataID *types.PrimitiveU32 + Tags *types.List[*types.String] + ResultOrderColumn *types.PrimitiveU8 + ResultOrder *types.PrimitiveU8 + ResultRange *types.ResultRange + ResultOption *types.PrimitiveU8 + MinimalRatingFrequency *types.PrimitiveU32 + UseCache *types.PrimitiveBool + TotalCountEnabled *types.PrimitiveBool + DataTypes *types.List[*types.PrimitiveU16] +} + +// WriteTo writes the DataStoreSearchParam to the given writable +func (dssp *DataStoreSearchParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dssp.SearchTarget.WriteTo(contentWritable) + dssp.OwnerIDs.WriteTo(contentWritable) + dssp.OwnerType.WriteTo(contentWritable) + dssp.DestinationIDs.WriteTo(contentWritable) + dssp.DataType.WriteTo(contentWritable) + dssp.CreatedAfter.WriteTo(contentWritable) + dssp.CreatedBefore.WriteTo(contentWritable) + dssp.UpdatedAfter.WriteTo(contentWritable) + dssp.UpdatedBefore.WriteTo(contentWritable) + dssp.ReferDataID.WriteTo(contentWritable) + dssp.Tags.WriteTo(contentWritable) + dssp.ResultOrderColumn.WriteTo(contentWritable) + dssp.ResultOrder.WriteTo(contentWritable) + dssp.ResultRange.WriteTo(contentWritable) + dssp.ResultOption.WriteTo(contentWritable) + dssp.MinimalRatingFrequency.WriteTo(contentWritable) + dssp.UseCache.WriteTo(contentWritable) + dssp.TotalCountEnabled.WriteTo(contentWritable) + dssp.DataTypes.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dssp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreSearchParam from the given readable +func (dssp *DataStoreSearchParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dssp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam header. %s", err.Error()) + } + + err = dssp.SearchTarget.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.SearchTarget. %s", err.Error()) + } + + err = dssp.OwnerIDs.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.OwnerIDs. %s", err.Error()) + } + + err = dssp.OwnerType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.OwnerType. %s", err.Error()) + } + + err = dssp.DestinationIDs.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.DestinationIDs. %s", err.Error()) + } + + err = dssp.DataType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.DataType. %s", err.Error()) + } + + err = dssp.CreatedAfter.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.CreatedAfter. %s", err.Error()) + } + + err = dssp.CreatedBefore.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.CreatedBefore. %s", err.Error()) + } + + err = dssp.UpdatedAfter.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.UpdatedAfter. %s", err.Error()) + } + + err = dssp.UpdatedBefore.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.UpdatedBefore. %s", err.Error()) + } + + err = dssp.ReferDataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.ReferDataID. %s", err.Error()) + } + + err = dssp.Tags.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.Tags. %s", err.Error()) + } + + err = dssp.ResultOrderColumn.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.ResultOrderColumn. %s", err.Error()) + } + + err = dssp.ResultOrder.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.ResultOrder. %s", err.Error()) + } + + err = dssp.ResultRange.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.ResultRange. %s", err.Error()) + } + + err = dssp.ResultOption.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.ResultOption. %s", err.Error()) + } + + err = dssp.MinimalRatingFrequency.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.MinimalRatingFrequency. %s", err.Error()) + } + + err = dssp.UseCache.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.UseCache. %s", err.Error()) + } + + err = dssp.TotalCountEnabled.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.TotalCountEnabled. %s", err.Error()) + } + + err = dssp.DataTypes.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchParam.DataTypes. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreSearchParam +func (dssp *DataStoreSearchParam) Copy() types.RVType { + copied := NewDataStoreSearchParam() + + copied.StructureVersion = dssp.StructureVersion + copied.SearchTarget = dssp.SearchTarget.Copy().(*types.PrimitiveU8) + copied.OwnerIDs = dssp.OwnerIDs.Copy().(*types.List[*types.PID]) + copied.OwnerType = dssp.OwnerType.Copy().(*types.PrimitiveU8) + copied.DestinationIDs = dssp.DestinationIDs.Copy().(*types.List[*types.PID]) + copied.DataType = dssp.DataType.Copy().(*types.PrimitiveU16) + copied.CreatedAfter = dssp.CreatedAfter.Copy().(*types.DateTime) + copied.CreatedBefore = dssp.CreatedBefore.Copy().(*types.DateTime) + copied.UpdatedAfter = dssp.UpdatedAfter.Copy().(*types.DateTime) + copied.UpdatedBefore = dssp.UpdatedBefore.Copy().(*types.DateTime) + copied.ReferDataID = dssp.ReferDataID.Copy().(*types.PrimitiveU32) + copied.Tags = dssp.Tags.Copy().(*types.List[*types.String]) + copied.ResultOrderColumn = dssp.ResultOrderColumn.Copy().(*types.PrimitiveU8) + copied.ResultOrder = dssp.ResultOrder.Copy().(*types.PrimitiveU8) + copied.ResultRange = dssp.ResultRange.Copy().(*types.ResultRange) + copied.ResultOption = dssp.ResultOption.Copy().(*types.PrimitiveU8) + copied.MinimalRatingFrequency = dssp.MinimalRatingFrequency.Copy().(*types.PrimitiveU32) + copied.UseCache = dssp.UseCache.Copy().(*types.PrimitiveBool) + copied.TotalCountEnabled = dssp.TotalCountEnabled.Copy().(*types.PrimitiveBool) + copied.DataTypes = dssp.DataTypes.Copy().(*types.List[*types.PrimitiveU16]) + + return copied +} + +// Equals checks if the given DataStoreSearchParam contains the same data as the current DataStoreSearchParam +func (dssp *DataStoreSearchParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreSearchParam); !ok { + return false + } + + other := o.(*DataStoreSearchParam) + + if dssp.StructureVersion != other.StructureVersion { + return false + } + + if !dssp.SearchTarget.Equals(other.SearchTarget) { + return false + } + + if !dssp.OwnerIDs.Equals(other.OwnerIDs) { + return false + } + + if !dssp.OwnerType.Equals(other.OwnerType) { + return false + } + + if !dssp.DestinationIDs.Equals(other.DestinationIDs) { + return false + } + + if !dssp.DataType.Equals(other.DataType) { + return false + } + + if !dssp.CreatedAfter.Equals(other.CreatedAfter) { + return false + } + + if !dssp.CreatedBefore.Equals(other.CreatedBefore) { + return false + } + + if !dssp.UpdatedAfter.Equals(other.UpdatedAfter) { + return false + } + + if !dssp.UpdatedBefore.Equals(other.UpdatedBefore) { + return false + } + + if !dssp.ReferDataID.Equals(other.ReferDataID) { + return false + } + + if !dssp.Tags.Equals(other.Tags) { + return false + } + + if !dssp.ResultOrderColumn.Equals(other.ResultOrderColumn) { + return false + } + + if !dssp.ResultOrder.Equals(other.ResultOrder) { + return false + } + + if !dssp.ResultRange.Equals(other.ResultRange) { + return false + } + + if !dssp.ResultOption.Equals(other.ResultOption) { + return false + } + + if !dssp.MinimalRatingFrequency.Equals(other.MinimalRatingFrequency) { + return false + } + + if !dssp.UseCache.Equals(other.UseCache) { + return false + } + + if !dssp.TotalCountEnabled.Equals(other.TotalCountEnabled) { + return false + } + + return dssp.DataTypes.Equals(other.DataTypes) +} + +// String returns the string representation of the DataStoreSearchParam +func (dssp *DataStoreSearchParam) String() string { + return dssp.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreSearchParam using the provided indentation level +func (dssp *DataStoreSearchParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreSearchParam{\n") + b.WriteString(fmt.Sprintf("%sSearchTarget: %s,\n", indentationValues, dssp.SearchTarget)) + b.WriteString(fmt.Sprintf("%sOwnerIDs: %s,\n", indentationValues, dssp.OwnerIDs)) + b.WriteString(fmt.Sprintf("%sOwnerType: %s,\n", indentationValues, dssp.OwnerType)) + b.WriteString(fmt.Sprintf("%sDestinationIDs: %s,\n", indentationValues, dssp.DestinationIDs)) + b.WriteString(fmt.Sprintf("%sDataType: %s,\n", indentationValues, dssp.DataType)) + b.WriteString(fmt.Sprintf("%sCreatedAfter: %s,\n", indentationValues, dssp.CreatedAfter.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sCreatedBefore: %s,\n", indentationValues, dssp.CreatedBefore.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUpdatedAfter: %s,\n", indentationValues, dssp.UpdatedAfter.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUpdatedBefore: %s,\n", indentationValues, dssp.UpdatedBefore.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sReferDataID: %s,\n", indentationValues, dssp.ReferDataID)) + b.WriteString(fmt.Sprintf("%sTags: %s,\n", indentationValues, dssp.Tags)) + b.WriteString(fmt.Sprintf("%sResultOrderColumn: %s,\n", indentationValues, dssp.ResultOrderColumn)) + b.WriteString(fmt.Sprintf("%sResultOrder: %s,\n", indentationValues, dssp.ResultOrder)) + b.WriteString(fmt.Sprintf("%sResultRange: %s,\n", indentationValues, dssp.ResultRange.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sResultOption: %s,\n", indentationValues, dssp.ResultOption)) + b.WriteString(fmt.Sprintf("%sMinimalRatingFrequency: %s,\n", indentationValues, dssp.MinimalRatingFrequency)) + b.WriteString(fmt.Sprintf("%sUseCache: %s,\n", indentationValues, dssp.UseCache)) + b.WriteString(fmt.Sprintf("%sTotalCountEnabled: %s,\n", indentationValues, dssp.TotalCountEnabled)) + b.WriteString(fmt.Sprintf("%sDataTypes: %s,\n", indentationValues, dssp.DataTypes)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreSearchParam returns a new DataStoreSearchParam +func NewDataStoreSearchParam() *DataStoreSearchParam { + dssp := &DataStoreSearchParam{ + SearchTarget: types.NewPrimitiveU8(0), + OwnerIDs: types.NewList[*types.PID](), + OwnerType: types.NewPrimitiveU8(0), + DestinationIDs: types.NewList[*types.PID](), + DataType: types.NewPrimitiveU16(0), + CreatedAfter: types.NewDateTime(0), + CreatedBefore: types.NewDateTime(0), + UpdatedAfter: types.NewDateTime(0), + UpdatedBefore: types.NewDateTime(0), + ReferDataID: types.NewPrimitiveU32(0), + Tags: types.NewList[*types.String](), + ResultOrderColumn: types.NewPrimitiveU8(0), + ResultOrder: types.NewPrimitiveU8(0), + ResultRange: types.NewResultRange(), + ResultOption: types.NewPrimitiveU8(0), + MinimalRatingFrequency: types.NewPrimitiveU32(0), + UseCache: types.NewPrimitiveBool(false), + TotalCountEnabled: types.NewPrimitiveBool(false), + DataTypes: types.NewList[*types.PrimitiveU16](), + } + + dssp.OwnerIDs.Type = types.NewPID(0) + dssp.DestinationIDs.Type = types.NewPID(0) + dssp.Tags.Type = types.NewString("") + dssp.DataTypes.Type = types.NewPrimitiveU16(0) + + return dssp +} diff --git a/nex-protocols-go/datastore/types/datastore_search_result.go b/nex-protocols-go/datastore/types/datastore_search_result.go new file mode 100644 index 0000000..fd8675c --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_search_result.go @@ -0,0 +1,128 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreSearchResult is a type within the DataStore protocol +type DataStoreSearchResult struct { + types.Structure + TotalCount *types.PrimitiveU32 + Result *types.List[*DataStoreMetaInfo] + TotalCountType *types.PrimitiveU8 +} + +// WriteTo writes the DataStoreSearchResult to the given writable +func (dssr *DataStoreSearchResult) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dssr.TotalCount.WriteTo(contentWritable) + dssr.Result.WriteTo(contentWritable) + dssr.TotalCountType.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dssr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreSearchResult from the given readable +func (dssr *DataStoreSearchResult) ExtractFrom(readable types.Readable) error { + var err error + + err = dssr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchResult header. %s", err.Error()) + } + + err = dssr.TotalCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchResult.TotalCount. %s", err.Error()) + } + + err = dssr.Result.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchResult.Result. %s", err.Error()) + } + + err = dssr.TotalCountType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSearchResult.TotalCountType. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreSearchResult +func (dssr *DataStoreSearchResult) Copy() types.RVType { + copied := NewDataStoreSearchResult() + + copied.StructureVersion = dssr.StructureVersion + copied.TotalCount = dssr.TotalCount.Copy().(*types.PrimitiveU32) + copied.Result = dssr.Result.Copy().(*types.List[*DataStoreMetaInfo]) + copied.TotalCountType = dssr.TotalCountType.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given DataStoreSearchResult contains the same data as the current DataStoreSearchResult +func (dssr *DataStoreSearchResult) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreSearchResult); !ok { + return false + } + + other := o.(*DataStoreSearchResult) + + if dssr.StructureVersion != other.StructureVersion { + return false + } + + if !dssr.TotalCount.Equals(other.TotalCount) { + return false + } + + if !dssr.Result.Equals(other.Result) { + return false + } + + return dssr.TotalCountType.Equals(other.TotalCountType) +} + +// String returns the string representation of the DataStoreSearchResult +func (dssr *DataStoreSearchResult) String() string { + return dssr.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreSearchResult using the provided indentation level +func (dssr *DataStoreSearchResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreSearchResult{\n") + b.WriteString(fmt.Sprintf("%sTotalCount: %s,\n", indentationValues, dssr.TotalCount)) + b.WriteString(fmt.Sprintf("%sResult: %s,\n", indentationValues, dssr.Result)) + b.WriteString(fmt.Sprintf("%sTotalCountType: %s,\n", indentationValues, dssr.TotalCountType)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreSearchResult returns a new DataStoreSearchResult +func NewDataStoreSearchResult() *DataStoreSearchResult { + dssr := &DataStoreSearchResult{ + TotalCount: types.NewPrimitiveU32(0), + Result: types.NewList[*DataStoreMetaInfo](), + TotalCountType: types.NewPrimitiveU8(0), + } + + dssr.Result.Type = NewDataStoreMetaInfo() + + return dssr +} diff --git a/nex-protocols-go/datastore/types/datastore_specific_meta_info.go b/nex-protocols-go/datastore/types/datastore_specific_meta_info.go new file mode 100644 index 0000000..df06208 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_specific_meta_info.go @@ -0,0 +1,154 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreSpecificMetaInfo is a type within the DataStore protocol +type DataStoreSpecificMetaInfo struct { + types.Structure + DataID *types.PrimitiveU64 + OwnerID *types.PID + Size *types.PrimitiveU32 + DataType *types.PrimitiveU16 + Version *types.PrimitiveU32 +} + +// WriteTo writes the DataStoreSpecificMetaInfo to the given writable +func (dssmi *DataStoreSpecificMetaInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dssmi.DataID.WriteTo(contentWritable) + dssmi.OwnerID.WriteTo(contentWritable) + dssmi.Size.WriteTo(contentWritable) + dssmi.DataType.WriteTo(contentWritable) + dssmi.Version.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dssmi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreSpecificMetaInfo from the given readable +func (dssmi *DataStoreSpecificMetaInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = dssmi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSpecificMetaInfo header. %s", err.Error()) + } + + err = dssmi.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSpecificMetaInfo.DataID. %s", err.Error()) + } + + err = dssmi.OwnerID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSpecificMetaInfo.OwnerID. %s", err.Error()) + } + + err = dssmi.Size.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSpecificMetaInfo.Size. %s", err.Error()) + } + + err = dssmi.DataType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSpecificMetaInfo.DataType. %s", err.Error()) + } + + err = dssmi.Version.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSpecificMetaInfo.Version. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreSpecificMetaInfo +func (dssmi *DataStoreSpecificMetaInfo) Copy() types.RVType { + copied := NewDataStoreSpecificMetaInfo() + + copied.StructureVersion = dssmi.StructureVersion + copied.DataID = dssmi.DataID.Copy().(*types.PrimitiveU64) + copied.OwnerID = dssmi.OwnerID.Copy().(*types.PID) + copied.Size = dssmi.Size.Copy().(*types.PrimitiveU32) + copied.DataType = dssmi.DataType.Copy().(*types.PrimitiveU16) + copied.Version = dssmi.Version.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given DataStoreSpecificMetaInfo contains the same data as the current DataStoreSpecificMetaInfo +func (dssmi *DataStoreSpecificMetaInfo) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreSpecificMetaInfo); !ok { + return false + } + + other := o.(*DataStoreSpecificMetaInfo) + + if dssmi.StructureVersion != other.StructureVersion { + return false + } + + if !dssmi.DataID.Equals(other.DataID) { + return false + } + + if !dssmi.OwnerID.Equals(other.OwnerID) { + return false + } + + if !dssmi.Size.Equals(other.Size) { + return false + } + + if !dssmi.DataType.Equals(other.DataType) { + return false + } + + return dssmi.Version.Equals(other.Version) +} + +// String returns the string representation of the DataStoreSpecificMetaInfo +func (dssmi *DataStoreSpecificMetaInfo) String() string { + return dssmi.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreSpecificMetaInfo using the provided indentation level +func (dssmi *DataStoreSpecificMetaInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreSpecificMetaInfo{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dssmi.DataID)) + b.WriteString(fmt.Sprintf("%sOwnerID: %s,\n", indentationValues, dssmi.OwnerID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sSize: %s,\n", indentationValues, dssmi.Size)) + b.WriteString(fmt.Sprintf("%sDataType: %s,\n", indentationValues, dssmi.DataType)) + b.WriteString(fmt.Sprintf("%sVersion: %s,\n", indentationValues, dssmi.Version)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreSpecificMetaInfo returns a new DataStoreSpecificMetaInfo +func NewDataStoreSpecificMetaInfo() *DataStoreSpecificMetaInfo { + dssmi := &DataStoreSpecificMetaInfo{ + DataID: types.NewPrimitiveU64(0), + OwnerID: types.NewPID(0), + Size: types.NewPrimitiveU32(0), + DataType: types.NewPrimitiveU16(0), + Version: types.NewPrimitiveU32(0), + } + + return dssmi +} diff --git a/nex-protocols-go/datastore/types/datastore_specific_meta_info_v1.go b/nex-protocols-go/datastore/types/datastore_specific_meta_info_v1.go new file mode 100644 index 0000000..8cafa0d --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_specific_meta_info_v1.go @@ -0,0 +1,154 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreSpecificMetaInfoV1 is a type within the DataStore protocol +type DataStoreSpecificMetaInfoV1 struct { + types.Structure + DataID *types.PrimitiveU32 + OwnerID *types.PID + Size *types.PrimitiveU32 + DataType *types.PrimitiveU16 + Version *types.PrimitiveU16 +} + +// WriteTo writes the DataStoreSpecificMetaInfoV1 to the given writable +func (dssmiv *DataStoreSpecificMetaInfoV1) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dssmiv.DataID.WriteTo(contentWritable) + dssmiv.OwnerID.WriteTo(contentWritable) + dssmiv.Size.WriteTo(contentWritable) + dssmiv.DataType.WriteTo(contentWritable) + dssmiv.Version.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dssmiv.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreSpecificMetaInfoV1 from the given readable +func (dssmiv *DataStoreSpecificMetaInfoV1) ExtractFrom(readable types.Readable) error { + var err error + + err = dssmiv.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSpecificMetaInfoV1 header. %s", err.Error()) + } + + err = dssmiv.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSpecificMetaInfoV1.DataID. %s", err.Error()) + } + + err = dssmiv.OwnerID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSpecificMetaInfoV1.OwnerID. %s", err.Error()) + } + + err = dssmiv.Size.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSpecificMetaInfoV1.Size. %s", err.Error()) + } + + err = dssmiv.DataType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSpecificMetaInfoV1.DataType. %s", err.Error()) + } + + err = dssmiv.Version.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreSpecificMetaInfoV1.Version. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreSpecificMetaInfoV1 +func (dssmiv *DataStoreSpecificMetaInfoV1) Copy() types.RVType { + copied := NewDataStoreSpecificMetaInfoV1() + + copied.StructureVersion = dssmiv.StructureVersion + copied.DataID = dssmiv.DataID.Copy().(*types.PrimitiveU32) + copied.OwnerID = dssmiv.OwnerID.Copy().(*types.PID) + copied.Size = dssmiv.Size.Copy().(*types.PrimitiveU32) + copied.DataType = dssmiv.DataType.Copy().(*types.PrimitiveU16) + copied.Version = dssmiv.Version.Copy().(*types.PrimitiveU16) + + return copied +} + +// Equals checks if the given DataStoreSpecificMetaInfoV1 contains the same data as the current DataStoreSpecificMetaInfoV1 +func (dssmiv *DataStoreSpecificMetaInfoV1) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreSpecificMetaInfoV1); !ok { + return false + } + + other := o.(*DataStoreSpecificMetaInfoV1) + + if dssmiv.StructureVersion != other.StructureVersion { + return false + } + + if !dssmiv.DataID.Equals(other.DataID) { + return false + } + + if !dssmiv.OwnerID.Equals(other.OwnerID) { + return false + } + + if !dssmiv.Size.Equals(other.Size) { + return false + } + + if !dssmiv.DataType.Equals(other.DataType) { + return false + } + + return dssmiv.Version.Equals(other.Version) +} + +// String returns the string representation of the DataStoreSpecificMetaInfoV1 +func (dssmiv *DataStoreSpecificMetaInfoV1) String() string { + return dssmiv.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreSpecificMetaInfoV1 using the provided indentation level +func (dssmiv *DataStoreSpecificMetaInfoV1) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreSpecificMetaInfoV1{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dssmiv.DataID)) + b.WriteString(fmt.Sprintf("%sOwnerID: %s,\n", indentationValues, dssmiv.OwnerID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sSize: %s,\n", indentationValues, dssmiv.Size)) + b.WriteString(fmt.Sprintf("%sDataType: %s,\n", indentationValues, dssmiv.DataType)) + b.WriteString(fmt.Sprintf("%sVersion: %s,\n", indentationValues, dssmiv.Version)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreSpecificMetaInfoV1 returns a new DataStoreSpecificMetaInfoV1 +func NewDataStoreSpecificMetaInfoV1() *DataStoreSpecificMetaInfoV1 { + dssmiv := &DataStoreSpecificMetaInfoV1{ + DataID: types.NewPrimitiveU32(0), + OwnerID: types.NewPID(0), + Size: types.NewPrimitiveU32(0), + DataType: types.NewPrimitiveU16(0), + Version: types.NewPrimitiveU16(0), + } + + return dssmiv +} diff --git a/nex-protocols-go/datastore/types/datastore_touch_object_param.go b/nex-protocols-go/datastore/types/datastore_touch_object_param.go new file mode 100644 index 0000000..79568e1 --- /dev/null +++ b/nex-protocols-go/datastore/types/datastore_touch_object_param.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the DataStore protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DataStoreTouchObjectParam is a type within the DataStore protocol +type DataStoreTouchObjectParam struct { + types.Structure + DataID *types.PrimitiveU64 + LockID *types.PrimitiveU32 + AccessPassword *types.PrimitiveU64 +} + +// WriteTo writes the DataStoreTouchObjectParam to the given writable +func (dstop *DataStoreTouchObjectParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + dstop.DataID.WriteTo(contentWritable) + dstop.LockID.WriteTo(contentWritable) + dstop.AccessPassword.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + dstop.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DataStoreTouchObjectParam from the given readable +func (dstop *DataStoreTouchObjectParam) ExtractFrom(readable types.Readable) error { + var err error + + err = dstop.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreTouchObjectParam header. %s", err.Error()) + } + + err = dstop.DataID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreTouchObjectParam.DataID. %s", err.Error()) + } + + err = dstop.LockID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreTouchObjectParam.LockID. %s", err.Error()) + } + + err = dstop.AccessPassword.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DataStoreTouchObjectParam.AccessPassword. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DataStoreTouchObjectParam +func (dstop *DataStoreTouchObjectParam) Copy() types.RVType { + copied := NewDataStoreTouchObjectParam() + + copied.StructureVersion = dstop.StructureVersion + copied.DataID = dstop.DataID.Copy().(*types.PrimitiveU64) + copied.LockID = dstop.LockID.Copy().(*types.PrimitiveU32) + copied.AccessPassword = dstop.AccessPassword.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given DataStoreTouchObjectParam contains the same data as the current DataStoreTouchObjectParam +func (dstop *DataStoreTouchObjectParam) Equals(o types.RVType) bool { + if _, ok := o.(*DataStoreTouchObjectParam); !ok { + return false + } + + other := o.(*DataStoreTouchObjectParam) + + if dstop.StructureVersion != other.StructureVersion { + return false + } + + if !dstop.DataID.Equals(other.DataID) { + return false + } + + if !dstop.LockID.Equals(other.LockID) { + return false + } + + return dstop.AccessPassword.Equals(other.AccessPassword) +} + +// String returns the string representation of the DataStoreTouchObjectParam +func (dstop *DataStoreTouchObjectParam) String() string { + return dstop.FormatToString(0) +} + +// FormatToString pretty-prints the DataStoreTouchObjectParam using the provided indentation level +func (dstop *DataStoreTouchObjectParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DataStoreTouchObjectParam{\n") + b.WriteString(fmt.Sprintf("%sDataID: %s,\n", indentationValues, dstop.DataID)) + b.WriteString(fmt.Sprintf("%sLockID: %s,\n", indentationValues, dstop.LockID)) + b.WriteString(fmt.Sprintf("%sAccessPassword: %s,\n", indentationValues, dstop.AccessPassword)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDataStoreTouchObjectParam returns a new DataStoreTouchObjectParam +func NewDataStoreTouchObjectParam() *DataStoreTouchObjectParam { + dstop := &DataStoreTouchObjectParam{ + DataID: types.NewPrimitiveU64(0), + LockID: types.NewPrimitiveU32(0), + AccessPassword: types.NewPrimitiveU64(0), + } + + return dstop +} diff --git a/nex-protocols-go/datastore/unperpetuate_object.go b/nex-protocols-go/datastore/unperpetuate_object.go new file mode 100644 index 0000000..c38f6ff --- /dev/null +++ b/nex-protocols-go/datastore/unperpetuate_object.go @@ -0,0 +1,60 @@ +// Package protocol implements the DataStore protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUnperpetuateObject(packet nex.PacketInterface) { + if protocol.UnperpetuateObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "DataStore::UnperpetuateObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + persistenceSlotID := types.NewPrimitiveU16(0) + deleteLastObject := types.NewPrimitiveBool(false) + + var err error + + err = persistenceSlotID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UnperpetuateObject(fmt.Errorf("Failed to read persistenceSlotID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = deleteLastObject.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UnperpetuateObject(fmt.Errorf("Failed to read deleteLastObject from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UnperpetuateObject(nil, packet, callID, persistenceSlotID, deleteLastObject) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/debug/disable_api_recorder.go b/nex-protocols-go/debug/disable_api_recorder.go new file mode 100644 index 0000000..34280c2 --- /dev/null +++ b/nex-protocols-go/debug/disable_api_recorder.go @@ -0,0 +1,29 @@ +// Package protocol implements the Debug protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDisableAPIRecorder(packet nex.PacketInterface) { + if protocol.DisableAPIRecorder == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Debug::DisableAPIRecorder not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.DisableAPIRecorder(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/debug/enable_api_recorder.go b/nex-protocols-go/debug/enable_api_recorder.go new file mode 100644 index 0000000..e0bd061 --- /dev/null +++ b/nex-protocols-go/debug/enable_api_recorder.go @@ -0,0 +1,29 @@ +// Package protocol implements the Debug protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleEnableAPIRecorder(packet nex.PacketInterface) { + if protocol.EnableAPIRecorder == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Debug::EnableAPIRecorder not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.EnableAPIRecorder(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/debug/get_api_call_summary.go b/nex-protocols-go/debug/get_api_call_summary.go new file mode 100644 index 0000000..ee8ff5c --- /dev/null +++ b/nex-protocols-go/debug/get_api_call_summary.go @@ -0,0 +1,31 @@ +// Package protocol implements the Debug protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetAPICallSummary(packet nex.PacketInterface) { + if protocol.GetAPICallSummary == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Debug::GetAPICallSummary not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("Debug::GetAPICallSummary STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetAPICallSummary(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/debug/get_api_calls.go b/nex-protocols-go/debug/get_api_calls.go new file mode 100644 index 0000000..c657ed9 --- /dev/null +++ b/nex-protocols-go/debug/get_api_calls.go @@ -0,0 +1,72 @@ +// Package protocol implements the Debug protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetAPICalls(packet nex.PacketInterface) { + if protocol.GetAPICalls == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Debug::GetAPICalls not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pids := types.NewList[*types.PID]() + pids.Type = types.NewPID(0) + unknown := types.NewDateTime(0) + unknown2 := types.NewDateTime(0) + + var err error + + err = pids.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetAPICalls(fmt.Errorf("Failed to read pids from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = unknown.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetAPICalls(fmt.Errorf("Failed to read unknown from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = unknown2.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetAPICalls(fmt.Errorf("Failed to read unknown2 from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetAPICalls(nil, packet, callID, pids, unknown, unknown2) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/debug/get_exclude_joined_matchmake_session.go b/nex-protocols-go/debug/get_exclude_joined_matchmake_session.go new file mode 100644 index 0000000..c0e1897 --- /dev/null +++ b/nex-protocols-go/debug/get_exclude_joined_matchmake_session.go @@ -0,0 +1,31 @@ +// Package protocol implements the Debug protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetExcludeJoinedMatchmakeSession(packet nex.PacketInterface) { + if protocol.GetExcludeJoinedMatchmakeSession == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Debug::GetExcludeJoinedMatchmakeSession not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("Debug::GetExcludeJoinedMatchmakeSession STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetExcludeJoinedMatchmakeSession(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/debug/is_api_recorder_enabled.go b/nex-protocols-go/debug/is_api_recorder_enabled.go new file mode 100644 index 0000000..fa784a6 --- /dev/null +++ b/nex-protocols-go/debug/is_api_recorder_enabled.go @@ -0,0 +1,29 @@ +// Package protocol implements the Debug protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleIsAPIRecorderEnabled(packet nex.PacketInterface) { + if protocol.IsAPIRecorderEnabled == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Debug::IsAPIRecorderEnabled not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.IsAPIRecorderEnabled(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/debug/protocol.go b/nex-protocols-go/debug/protocol.go new file mode 100644 index 0000000..bb28e0f --- /dev/null +++ b/nex-protocols-go/debug/protocol.go @@ -0,0 +1,151 @@ +// Package protocol implements the Debug protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the Debug protocol + ProtocolID = 0x74 + + // MethodEnableAPIRecorder is the method ID for the method EnableAPIRecorder + MethodEnableAPIRecorder = 0x1 + + // MethodDisableAPIRecorder is the method ID for the method DisableAPIRecorder + MethodDisableAPIRecorder = 0x2 + + // MethodIsAPIRecorderEnabled is the method ID for the method IsAPIRecorderEnabled + MethodIsAPIRecorderEnabled = 0x3 + + // MethodGetAPICalls is the method ID for the method GetAPICalls + MethodGetAPICalls = 0x4 + + // MethodSetExcludeJoinedMatchmakeSession is the method ID for the method SetExcludeJoinedMatchmakeSession + MethodSetExcludeJoinedMatchmakeSession = 0x5 + + // MethodGetExcludeJoinedMatchmakeSession is the method ID for the method GetExcludeJoinedMatchmakeSession + MethodGetExcludeJoinedMatchmakeSession = 0x6 + + // MethodGetAPICallSummary is the method ID for the method GetAPICallSummary + MethodGetAPICallSummary = 0x7 +) + +// Protocol handles the Debug protocol +type Protocol struct { + endpoint nex.EndpointInterface + EnableAPIRecorder func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + DisableAPIRecorder func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + IsAPIRecorderEnabled func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + GetAPICalls func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID], unknown *types.DateTime, unknown2 *types.DateTime) (*nex.RMCMessage, *nex.Error) + SetExcludeJoinedMatchmakeSession func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) // TODO - Unknown request/response format + GetExcludeJoinedMatchmakeSession func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) // TODO - Unknown request/response format + GetAPICallSummary func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) // TODO - Unknown request/response format + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Debug protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerEnableAPIRecorder(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerDisableAPIRecorder(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerIsAPIRecorderEnabled(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetAPICalls(handler func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID], unknown *types.DateTime, unknown2 *types.DateTime) (*nex.RMCMessage, *nex.Error)) + SetHandlerSetExcludeJoinedMatchmakeSession(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetExcludeJoinedMatchmakeSession(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetAPICallSummary(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerEnableAPIRecorder sets the handler for the EnableAPIRecorder method +func (protocol *Protocol) SetHandlerEnableAPIRecorder(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.EnableAPIRecorder = handler +} + +// SetHandlerDisableAPIRecorder sets the handler for the DisableAPIRecorder method +func (protocol *Protocol) SetHandlerDisableAPIRecorder(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.DisableAPIRecorder = handler +} + +// SetHandlerIsAPIRecorderEnabled sets the handler for the IsAPIRecorderEnabled method +func (protocol *Protocol) SetHandlerIsAPIRecorderEnabled(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.IsAPIRecorderEnabled = handler +} + +// SetHandlerGetAPICalls sets the handler for the GetAPICalls method +func (protocol *Protocol) SetHandlerGetAPICalls(handler func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID], unknown *types.DateTime, unknown2 *types.DateTime) (*nex.RMCMessage, *nex.Error)) { + protocol.GetAPICalls = handler +} + +// SetHandlerSetExcludeJoinedMatchmakeSession sets the handler for the SetExcludeJoinedMatchmakeSession method +func (protocol *Protocol) SetHandlerSetExcludeJoinedMatchmakeSession(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) { + protocol.SetExcludeJoinedMatchmakeSession = handler +} + +// SetHandlerGetExcludeJoinedMatchmakeSession sets the handler for the GetExcludeJoinedMatchmakeSession method +func (protocol *Protocol) SetHandlerGetExcludeJoinedMatchmakeSession(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) { + protocol.GetExcludeJoinedMatchmakeSession = handler +} + +// SetHandlerGetAPICallSummary sets the handler for the GetAPICallSummary method +func (protocol *Protocol) SetHandlerGetAPICallSummary(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) { + protocol.GetAPICallSummary = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodEnableAPIRecorder: + protocol.handleEnableAPIRecorder(packet) + case MethodDisableAPIRecorder: + protocol.handleDisableAPIRecorder(packet) + case MethodIsAPIRecorderEnabled: + protocol.handleIsAPIRecorderEnabled(packet) + case MethodGetAPICalls: + protocol.handleGetAPICalls(packet) + case MethodSetExcludeJoinedMatchmakeSession: + protocol.handleSetExcludeJoinedMatchmakeSession(packet) + case MethodGetExcludeJoinedMatchmakeSession: + protocol.handleGetExcludeJoinedMatchmakeSession(packet) + case MethodGetAPICallSummary: + protocol.handleGetAPICallSummary(packet) + default: + errMessage := fmt.Sprintf("Unsupported Debug method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Debug protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/debug/set_exclude_joined_matchmake_session.go b/nex-protocols-go/debug/set_exclude_joined_matchmake_session.go new file mode 100644 index 0000000..0494aff --- /dev/null +++ b/nex-protocols-go/debug/set_exclude_joined_matchmake_session.go @@ -0,0 +1,31 @@ +// Package protocol implements the Debug protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSetExcludeJoinedMatchmakeSession(packet nex.PacketInterface) { + if protocol.SetExcludeJoinedMatchmakeSession == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Debug::SetExcludeJoinedMatchmakeSession not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("Debug::SetExcludeJoinedMatchmakeSession STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.SetExcludeJoinedMatchmakeSession(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/add_friend_by_lst_principal_id.go b/nex-protocols-go/friends-3ds/add_friend_by_lst_principal_id.go new file mode 100644 index 0000000..93e4a18 --- /dev/null +++ b/nex-protocols-go/friends-3ds/add_friend_by_lst_principal_id.go @@ -0,0 +1,61 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAddFriendBylstPrincipalID(packet nex.PacketInterface) { + if protocol.AddFriendBylstPrincipalID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::AddFriendBylstPrincipalID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lfc := types.NewPrimitiveU64(0) + pids := types.NewList[*types.PID]() + pids.Type = types.NewPID(0) + + var err error + + err = lfc.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendBylstPrincipalID(fmt.Errorf("Failed to read lfc from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = pids.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendBylstPrincipalID(fmt.Errorf("Failed to read pids from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AddFriendBylstPrincipalID(nil, packet, callID, lfc, pids) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/add_friend_by_principal_id.go b/nex-protocols-go/friends-3ds/add_friend_by_principal_id.go new file mode 100644 index 0000000..b963451 --- /dev/null +++ b/nex-protocols-go/friends-3ds/add_friend_by_principal_id.go @@ -0,0 +1,60 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAddFriendByPrincipalID(packet nex.PacketInterface) { + if protocol.AddFriendByPrincipalID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::AddFriendByPrincipalID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lfc := types.NewPrimitiveU64(0) + pid := types.NewPID(0) + + var err error + + err = lfc.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendByPrincipalID(fmt.Errorf("Failed to read lfc from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = pid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendByPrincipalID(fmt.Errorf("Failed to read pid from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AddFriendByPrincipalID(nil, packet, callID, lfc, pid) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/get_all_friends.go b/nex-protocols-go/friends-3ds/get_all_friends.go new file mode 100644 index 0000000..fd8260e --- /dev/null +++ b/nex-protocols-go/friends-3ds/get_all_friends.go @@ -0,0 +1,29 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetAllFriends(packet nex.PacketInterface) { + if protocol.GetAllFriends == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::GetAllFriends not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetAllFriends(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/get_friend_comment.go b/nex-protocols-go/friends-3ds/get_friend_comment.go new file mode 100644 index 0000000..0e2ebba --- /dev/null +++ b/nex-protocols-go/friends-3ds/get_friend_comment.go @@ -0,0 +1,49 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-3ds/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetFriendComment(packet nex.PacketInterface) { + if protocol.GetFriendComment == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::GetFriendComment not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + friends := types.NewList[*friends_3ds_types.FriendInfo]() + friends.Type = friends_3ds_types.NewFriendInfo() + + err := friends.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetFriendComment(fmt.Errorf("Failed to read friends from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetFriendComment(nil, packet, callID, friends) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/get_friend_mii.go b/nex-protocols-go/friends-3ds/get_friend_mii.go new file mode 100644 index 0000000..7417c83 --- /dev/null +++ b/nex-protocols-go/friends-3ds/get_friend_mii.go @@ -0,0 +1,49 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-3ds/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetFriendMii(packet nex.PacketInterface) { + if protocol.GetFriendMii == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::GetFriendMii not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + friends := types.NewList[*friends_3ds_types.FriendInfo]() + friends.Type = friends_3ds_types.NewFriendInfo() + + err := friends.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetFriendMii(fmt.Errorf("Failed to read friends from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetFriendMii(nil, packet, callID, friends) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/get_friend_mii_list.go b/nex-protocols-go/friends-3ds/get_friend_mii_list.go new file mode 100644 index 0000000..de318ad --- /dev/null +++ b/nex-protocols-go/friends-3ds/get_friend_mii_list.go @@ -0,0 +1,49 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-3ds/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetFriendMiiList(packet nex.PacketInterface) { + if protocol.GetFriendMiiList == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::GetFriendMiiList not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + friends := types.NewList[*friends_3ds_types.FriendInfo]() + friends.Type = friends_3ds_types.NewFriendInfo() + + err := friends.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetFriendMiiList(fmt.Errorf("Failed to read friends from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetFriendMiiList(nil, packet, callID, friends) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/get_friend_persistent_info.go b/nex-protocols-go/friends-3ds/get_friend_persistent_info.go new file mode 100644 index 0000000..d7748c9 --- /dev/null +++ b/nex-protocols-go/friends-3ds/get_friend_persistent_info.go @@ -0,0 +1,48 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetFriendPersistentInfo(packet nex.PacketInterface) { + if protocol.GetFriendPersistentInfo == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::GetFriendPersistentInfo not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pidList := types.NewList[*types.PID]() + pidList.Type = types.NewPID(0) + + err := pidList.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetFriendPersistentInfo(fmt.Errorf("Failed to read pidList from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetFriendPersistentInfo(nil, packet, callID, pidList) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/get_friend_picture.go b/nex-protocols-go/friends-3ds/get_friend_picture.go new file mode 100644 index 0000000..3951098 --- /dev/null +++ b/nex-protocols-go/friends-3ds/get_friend_picture.go @@ -0,0 +1,48 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetFriendPicture(packet nex.PacketInterface) { + if protocol.GetFriendPicture == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::GetFriendPicture not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + unknown := types.NewList[*types.PrimitiveU32]() + unknown.Type = types.NewPrimitiveU32(0) + + err := unknown.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetFriendPicture(fmt.Errorf("Failed to read unknown from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetFriendPicture(nil, packet, callID, unknown) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/get_friend_presence.go b/nex-protocols-go/friends-3ds/get_friend_presence.go new file mode 100644 index 0000000..e7d5296 --- /dev/null +++ b/nex-protocols-go/friends-3ds/get_friend_presence.go @@ -0,0 +1,48 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetFriendPresence(packet nex.PacketInterface) { + if protocol.GetFriendPresence == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::GetFriendPresence not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pidList := types.NewList[*types.PID]() + pidList.Type = types.NewPID(0) + + err := pidList.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetFriendPresence(fmt.Errorf("Failed to read pidList from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetFriendPresence(nil, packet, callID, pidList) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/get_friend_relationships.go b/nex-protocols-go/friends-3ds/get_friend_relationships.go new file mode 100644 index 0000000..a98d073 --- /dev/null +++ b/nex-protocols-go/friends-3ds/get_friend_relationships.go @@ -0,0 +1,48 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetFriendRelationships(packet nex.PacketInterface) { + if protocol.GetFriendRelationships == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::GetFriendRelationships not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pids := types.NewList[*types.PID]() + pids.Type = types.NewPID(0) + + err := pids.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetFriendRelationships(fmt.Errorf("Failed to read pids from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetFriendRelationships(nil, packet, callID, pids) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/get_principal_id_by_local_friend_code.go b/nex-protocols-go/friends-3ds/get_principal_id_by_local_friend_code.go new file mode 100644 index 0000000..17ff95d --- /dev/null +++ b/nex-protocols-go/friends-3ds/get_principal_id_by_local_friend_code.go @@ -0,0 +1,61 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetPrincipalIDByLocalFriendCode(packet nex.PacketInterface) { + if protocol.GetPrincipalIDByLocalFriendCode == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::GetPrincipalIDByLocalFriendCode not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lfc := types.NewPrimitiveU64(0) + lfcList := types.NewList[*types.PrimitiveU64]() + lfcList.Type = types.NewPrimitiveU64(0) + + var err error + + err = lfc.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPrincipalIDByLocalFriendCode(fmt.Errorf("Failed to read lfc from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = lfcList.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPrincipalIDByLocalFriendCode(fmt.Errorf("Failed to read lfcList from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetPrincipalIDByLocalFriendCode(nil, packet, callID, lfc, lfcList) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/is_active_game.go b/nex-protocols-go/friends-3ds/is_active_game.go new file mode 100644 index 0000000..1b469a0 --- /dev/null +++ b/nex-protocols-go/friends-3ds/is_active_game.go @@ -0,0 +1,62 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-3ds/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleIsActiveGame(packet nex.PacketInterface) { + if protocol.IsActiveGame == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::IsActiveGame not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pids := types.NewList[*types.PID]() + pids.Type = types.NewPID(0) + gameKey := friends_3ds_types.NewGameKey() + + var err error + + err = pids.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.IsActiveGame(fmt.Errorf("Failed to read pids from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = gameKey.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.IsActiveGame(fmt.Errorf("Failed to read gameKey from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.IsActiveGame(nil, packet, callID, pids, gameKey) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/protocol.go b/nex-protocols-go/friends-3ds/protocol.go new file mode 100644 index 0000000..e342070 --- /dev/null +++ b/nex-protocols-go/friends-3ds/protocol.go @@ -0,0 +1,380 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-3ds/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the Friends (3DS) protocol + ProtocolID = 0x65 + + // MethodUpdateProfile is the method ID for method UpdateProfile + MethodUpdateProfile = 0x1 + + // MethodUpdateMii is the method ID for method UpdateMii + MethodUpdateMii = 0x2 + + // MethodUpdateMiiList is the method ID for method UpdateMiiList + MethodUpdateMiiList = 0x3 + + // MethodUpdatePlayedGames is the method ID for method UpdatePlayedGames + MethodUpdatePlayedGames = 0x4 + + // MethodUpdatePreference is the method ID for method UpdatePreference + MethodUpdatePreference = 0x5 + + // MethodGetFriendMii is the method ID for method GetFriendMii + MethodGetFriendMii = 0x6 + + // MethodGetFriendMiiList is the method ID for method GetFriendMiiList + MethodGetFriendMiiList = 0x7 + + // MethodIsActiveGame is the method ID for method IsActiveGame + MethodIsActiveGame = 0x8 + + // MethodGetPrincipalIDByLocalFriendCode is the method ID for method GetPrincipalIDByLocalFriendCode + MethodGetPrincipalIDByLocalFriendCode = 0x9 + + // MethodGetFriendRelationships is the method ID for method GetFriendRelationships + MethodGetFriendRelationships = 0xA + + // MethodAddFriendByPrincipalID is the method ID for method AddFriendByPrincipalID + MethodAddFriendByPrincipalID = 0xB + + // MethodAddFriendBylstPrincipalID is the method ID for method AddFriendBylstPrincipalID + MethodAddFriendBylstPrincipalID = 0xC + + // MethodRemoveFriendByLocalFriendCode is the method ID for method RemoveFriendByLocalFriendCode + MethodRemoveFriendByLocalFriendCode = 0xD + + // MethodRemoveFriendByPrincipalID is the method ID for method RemoveFriendByPrincipalID + MethodRemoveFriendByPrincipalID = 0xE + + // MethodGetAllFriends is the method ID for method GetAllFriends + MethodGetAllFriends = 0xF + + // MethodUpdateBlackList is the method ID for method UpdateBlackList + MethodUpdateBlackList = 0x10 + + // MethodSyncFriend is the method ID for method SyncFriend + MethodSyncFriend = 0x11 + + // MethodUpdatePresence is the method ID for method UpdatePresence + MethodUpdatePresence = 0x12 + + // MethodUpdateFavoriteGameKey is the method ID for method UpdateFavoriteGameKey + MethodUpdateFavoriteGameKey = 0x13 + + // MethodUpdateComment is the method ID for method UpdateComment + MethodUpdateComment = 0x14 + + // MethodUpdatePicture is the method ID for method UpdatePicture + MethodUpdatePicture = 0x15 + + // MethodGetFriendPresence is the method ID for method GetFriendPresence + MethodGetFriendPresence = 0x16 + + // MethodGetFriendComment is the method ID for method GetFriendComment + MethodGetFriendComment = 0x17 + + // MethodGetFriendPicture is the method ID for method GetFriendPicture + MethodGetFriendPicture = 0x18 + + // MethodGetFriendPersistentInfo is the method ID for method GetFriendPersistentInfo + MethodGetFriendPersistentInfo = 0x19 + + // MethodSendInvitation is the method ID for method SendInvitation + MethodSendInvitation = 0x1A +) + +// Protocol stores all the RMC method handlers for the Friends (3DS) protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + UpdateProfile func(err error, packet nex.PacketInterface, callID uint32, profileData *friends_3ds_types.MyProfile) (*nex.RMCMessage, *nex.Error) + UpdateMii func(err error, packet nex.PacketInterface, callID uint32, mii *friends_3ds_types.Mii) (*nex.RMCMessage, *nex.Error) + UpdateMiiList func(err error, packet nex.PacketInterface, callID uint32, miiList *friends_3ds_types.MiiList) (*nex.RMCMessage, *nex.Error) + UpdatePlayedGames func(err error, packet nex.PacketInterface, callID uint32, playedGames *types.List[*friends_3ds_types.PlayedGame]) (*nex.RMCMessage, *nex.Error) + UpdatePreference func(err error, packet nex.PacketInterface, callID uint32, publicMode *types.PrimitiveBool, showGame *types.PrimitiveBool, showPlayedGame *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + GetFriendMii func(err error, packet nex.PacketInterface, callID uint32, friends *types.List[*friends_3ds_types.FriendInfo]) (*nex.RMCMessage, *nex.Error) + GetFriendMiiList func(err error, packet nex.PacketInterface, callID uint32, friends *types.List[*friends_3ds_types.FriendInfo]) (*nex.RMCMessage, *nex.Error) + IsActiveGame func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID], gameKey *friends_3ds_types.GameKey) (*nex.RMCMessage, *nex.Error) + GetPrincipalIDByLocalFriendCode func(err error, packet nex.PacketInterface, callID uint32, lfc *types.PrimitiveU64, lfcList *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error) + GetFriendRelationships func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error) + AddFriendByPrincipalID func(err error, packet nex.PacketInterface, callID uint32, lfc *types.PrimitiveU64, pid *types.PID) (*nex.RMCMessage, *nex.Error) + AddFriendBylstPrincipalID func(err error, packet nex.PacketInterface, callID uint32, lfc *types.PrimitiveU64, pids *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error) + RemoveFriendByLocalFriendCode func(err error, packet nex.PacketInterface, callID uint32, lfc *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + RemoveFriendByPrincipalID func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID) (*nex.RMCMessage, *nex.Error) + GetAllFriends func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + UpdateBlackList func(err error, packet nex.PacketInterface, callID uint32, unknown *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error) + SyncFriend func(err error, packet nex.PacketInterface, callID uint32, lfc *types.PrimitiveU64, pids *types.List[*types.PID], lfcList *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error) + UpdatePresence func(err error, packet nex.PacketInterface, callID uint32, presence *friends_3ds_types.NintendoPresence, showGame *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + UpdateFavoriteGameKey func(err error, packet nex.PacketInterface, callID uint32, gameKey *friends_3ds_types.GameKey) (*nex.RMCMessage, *nex.Error) + UpdateComment func(err error, packet nex.PacketInterface, callID uint32, comment *types.String) (*nex.RMCMessage, *nex.Error) + UpdatePicture func(err error, packet nex.PacketInterface, callID uint32, unknown *types.PrimitiveU32, picture *types.Buffer) (*nex.RMCMessage, *nex.Error) + GetFriendPresence func(err error, packet nex.PacketInterface, callID uint32, pidList *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error) + GetFriendComment func(err error, packet nex.PacketInterface, callID uint32, friends *types.List[*friends_3ds_types.FriendInfo]) (*nex.RMCMessage, *nex.Error) + GetFriendPicture func(err error, packet nex.PacketInterface, callID uint32, unknown *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error) + GetFriendPersistentInfo func(err error, packet nex.PacketInterface, callID uint32, pidList *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error) + SendInvitation func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Friends (3DS) protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerUpdateProfile(handler func(err error, packet nex.PacketInterface, callID uint32, profileData *friends_3ds_types.MyProfile) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateMii(handler func(err error, packet nex.PacketInterface, callID uint32, mii *friends_3ds_types.Mii) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateMiiList(handler func(err error, packet nex.PacketInterface, callID uint32, miiList *friends_3ds_types.MiiList) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdatePlayedGames(handler func(err error, packet nex.PacketInterface, callID uint32, playedGames *types.List[*friends_3ds_types.PlayedGame]) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdatePreference(handler func(err error, packet nex.PacketInterface, callID uint32, publicMode *types.PrimitiveBool, showGame *types.PrimitiveBool, showPlayedGame *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetFriendMii(handler func(err error, packet nex.PacketInterface, callID uint32, friends *types.List[*friends_3ds_types.FriendInfo]) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetFriendMiiList(handler func(err error, packet nex.PacketInterface, callID uint32, friends *types.List[*friends_3ds_types.FriendInfo]) (*nex.RMCMessage, *nex.Error)) + SetHandlerIsActiveGame(handler func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID], gameKey *friends_3ds_types.GameKey) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetPrincipalIDByLocalFriendCode(handler func(err error, packet nex.PacketInterface, callID uint32, lfc *types.PrimitiveU64, lfcList *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetFriendRelationships(handler func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) + SetHandlerAddFriendByPrincipalID(handler func(err error, packet nex.PacketInterface, callID uint32, lfc *types.PrimitiveU64, pid *types.PID) (*nex.RMCMessage, *nex.Error)) + SetHandlerAddFriendBylstPrincipalID(handler func(err error, packet nex.PacketInterface, callID uint32, lfc *types.PrimitiveU64, pids *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) + SetHandlerRemoveFriendByLocalFriendCode(handler func(err error, packet nex.PacketInterface, callID uint32, lfc *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerRemoveFriendByPrincipalID(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetAllFriends(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateBlackList(handler func(err error, packet nex.PacketInterface, callID uint32, unknown *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) + SetHandlerSyncFriend(handler func(err error, packet nex.PacketInterface, callID uint32, lfc *types.PrimitiveU64, pids *types.List[*types.PID], lfcList *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdatePresence(handler func(err error, packet nex.PacketInterface, callID uint32, presence *friends_3ds_types.NintendoPresence, showGame *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateFavoriteGameKey(handler func(err error, packet nex.PacketInterface, callID uint32, gameKey *friends_3ds_types.GameKey) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateComment(handler func(err error, packet nex.PacketInterface, callID uint32, comment *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdatePicture(handler func(err error, packet nex.PacketInterface, callID uint32, unknown *types.PrimitiveU32, picture *types.Buffer) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetFriendPresence(handler func(err error, packet nex.PacketInterface, callID uint32, pidList *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetFriendComment(handler func(err error, packet nex.PacketInterface, callID uint32, friends *types.List[*friends_3ds_types.FriendInfo]) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetFriendPicture(handler func(err error, packet nex.PacketInterface, callID uint32, unknown *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetFriendPersistentInfo(handler func(err error, packet nex.PacketInterface, callID uint32, pidList *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) + SetHandlerSendInvitation(handler func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerUpdateProfile sets the handler for the UpdateProfile method +func (protocol *Protocol) SetHandlerUpdateProfile(handler func(err error, packet nex.PacketInterface, callID uint32, profileData *friends_3ds_types.MyProfile) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateProfile = handler +} + +// SetHandlerUpdateMii sets the handler for the UpdateMii method +func (protocol *Protocol) SetHandlerUpdateMii(handler func(err error, packet nex.PacketInterface, callID uint32, mii *friends_3ds_types.Mii) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateMii = handler +} + +// SetHandlerUpdateMiiList sets the handler for the UpdateMiiList method +func (protocol *Protocol) SetHandlerUpdateMiiList(handler func(err error, packet nex.PacketInterface, callID uint32, miiList *friends_3ds_types.MiiList) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateMiiList = handler +} + +// SetHandlerUpdatePlayedGames sets the handler for the UpdatePlayedGames method +func (protocol *Protocol) SetHandlerUpdatePlayedGames(handler func(err error, packet nex.PacketInterface, callID uint32, playedGames *types.List[*friends_3ds_types.PlayedGame]) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdatePlayedGames = handler +} + +// SetHandlerUpdatePreference sets the handler for the UpdatePreference method +func (protocol *Protocol) SetHandlerUpdatePreference(handler func(err error, packet nex.PacketInterface, callID uint32, publicMode *types.PrimitiveBool, showGame *types.PrimitiveBool, showPlayedGame *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdatePreference = handler +} + +// SetHandlerGetFriendMii sets the handler for the GetFriendMii method +func (protocol *Protocol) SetHandlerGetFriendMii(handler func(err error, packet nex.PacketInterface, callID uint32, friends *types.List[*friends_3ds_types.FriendInfo]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetFriendMii = handler +} + +// SetHandlerGetFriendMiiList sets the handler for the GetFriendMiiList method +func (protocol *Protocol) SetHandlerGetFriendMiiList(handler func(err error, packet nex.PacketInterface, callID uint32, friends *types.List[*friends_3ds_types.FriendInfo]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetFriendMiiList = handler +} + +// SetHandlerIsActiveGame sets the handler for the IsActiveGame method +func (protocol *Protocol) SetHandlerIsActiveGame(handler func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID], gameKey *friends_3ds_types.GameKey) (*nex.RMCMessage, *nex.Error)) { + protocol.IsActiveGame = handler +} + +// SetHandlerGetPrincipalIDByLocalFriendCode sets the handler for the GetPrincipalIDByLocalFriendCode method +func (protocol *Protocol) SetHandlerGetPrincipalIDByLocalFriendCode(handler func(err error, packet nex.PacketInterface, callID uint32, lfc *types.PrimitiveU64, lfcList *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetPrincipalIDByLocalFriendCode = handler +} + +// SetHandlerGetFriendRelationships sets the handler for the GetFriendRelationships method +func (protocol *Protocol) SetHandlerGetFriendRelationships(handler func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetFriendRelationships = handler +} + +// SetHandlerAddFriendByPrincipalID sets the handler for the AddFriendByPrincipalID method +func (protocol *Protocol) SetHandlerAddFriendByPrincipalID(handler func(err error, packet nex.PacketInterface, callID uint32, lfc *types.PrimitiveU64, pid *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.AddFriendByPrincipalID = handler +} + +// SetHandlerAddFriendBylstPrincipalID sets the handler for the AddFriendBylstPrincipalID method +func (protocol *Protocol) SetHandlerAddFriendBylstPrincipalID(handler func(err error, packet nex.PacketInterface, callID uint32, lfc *types.PrimitiveU64, pids *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) { + protocol.AddFriendBylstPrincipalID = handler +} + +// SetHandlerRemoveFriendByLocalFriendCode sets the handler for the RemoveFriendByLocalFriendCode method +func (protocol *Protocol) SetHandlerRemoveFriendByLocalFriendCode(handler func(err error, packet nex.PacketInterface, callID uint32, lfc *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.RemoveFriendByLocalFriendCode = handler +} + +// SetHandlerRemoveFriendByPrincipalID sets the handler for the RemoveFriendByPrincipalID method +func (protocol *Protocol) SetHandlerRemoveFriendByPrincipalID(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.RemoveFriendByPrincipalID = handler +} + +// SetHandlerGetAllFriends sets the handler for the GetAllFriends method +func (protocol *Protocol) SetHandlerGetAllFriends(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetAllFriends = handler +} + +// SetHandlerUpdateBlackList sets the handler for the UpdateBlackList method +func (protocol *Protocol) SetHandlerUpdateBlackList(handler func(err error, packet nex.PacketInterface, callID uint32, unknown *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateBlackList = handler +} + +// SetHandlerSyncFriend sets the handler for the SyncFriend method +func (protocol *Protocol) SetHandlerSyncFriend(handler func(err error, packet nex.PacketInterface, callID uint32, lfc *types.PrimitiveU64, pids *types.List[*types.PID], lfcList *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error)) { + protocol.SyncFriend = handler +} + +// SetHandlerUpdatePresence sets the handler for the UpdatePresence method +func (protocol *Protocol) SetHandlerUpdatePresence(handler func(err error, packet nex.PacketInterface, callID uint32, presence *friends_3ds_types.NintendoPresence, showGame *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdatePresence = handler +} + +// SetHandlerUpdateFavoriteGameKey sets the handler for the UpdateFavoriteGameKey method +func (protocol *Protocol) SetHandlerUpdateFavoriteGameKey(handler func(err error, packet nex.PacketInterface, callID uint32, gameKey *friends_3ds_types.GameKey) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateFavoriteGameKey = handler +} + +// SetHandlerUpdateComment sets the handler for the UpdateComment method +func (protocol *Protocol) SetHandlerUpdateComment(handler func(err error, packet nex.PacketInterface, callID uint32, comment *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateComment = handler +} + +// SetHandlerUpdatePicture sets the handler for the UpdatePicture method +func (protocol *Protocol) SetHandlerUpdatePicture(handler func(err error, packet nex.PacketInterface, callID uint32, unknown *types.PrimitiveU32, picture *types.Buffer) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdatePicture = handler +} + +// SetHandlerGetFriendPresence sets the handler for the GetFriendPresence method +func (protocol *Protocol) SetHandlerGetFriendPresence(handler func(err error, packet nex.PacketInterface, callID uint32, pidList *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetFriendPresence = handler +} + +// SetHandlerGetFriendComment sets the handler for the GetFriendComment method +func (protocol *Protocol) SetHandlerGetFriendComment(handler func(err error, packet nex.PacketInterface, callID uint32, friends *types.List[*friends_3ds_types.FriendInfo]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetFriendComment = handler +} + +// SetHandlerGetFriendPicture sets the handler for the GetFriendPicture method +func (protocol *Protocol) SetHandlerGetFriendPicture(handler func(err error, packet nex.PacketInterface, callID uint32, unknown *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetFriendPicture = handler +} + +// SetHandlerGetFriendPersistentInfo sets the handler for the GetFriendPersistentInfo method +func (protocol *Protocol) SetHandlerGetFriendPersistentInfo(handler func(err error, packet nex.PacketInterface, callID uint32, pidList *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetFriendPersistentInfo = handler +} + +// SetHandlerSendInvitation sets the handler for the SendInvitation method +func (protocol *Protocol) SetHandlerSendInvitation(handler func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) { + protocol.SendInvitation = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodUpdateProfile: + protocol.handleUpdateProfile(packet) + case MethodUpdateMii: + protocol.handleUpdateMii(packet) + case MethodUpdateMiiList: + protocol.handleUpdateMiiList(packet) + case MethodUpdatePlayedGames: + protocol.handleUpdatePlayedGames(packet) + case MethodUpdatePreference: + protocol.handleUpdatePreference(packet) + case MethodGetFriendMii: + protocol.handleGetFriendMii(packet) + case MethodGetFriendMiiList: + protocol.handleGetFriendMiiList(packet) + case MethodIsActiveGame: + protocol.handleIsActiveGame(packet) + case MethodGetPrincipalIDByLocalFriendCode: + protocol.handleGetPrincipalIDByLocalFriendCode(packet) + case MethodGetFriendRelationships: + protocol.handleGetFriendRelationships(packet) + case MethodAddFriendByPrincipalID: + protocol.handleAddFriendByPrincipalID(packet) + case MethodAddFriendBylstPrincipalID: + protocol.handleAddFriendBylstPrincipalID(packet) + case MethodRemoveFriendByLocalFriendCode: + protocol.handleRemoveFriendByLocalFriendCode(packet) + case MethodRemoveFriendByPrincipalID: + protocol.handleRemoveFriendByPrincipalID(packet) + case MethodGetAllFriends: + protocol.handleGetAllFriends(packet) + case MethodUpdateBlackList: + protocol.handleUpdateBlackList(packet) + case MethodSyncFriend: + protocol.handleSyncFriend(packet) + case MethodUpdatePresence: + protocol.handleUpdatePresence(packet) + case MethodUpdateFavoriteGameKey: + protocol.handleUpdateFavoriteGameKey(packet) + case MethodUpdateComment: + protocol.handleUpdateComment(packet) + case MethodUpdatePicture: + protocol.handleUpdatePicture(packet) + case MethodGetFriendPresence: + protocol.handleGetFriendPresence(packet) + case MethodGetFriendComment: + protocol.handleGetFriendComment(packet) + case MethodGetFriendPicture: + protocol.handleGetFriendPicture(packet) + case MethodGetFriendPersistentInfo: + protocol.handleGetFriendPersistentInfo(packet) + case MethodSendInvitation: + protocol.handleSendInvitation(packet) + default: + errMessage := fmt.Sprintf("Unsupported Friends (3DS) method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Friends (3DS) protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/friends-3ds/remove_friend_by_local_friend_code.go b/nex-protocols-go/friends-3ds/remove_friend_by_local_friend_code.go new file mode 100644 index 0000000..7784089 --- /dev/null +++ b/nex-protocols-go/friends-3ds/remove_friend_by_local_friend_code.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRemoveFriendByLocalFriendCode(packet nex.PacketInterface) { + if protocol.RemoveFriendByLocalFriendCode == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::RemoveFriendByLocalFriendCode not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lfc := types.NewPrimitiveU64(0) + + err := lfc.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RemoveFriendByLocalFriendCode(fmt.Errorf("Failed to read lfc from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RemoveFriendByLocalFriendCode(nil, packet, callID, lfc) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/remove_friend_by_principal_id.go b/nex-protocols-go/friends-3ds/remove_friend_by_principal_id.go new file mode 100644 index 0000000..c55275a --- /dev/null +++ b/nex-protocols-go/friends-3ds/remove_friend_by_principal_id.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRemoveFriendByPrincipalID(packet nex.PacketInterface) { + if protocol.RemoveFriendByPrincipalID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::RemoveFriendByPrincipalID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pid := types.NewPID(0) + + err := pid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RemoveFriendByPrincipalID(fmt.Errorf("Failed to read pid from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RemoveFriendByPrincipalID(nil, packet, callID, pid) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/send_invitation.go b/nex-protocols-go/friends-3ds/send_invitation.go new file mode 100644 index 0000000..6197451 --- /dev/null +++ b/nex-protocols-go/friends-3ds/send_invitation.go @@ -0,0 +1,48 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSendInvitation(packet nex.PacketInterface) { + if protocol.SendInvitation == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::SendInvitation not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pids := types.NewList[*types.PID]() + pids.Type = types.NewPID(0) + + err := pids.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SendInvitation(fmt.Errorf("Failed to read pids from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SendInvitation(nil, packet, callID, pids) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/sync_friend.go b/nex-protocols-go/friends-3ds/sync_friend.go new file mode 100644 index 0000000..ef10b50 --- /dev/null +++ b/nex-protocols-go/friends-3ds/sync_friend.go @@ -0,0 +1,73 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSyncFriend(packet nex.PacketInterface) { + if protocol.SyncFriend == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::SyncFriend not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lfc := types.NewPrimitiveU64(0) + pids := types.NewList[*types.PID]() + pids.Type = types.NewPID(0) + lfcList := types.NewList[*types.PrimitiveU64]() + lfcList.Type = types.NewPrimitiveU64(0) + + var err error + + err = lfc.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SyncFriend(fmt.Errorf("Failed to read lfc from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = pids.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SyncFriend(fmt.Errorf("Failed to read pids from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = lfcList.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SyncFriend(fmt.Errorf("Failed to read lfcList from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SyncFriend(nil, packet, callID, lfc, pids, lfcList) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/types/friend_comment.go b/nex-protocols-go/friends-3ds/types/friend_comment.go new file mode 100644 index 0000000..0a90db5 --- /dev/null +++ b/nex-protocols-go/friends-3ds/types/friend_comment.go @@ -0,0 +1,141 @@ +// Package types implements all the types used by the Friends3DS protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// FriendComment is a type within the Friends3DS protocol +type FriendComment struct { + types.Structure + *types.Data + PID *types.PID + Comment *types.String + ModifiedAt *types.DateTime +} + +// WriteTo writes the FriendComment to the given writable +func (fc *FriendComment) WriteTo(writable types.Writable) { + fc.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + fc.PID.WriteTo(contentWritable) + fc.Comment.WriteTo(contentWritable) + fc.ModifiedAt.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + fc.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the FriendComment from the given readable +func (fc *FriendComment) ExtractFrom(readable types.Readable) error { + var err error + + err = fc.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendComment.Data. %s", err.Error()) + } + + err = fc.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendComment header. %s", err.Error()) + } + + err = fc.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendComment.PID. %s", err.Error()) + } + + err = fc.Comment.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendComment.Comment. %s", err.Error()) + } + + err = fc.ModifiedAt.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendComment.ModifiedAt. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of FriendComment +func (fc *FriendComment) Copy() types.RVType { + copied := NewFriendComment() + + copied.StructureVersion = fc.StructureVersion + copied.Data = fc.Data.Copy().(*types.Data) + copied.PID = fc.PID.Copy().(*types.PID) + copied.Comment = fc.Comment.Copy().(*types.String) + copied.ModifiedAt = fc.ModifiedAt.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given FriendComment contains the same data as the current FriendComment +func (fc *FriendComment) Equals(o types.RVType) bool { + if _, ok := o.(*FriendComment); !ok { + return false + } + + other := o.(*FriendComment) + + if fc.StructureVersion != other.StructureVersion { + return false + } + + if !fc.Data.Equals(other.Data) { + return false + } + + if !fc.PID.Equals(other.PID) { + return false + } + + if !fc.Comment.Equals(other.Comment) { + return false + } + + return fc.ModifiedAt.Equals(other.ModifiedAt) +} + +// String returns the string representation of the FriendComment +func (fc *FriendComment) String() string { + return fc.FormatToString(0) +} + +// FormatToString pretty-prints the FriendComment using the provided indentation level +func (fc *FriendComment) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("FriendComment{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, fc.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, fc.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sComment: %s,\n", indentationValues, fc.Comment)) + b.WriteString(fmt.Sprintf("%sModifiedAt: %s,\n", indentationValues, fc.ModifiedAt.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewFriendComment returns a new FriendComment +func NewFriendComment() *FriendComment { + fc := &FriendComment{ + Data: types.NewData(), + PID: types.NewPID(0), + Comment: types.NewString(""), + ModifiedAt: types.NewDateTime(0), + } + + return fc +} diff --git a/nex-protocols-go/friends-3ds/types/friend_info.go b/nex-protocols-go/friends-3ds/types/friend_info.go new file mode 100644 index 0000000..0312494 --- /dev/null +++ b/nex-protocols-go/friends-3ds/types/friend_info.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the Friends3DS protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// FriendInfo is a type within the Friends3DS protocol +type FriendInfo struct { + types.Structure + PID *types.PID + Unknown *types.DateTime +} + +// WriteTo writes the FriendInfo to the given writable +func (fi *FriendInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + fi.PID.WriteTo(contentWritable) + fi.Unknown.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + fi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the FriendInfo from the given readable +func (fi *FriendInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = fi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendInfo header. %s", err.Error()) + } + + err = fi.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendInfo.PID. %s", err.Error()) + } + + err = fi.Unknown.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendInfo.Unknown. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of FriendInfo +func (fi *FriendInfo) Copy() types.RVType { + copied := NewFriendInfo() + + copied.StructureVersion = fi.StructureVersion + copied.PID = fi.PID.Copy().(*types.PID) + copied.Unknown = fi.Unknown.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given FriendInfo contains the same data as the current FriendInfo +func (fi *FriendInfo) Equals(o types.RVType) bool { + if _, ok := o.(*FriendInfo); !ok { + return false + } + + other := o.(*FriendInfo) + + if fi.StructureVersion != other.StructureVersion { + return false + } + + if !fi.PID.Equals(other.PID) { + return false + } + + return fi.Unknown.Equals(other.Unknown) +} + +// String returns the string representation of the FriendInfo +func (fi *FriendInfo) String() string { + return fi.FormatToString(0) +} + +// FormatToString pretty-prints the FriendInfo using the provided indentation level +func (fi *FriendInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("FriendInfo{\n") + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, fi.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUnknown: %s,\n", indentationValues, fi.Unknown.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewFriendInfo returns a new FriendInfo +func NewFriendInfo() *FriendInfo { + fi := &FriendInfo{ + PID: types.NewPID(0), + Unknown: types.NewDateTime(0), + } + + return fi +} diff --git a/nex-protocols-go/friends-3ds/types/friend_mii.go b/nex-protocols-go/friends-3ds/types/friend_mii.go new file mode 100644 index 0000000..8b0bbd4 --- /dev/null +++ b/nex-protocols-go/friends-3ds/types/friend_mii.go @@ -0,0 +1,141 @@ +// Package types implements all the types used by the Friends3DS protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// FriendMii is a type within the Friends3DS protocol +type FriendMii struct { + types.Structure + *types.Data + PID *types.PID + Mii *Mii + ModifiedAt *types.DateTime +} + +// WriteTo writes the FriendMii to the given writable +func (fm *FriendMii) WriteTo(writable types.Writable) { + fm.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + fm.PID.WriteTo(contentWritable) + fm.Mii.WriteTo(contentWritable) + fm.ModifiedAt.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + fm.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the FriendMii from the given readable +func (fm *FriendMii) ExtractFrom(readable types.Readable) error { + var err error + + err = fm.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendMii.Data. %s", err.Error()) + } + + err = fm.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendMii header. %s", err.Error()) + } + + err = fm.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendMii.PID. %s", err.Error()) + } + + err = fm.Mii.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendMii.Mii. %s", err.Error()) + } + + err = fm.ModifiedAt.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendMii.ModifiedAt. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of FriendMii +func (fm *FriendMii) Copy() types.RVType { + copied := NewFriendMii() + + copied.StructureVersion = fm.StructureVersion + copied.Data = fm.Data.Copy().(*types.Data) + copied.PID = fm.PID.Copy().(*types.PID) + copied.Mii = fm.Mii.Copy().(*Mii) + copied.ModifiedAt = fm.ModifiedAt.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given FriendMii contains the same data as the current FriendMii +func (fm *FriendMii) Equals(o types.RVType) bool { + if _, ok := o.(*FriendMii); !ok { + return false + } + + other := o.(*FriendMii) + + if fm.StructureVersion != other.StructureVersion { + return false + } + + if !fm.Data.Equals(other.Data) { + return false + } + + if !fm.PID.Equals(other.PID) { + return false + } + + if !fm.Mii.Equals(other.Mii) { + return false + } + + return fm.ModifiedAt.Equals(other.ModifiedAt) +} + +// String returns the string representation of the FriendMii +func (fm *FriendMii) String() string { + return fm.FormatToString(0) +} + +// FormatToString pretty-prints the FriendMii using the provided indentation level +func (fm *FriendMii) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("FriendMii{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, fm.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, fm.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sMii: %s,\n", indentationValues, fm.Mii.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sModifiedAt: %s,\n", indentationValues, fm.ModifiedAt.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewFriendMii returns a new FriendMii +func NewFriendMii() *FriendMii { + fm := &FriendMii{ + Data: types.NewData(), + PID: types.NewPID(0), + Mii: NewMii(), + ModifiedAt: types.NewDateTime(0), + } + + return fm +} diff --git a/nex-protocols-go/friends-3ds/types/friend_mii_list.go b/nex-protocols-go/friends-3ds/types/friend_mii_list.go new file mode 100644 index 0000000..8bc8b83 --- /dev/null +++ b/nex-protocols-go/friends-3ds/types/friend_mii_list.go @@ -0,0 +1,141 @@ +// Package types implements all the types used by the Friends3DS protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// FriendMiiList is a type within the Friends3DS protocol +type FriendMiiList struct { + types.Structure + *types.Data + Unknown1 *types.PrimitiveU32 + MiiList *MiiList + Unknown2 *types.DateTime +} + +// WriteTo writes the FriendMiiList to the given writable +func (fml *FriendMiiList) WriteTo(writable types.Writable) { + fml.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + fml.Unknown1.WriteTo(contentWritable) + fml.MiiList.WriteTo(contentWritable) + fml.Unknown2.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + fml.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the FriendMiiList from the given readable +func (fml *FriendMiiList) ExtractFrom(readable types.Readable) error { + var err error + + err = fml.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendMiiList.Data. %s", err.Error()) + } + + err = fml.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendMiiList header. %s", err.Error()) + } + + err = fml.Unknown1.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendMiiList.Unknown1. %s", err.Error()) + } + + err = fml.MiiList.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendMiiList.MiiList. %s", err.Error()) + } + + err = fml.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendMiiList.Unknown2. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of FriendMiiList +func (fml *FriendMiiList) Copy() types.RVType { + copied := NewFriendMiiList() + + copied.StructureVersion = fml.StructureVersion + copied.Data = fml.Data.Copy().(*types.Data) + copied.Unknown1 = fml.Unknown1.Copy().(*types.PrimitiveU32) + copied.MiiList = fml.MiiList.Copy().(*MiiList) + copied.Unknown2 = fml.Unknown2.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given FriendMiiList contains the same data as the current FriendMiiList +func (fml *FriendMiiList) Equals(o types.RVType) bool { + if _, ok := o.(*FriendMiiList); !ok { + return false + } + + other := o.(*FriendMiiList) + + if fml.StructureVersion != other.StructureVersion { + return false + } + + if !fml.Data.Equals(other.Data) { + return false + } + + if !fml.Unknown1.Equals(other.Unknown1) { + return false + } + + if !fml.MiiList.Equals(other.MiiList) { + return false + } + + return fml.Unknown2.Equals(other.Unknown2) +} + +// String returns the string representation of the FriendMiiList +func (fml *FriendMiiList) String() string { + return fml.FormatToString(0) +} + +// FormatToString pretty-prints the FriendMiiList using the provided indentation level +func (fml *FriendMiiList) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("FriendMiiList{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, fml.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUnknown1: %s,\n", indentationValues, fml.Unknown1)) + b.WriteString(fmt.Sprintf("%sMiiList: %s,\n", indentationValues, fml.MiiList.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, fml.Unknown2.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewFriendMiiList returns a new FriendMiiList +func NewFriendMiiList() *FriendMiiList { + fml := &FriendMiiList{ + Data: types.NewData(), + Unknown1: types.NewPrimitiveU32(0), + MiiList: NewMiiList(), + Unknown2: types.NewDateTime(0), + } + + return fml +} diff --git a/nex-protocols-go/friends-3ds/types/friend_persistent_info.go b/nex-protocols-go/friends-3ds/types/friend_persistent_info.go new file mode 100644 index 0000000..fd6f211 --- /dev/null +++ b/nex-protocols-go/friends-3ds/types/friend_persistent_info.go @@ -0,0 +1,253 @@ +// Package types implements all the types used by the Friends3DS protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// FriendPersistentInfo is a type within the Friends3DS protocol +type FriendPersistentInfo struct { + types.Structure + *types.Data + PID *types.PID + Region *types.PrimitiveU8 + Country *types.PrimitiveU8 + Area *types.PrimitiveU8 + Language *types.PrimitiveU8 + Platform *types.PrimitiveU8 + GameKey *GameKey + Message *types.String + MessageUpdatedAt *types.DateTime + MiiModifiedAt *types.DateTime + LastOnline *types.DateTime +} + +// WriteTo writes the FriendPersistentInfo to the given writable +func (fpi *FriendPersistentInfo) WriteTo(writable types.Writable) { + fpi.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + fpi.PID.WriteTo(contentWritable) + fpi.Region.WriteTo(contentWritable) + fpi.Country.WriteTo(contentWritable) + fpi.Area.WriteTo(contentWritable) + fpi.Language.WriteTo(contentWritable) + fpi.Platform.WriteTo(contentWritable) + fpi.GameKey.WriteTo(contentWritable) + fpi.Message.WriteTo(contentWritable) + fpi.MessageUpdatedAt.WriteTo(contentWritable) + fpi.MiiModifiedAt.WriteTo(contentWritable) + fpi.LastOnline.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + fpi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the FriendPersistentInfo from the given readable +func (fpi *FriendPersistentInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = fpi.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPersistentInfo.Data. %s", err.Error()) + } + + err = fpi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPersistentInfo header. %s", err.Error()) + } + + err = fpi.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPersistentInfo.PID. %s", err.Error()) + } + + err = fpi.Region.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPersistentInfo.Region. %s", err.Error()) + } + + err = fpi.Country.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPersistentInfo.Country. %s", err.Error()) + } + + err = fpi.Area.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPersistentInfo.Area. %s", err.Error()) + } + + err = fpi.Language.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPersistentInfo.Language. %s", err.Error()) + } + + err = fpi.Platform.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPersistentInfo.Platform. %s", err.Error()) + } + + err = fpi.GameKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPersistentInfo.GameKey. %s", err.Error()) + } + + err = fpi.Message.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPersistentInfo.Message. %s", err.Error()) + } + + err = fpi.MessageUpdatedAt.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPersistentInfo.MessageUpdatedAt. %s", err.Error()) + } + + err = fpi.MiiModifiedAt.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPersistentInfo.MiiModifiedAt. %s", err.Error()) + } + + err = fpi.LastOnline.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPersistentInfo.LastOnline. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of FriendPersistentInfo +func (fpi *FriendPersistentInfo) Copy() types.RVType { + copied := NewFriendPersistentInfo() + + copied.StructureVersion = fpi.StructureVersion + copied.Data = fpi.Data.Copy().(*types.Data) + copied.PID = fpi.PID.Copy().(*types.PID) + copied.Region = fpi.Region.Copy().(*types.PrimitiveU8) + copied.Country = fpi.Country.Copy().(*types.PrimitiveU8) + copied.Area = fpi.Area.Copy().(*types.PrimitiveU8) + copied.Language = fpi.Language.Copy().(*types.PrimitiveU8) + copied.Platform = fpi.Platform.Copy().(*types.PrimitiveU8) + copied.GameKey = fpi.GameKey.Copy().(*GameKey) + copied.Message = fpi.Message.Copy().(*types.String) + copied.MessageUpdatedAt = fpi.MessageUpdatedAt.Copy().(*types.DateTime) + copied.MiiModifiedAt = fpi.MiiModifiedAt.Copy().(*types.DateTime) + copied.LastOnline = fpi.LastOnline.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given FriendPersistentInfo contains the same data as the current FriendPersistentInfo +func (fpi *FriendPersistentInfo) Equals(o types.RVType) bool { + if _, ok := o.(*FriendPersistentInfo); !ok { + return false + } + + other := o.(*FriendPersistentInfo) + + if fpi.StructureVersion != other.StructureVersion { + return false + } + + if !fpi.Data.Equals(other.Data) { + return false + } + + if !fpi.PID.Equals(other.PID) { + return false + } + + if !fpi.Region.Equals(other.Region) { + return false + } + + if !fpi.Country.Equals(other.Country) { + return false + } + + if !fpi.Area.Equals(other.Area) { + return false + } + + if !fpi.Language.Equals(other.Language) { + return false + } + + if !fpi.Platform.Equals(other.Platform) { + return false + } + + if !fpi.GameKey.Equals(other.GameKey) { + return false + } + + if !fpi.Message.Equals(other.Message) { + return false + } + + if !fpi.MessageUpdatedAt.Equals(other.MessageUpdatedAt) { + return false + } + + if !fpi.MiiModifiedAt.Equals(other.MiiModifiedAt) { + return false + } + + return fpi.LastOnline.Equals(other.LastOnline) +} + +// String returns the string representation of the FriendPersistentInfo +func (fpi *FriendPersistentInfo) String() string { + return fpi.FormatToString(0) +} + +// FormatToString pretty-prints the FriendPersistentInfo using the provided indentation level +func (fpi *FriendPersistentInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("FriendPersistentInfo{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, fpi.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, fpi.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sRegion: %s,\n", indentationValues, fpi.Region)) + b.WriteString(fmt.Sprintf("%sCountry: %s,\n", indentationValues, fpi.Country)) + b.WriteString(fmt.Sprintf("%sArea: %s,\n", indentationValues, fpi.Area)) + b.WriteString(fmt.Sprintf("%sLanguage: %s,\n", indentationValues, fpi.Language)) + b.WriteString(fmt.Sprintf("%sPlatform: %s,\n", indentationValues, fpi.Platform)) + b.WriteString(fmt.Sprintf("%sGameKey: %s,\n", indentationValues, fpi.GameKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sMessage: %s,\n", indentationValues, fpi.Message)) + b.WriteString(fmt.Sprintf("%sMessageUpdatedAt: %s,\n", indentationValues, fpi.MessageUpdatedAt.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sMiiModifiedAt: %s,\n", indentationValues, fpi.MiiModifiedAt.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sLastOnline: %s,\n", indentationValues, fpi.LastOnline.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewFriendPersistentInfo returns a new FriendPersistentInfo +func NewFriendPersistentInfo() *FriendPersistentInfo { + fpi := &FriendPersistentInfo{ + Data: types.NewData(), + PID: types.NewPID(0), + Region: types.NewPrimitiveU8(0), + Country: types.NewPrimitiveU8(0), + Area: types.NewPrimitiveU8(0), + Language: types.NewPrimitiveU8(0), + Platform: types.NewPrimitiveU8(0), + GameKey: NewGameKey(), + Message: types.NewString(""), + MessageUpdatedAt: types.NewDateTime(0), + MiiModifiedAt: types.NewDateTime(0), + LastOnline: types.NewDateTime(0), + } + + return fpi +} diff --git a/nex-protocols-go/friends-3ds/types/friend_picture.go b/nex-protocols-go/friends-3ds/types/friend_picture.go new file mode 100644 index 0000000..0a20128 --- /dev/null +++ b/nex-protocols-go/friends-3ds/types/friend_picture.go @@ -0,0 +1,141 @@ +// Package types implements all the types used by the Friends3DS protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// FriendPicture is a type within the Friends3DS protocol +type FriendPicture struct { + types.Structure + *types.Data + Unknown1 *types.PrimitiveU32 + PictureData *types.Buffer + Unknown2 *types.DateTime +} + +// WriteTo writes the FriendPicture to the given writable +func (fp *FriendPicture) WriteTo(writable types.Writable) { + fp.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + fp.Unknown1.WriteTo(contentWritable) + fp.PictureData.WriteTo(contentWritable) + fp.Unknown2.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + fp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the FriendPicture from the given readable +func (fp *FriendPicture) ExtractFrom(readable types.Readable) error { + var err error + + err = fp.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPicture.Data. %s", err.Error()) + } + + err = fp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPicture header. %s", err.Error()) + } + + err = fp.Unknown1.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPicture.Unknown1. %s", err.Error()) + } + + err = fp.PictureData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPicture.PictureData. %s", err.Error()) + } + + err = fp.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPicture.Unknown2. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of FriendPicture +func (fp *FriendPicture) Copy() types.RVType { + copied := NewFriendPicture() + + copied.StructureVersion = fp.StructureVersion + copied.Data = fp.Data.Copy().(*types.Data) + copied.Unknown1 = fp.Unknown1.Copy().(*types.PrimitiveU32) + copied.PictureData = fp.PictureData.Copy().(*types.Buffer) + copied.Unknown2 = fp.Unknown2.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given FriendPicture contains the same data as the current FriendPicture +func (fp *FriendPicture) Equals(o types.RVType) bool { + if _, ok := o.(*FriendPicture); !ok { + return false + } + + other := o.(*FriendPicture) + + if fp.StructureVersion != other.StructureVersion { + return false + } + + if !fp.Data.Equals(other.Data) { + return false + } + + if !fp.Unknown1.Equals(other.Unknown1) { + return false + } + + if !fp.PictureData.Equals(other.PictureData) { + return false + } + + return fp.Unknown2.Equals(other.Unknown2) +} + +// String returns the string representation of the FriendPicture +func (fp *FriendPicture) String() string { + return fp.FormatToString(0) +} + +// FormatToString pretty-prints the FriendPicture using the provided indentation level +func (fp *FriendPicture) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("FriendPicture{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, fp.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUnknown1: %s,\n", indentationValues, fp.Unknown1)) + b.WriteString(fmt.Sprintf("%sPictureData: %s,\n", indentationValues, fp.PictureData)) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, fp.Unknown2.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewFriendPicture returns a new FriendPicture +func NewFriendPicture() *FriendPicture { + fp := &FriendPicture{ + Data: types.NewData(), + Unknown1: types.NewPrimitiveU32(0), + PictureData: types.NewBuffer(nil), + Unknown2: types.NewDateTime(0), + } + + return fp +} diff --git a/nex-protocols-go/friends-3ds/types/friend_presence.go b/nex-protocols-go/friends-3ds/types/friend_presence.go new file mode 100644 index 0000000..50e8e96 --- /dev/null +++ b/nex-protocols-go/friends-3ds/types/friend_presence.go @@ -0,0 +1,127 @@ +// Package types implements all the types used by the Friends3DS protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// FriendPresence is a type within the Friends3DS protocol +type FriendPresence struct { + types.Structure + *types.Data + PID *types.PID + Presence *NintendoPresence +} + +// WriteTo writes the FriendPresence to the given writable +func (fp *FriendPresence) WriteTo(writable types.Writable) { + fp.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + fp.PID.WriteTo(contentWritable) + fp.Presence.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + fp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the FriendPresence from the given readable +func (fp *FriendPresence) ExtractFrom(readable types.Readable) error { + var err error + + err = fp.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPresence.Data. %s", err.Error()) + } + + err = fp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPresence header. %s", err.Error()) + } + + err = fp.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPresence.PID. %s", err.Error()) + } + + err = fp.Presence.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendPresence.Presence. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of FriendPresence +func (fp *FriendPresence) Copy() types.RVType { + copied := NewFriendPresence() + + copied.StructureVersion = fp.StructureVersion + copied.Data = fp.Data.Copy().(*types.Data) + copied.PID = fp.PID.Copy().(*types.PID) + copied.Presence = fp.Presence.Copy().(*NintendoPresence) + + return copied +} + +// Equals checks if the given FriendPresence contains the same data as the current FriendPresence +func (fp *FriendPresence) Equals(o types.RVType) bool { + if _, ok := o.(*FriendPresence); !ok { + return false + } + + other := o.(*FriendPresence) + + if fp.StructureVersion != other.StructureVersion { + return false + } + + if !fp.Data.Equals(other.Data) { + return false + } + + if !fp.PID.Equals(other.PID) { + return false + } + + return fp.Presence.Equals(other.Presence) +} + +// String returns the string representation of the FriendPresence +func (fp *FriendPresence) String() string { + return fp.FormatToString(0) +} + +// FormatToString pretty-prints the FriendPresence using the provided indentation level +func (fp *FriendPresence) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("FriendPresence{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, fp.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, fp.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPresence: %s,\n", indentationValues, fp.Presence.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewFriendPresence returns a new FriendPresence +func NewFriendPresence() *FriendPresence { + fp := &FriendPresence{ + Data: types.NewData(), + PID: types.NewPID(0), + Presence: NewNintendoPresence(), + } + + return fp +} diff --git a/nex-protocols-go/friends-3ds/types/friend_relationship.go b/nex-protocols-go/friends-3ds/types/friend_relationship.go new file mode 100644 index 0000000..0a7f635 --- /dev/null +++ b/nex-protocols-go/friends-3ds/types/friend_relationship.go @@ -0,0 +1,141 @@ +// Package types implements all the types used by the Friends3DS protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// FriendRelationship is a type within the Friends3DS protocol +type FriendRelationship struct { + types.Structure + *types.Data + PID *types.PID + LFC *types.PrimitiveU64 + RelationshipType *types.PrimitiveU8 +} + +// WriteTo writes the FriendRelationship to the given writable +func (fr *FriendRelationship) WriteTo(writable types.Writable) { + fr.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + fr.PID.WriteTo(contentWritable) + fr.LFC.WriteTo(contentWritable) + fr.RelationshipType.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + fr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the FriendRelationship from the given readable +func (fr *FriendRelationship) ExtractFrom(readable types.Readable) error { + var err error + + err = fr.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRelationship.Data. %s", err.Error()) + } + + err = fr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRelationship header. %s", err.Error()) + } + + err = fr.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRelationship.PID. %s", err.Error()) + } + + err = fr.LFC.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRelationship.LFC. %s", err.Error()) + } + + err = fr.RelationshipType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRelationship.RelationshipType. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of FriendRelationship +func (fr *FriendRelationship) Copy() types.RVType { + copied := NewFriendRelationship() + + copied.StructureVersion = fr.StructureVersion + copied.Data = fr.Data.Copy().(*types.Data) + copied.PID = fr.PID.Copy().(*types.PID) + copied.LFC = fr.LFC.Copy().(*types.PrimitiveU64) + copied.RelationshipType = fr.RelationshipType.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given FriendRelationship contains the same data as the current FriendRelationship +func (fr *FriendRelationship) Equals(o types.RVType) bool { + if _, ok := o.(*FriendRelationship); !ok { + return false + } + + other := o.(*FriendRelationship) + + if fr.StructureVersion != other.StructureVersion { + return false + } + + if !fr.Data.Equals(other.Data) { + return false + } + + if !fr.PID.Equals(other.PID) { + return false + } + + if !fr.LFC.Equals(other.LFC) { + return false + } + + return fr.RelationshipType.Equals(other.RelationshipType) +} + +// String returns the string representation of the FriendRelationship +func (fr *FriendRelationship) String() string { + return fr.FormatToString(0) +} + +// FormatToString pretty-prints the FriendRelationship using the provided indentation level +func (fr *FriendRelationship) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("FriendRelationship{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, fr.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, fr.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sLFC: %s,\n", indentationValues, fr.LFC)) + b.WriteString(fmt.Sprintf("%sRelationshipType: %s,\n", indentationValues, fr.RelationshipType)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewFriendRelationship returns a new FriendRelationship +func NewFriendRelationship() *FriendRelationship { + fr := &FriendRelationship{ + Data: types.NewData(), + PID: types.NewPID(0), + LFC: types.NewPrimitiveU64(0), + RelationshipType: types.NewPrimitiveU8(0), + } + + return fr +} diff --git a/nex-protocols-go/friends-3ds/types/game_key.go b/nex-protocols-go/friends-3ds/types/game_key.go new file mode 100644 index 0000000..51691b9 --- /dev/null +++ b/nex-protocols-go/friends-3ds/types/game_key.go @@ -0,0 +1,127 @@ +// Package types implements all the types used by the Friends3DS protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GameKey is a type within the Friends3DS protocol +type GameKey struct { + types.Structure + *types.Data + TitleID *types.PrimitiveU64 + TitleVersion *types.PrimitiveU16 +} + +// WriteTo writes the GameKey to the given writable +func (gk *GameKey) WriteTo(writable types.Writable) { + gk.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + gk.TitleID.WriteTo(contentWritable) + gk.TitleVersion.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gk.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GameKey from the given readable +func (gk *GameKey) ExtractFrom(readable types.Readable) error { + var err error + + err = gk.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GameKey.Data. %s", err.Error()) + } + + err = gk.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GameKey header. %s", err.Error()) + } + + err = gk.TitleID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GameKey.TitleID. %s", err.Error()) + } + + err = gk.TitleVersion.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GameKey.TitleVersion. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GameKey +func (gk *GameKey) Copy() types.RVType { + copied := NewGameKey() + + copied.StructureVersion = gk.StructureVersion + copied.Data = gk.Data.Copy().(*types.Data) + copied.TitleID = gk.TitleID.Copy().(*types.PrimitiveU64) + copied.TitleVersion = gk.TitleVersion.Copy().(*types.PrimitiveU16) + + return copied +} + +// Equals checks if the given GameKey contains the same data as the current GameKey +func (gk *GameKey) Equals(o types.RVType) bool { + if _, ok := o.(*GameKey); !ok { + return false + } + + other := o.(*GameKey) + + if gk.StructureVersion != other.StructureVersion { + return false + } + + if !gk.Data.Equals(other.Data) { + return false + } + + if !gk.TitleID.Equals(other.TitleID) { + return false + } + + return gk.TitleVersion.Equals(other.TitleVersion) +} + +// String returns the string representation of the GameKey +func (gk *GameKey) String() string { + return gk.FormatToString(0) +} + +// FormatToString pretty-prints the GameKey using the provided indentation level +func (gk *GameKey) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GameKey{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, gk.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sTitleID: %s,\n", indentationValues, gk.TitleID)) + b.WriteString(fmt.Sprintf("%sTitleVersion: %s,\n", indentationValues, gk.TitleVersion)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGameKey returns a new GameKey +func NewGameKey() *GameKey { + gk := &GameKey{ + Data: types.NewData(), + TitleID: types.NewPrimitiveU64(0), + TitleVersion: types.NewPrimitiveU16(0), + } + + return gk +} diff --git a/nex-protocols-go/friends-3ds/types/mii.go b/nex-protocols-go/friends-3ds/types/mii.go new file mode 100644 index 0000000..c8b1bc6 --- /dev/null +++ b/nex-protocols-go/friends-3ds/types/mii.go @@ -0,0 +1,155 @@ +// Package types implements all the types used by the Friends3DS protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// Mii is a type within the Friends3DS protocol +type Mii struct { + types.Structure + *types.Data + Name *types.String + Unknown2 *types.PrimitiveBool + Unknown3 *types.PrimitiveU8 + MiiData *types.Buffer +} + +// WriteTo writes the Mii to the given writable +func (m *Mii) WriteTo(writable types.Writable) { + m.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + m.Name.WriteTo(contentWritable) + m.Unknown2.WriteTo(contentWritable) + m.Unknown3.WriteTo(contentWritable) + m.MiiData.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + m.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the Mii from the given readable +func (m *Mii) ExtractFrom(readable types.Readable) error { + var err error + + err = m.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Mii.Data. %s", err.Error()) + } + + err = m.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Mii header. %s", err.Error()) + } + + err = m.Name.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Mii.Name. %s", err.Error()) + } + + err = m.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Mii.Unknown2. %s", err.Error()) + } + + err = m.Unknown3.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Mii.Unknown3. %s", err.Error()) + } + + err = m.MiiData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Mii.MiiData. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of Mii +func (m *Mii) Copy() types.RVType { + copied := NewMii() + + copied.StructureVersion = m.StructureVersion + copied.Data = m.Data.Copy().(*types.Data) + copied.Name = m.Name.Copy().(*types.String) + copied.Unknown2 = m.Unknown2.Copy().(*types.PrimitiveBool) + copied.Unknown3 = m.Unknown3.Copy().(*types.PrimitiveU8) + copied.MiiData = m.MiiData.Copy().(*types.Buffer) + + return copied +} + +// Equals checks if the given Mii contains the same data as the current Mii +func (m *Mii) Equals(o types.RVType) bool { + if _, ok := o.(*Mii); !ok { + return false + } + + other := o.(*Mii) + + if m.StructureVersion != other.StructureVersion { + return false + } + + if !m.Data.Equals(other.Data) { + return false + } + + if !m.Name.Equals(other.Name) { + return false + } + + if !m.Unknown2.Equals(other.Unknown2) { + return false + } + + if !m.Unknown3.Equals(other.Unknown3) { + return false + } + + return m.MiiData.Equals(other.MiiData) +} + +// String returns the string representation of the Mii +func (m *Mii) String() string { + return m.FormatToString(0) +} + +// FormatToString pretty-prints the Mii using the provided indentation level +func (m *Mii) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("Mii{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, m.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sName: %s,\n", indentationValues, m.Name)) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, m.Unknown2)) + b.WriteString(fmt.Sprintf("%sUnknown3: %s,\n", indentationValues, m.Unknown3)) + b.WriteString(fmt.Sprintf("%sMiiData: %s,\n", indentationValues, m.MiiData)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMii returns a new Mii +func NewMii() *Mii { + m := &Mii{ + Data: types.NewData(), + Name: types.NewString(""), + Unknown2: types.NewPrimitiveBool(false), + Unknown3: types.NewPrimitiveU8(0), + MiiData: types.NewBuffer(nil), + } + + return m +} diff --git a/nex-protocols-go/friends-3ds/types/mii_list.go b/nex-protocols-go/friends-3ds/types/mii_list.go new file mode 100644 index 0000000..7fd1d33 --- /dev/null +++ b/nex-protocols-go/friends-3ds/types/mii_list.go @@ -0,0 +1,157 @@ +// Package types implements all the types used by the Friends3DS protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// MiiList is a type within the Friends3DS protocol +type MiiList struct { + types.Structure + *types.Data + Unknown1 *types.String + Unknown2 *types.PrimitiveBool + Unknown3 *types.PrimitiveU8 + MiiDataList *types.List[*types.Buffer] +} + +// WriteTo writes the MiiList to the given writable +func (ml *MiiList) WriteTo(writable types.Writable) { + ml.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + ml.Unknown1.WriteTo(contentWritable) + ml.Unknown2.WriteTo(contentWritable) + ml.Unknown3.WriteTo(contentWritable) + ml.MiiDataList.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + ml.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MiiList from the given readable +func (ml *MiiList) ExtractFrom(readable types.Readable) error { + var err error + + err = ml.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiList.Data. %s", err.Error()) + } + + err = ml.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiList header. %s", err.Error()) + } + + err = ml.Unknown1.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiList.Unknown1. %s", err.Error()) + } + + err = ml.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiList.Unknown2. %s", err.Error()) + } + + err = ml.Unknown3.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiList.Unknown3. %s", err.Error()) + } + + err = ml.MiiDataList.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiList.MiiDataList. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of MiiList +func (ml *MiiList) Copy() types.RVType { + copied := NewMiiList() + + copied.StructureVersion = ml.StructureVersion + copied.Data = ml.Data.Copy().(*types.Data) + copied.Unknown1 = ml.Unknown1.Copy().(*types.String) + copied.Unknown2 = ml.Unknown2.Copy().(*types.PrimitiveBool) + copied.Unknown3 = ml.Unknown3.Copy().(*types.PrimitiveU8) + copied.MiiDataList = ml.MiiDataList.Copy().(*types.List[*types.Buffer]) + + return copied +} + +// Equals checks if the given MiiList contains the same data as the current MiiList +func (ml *MiiList) Equals(o types.RVType) bool { + if _, ok := o.(*MiiList); !ok { + return false + } + + other := o.(*MiiList) + + if ml.StructureVersion != other.StructureVersion { + return false + } + + if !ml.Data.Equals(other.Data) { + return false + } + + if !ml.Unknown1.Equals(other.Unknown1) { + return false + } + + if !ml.Unknown2.Equals(other.Unknown2) { + return false + } + + if !ml.Unknown3.Equals(other.Unknown3) { + return false + } + + return ml.MiiDataList.Equals(other.MiiDataList) +} + +// String returns the string representation of the MiiList +func (ml *MiiList) String() string { + return ml.FormatToString(0) +} + +// FormatToString pretty-prints the MiiList using the provided indentation level +func (ml *MiiList) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MiiList{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, ml.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUnknown1: %s,\n", indentationValues, ml.Unknown1)) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, ml.Unknown2)) + b.WriteString(fmt.Sprintf("%sUnknown3: %s,\n", indentationValues, ml.Unknown3)) + b.WriteString(fmt.Sprintf("%sMiiDataList: %s,\n", indentationValues, ml.MiiDataList)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMiiList returns a new MiiList +func NewMiiList() *MiiList { + ml := &MiiList{ + Data: types.NewData(), + Unknown1: types.NewString(""), + Unknown2: types.NewPrimitiveBool(false), + Unknown3: types.NewPrimitiveU8(0), + MiiDataList: types.NewList[*types.Buffer](), + } + + ml.MiiDataList.Type = types.NewBuffer(nil) + + return ml +} diff --git a/nex-protocols-go/friends-3ds/types/my_profile.go b/nex-protocols-go/friends-3ds/types/my_profile.go new file mode 100644 index 0000000..92a455a --- /dev/null +++ b/nex-protocols-go/friends-3ds/types/my_profile.go @@ -0,0 +1,211 @@ +// Package types implements all the types used by the Friends3DS protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// MyProfile is a type within the Friends3DS protocol +type MyProfile struct { + types.Structure + *types.Data + Region *types.PrimitiveU8 + Country *types.PrimitiveU8 + Area *types.PrimitiveU8 + Language *types.PrimitiveU8 + Platform *types.PrimitiveU8 + Unknown1 *types.PrimitiveU64 + Unknown2 *types.String + Unknown3 *types.String +} + +// WriteTo writes the MyProfile to the given writable +func (mp *MyProfile) WriteTo(writable types.Writable) { + mp.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + mp.Region.WriteTo(contentWritable) + mp.Country.WriteTo(contentWritable) + mp.Area.WriteTo(contentWritable) + mp.Language.WriteTo(contentWritable) + mp.Platform.WriteTo(contentWritable) + mp.Unknown1.WriteTo(contentWritable) + mp.Unknown2.WriteTo(contentWritable) + mp.Unknown3.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + mp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MyProfile from the given readable +func (mp *MyProfile) ExtractFrom(readable types.Readable) error { + var err error + + err = mp.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MyProfile.Data. %s", err.Error()) + } + + err = mp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MyProfile header. %s", err.Error()) + } + + err = mp.Region.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MyProfile.Region. %s", err.Error()) + } + + err = mp.Country.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MyProfile.Country. %s", err.Error()) + } + + err = mp.Area.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MyProfile.Area. %s", err.Error()) + } + + err = mp.Language.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MyProfile.Language. %s", err.Error()) + } + + err = mp.Platform.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MyProfile.Platform. %s", err.Error()) + } + + err = mp.Unknown1.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MyProfile.Unknown1. %s", err.Error()) + } + + err = mp.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MyProfile.Unknown2. %s", err.Error()) + } + + err = mp.Unknown3.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MyProfile.Unknown3. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of MyProfile +func (mp *MyProfile) Copy() types.RVType { + copied := NewMyProfile() + + copied.StructureVersion = mp.StructureVersion + copied.Data = mp.Data.Copy().(*types.Data) + copied.Region = mp.Region.Copy().(*types.PrimitiveU8) + copied.Country = mp.Country.Copy().(*types.PrimitiveU8) + copied.Area = mp.Area.Copy().(*types.PrimitiveU8) + copied.Language = mp.Language.Copy().(*types.PrimitiveU8) + copied.Platform = mp.Platform.Copy().(*types.PrimitiveU8) + copied.Unknown1 = mp.Unknown1.Copy().(*types.PrimitiveU64) + copied.Unknown2 = mp.Unknown2.Copy().(*types.String) + copied.Unknown3 = mp.Unknown3.Copy().(*types.String) + + return copied +} + +// Equals checks if the given MyProfile contains the same data as the current MyProfile +func (mp *MyProfile) Equals(o types.RVType) bool { + if _, ok := o.(*MyProfile); !ok { + return false + } + + other := o.(*MyProfile) + + if mp.StructureVersion != other.StructureVersion { + return false + } + + if !mp.Data.Equals(other.Data) { + return false + } + + if !mp.Region.Equals(other.Region) { + return false + } + + if !mp.Country.Equals(other.Country) { + return false + } + + if !mp.Area.Equals(other.Area) { + return false + } + + if !mp.Language.Equals(other.Language) { + return false + } + + if !mp.Platform.Equals(other.Platform) { + return false + } + + if !mp.Unknown1.Equals(other.Unknown1) { + return false + } + + if !mp.Unknown2.Equals(other.Unknown2) { + return false + } + + return mp.Unknown3.Equals(other.Unknown3) +} + +// String returns the string representation of the MyProfile +func (mp *MyProfile) String() string { + return mp.FormatToString(0) +} + +// FormatToString pretty-prints the MyProfile using the provided indentation level +func (mp *MyProfile) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MyProfile{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, mp.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sRegion: %s,\n", indentationValues, mp.Region)) + b.WriteString(fmt.Sprintf("%sCountry: %s,\n", indentationValues, mp.Country)) + b.WriteString(fmt.Sprintf("%sArea: %s,\n", indentationValues, mp.Area)) + b.WriteString(fmt.Sprintf("%sLanguage: %s,\n", indentationValues, mp.Language)) + b.WriteString(fmt.Sprintf("%sPlatform: %s,\n", indentationValues, mp.Platform)) + b.WriteString(fmt.Sprintf("%sUnknown1: %s,\n", indentationValues, mp.Unknown1)) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, mp.Unknown2)) + b.WriteString(fmt.Sprintf("%sUnknown3: %s,\n", indentationValues, mp.Unknown3)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMyProfile returns a new MyProfile +func NewMyProfile() *MyProfile { + mp := &MyProfile{ + Data: types.NewData(), + Region: types.NewPrimitiveU8(0), + Country: types.NewPrimitiveU8(0), + Area: types.NewPrimitiveU8(0), + Language: types.NewPrimitiveU8(0), + Platform: types.NewPrimitiveU8(0), + Unknown1: types.NewPrimitiveU64(0), + Unknown2: types.NewString(""), + Unknown3: types.NewString(""), + } + + return mp +} diff --git a/nex-protocols-go/friends-3ds/types/nintendo_presence.go b/nex-protocols-go/friends-3ds/types/nintendo_presence.go new file mode 100644 index 0000000..250d97f --- /dev/null +++ b/nex-protocols-go/friends-3ds/types/nintendo_presence.go @@ -0,0 +1,239 @@ +// Package types implements all the types used by the Friends3DS protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// NintendoPresence is a type within the Friends3DS protocol +type NintendoPresence struct { + types.Structure + *types.Data + ChangedFlags *types.PrimitiveU32 + GameKey *GameKey + Message *types.String + JoinAvailableFlag *types.PrimitiveU32 + MatchmakeType *types.PrimitiveU8 + JoinGameID *types.PrimitiveU32 + JoinGameMode *types.PrimitiveU32 + OwnerPID *types.PID + JoinGroupID *types.PrimitiveU32 + ApplicationArg *types.Buffer +} + +// WriteTo writes the NintendoPresence to the given writable +func (np *NintendoPresence) WriteTo(writable types.Writable) { + np.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + np.ChangedFlags.WriteTo(contentWritable) + np.GameKey.WriteTo(contentWritable) + np.Message.WriteTo(contentWritable) + np.JoinAvailableFlag.WriteTo(contentWritable) + np.MatchmakeType.WriteTo(contentWritable) + np.JoinGameID.WriteTo(contentWritable) + np.JoinGameMode.WriteTo(contentWritable) + np.OwnerPID.WriteTo(contentWritable) + np.JoinGroupID.WriteTo(contentWritable) + np.ApplicationArg.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + np.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the NintendoPresence from the given readable +func (np *NintendoPresence) ExtractFrom(readable types.Readable) error { + var err error + + err = np.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresence.Data. %s", err.Error()) + } + + err = np.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresence header. %s", err.Error()) + } + + err = np.ChangedFlags.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresence.ChangedFlags. %s", err.Error()) + } + + err = np.GameKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresence.GameKey. %s", err.Error()) + } + + err = np.Message.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresence.Message. %s", err.Error()) + } + + err = np.JoinAvailableFlag.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresence.JoinAvailableFlag. %s", err.Error()) + } + + err = np.MatchmakeType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresence.MatchmakeType. %s", err.Error()) + } + + err = np.JoinGameID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresence.JoinGameID. %s", err.Error()) + } + + err = np.JoinGameMode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresence.JoinGameMode. %s", err.Error()) + } + + err = np.OwnerPID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresence.OwnerPID. %s", err.Error()) + } + + err = np.JoinGroupID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresence.JoinGroupID. %s", err.Error()) + } + + err = np.ApplicationArg.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresence.ApplicationArg. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of NintendoPresence +func (np *NintendoPresence) Copy() types.RVType { + copied := NewNintendoPresence() + + copied.StructureVersion = np.StructureVersion + copied.Data = np.Data.Copy().(*types.Data) + copied.ChangedFlags = np.ChangedFlags.Copy().(*types.PrimitiveU32) + copied.GameKey = np.GameKey.Copy().(*GameKey) + copied.Message = np.Message.Copy().(*types.String) + copied.JoinAvailableFlag = np.JoinAvailableFlag.Copy().(*types.PrimitiveU32) + copied.MatchmakeType = np.MatchmakeType.Copy().(*types.PrimitiveU8) + copied.JoinGameID = np.JoinGameID.Copy().(*types.PrimitiveU32) + copied.JoinGameMode = np.JoinGameMode.Copy().(*types.PrimitiveU32) + copied.OwnerPID = np.OwnerPID.Copy().(*types.PID) + copied.JoinGroupID = np.JoinGroupID.Copy().(*types.PrimitiveU32) + copied.ApplicationArg = np.ApplicationArg.Copy().(*types.Buffer) + + return copied +} + +// Equals checks if the given NintendoPresence contains the same data as the current NintendoPresence +func (np *NintendoPresence) Equals(o types.RVType) bool { + if _, ok := o.(*NintendoPresence); !ok { + return false + } + + other := o.(*NintendoPresence) + + if np.StructureVersion != other.StructureVersion { + return false + } + + if !np.Data.Equals(other.Data) { + return false + } + + if !np.ChangedFlags.Equals(other.ChangedFlags) { + return false + } + + if !np.GameKey.Equals(other.GameKey) { + return false + } + + if !np.Message.Equals(other.Message) { + return false + } + + if !np.JoinAvailableFlag.Equals(other.JoinAvailableFlag) { + return false + } + + if !np.MatchmakeType.Equals(other.MatchmakeType) { + return false + } + + if !np.JoinGameID.Equals(other.JoinGameID) { + return false + } + + if !np.JoinGameMode.Equals(other.JoinGameMode) { + return false + } + + if !np.OwnerPID.Equals(other.OwnerPID) { + return false + } + + if !np.JoinGroupID.Equals(other.JoinGroupID) { + return false + } + + return np.ApplicationArg.Equals(other.ApplicationArg) +} + +// String returns the string representation of the NintendoPresence +func (np *NintendoPresence) String() string { + return np.FormatToString(0) +} + +// FormatToString pretty-prints the NintendoPresence using the provided indentation level +func (np *NintendoPresence) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("NintendoPresence{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, np.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sChangedFlags: %s,\n", indentationValues, np.ChangedFlags)) + b.WriteString(fmt.Sprintf("%sGameKey: %s,\n", indentationValues, np.GameKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sMessage: %s,\n", indentationValues, np.Message)) + b.WriteString(fmt.Sprintf("%sJoinAvailableFlag: %s,\n", indentationValues, np.JoinAvailableFlag)) + b.WriteString(fmt.Sprintf("%sMatchmakeType: %s,\n", indentationValues, np.MatchmakeType)) + b.WriteString(fmt.Sprintf("%sJoinGameID: %s,\n", indentationValues, np.JoinGameID)) + b.WriteString(fmt.Sprintf("%sJoinGameMode: %s,\n", indentationValues, np.JoinGameMode)) + b.WriteString(fmt.Sprintf("%sOwnerPID: %s,\n", indentationValues, np.OwnerPID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sJoinGroupID: %s,\n", indentationValues, np.JoinGroupID)) + b.WriteString(fmt.Sprintf("%sApplicationArg: %s,\n", indentationValues, np.ApplicationArg)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewNintendoPresence returns a new NintendoPresence +func NewNintendoPresence() *NintendoPresence { + np := &NintendoPresence{ + Data: types.NewData(), + ChangedFlags: types.NewPrimitiveU32(0), + GameKey: NewGameKey(), + Message: types.NewString(""), + JoinAvailableFlag: types.NewPrimitiveU32(0), + MatchmakeType: types.NewPrimitiveU8(0), + JoinGameID: types.NewPrimitiveU32(0), + JoinGameMode: types.NewPrimitiveU32(0), + OwnerPID: types.NewPID(0), + JoinGroupID: types.NewPrimitiveU32(0), + ApplicationArg: types.NewBuffer(nil), + } + + return np +} diff --git a/nex-protocols-go/friends-3ds/types/played_game.go b/nex-protocols-go/friends-3ds/types/played_game.go new file mode 100644 index 0000000..24bc936 --- /dev/null +++ b/nex-protocols-go/friends-3ds/types/played_game.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the Friends3DS protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// PlayedGame is a type within the Friends3DS protocol +type PlayedGame struct { + types.Structure + GameKey *GameKey + Unknown *types.DateTime +} + +// WriteTo writes the PlayedGame to the given writable +func (pg *PlayedGame) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + pg.GameKey.WriteTo(contentWritable) + pg.Unknown.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + pg.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the PlayedGame from the given readable +func (pg *PlayedGame) ExtractFrom(readable types.Readable) error { + var err error + + err = pg.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PlayedGame header. %s", err.Error()) + } + + err = pg.GameKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PlayedGame.GameKey. %s", err.Error()) + } + + err = pg.Unknown.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PlayedGame.Unknown. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of PlayedGame +func (pg *PlayedGame) Copy() types.RVType { + copied := NewPlayedGame() + + copied.StructureVersion = pg.StructureVersion + copied.GameKey = pg.GameKey.Copy().(*GameKey) + copied.Unknown = pg.Unknown.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given PlayedGame contains the same data as the current PlayedGame +func (pg *PlayedGame) Equals(o types.RVType) bool { + if _, ok := o.(*PlayedGame); !ok { + return false + } + + other := o.(*PlayedGame) + + if pg.StructureVersion != other.StructureVersion { + return false + } + + if !pg.GameKey.Equals(other.GameKey) { + return false + } + + return pg.Unknown.Equals(other.Unknown) +} + +// String returns the string representation of the PlayedGame +func (pg *PlayedGame) String() string { + return pg.FormatToString(0) +} + +// FormatToString pretty-prints the PlayedGame using the provided indentation level +func (pg *PlayedGame) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("PlayedGame{\n") + b.WriteString(fmt.Sprintf("%sGameKey: %s,\n", indentationValues, pg.GameKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUnknown: %s,\n", indentationValues, pg.Unknown.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewPlayedGame returns a new PlayedGame +func NewPlayedGame() *PlayedGame { + pg := &PlayedGame{ + GameKey: NewGameKey(), + Unknown: types.NewDateTime(0), + } + + return pg +} diff --git a/nex-protocols-go/friends-3ds/update_black_list.go b/nex-protocols-go/friends-3ds/update_black_list.go new file mode 100644 index 0000000..0f6db6b --- /dev/null +++ b/nex-protocols-go/friends-3ds/update_black_list.go @@ -0,0 +1,48 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateBlackList(packet nex.PacketInterface) { + if protocol.UpdateBlackList == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::UpdateBlackList not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + unknown := types.NewList[*types.PrimitiveU32]() + unknown.Type = types.NewPrimitiveU32(0) + + err := unknown.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateBlackList(fmt.Errorf("Failed to read unknown from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateBlackList(nil, packet, callID, unknown) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/update_comment.go b/nex-protocols-go/friends-3ds/update_comment.go new file mode 100644 index 0000000..b6acde6 --- /dev/null +++ b/nex-protocols-go/friends-3ds/update_comment.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateComment(packet nex.PacketInterface) { + if protocol.UpdateComment == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::UpdateComment not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + comment := types.NewString("") + + err := comment.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateComment(fmt.Errorf("Failed to read comment from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateComment(nil, packet, callID, comment) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/update_favorite_game_key.go b/nex-protocols-go/friends-3ds/update_favorite_game_key.go new file mode 100644 index 0000000..fd616e7 --- /dev/null +++ b/nex-protocols-go/friends-3ds/update_favorite_game_key.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-3ds/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateFavoriteGameKey(packet nex.PacketInterface) { + if protocol.UpdateFavoriteGameKey == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::UpdateFavoriteGameKey not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gameKey := friends_3ds_types.NewGameKey() + + err := gameKey.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateFavoriteGameKey(fmt.Errorf("Failed to read gameKey from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateFavoriteGameKey(nil, packet, callID, gameKey) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/update_mii.go b/nex-protocols-go/friends-3ds/update_mii.go new file mode 100644 index 0000000..bcd7d03 --- /dev/null +++ b/nex-protocols-go/friends-3ds/update_mii.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-3ds/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateMii(packet nex.PacketInterface) { + if protocol.UpdateMii == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::UpdateMii not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + mii := friends_3ds_types.NewMii() + + err := mii.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateMii(fmt.Errorf("Failed to read mii from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateMii(nil, packet, callID, mii) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/update_mii_list.go b/nex-protocols-go/friends-3ds/update_mii_list.go new file mode 100644 index 0000000..38f7d17 --- /dev/null +++ b/nex-protocols-go/friends-3ds/update_mii_list.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-3ds/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateMiiList(packet nex.PacketInterface) { + if protocol.UpdateMiiList == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::UpdateMiiList not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + miiList := friends_3ds_types.NewMiiList() + + err := miiList.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateMiiList(fmt.Errorf("Failed to read miiList from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateMiiList(nil, packet, callID, miiList) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/update_picture.go b/nex-protocols-go/friends-3ds/update_picture.go new file mode 100644 index 0000000..3179ff0 --- /dev/null +++ b/nex-protocols-go/friends-3ds/update_picture.go @@ -0,0 +1,60 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdatePicture(packet nex.PacketInterface) { + if protocol.UpdatePicture == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::UpdatePicture not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + unknown := types.NewPrimitiveU32(0) + picture := types.NewBuffer(nil) + + var err error + + err = unknown.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdatePicture(fmt.Errorf("Failed to read unknown from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = picture.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdatePicture(fmt.Errorf("Failed to read picture from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdatePicture(nil, packet, callID, unknown, picture) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/update_played_games.go b/nex-protocols-go/friends-3ds/update_played_games.go new file mode 100644 index 0000000..160cbd9 --- /dev/null +++ b/nex-protocols-go/friends-3ds/update_played_games.go @@ -0,0 +1,49 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-3ds/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdatePlayedGames(packet nex.PacketInterface) { + if protocol.UpdatePlayedGames == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::UpdatePlayedGames not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + playedGames := types.NewList[*friends_3ds_types.PlayedGame]() + playedGames.Type = friends_3ds_types.NewPlayedGame() + + err := playedGames.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdatePlayedGames(fmt.Errorf("Failed to read playedGames from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdatePlayedGames(nil, packet, callID, playedGames) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/update_preference.go b/nex-protocols-go/friends-3ds/update_preference.go new file mode 100644 index 0000000..bf47d81 --- /dev/null +++ b/nex-protocols-go/friends-3ds/update_preference.go @@ -0,0 +1,71 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdatePreference(packet nex.PacketInterface) { + if protocol.UpdatePreference == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::UpdatePreference not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + publicMode := types.NewPrimitiveBool(false) + showGame := types.NewPrimitiveBool(false) + showPlayedGame := types.NewPrimitiveBool(false) + + var err error + + err = publicMode.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdatePreference(fmt.Errorf("Failed to read publicMode from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = showGame.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdatePreference(fmt.Errorf("Failed to read showGame from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = showPlayedGame.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdatePreference(fmt.Errorf("Failed to read showPlayedGame from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdatePreference(nil, packet, callID, publicMode, showGame, showPlayedGame) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/update_presence.go b/nex-protocols-go/friends-3ds/update_presence.go new file mode 100644 index 0000000..8fd1bf9 --- /dev/null +++ b/nex-protocols-go/friends-3ds/update_presence.go @@ -0,0 +1,61 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-3ds/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdatePresence(packet nex.PacketInterface) { + if protocol.UpdatePresence == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::UpdatePresence not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + nintendoPresence := friends_3ds_types.NewNintendoPresence() + showGame := types.NewPrimitiveBool(false) + + var err error + + err = nintendoPresence.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdatePresence(fmt.Errorf("Failed to read nintendoPresence from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = showGame.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdatePresence(fmt.Errorf("Failed to read showGame from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdatePresence(nil, packet, callID, nintendoPresence, showGame) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-3ds/update_profile.go b/nex-protocols-go/friends-3ds/update_profile.go new file mode 100644 index 0000000..9b3db75 --- /dev/null +++ b/nex-protocols-go/friends-3ds/update_profile.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends 3DS protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-3ds/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateProfile(packet nex.PacketInterface) { + if protocol.UpdateProfile == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends3DS::UpdateProfile not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + profileData := friends_3ds_types.NewMyProfile() + + err := profileData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateProfile(fmt.Errorf("Failed to read profileData from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateProfile(nil, packet, callID, profileData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/accept_friend_request.go b/nex-protocols-go/friends-wiiu/accept_friend_request.go new file mode 100644 index 0000000..d97f3dd --- /dev/null +++ b/nex-protocols-go/friends-wiiu/accept_friend_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAcceptFriendRequest(packet nex.PacketInterface) { + if protocol.AcceptFriendRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::AcceptFriendRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + id := types.NewPrimitiveU64(0) + + err := id.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AcceptFriendRequest(fmt.Errorf("Failed to read id from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AcceptFriendRequest(nil, packet, callID, id) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/add_black_list.go b/nex-protocols-go/friends-wiiu/add_black_list.go new file mode 100644 index 0000000..285f36c --- /dev/null +++ b/nex-protocols-go/friends-wiiu/add_black_list.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-wiiu/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAddBlackList(packet nex.PacketInterface) { + if protocol.AddBlackList == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::AddBlackList not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + blacklistedPrincipal := friends_wiiu_types.NewBlacklistedPrincipal() + + err := blacklistedPrincipal.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddBlackList(fmt.Errorf("Failed to read blacklistedPrincipal from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AddBlackList(nil, packet, callID, blacklistedPrincipal) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/add_friend.go b/nex-protocols-go/friends-wiiu/add_friend.go new file mode 100644 index 0000000..5137b58 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/add_friend.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAddFriend(packet nex.PacketInterface) { + if protocol.AddFriend == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::AddFriend not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pid := types.NewPID(0) + + err := pid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriend(fmt.Errorf("Failed to read pid from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AddFriend(nil, packet, callID, pid) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/add_friend_by_name.go b/nex-protocols-go/friends-wiiu/add_friend_by_name.go new file mode 100644 index 0000000..c386ba5 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/add_friend_by_name.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAddFriendByName(packet nex.PacketInterface) { + if protocol.AddFriendByName == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::AddFriendByName not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + username := types.NewString("") + + err := username.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendByName(fmt.Errorf("Failed to read username from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AddFriendByName(nil, packet, callID, username) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/add_friend_request.go b/nex-protocols-go/friends-wiiu/add_friend_request.go new file mode 100644 index 0000000..f1cd48f --- /dev/null +++ b/nex-protocols-go/friends-wiiu/add_friend_request.go @@ -0,0 +1,116 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-wiiu/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAddFriendRequest(packet nex.PacketInterface) { + if protocol.AddFriendRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::AddFriendRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pid := types.NewPID(0) + unknown2 := types.NewPrimitiveU8(0) + message := types.NewString("") + unknown4 := types.NewPrimitiveU8(0) + unknown5 := types.NewString("") + gameKey := friends_wiiu_types.NewGameKey() + unknown6 := types.NewDateTime(0) + + var err error + + err = pid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendRequest(fmt.Errorf("Failed to read pid from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = unknown2.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendRequest(fmt.Errorf("Failed to read unknown2 from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = message.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendRequest(fmt.Errorf("Failed to read message from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = unknown4.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendRequest(fmt.Errorf("Failed to read unknown4 from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = unknown5.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendRequest(fmt.Errorf("Failed to read unknown5 from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = gameKey.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendRequest(fmt.Errorf("Failed to read gameKey from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = unknown6.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendRequest(fmt.Errorf("Failed to read unknown6 from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AddFriendRequest(nil, packet, callID, pid, unknown2, message, unknown4, unknown5, gameKey, unknown6) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/cancel_friend_request.go b/nex-protocols-go/friends-wiiu/cancel_friend_request.go new file mode 100644 index 0000000..553248b --- /dev/null +++ b/nex-protocols-go/friends-wiiu/cancel_friend_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCancelFriendRequest(packet nex.PacketInterface) { + if protocol.CancelFriendRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::CancelFriendRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + id := types.NewPrimitiveU64(0) + + err := id.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CancelFriendRequest(fmt.Errorf("Failed to read id from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CancelFriendRequest(nil, packet, callID, id) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/check_setting_status.go b/nex-protocols-go/friends-wiiu/check_setting_status.go new file mode 100644 index 0000000..d14fbfc --- /dev/null +++ b/nex-protocols-go/friends-wiiu/check_setting_status.go @@ -0,0 +1,29 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCheckSettingStatus(packet nex.PacketInterface) { + if protocol.CheckSettingStatus == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::CheckSettingStatus not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.CheckSettingStatus(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/delete_friend_request.go b/nex-protocols-go/friends-wiiu/delete_friend_request.go new file mode 100644 index 0000000..c4d1b1b --- /dev/null +++ b/nex-protocols-go/friends-wiiu/delete_friend_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteFriendRequest(packet nex.PacketInterface) { + if protocol.DeleteFriendRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::DeleteFriendRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + id := types.NewPrimitiveU64(0) + + err := id.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteFriendRequest(fmt.Errorf("Failed to read id from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteFriendRequest(nil, packet, callID, id) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/delete_persistent_notification.go b/nex-protocols-go/friends-wiiu/delete_persistent_notification.go new file mode 100644 index 0000000..f05be7c --- /dev/null +++ b/nex-protocols-go/friends-wiiu/delete_persistent_notification.go @@ -0,0 +1,49 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-wiiu/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeletePersistentNotification(packet nex.PacketInterface) { + if protocol.DeletePersistentNotification == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::DeletePersistentNotification not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + persistentNotifications := types.NewList[*friends_wiiu_types.PersistentNotification]() + persistentNotifications.Type = friends_wiiu_types.NewPersistentNotification() + + err := persistentNotifications.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeletePersistentNotification(fmt.Errorf("Failed to read persistentNotifications from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeletePersistentNotification(nil, packet, callID, persistentNotifications) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/deny_friend_request.go b/nex-protocols-go/friends-wiiu/deny_friend_request.go new file mode 100644 index 0000000..0130193 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/deny_friend_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDenyFriendRequest(packet nex.PacketInterface) { + if protocol.DenyFriendRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::DenyFriendRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + id := types.NewPrimitiveU64(0) + + err := id.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DenyFriendRequest(fmt.Errorf("Failed to read id from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DenyFriendRequest(nil, packet, callID, id) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/get_basic_info.go b/nex-protocols-go/friends-wiiu/get_basic_info.go new file mode 100644 index 0000000..d06c72c --- /dev/null +++ b/nex-protocols-go/friends-wiiu/get_basic_info.go @@ -0,0 +1,48 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetBasicInfo(packet nex.PacketInterface) { + if protocol.GetBasicInfo == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::GetBasicInfo not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pids := types.NewList[*types.PID]() + pids.Type = types.NewPID(0) + + err := pids.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetBasicInfo(fmt.Errorf("Failed to read pids from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetBasicInfo(nil, packet, callID, pids) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/get_request_block_settings.go b/nex-protocols-go/friends-wiiu/get_request_block_settings.go new file mode 100644 index 0000000..a4dcd4d --- /dev/null +++ b/nex-protocols-go/friends-wiiu/get_request_block_settings.go @@ -0,0 +1,48 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetRequestBlockSettings(packet nex.PacketInterface) { + if protocol.GetRequestBlockSettings == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::GetRequestBlockSettings not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pids := types.NewList[*types.PrimitiveU32]() + pids.Type = types.NewPrimitiveU32(0) + + err := pids.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRequestBlockSettings(fmt.Errorf("Failed to read pids from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetRequestBlockSettings(nil, packet, callID, pids) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/mark_friend_requests_as_received.go b/nex-protocols-go/friends-wiiu/mark_friend_requests_as_received.go new file mode 100644 index 0000000..d112825 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/mark_friend_requests_as_received.go @@ -0,0 +1,48 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleMarkFriendRequestsAsReceived(packet nex.PacketInterface) { + if protocol.MarkFriendRequestsAsReceived == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::MarkFriendRequestsAsReceived not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + ids := types.NewList[*types.PrimitiveU64]() + ids.Type = types.NewPrimitiveU64(0) + + err := ids.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.MarkFriendRequestsAsReceived(fmt.Errorf("Failed to read ids from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.MarkFriendRequestsAsReceived(nil, packet, callID, ids) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/protocol.go b/nex-protocols-go/friends-wiiu/protocol.go new file mode 100644 index 0000000..745cff9 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/protocol.go @@ -0,0 +1,308 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-wiiu/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the Friends (WiiU) protocol + ProtocolID = 0x66 + + // MethodUpdateAndGetAllInformation is the method ID for method UpdateAndGetAllInformation + MethodUpdateAndGetAllInformation = 0x1 + + // MethodAddFriend is the method ID for method AddFriend + MethodAddFriend = 0x2 + + // MethodAddFriendByName is the method ID for method AddFriendByName + MethodAddFriendByName = 0x3 + + // MethodRemoveFriend is the method ID for method RemoveFriend + MethodRemoveFriend = 0x4 + + // MethodAddFriendRequest is the method ID for method AddFriendRequest + MethodAddFriendRequest = 0x5 + + // MethodCancelFriendRequest is the method ID for method CancelFriendRequest + MethodCancelFriendRequest = 0x6 + + // MethodAcceptFriendRequest is the method ID for method AcceptFriendRequest + MethodAcceptFriendRequest = 0x7 + + // MethodDeleteFriendRequest is the method ID for method DeleteFriendRequest + MethodDeleteFriendRequest = 0x8 + + // MethodDenyFriendRequest is the method ID for method DenyFriendRequest + MethodDenyFriendRequest = 0x9 + + // MethodMarkFriendRequestsAsReceived is the method ID for method MarkFriendRequestsAsReceived + MethodMarkFriendRequestsAsReceived = 0xA + + // MethodAddBlackList is the method ID for method AddBlackList + MethodAddBlackList = 0xB + + // MethodRemoveBlackList is the method ID for method RemoveBlackList + MethodRemoveBlackList = 0xC + + // MethodUpdatePresence is the method ID for method UpdatePresence + MethodUpdatePresence = 0xD + + // MethodUpdateMii is the method ID for method UpdateMii + MethodUpdateMii = 0xE + + // MethodUpdateComment is the method ID for method UpdateComment + MethodUpdateComment = 0xF + + // MethodUpdatePreference is the method ID for method UpdatePreference + MethodUpdatePreference = 0x10 + + // MethodGetBasicInfo is the method ID for method GetBasicInfo + MethodGetBasicInfo = 0x11 + + // MethodDeletePersistentNotification is the method ID for method DeletePersistentNotification + MethodDeletePersistentNotification = 0x12 + + // MethodCheckSettingStatus is the method ID for method CheckSettingStatus + MethodCheckSettingStatus = 0x13 + + // MethodGetRequestBlockSettings is the method ID for method GetRequestBlockSettings + MethodGetRequestBlockSettings = 0x14 +) + +// Protocol stores all the RMC method handlers for the Friends (WiiU) protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + UpdateAndGetAllInformation func(err error, packet nex.PacketInterface, callID uint32, nnaInfo *friends_wiiu_types.NNAInfo, presence *friends_wiiu_types.NintendoPresenceV2, birthday *types.DateTime) (*nex.RMCMessage, *nex.Error) + AddFriend func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID) (*nex.RMCMessage, *nex.Error) + AddFriendByName func(err error, packet nex.PacketInterface, callID uint32, username *types.String) (*nex.RMCMessage, *nex.Error) + RemoveFriend func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID) (*nex.RMCMessage, *nex.Error) + AddFriendRequest func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID, unknown2 *types.PrimitiveU8, message *types.String, unknown4 *types.PrimitiveU8, unknown5 *types.String, gameKey *friends_wiiu_types.GameKey, unknown6 *types.DateTime) (*nex.RMCMessage, *nex.Error) + CancelFriendRequest func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + AcceptFriendRequest func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + DeleteFriendRequest func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + DenyFriendRequest func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + MarkFriendRequestsAsReceived func(err error, packet nex.PacketInterface, callID uint32, ids *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error) + AddBlackList func(err error, packet nex.PacketInterface, callID uint32, blacklistedPrincipal *friends_wiiu_types.BlacklistedPrincipal) (*nex.RMCMessage, *nex.Error) + RemoveBlackList func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID) (*nex.RMCMessage, *nex.Error) + UpdatePresence func(err error, packet nex.PacketInterface, callID uint32, presence *friends_wiiu_types.NintendoPresenceV2) (*nex.RMCMessage, *nex.Error) + UpdateMii func(err error, packet nex.PacketInterface, callID uint32, mii *friends_wiiu_types.MiiV2) (*nex.RMCMessage, *nex.Error) + UpdateComment func(err error, packet nex.PacketInterface, callID uint32, comment *friends_wiiu_types.Comment) (*nex.RMCMessage, *nex.Error) + UpdatePreference func(err error, packet nex.PacketInterface, callID uint32, preference *friends_wiiu_types.PrincipalPreference) (*nex.RMCMessage, *nex.Error) + GetBasicInfo func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error) + DeletePersistentNotification func(err error, packet nex.PacketInterface, callID uint32, notifications *types.List[*friends_wiiu_types.PersistentNotification]) (*nex.RMCMessage, *nex.Error) + CheckSettingStatus func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + GetRequestBlockSettings func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Friends WiiU protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerUpdateAndGetAllInformation(handler func(err error, packet nex.PacketInterface, callID uint32, nnaInfo *friends_wiiu_types.NNAInfo, presence *friends_wiiu_types.NintendoPresenceV2, birthday *types.DateTime) (*nex.RMCMessage, *nex.Error)) + SetHandlerAddFriend(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID) (*nex.RMCMessage, *nex.Error)) + SetHandlerAddFriendByName(handler func(err error, packet nex.PacketInterface, callID uint32, username *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerRemoveFriend(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID) (*nex.RMCMessage, *nex.Error)) + SetHandlerAddFriendRequest(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID, unknown2 *types.PrimitiveU8, message *types.String, unknown4 *types.PrimitiveU8, unknown5 *types.String, gameKey *friends_wiiu_types.GameKey, unknown6 *types.DateTime) (*nex.RMCMessage, *nex.Error)) + SetHandlerCancelFriendRequest(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerAcceptFriendRequest(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeleteFriendRequest(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerDenyFriendRequest(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerMarkFriendRequestsAsReceived(handler func(err error, packet nex.PacketInterface, callID uint32, ids *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error)) + SetHandlerAddBlackList(handler func(err error, packet nex.PacketInterface, callID uint32, blacklistedPrincipal *friends_wiiu_types.BlacklistedPrincipal) (*nex.RMCMessage, *nex.Error)) + SetHandlerRemoveBlackList(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdatePresence(handler func(err error, packet nex.PacketInterface, callID uint32, presence *friends_wiiu_types.NintendoPresenceV2) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateMii(handler func(err error, packet nex.PacketInterface, callID uint32, mii *friends_wiiu_types.MiiV2) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateComment(handler func(err error, packet nex.PacketInterface, callID uint32, comment *friends_wiiu_types.Comment) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdatePreference(handler func(err error, packet nex.PacketInterface, callID uint32, preference *friends_wiiu_types.PrincipalPreference) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetBasicInfo(handler func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeletePersistentNotification(handler func(err error, packet nex.PacketInterface, callID uint32, notifications *types.List[*friends_wiiu_types.PersistentNotification]) (*nex.RMCMessage, *nex.Error)) + SetHandlerCheckSettingStatus(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetRequestBlockSettings(handler func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerUpdateAndGetAllInformation sets the handler for the UpdateAndGetAllInformation method +func (protocol *Protocol) SetHandlerUpdateAndGetAllInformation(handler func(err error, packet nex.PacketInterface, callID uint32, nnaInfo *friends_wiiu_types.NNAInfo, presence *friends_wiiu_types.NintendoPresenceV2, birthday *types.DateTime) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateAndGetAllInformation = handler +} + +// SetHandlerAddFriend sets the handler for the AddFriend method +func (protocol *Protocol) SetHandlerAddFriend(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.AddFriend = handler +} + +// SetHandlerAddFriendByName sets the handler for the AddFriendByName method +func (protocol *Protocol) SetHandlerAddFriendByName(handler func(err error, packet nex.PacketInterface, callID uint32, username *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.AddFriendByName = handler +} + +// SetHandlerRemoveFriend sets the handler for the RemoveFriend method +func (protocol *Protocol) SetHandlerRemoveFriend(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.RemoveFriend = handler +} + +// SetHandlerAddFriendRequest sets the handler for the AddFriendRequest method +func (protocol *Protocol) SetHandlerAddFriendRequest(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID, unknown2 *types.PrimitiveU8, message *types.String, unknown4 *types.PrimitiveU8, unknown5 *types.String, gameKey *friends_wiiu_types.GameKey, unknown6 *types.DateTime) (*nex.RMCMessage, *nex.Error)) { + protocol.AddFriendRequest = handler +} + +// SetHandlerCancelFriendRequest sets the handler for the CancelFriendRequest method +func (protocol *Protocol) SetHandlerCancelFriendRequest(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.CancelFriendRequest = handler +} + +// SetHandlerAcceptFriendRequest sets the handler for the AcceptFriendRequest method +func (protocol *Protocol) SetHandlerAcceptFriendRequest(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.AcceptFriendRequest = handler +} + +// SetHandlerDeleteFriendRequest sets the handler for the DeleteFriendRequest method +func (protocol *Protocol) SetHandlerDeleteFriendRequest(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.DeleteFriendRequest = handler +} + +// SetHandlerDenyFriendRequest sets the handler for the DenyFriendRequest method +func (protocol *Protocol) SetHandlerDenyFriendRequest(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.DenyFriendRequest = handler +} + +// SetHandlerMarkFriendRequestsAsReceived sets the handler for the MarkFriendRequestsAsReceived method +func (protocol *Protocol) SetHandlerMarkFriendRequestsAsReceived(handler func(err error, packet nex.PacketInterface, callID uint32, ids *types.List[*types.PrimitiveU64]) (*nex.RMCMessage, *nex.Error)) { + protocol.MarkFriendRequestsAsReceived = handler +} + +// SetHandlerAddBlackList sets the handler for the AddBlackList method +func (protocol *Protocol) SetHandlerAddBlackList(handler func(err error, packet nex.PacketInterface, callID uint32, blacklistedPrincipal *friends_wiiu_types.BlacklistedPrincipal) (*nex.RMCMessage, *nex.Error)) { + protocol.AddBlackList = handler +} + +// SetHandlerRemoveBlackList sets the handler for the RemoveBlackList method +func (protocol *Protocol) SetHandlerRemoveBlackList(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.RemoveBlackList = handler +} + +// SetHandlerUpdatePresence sets the handler for the UpdatePresence method +func (protocol *Protocol) SetHandlerUpdatePresence(handler func(err error, packet nex.PacketInterface, callID uint32, presence *friends_wiiu_types.NintendoPresenceV2) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdatePresence = handler +} + +// SetHandlerUpdateMii sets the handler for the UpdateMii method +func (protocol *Protocol) SetHandlerUpdateMii(handler func(err error, packet nex.PacketInterface, callID uint32, mii *friends_wiiu_types.MiiV2) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateMii = handler +} + +// SetHandlerUpdateComment sets the handler for the UpdateComment method +func (protocol *Protocol) SetHandlerUpdateComment(handler func(err error, packet nex.PacketInterface, callID uint32, comment *friends_wiiu_types.Comment) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateComment = handler +} + +// SetHandlerUpdatePreference sets the handler for the UpdatePreference method +func (protocol *Protocol) SetHandlerUpdatePreference(handler func(err error, packet nex.PacketInterface, callID uint32, preference *friends_wiiu_types.PrincipalPreference) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdatePreference = handler +} + +// SetHandlerGetBasicInfo sets the handler for the GetBasicInfo method +func (protocol *Protocol) SetHandlerGetBasicInfo(handler func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetBasicInfo = handler +} + +// SetHandlerDeletePersistentNotification sets the handler for the DeletePersistentNotification method +func (protocol *Protocol) SetHandlerDeletePersistentNotification(handler func(err error, packet nex.PacketInterface, callID uint32, notifications *types.List[*friends_wiiu_types.PersistentNotification]) (*nex.RMCMessage, *nex.Error)) { + protocol.DeletePersistentNotification = handler +} + +// SetHandlerCheckSettingStatus sets the handler for the CheckSettingStatus method +func (protocol *Protocol) SetHandlerCheckSettingStatus(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.CheckSettingStatus = handler +} + +// SetHandlerGetRequestBlockSettings sets the handler for the GetRequestBlockSettings method +func (protocol *Protocol) SetHandlerGetRequestBlockSettings(handler func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetRequestBlockSettings = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodUpdateAndGetAllInformation: + protocol.handleUpdateAndGetAllInformation(packet) + case MethodAddFriend: + protocol.handleAddFriend(packet) + case MethodAddFriendByName: + protocol.handleAddFriendByName(packet) + case MethodRemoveFriend: + protocol.handleRemoveFriend(packet) + case MethodAddFriendRequest: + protocol.handleAddFriendRequest(packet) + case MethodCancelFriendRequest: + protocol.handleCancelFriendRequest(packet) + case MethodAcceptFriendRequest: + protocol.handleAcceptFriendRequest(packet) + case MethodDeleteFriendRequest: + protocol.handleDeleteFriendRequest(packet) + case MethodDenyFriendRequest: + protocol.handleDenyFriendRequest(packet) + case MethodMarkFriendRequestsAsReceived: + protocol.handleMarkFriendRequestsAsReceived(packet) + case MethodAddBlackList: + protocol.handleAddBlackList(packet) + case MethodRemoveBlackList: + protocol.handleRemoveBlackList(packet) + case MethodUpdatePresence: + protocol.handleUpdatePresence(packet) + case MethodUpdateMii: + protocol.handleUpdateMii(packet) + case MethodUpdateComment: + protocol.handleUpdateComment(packet) + case MethodUpdatePreference: + protocol.handleUpdatePreference(packet) + case MethodGetBasicInfo: + protocol.handleGetBasicInfo(packet) + case MethodDeletePersistentNotification: + protocol.handleDeletePersistentNotification(packet) + case MethodCheckSettingStatus: + protocol.handleCheckSettingStatus(packet) + case MethodGetRequestBlockSettings: + protocol.handleGetRequestBlockSettings(packet) + default: + errMessage := fmt.Sprintf("Unsupported Friends (WiiU) method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Friends (WiiU) protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/friends-wiiu/remove_black_list.go b/nex-protocols-go/friends-wiiu/remove_black_list.go new file mode 100644 index 0000000..d9b1b67 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/remove_black_list.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRemoveBlackList(packet nex.PacketInterface) { + if protocol.RemoveBlackList == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::RemoveBlackList not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pid := types.NewPID(0) + + err := pid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RemoveBlackList(fmt.Errorf("Failed to read pid from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RemoveBlackList(nil, packet, callID, pid) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/remove_friend.go b/nex-protocols-go/friends-wiiu/remove_friend.go new file mode 100644 index 0000000..d719dc8 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/remove_friend.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRemoveFriend(packet nex.PacketInterface) { + if protocol.RemoveFriend == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::RemoveFriend not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pid := types.NewPID(0) + + err := pid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RemoveFriend(fmt.Errorf("Failed to read pid from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RemoveFriend(nil, packet, callID, pid) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/types/blacklisted_principal.go b/nex-protocols-go/friends-wiiu/types/blacklisted_principal.go new file mode 100644 index 0000000..3ae5ad7 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/types/blacklisted_principal.go @@ -0,0 +1,141 @@ +// Package types implements all the types used by the FriendsWiiU protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// BlacklistedPrincipal is a type within the FriendsWiiU protocol +type BlacklistedPrincipal struct { + types.Structure + *types.Data + PrincipalBasicInfo *PrincipalBasicInfo + GameKey *GameKey + BlackListedSince *types.DateTime +} + +// WriteTo writes the BlacklistedPrincipal to the given writable +func (bp *BlacklistedPrincipal) WriteTo(writable types.Writable) { + bp.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + bp.PrincipalBasicInfo.WriteTo(contentWritable) + bp.GameKey.WriteTo(contentWritable) + bp.BlackListedSince.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + bp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the BlacklistedPrincipal from the given readable +func (bp *BlacklistedPrincipal) ExtractFrom(readable types.Readable) error { + var err error + + err = bp.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BlacklistedPrincipal.Data. %s", err.Error()) + } + + err = bp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BlacklistedPrincipal header. %s", err.Error()) + } + + err = bp.PrincipalBasicInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BlacklistedPrincipal.PrincipalBasicInfo. %s", err.Error()) + } + + err = bp.GameKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BlacklistedPrincipal.GameKey. %s", err.Error()) + } + + err = bp.BlackListedSince.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BlacklistedPrincipal.BlackListedSince. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of BlacklistedPrincipal +func (bp *BlacklistedPrincipal) Copy() types.RVType { + copied := NewBlacklistedPrincipal() + + copied.StructureVersion = bp.StructureVersion + copied.Data = bp.Data.Copy().(*types.Data) + copied.PrincipalBasicInfo = bp.PrincipalBasicInfo.Copy().(*PrincipalBasicInfo) + copied.GameKey = bp.GameKey.Copy().(*GameKey) + copied.BlackListedSince = bp.BlackListedSince.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given BlacklistedPrincipal contains the same data as the current BlacklistedPrincipal +func (bp *BlacklistedPrincipal) Equals(o types.RVType) bool { + if _, ok := o.(*BlacklistedPrincipal); !ok { + return false + } + + other := o.(*BlacklistedPrincipal) + + if bp.StructureVersion != other.StructureVersion { + return false + } + + if !bp.Data.Equals(other.Data) { + return false + } + + if !bp.PrincipalBasicInfo.Equals(other.PrincipalBasicInfo) { + return false + } + + if !bp.GameKey.Equals(other.GameKey) { + return false + } + + return bp.BlackListedSince.Equals(other.BlackListedSince) +} + +// String returns the string representation of the BlacklistedPrincipal +func (bp *BlacklistedPrincipal) String() string { + return bp.FormatToString(0) +} + +// FormatToString pretty-prints the BlacklistedPrincipal using the provided indentation level +func (bp *BlacklistedPrincipal) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("BlacklistedPrincipal{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, bp.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPrincipalBasicInfo: %s,\n", indentationValues, bp.PrincipalBasicInfo.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sGameKey: %s,\n", indentationValues, bp.GameKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sBlackListedSince: %s,\n", indentationValues, bp.BlackListedSince.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewBlacklistedPrincipal returns a new BlacklistedPrincipal +func NewBlacklistedPrincipal() *BlacklistedPrincipal { + bp := &BlacklistedPrincipal{ + Data: types.NewData(), + PrincipalBasicInfo: NewPrincipalBasicInfo(), + GameKey: NewGameKey(), + BlackListedSince: types.NewDateTime(0), + } + + return bp +} diff --git a/nex-protocols-go/friends-wiiu/types/comment.go b/nex-protocols-go/friends-wiiu/types/comment.go new file mode 100644 index 0000000..888de83 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/types/comment.go @@ -0,0 +1,141 @@ +// Package types implements all the types used by the FriendsWiiU protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// Comment is a type within the FriendsWiiU protocol +type Comment struct { + types.Structure + *types.Data + Unknown *types.PrimitiveU8 + Contents *types.String + LastChanged *types.DateTime +} + +// WriteTo writes the Comment to the given writable +func (c *Comment) WriteTo(writable types.Writable) { + c.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + c.Unknown.WriteTo(contentWritable) + c.Contents.WriteTo(contentWritable) + c.LastChanged.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + c.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the Comment from the given readable +func (c *Comment) ExtractFrom(readable types.Readable) error { + var err error + + err = c.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Comment.Data. %s", err.Error()) + } + + err = c.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Comment header. %s", err.Error()) + } + + err = c.Unknown.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Comment.Unknown. %s", err.Error()) + } + + err = c.Contents.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Comment.Contents. %s", err.Error()) + } + + err = c.LastChanged.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Comment.LastChanged. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of Comment +func (c *Comment) Copy() types.RVType { + copied := NewComment() + + copied.StructureVersion = c.StructureVersion + copied.Data = c.Data.Copy().(*types.Data) + copied.Unknown = c.Unknown.Copy().(*types.PrimitiveU8) + copied.Contents = c.Contents.Copy().(*types.String) + copied.LastChanged = c.LastChanged.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given Comment contains the same data as the current Comment +func (c *Comment) Equals(o types.RVType) bool { + if _, ok := o.(*Comment); !ok { + return false + } + + other := o.(*Comment) + + if c.StructureVersion != other.StructureVersion { + return false + } + + if !c.Data.Equals(other.Data) { + return false + } + + if !c.Unknown.Equals(other.Unknown) { + return false + } + + if !c.Contents.Equals(other.Contents) { + return false + } + + return c.LastChanged.Equals(other.LastChanged) +} + +// String returns the string representation of the Comment +func (c *Comment) String() string { + return c.FormatToString(0) +} + +// FormatToString pretty-prints the Comment using the provided indentation level +func (c *Comment) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("Comment{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, c.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUnknown: %s,\n", indentationValues, c.Unknown)) + b.WriteString(fmt.Sprintf("%sContents: %s,\n", indentationValues, c.Contents)) + b.WriteString(fmt.Sprintf("%sLastChanged: %s,\n", indentationValues, c.LastChanged.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewComment returns a new Comment +func NewComment() *Comment { + c := &Comment{ + Data: types.NewData(), + Unknown: types.NewPrimitiveU8(0), + Contents: types.NewString(""), + LastChanged: types.NewDateTime(0), + } + + return c +} diff --git a/nex-protocols-go/friends-wiiu/types/friend_info.go b/nex-protocols-go/friends-wiiu/types/friend_info.go new file mode 100644 index 0000000..8d2e7dc --- /dev/null +++ b/nex-protocols-go/friends-wiiu/types/friend_info.go @@ -0,0 +1,183 @@ +// Package types implements all the types used by the FriendsWiiU protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// FriendInfo is a type within the FriendsWiiU protocol +type FriendInfo struct { + types.Structure + *types.Data + NNAInfo *NNAInfo + Presence *NintendoPresenceV2 + Status *Comment + BecameFriend *types.DateTime + LastOnline *types.DateTime + Unknown *types.PrimitiveU64 +} + +// WriteTo writes the FriendInfo to the given writable +func (fi *FriendInfo) WriteTo(writable types.Writable) { + fi.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + fi.NNAInfo.WriteTo(contentWritable) + fi.Presence.WriteTo(contentWritable) + fi.Status.WriteTo(contentWritable) + fi.BecameFriend.WriteTo(contentWritable) + fi.LastOnline.WriteTo(contentWritable) + fi.Unknown.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + fi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the FriendInfo from the given readable +func (fi *FriendInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = fi.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendInfo.Data. %s", err.Error()) + } + + err = fi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendInfo header. %s", err.Error()) + } + + err = fi.NNAInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendInfo.NNAInfo. %s", err.Error()) + } + + err = fi.Presence.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendInfo.Presence. %s", err.Error()) + } + + err = fi.Status.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendInfo.Status. %s", err.Error()) + } + + err = fi.BecameFriend.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendInfo.BecameFriend. %s", err.Error()) + } + + err = fi.LastOnline.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendInfo.LastOnline. %s", err.Error()) + } + + err = fi.Unknown.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendInfo.Unknown. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of FriendInfo +func (fi *FriendInfo) Copy() types.RVType { + copied := NewFriendInfo() + + copied.StructureVersion = fi.StructureVersion + copied.Data = fi.Data.Copy().(*types.Data) + copied.NNAInfo = fi.NNAInfo.Copy().(*NNAInfo) + copied.Presence = fi.Presence.Copy().(*NintendoPresenceV2) + copied.Status = fi.Status.Copy().(*Comment) + copied.BecameFriend = fi.BecameFriend.Copy().(*types.DateTime) + copied.LastOnline = fi.LastOnline.Copy().(*types.DateTime) + copied.Unknown = fi.Unknown.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given FriendInfo contains the same data as the current FriendInfo +func (fi *FriendInfo) Equals(o types.RVType) bool { + if _, ok := o.(*FriendInfo); !ok { + return false + } + + other := o.(*FriendInfo) + + if fi.StructureVersion != other.StructureVersion { + return false + } + + if !fi.Data.Equals(other.Data) { + return false + } + + if !fi.NNAInfo.Equals(other.NNAInfo) { + return false + } + + if !fi.Presence.Equals(other.Presence) { + return false + } + + if !fi.Status.Equals(other.Status) { + return false + } + + if !fi.BecameFriend.Equals(other.BecameFriend) { + return false + } + + if !fi.LastOnline.Equals(other.LastOnline) { + return false + } + + return fi.Unknown.Equals(other.Unknown) +} + +// String returns the string representation of the FriendInfo +func (fi *FriendInfo) String() string { + return fi.FormatToString(0) +} + +// FormatToString pretty-prints the FriendInfo using the provided indentation level +func (fi *FriendInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("FriendInfo{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, fi.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sNNAInfo: %s,\n", indentationValues, fi.NNAInfo.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPresence: %s,\n", indentationValues, fi.Presence.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sStatus: %s,\n", indentationValues, fi.Status.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sBecameFriend: %s,\n", indentationValues, fi.BecameFriend.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sLastOnline: %s,\n", indentationValues, fi.LastOnline.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUnknown: %s,\n", indentationValues, fi.Unknown)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewFriendInfo returns a new FriendInfo +func NewFriendInfo() *FriendInfo { + fi := &FriendInfo{ + Data: types.NewData(), + NNAInfo: NewNNAInfo(), + Presence: NewNintendoPresenceV2(), + Status: NewComment(), + BecameFriend: types.NewDateTime(0), + LastOnline: types.NewDateTime(0), + Unknown: types.NewPrimitiveU64(0), + } + + return fi +} diff --git a/nex-protocols-go/friends-wiiu/types/friend_request.go b/nex-protocols-go/friends-wiiu/types/friend_request.go new file mode 100644 index 0000000..ac07d63 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/types/friend_request.go @@ -0,0 +1,141 @@ +// Package types implements all the types used by the FriendsWiiU protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// FriendRequest is a type within the FriendsWiiU protocol +type FriendRequest struct { + types.Structure + *types.Data + PrincipalInfo *PrincipalBasicInfo + Message *FriendRequestMessage + SentOn *types.DateTime +} + +// WriteTo writes the FriendRequest to the given writable +func (fr *FriendRequest) WriteTo(writable types.Writable) { + fr.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + fr.PrincipalInfo.WriteTo(contentWritable) + fr.Message.WriteTo(contentWritable) + fr.SentOn.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + fr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the FriendRequest from the given readable +func (fr *FriendRequest) ExtractFrom(readable types.Readable) error { + var err error + + err = fr.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRequest.Data. %s", err.Error()) + } + + err = fr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRequest header. %s", err.Error()) + } + + err = fr.PrincipalInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRequest.PrincipalInfo. %s", err.Error()) + } + + err = fr.Message.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRequest.Message. %s", err.Error()) + } + + err = fr.SentOn.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRequest.SentOn. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of FriendRequest +func (fr *FriendRequest) Copy() types.RVType { + copied := NewFriendRequest() + + copied.StructureVersion = fr.StructureVersion + copied.Data = fr.Data.Copy().(*types.Data) + copied.PrincipalInfo = fr.PrincipalInfo.Copy().(*PrincipalBasicInfo) + copied.Message = fr.Message.Copy().(*FriendRequestMessage) + copied.SentOn = fr.SentOn.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given FriendRequest contains the same data as the current FriendRequest +func (fr *FriendRequest) Equals(o types.RVType) bool { + if _, ok := o.(*FriendRequest); !ok { + return false + } + + other := o.(*FriendRequest) + + if fr.StructureVersion != other.StructureVersion { + return false + } + + if !fr.Data.Equals(other.Data) { + return false + } + + if !fr.PrincipalInfo.Equals(other.PrincipalInfo) { + return false + } + + if !fr.Message.Equals(other.Message) { + return false + } + + return fr.SentOn.Equals(other.SentOn) +} + +// String returns the string representation of the FriendRequest +func (fr *FriendRequest) String() string { + return fr.FormatToString(0) +} + +// FormatToString pretty-prints the FriendRequest using the provided indentation level +func (fr *FriendRequest) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("FriendRequest{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, fr.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPrincipalInfo: %s,\n", indentationValues, fr.PrincipalInfo.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sMessage: %s,\n", indentationValues, fr.Message.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sSentOn: %s,\n", indentationValues, fr.SentOn.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewFriendRequest returns a new FriendRequest +func NewFriendRequest() *FriendRequest { + fr := &FriendRequest{ + Data: types.NewData(), + PrincipalInfo: NewPrincipalBasicInfo(), + Message: NewFriendRequestMessage(), + SentOn: types.NewDateTime(0), + } + + return fr +} diff --git a/nex-protocols-go/friends-wiiu/types/friend_request_message.go b/nex-protocols-go/friends-wiiu/types/friend_request_message.go new file mode 100644 index 0000000..075c881 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/types/friend_request_message.go @@ -0,0 +1,225 @@ +// Package types implements all the types used by the FriendsWiiU protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// FriendRequestMessage is a type within the FriendsWiiU protocol +type FriendRequestMessage struct { + types.Structure + *types.Data + FriendRequestID *types.PrimitiveU64 + Received *types.PrimitiveBool + Unknown2 *types.PrimitiveU8 + Message *types.String + Unknown3 *types.PrimitiveU8 + Unknown4 *types.String + GameKey *GameKey + Unknown5 *types.DateTime + ExpiresOn *types.DateTime +} + +// WriteTo writes the FriendRequestMessage to the given writable +func (frm *FriendRequestMessage) WriteTo(writable types.Writable) { + frm.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + frm.FriendRequestID.WriteTo(contentWritable) + frm.Received.WriteTo(contentWritable) + frm.Unknown2.WriteTo(contentWritable) + frm.Message.WriteTo(contentWritable) + frm.Unknown3.WriteTo(contentWritable) + frm.Unknown4.WriteTo(contentWritable) + frm.GameKey.WriteTo(contentWritable) + frm.Unknown5.WriteTo(contentWritable) + frm.ExpiresOn.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + frm.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the FriendRequestMessage from the given readable +func (frm *FriendRequestMessage) ExtractFrom(readable types.Readable) error { + var err error + + err = frm.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRequestMessage.Data. %s", err.Error()) + } + + err = frm.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRequestMessage header. %s", err.Error()) + } + + err = frm.FriendRequestID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRequestMessage.FriendRequestID. %s", err.Error()) + } + + err = frm.Received.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRequestMessage.Received. %s", err.Error()) + } + + err = frm.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRequestMessage.Unknown2. %s", err.Error()) + } + + err = frm.Message.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRequestMessage.Message. %s", err.Error()) + } + + err = frm.Unknown3.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRequestMessage.Unknown3. %s", err.Error()) + } + + err = frm.Unknown4.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRequestMessage.Unknown4. %s", err.Error()) + } + + err = frm.GameKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRequestMessage.GameKey. %s", err.Error()) + } + + err = frm.Unknown5.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRequestMessage.Unknown5. %s", err.Error()) + } + + err = frm.ExpiresOn.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendRequestMessage.ExpiresOn. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of FriendRequestMessage +func (frm *FriendRequestMessage) Copy() types.RVType { + copied := NewFriendRequestMessage() + + copied.StructureVersion = frm.StructureVersion + copied.Data = frm.Data.Copy().(*types.Data) + copied.FriendRequestID = frm.FriendRequestID.Copy().(*types.PrimitiveU64) + copied.Received = frm.Received.Copy().(*types.PrimitiveBool) + copied.Unknown2 = frm.Unknown2.Copy().(*types.PrimitiveU8) + copied.Message = frm.Message.Copy().(*types.String) + copied.Unknown3 = frm.Unknown3.Copy().(*types.PrimitiveU8) + copied.Unknown4 = frm.Unknown4.Copy().(*types.String) + copied.GameKey = frm.GameKey.Copy().(*GameKey) + copied.Unknown5 = frm.Unknown5.Copy().(*types.DateTime) + copied.ExpiresOn = frm.ExpiresOn.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given FriendRequestMessage contains the same data as the current FriendRequestMessage +func (frm *FriendRequestMessage) Equals(o types.RVType) bool { + if _, ok := o.(*FriendRequestMessage); !ok { + return false + } + + other := o.(*FriendRequestMessage) + + if frm.StructureVersion != other.StructureVersion { + return false + } + + if !frm.Data.Equals(other.Data) { + return false + } + + if !frm.FriendRequestID.Equals(other.FriendRequestID) { + return false + } + + if !frm.Received.Equals(other.Received) { + return false + } + + if !frm.Unknown2.Equals(other.Unknown2) { + return false + } + + if !frm.Message.Equals(other.Message) { + return false + } + + if !frm.Unknown3.Equals(other.Unknown3) { + return false + } + + if !frm.Unknown4.Equals(other.Unknown4) { + return false + } + + if !frm.GameKey.Equals(other.GameKey) { + return false + } + + if !frm.Unknown5.Equals(other.Unknown5) { + return false + } + + return frm.ExpiresOn.Equals(other.ExpiresOn) +} + +// String returns the string representation of the FriendRequestMessage +func (frm *FriendRequestMessage) String() string { + return frm.FormatToString(0) +} + +// FormatToString pretty-prints the FriendRequestMessage using the provided indentation level +func (frm *FriendRequestMessage) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("FriendRequestMessage{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, frm.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sFriendRequestID: %s,\n", indentationValues, frm.FriendRequestID)) + b.WriteString(fmt.Sprintf("%sReceived: %s,\n", indentationValues, frm.Received)) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, frm.Unknown2)) + b.WriteString(fmt.Sprintf("%sMessage: %s,\n", indentationValues, frm.Message)) + b.WriteString(fmt.Sprintf("%sUnknown3: %s,\n", indentationValues, frm.Unknown3)) + b.WriteString(fmt.Sprintf("%sUnknown4: %s,\n", indentationValues, frm.Unknown4)) + b.WriteString(fmt.Sprintf("%sGameKey: %s,\n", indentationValues, frm.GameKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUnknown5: %s,\n", indentationValues, frm.Unknown5.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sExpiresOn: %s,\n", indentationValues, frm.ExpiresOn.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewFriendRequestMessage returns a new FriendRequestMessage +func NewFriendRequestMessage() *FriendRequestMessage { + frm := &FriendRequestMessage{ + Data: types.NewData(), + FriendRequestID: types.NewPrimitiveU64(0), + Received: types.NewPrimitiveBool(false), + Unknown2: types.NewPrimitiveU8(0), + Message: types.NewString(""), + Unknown3: types.NewPrimitiveU8(0), + Unknown4: types.NewString(""), + GameKey: NewGameKey(), + Unknown5: types.NewDateTime(0), + ExpiresOn: types.NewDateTime(0), + } + + return frm +} diff --git a/nex-protocols-go/friends-wiiu/types/game_key.go b/nex-protocols-go/friends-wiiu/types/game_key.go new file mode 100644 index 0000000..28a2705 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/types/game_key.go @@ -0,0 +1,127 @@ +// Package types implements all the types used by the FriendsWiiU protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GameKey is a type within the FriendsWiiU protocol +type GameKey struct { + types.Structure + *types.Data + TitleID *types.PrimitiveU64 + TitleVersion *types.PrimitiveU16 +} + +// WriteTo writes the GameKey to the given writable +func (gk *GameKey) WriteTo(writable types.Writable) { + gk.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + gk.TitleID.WriteTo(contentWritable) + gk.TitleVersion.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gk.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GameKey from the given readable +func (gk *GameKey) ExtractFrom(readable types.Readable) error { + var err error + + err = gk.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GameKey.Data. %s", err.Error()) + } + + err = gk.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GameKey header. %s", err.Error()) + } + + err = gk.TitleID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GameKey.TitleID. %s", err.Error()) + } + + err = gk.TitleVersion.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GameKey.TitleVersion. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GameKey +func (gk *GameKey) Copy() types.RVType { + copied := NewGameKey() + + copied.StructureVersion = gk.StructureVersion + copied.Data = gk.Data.Copy().(*types.Data) + copied.TitleID = gk.TitleID.Copy().(*types.PrimitiveU64) + copied.TitleVersion = gk.TitleVersion.Copy().(*types.PrimitiveU16) + + return copied +} + +// Equals checks if the given GameKey contains the same data as the current GameKey +func (gk *GameKey) Equals(o types.RVType) bool { + if _, ok := o.(*GameKey); !ok { + return false + } + + other := o.(*GameKey) + + if gk.StructureVersion != other.StructureVersion { + return false + } + + if !gk.Data.Equals(other.Data) { + return false + } + + if !gk.TitleID.Equals(other.TitleID) { + return false + } + + return gk.TitleVersion.Equals(other.TitleVersion) +} + +// String returns the string representation of the GameKey +func (gk *GameKey) String() string { + return gk.FormatToString(0) +} + +// FormatToString pretty-prints the GameKey using the provided indentation level +func (gk *GameKey) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GameKey{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, gk.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sTitleID: %s,\n", indentationValues, gk.TitleID)) + b.WriteString(fmt.Sprintf("%sTitleVersion: %s,\n", indentationValues, gk.TitleVersion)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGameKey returns a new GameKey +func NewGameKey() *GameKey { + gk := &GameKey{ + Data: types.NewData(), + TitleID: types.NewPrimitiveU64(0), + TitleVersion: types.NewPrimitiveU16(0), + } + + return gk +} diff --git a/nex-protocols-go/friends-wiiu/types/mii_v2.go b/nex-protocols-go/friends-wiiu/types/mii_v2.go new file mode 100644 index 0000000..361c9aa --- /dev/null +++ b/nex-protocols-go/friends-wiiu/types/mii_v2.go @@ -0,0 +1,169 @@ +// Package types implements all the types used by the FriendsWiiU protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// MiiV2 is a type within the FriendsWiiU protocol +type MiiV2 struct { + types.Structure + *types.Data + Name *types.String + Unknown1 *types.PrimitiveU8 + Unknown2 *types.PrimitiveU8 + MiiData *types.Buffer + Datetime *types.DateTime +} + +// WriteTo writes the MiiV2 to the given writable +func (mv *MiiV2) WriteTo(writable types.Writable) { + mv.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + mv.Name.WriteTo(contentWritable) + mv.Unknown1.WriteTo(contentWritable) + mv.Unknown2.WriteTo(contentWritable) + mv.MiiData.WriteTo(contentWritable) + mv.Datetime.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + mv.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MiiV2 from the given readable +func (mv *MiiV2) ExtractFrom(readable types.Readable) error { + var err error + + err = mv.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiV2.Data. %s", err.Error()) + } + + err = mv.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiV2 header. %s", err.Error()) + } + + err = mv.Name.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiV2.Name. %s", err.Error()) + } + + err = mv.Unknown1.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiV2.Unknown1. %s", err.Error()) + } + + err = mv.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiV2.Unknown2. %s", err.Error()) + } + + err = mv.MiiData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiV2.MiiData. %s", err.Error()) + } + + err = mv.Datetime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MiiV2.Datetime. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of MiiV2 +func (mv *MiiV2) Copy() types.RVType { + copied := NewMiiV2() + + copied.StructureVersion = mv.StructureVersion + copied.Data = mv.Data.Copy().(*types.Data) + copied.Name = mv.Name.Copy().(*types.String) + copied.Unknown1 = mv.Unknown1.Copy().(*types.PrimitiveU8) + copied.Unknown2 = mv.Unknown2.Copy().(*types.PrimitiveU8) + copied.MiiData = mv.MiiData.Copy().(*types.Buffer) + copied.Datetime = mv.Datetime.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given MiiV2 contains the same data as the current MiiV2 +func (mv *MiiV2) Equals(o types.RVType) bool { + if _, ok := o.(*MiiV2); !ok { + return false + } + + other := o.(*MiiV2) + + if mv.StructureVersion != other.StructureVersion { + return false + } + + if !mv.Data.Equals(other.Data) { + return false + } + + if !mv.Name.Equals(other.Name) { + return false + } + + if !mv.Unknown1.Equals(other.Unknown1) { + return false + } + + if !mv.Unknown2.Equals(other.Unknown2) { + return false + } + + if !mv.MiiData.Equals(other.MiiData) { + return false + } + + return mv.Datetime.Equals(other.Datetime) +} + +// String returns the string representation of the MiiV2 +func (mv *MiiV2) String() string { + return mv.FormatToString(0) +} + +// FormatToString pretty-prints the MiiV2 using the provided indentation level +func (mv *MiiV2) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MiiV2{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, mv.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sName: %s,\n", indentationValues, mv.Name)) + b.WriteString(fmt.Sprintf("%sUnknown1: %s,\n", indentationValues, mv.Unknown1)) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, mv.Unknown2)) + b.WriteString(fmt.Sprintf("%sMiiData: %s,\n", indentationValues, mv.MiiData)) + b.WriteString(fmt.Sprintf("%sDatetime: %s,\n", indentationValues, mv.Datetime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMiiV2 returns a new MiiV2 +func NewMiiV2() *MiiV2 { + mv := &MiiV2{ + Data: types.NewData(), + Name: types.NewString(""), + Unknown1: types.NewPrimitiveU8(0), + Unknown2: types.NewPrimitiveU8(0), + MiiData: types.NewBuffer(nil), + Datetime: types.NewDateTime(0), + } + + return mv +} diff --git a/nex-protocols-go/friends-wiiu/types/nintendo_presence_v2.go b/nex-protocols-go/friends-wiiu/types/nintendo_presence_v2.go new file mode 100644 index 0000000..97aa486 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/types/nintendo_presence_v2.go @@ -0,0 +1,309 @@ +// Package types implements all the types used by the FriendsWiiU protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// NintendoPresenceV2 is a type within the FriendsWiiU protocol +type NintendoPresenceV2 struct { + types.Structure + *types.Data + ChangedFlags *types.PrimitiveU32 + Online *types.PrimitiveBool + GameKey *GameKey + Unknown1 *types.PrimitiveU8 + Message *types.String + Unknown2 *types.PrimitiveU32 + Unknown3 *types.PrimitiveU8 + GameServerID *types.PrimitiveU32 + Unknown4 *types.PrimitiveU32 + PID *types.PID + GatheringID *types.PrimitiveU32 + ApplicationData *types.Buffer + Unknown5 *types.PrimitiveU8 + Unknown6 *types.PrimitiveU8 + Unknown7 *types.PrimitiveU8 +} + +// WriteTo writes the NintendoPresenceV2 to the given writable +func (npv *NintendoPresenceV2) WriteTo(writable types.Writable) { + npv.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + npv.ChangedFlags.WriteTo(contentWritable) + npv.Online.WriteTo(contentWritable) + npv.GameKey.WriteTo(contentWritable) + npv.Unknown1.WriteTo(contentWritable) + npv.Message.WriteTo(contentWritable) + npv.Unknown2.WriteTo(contentWritable) + npv.Unknown3.WriteTo(contentWritable) + npv.GameServerID.WriteTo(contentWritable) + npv.Unknown4.WriteTo(contentWritable) + npv.PID.WriteTo(contentWritable) + npv.GatheringID.WriteTo(contentWritable) + npv.ApplicationData.WriteTo(contentWritable) + npv.Unknown5.WriteTo(contentWritable) + npv.Unknown6.WriteTo(contentWritable) + npv.Unknown7.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + npv.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the NintendoPresenceV2 from the given readable +func (npv *NintendoPresenceV2) ExtractFrom(readable types.Readable) error { + var err error + + err = npv.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresenceV2.Data. %s", err.Error()) + } + + err = npv.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresenceV2 header. %s", err.Error()) + } + + err = npv.ChangedFlags.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresenceV2.ChangedFlags. %s", err.Error()) + } + + err = npv.Online.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresenceV2.Online. %s", err.Error()) + } + + err = npv.GameKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresenceV2.GameKey. %s", err.Error()) + } + + err = npv.Unknown1.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresenceV2.Unknown1. %s", err.Error()) + } + + err = npv.Message.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresenceV2.Message. %s", err.Error()) + } + + err = npv.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresenceV2.Unknown2. %s", err.Error()) + } + + err = npv.Unknown3.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresenceV2.Unknown3. %s", err.Error()) + } + + err = npv.GameServerID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresenceV2.GameServerID. %s", err.Error()) + } + + err = npv.Unknown4.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresenceV2.Unknown4. %s", err.Error()) + } + + err = npv.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresenceV2.PID. %s", err.Error()) + } + + err = npv.GatheringID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresenceV2.GatheringID. %s", err.Error()) + } + + err = npv.ApplicationData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresenceV2.ApplicationData. %s", err.Error()) + } + + err = npv.Unknown5.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresenceV2.Unknown5. %s", err.Error()) + } + + err = npv.Unknown6.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresenceV2.Unknown6. %s", err.Error()) + } + + err = npv.Unknown7.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoPresenceV2.Unknown7. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of NintendoPresenceV2 +func (npv *NintendoPresenceV2) Copy() types.RVType { + copied := NewNintendoPresenceV2() + + copied.StructureVersion = npv.StructureVersion + copied.Data = npv.Data.Copy().(*types.Data) + copied.ChangedFlags = npv.ChangedFlags.Copy().(*types.PrimitiveU32) + copied.Online = npv.Online.Copy().(*types.PrimitiveBool) + copied.GameKey = npv.GameKey.Copy().(*GameKey) + copied.Unknown1 = npv.Unknown1.Copy().(*types.PrimitiveU8) + copied.Message = npv.Message.Copy().(*types.String) + copied.Unknown2 = npv.Unknown2.Copy().(*types.PrimitiveU32) + copied.Unknown3 = npv.Unknown3.Copy().(*types.PrimitiveU8) + copied.GameServerID = npv.GameServerID.Copy().(*types.PrimitiveU32) + copied.Unknown4 = npv.Unknown4.Copy().(*types.PrimitiveU32) + copied.PID = npv.PID.Copy().(*types.PID) + copied.GatheringID = npv.GatheringID.Copy().(*types.PrimitiveU32) + copied.ApplicationData = npv.ApplicationData.Copy().(*types.Buffer) + copied.Unknown5 = npv.Unknown5.Copy().(*types.PrimitiveU8) + copied.Unknown6 = npv.Unknown6.Copy().(*types.PrimitiveU8) + copied.Unknown7 = npv.Unknown7.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given NintendoPresenceV2 contains the same data as the current NintendoPresenceV2 +func (npv *NintendoPresenceV2) Equals(o types.RVType) bool { + if _, ok := o.(*NintendoPresenceV2); !ok { + return false + } + + other := o.(*NintendoPresenceV2) + + if npv.StructureVersion != other.StructureVersion { + return false + } + + if !npv.Data.Equals(other.Data) { + return false + } + + if !npv.ChangedFlags.Equals(other.ChangedFlags) { + return false + } + + if !npv.Online.Equals(other.Online) { + return false + } + + if !npv.GameKey.Equals(other.GameKey) { + return false + } + + if !npv.Unknown1.Equals(other.Unknown1) { + return false + } + + if !npv.Message.Equals(other.Message) { + return false + } + + if !npv.Unknown2.Equals(other.Unknown2) { + return false + } + + if !npv.Unknown3.Equals(other.Unknown3) { + return false + } + + if !npv.GameServerID.Equals(other.GameServerID) { + return false + } + + if !npv.Unknown4.Equals(other.Unknown4) { + return false + } + + if !npv.PID.Equals(other.PID) { + return false + } + + if !npv.GatheringID.Equals(other.GatheringID) { + return false + } + + if !npv.ApplicationData.Equals(other.ApplicationData) { + return false + } + + if !npv.Unknown5.Equals(other.Unknown5) { + return false + } + + if !npv.Unknown6.Equals(other.Unknown6) { + return false + } + + return npv.Unknown7.Equals(other.Unknown7) +} + +// String returns the string representation of the NintendoPresenceV2 +func (npv *NintendoPresenceV2) String() string { + return npv.FormatToString(0) +} + +// FormatToString pretty-prints the NintendoPresenceV2 using the provided indentation level +func (npv *NintendoPresenceV2) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("NintendoPresenceV2{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, npv.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sChangedFlags: %s,\n", indentationValues, npv.ChangedFlags)) + b.WriteString(fmt.Sprintf("%sOnline: %s,\n", indentationValues, npv.Online)) + b.WriteString(fmt.Sprintf("%sGameKey: %s,\n", indentationValues, npv.GameKey.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUnknown1: %s,\n", indentationValues, npv.Unknown1)) + b.WriteString(fmt.Sprintf("%sMessage: %s,\n", indentationValues, npv.Message)) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, npv.Unknown2)) + b.WriteString(fmt.Sprintf("%sUnknown3: %s,\n", indentationValues, npv.Unknown3)) + b.WriteString(fmt.Sprintf("%sGameServerID: %s,\n", indentationValues, npv.GameServerID)) + b.WriteString(fmt.Sprintf("%sUnknown4: %s,\n", indentationValues, npv.Unknown4)) + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, npv.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sGatheringID: %s,\n", indentationValues, npv.GatheringID)) + b.WriteString(fmt.Sprintf("%sApplicationData: %s,\n", indentationValues, npv.ApplicationData)) + b.WriteString(fmt.Sprintf("%sUnknown5: %s,\n", indentationValues, npv.Unknown5)) + b.WriteString(fmt.Sprintf("%sUnknown6: %s,\n", indentationValues, npv.Unknown6)) + b.WriteString(fmt.Sprintf("%sUnknown7: %s,\n", indentationValues, npv.Unknown7)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewNintendoPresenceV2 returns a new NintendoPresenceV2 +func NewNintendoPresenceV2() *NintendoPresenceV2 { + npv := &NintendoPresenceV2{ + Data: types.NewData(), + ChangedFlags: types.NewPrimitiveU32(0), + Online: types.NewPrimitiveBool(false), + GameKey: NewGameKey(), + Unknown1: types.NewPrimitiveU8(0), + Message: types.NewString(""), + Unknown2: types.NewPrimitiveU32(0), + Unknown3: types.NewPrimitiveU8(0), + GameServerID: types.NewPrimitiveU32(0), + Unknown4: types.NewPrimitiveU32(0), + PID: types.NewPID(0), + GatheringID: types.NewPrimitiveU32(0), + ApplicationData: types.NewBuffer(nil), + Unknown5: types.NewPrimitiveU8(0), + Unknown6: types.NewPrimitiveU8(0), + Unknown7: types.NewPrimitiveU8(0), + } + + return npv +} diff --git a/nex-protocols-go/friends-wiiu/types/nna_info.go b/nex-protocols-go/friends-wiiu/types/nna_info.go new file mode 100644 index 0000000..86a4e20 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/types/nna_info.go @@ -0,0 +1,141 @@ +// Package types implements all the types used by the FriendsWiiU protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// NNAInfo is a type within the FriendsWiiU protocol +type NNAInfo struct { + types.Structure + *types.Data + PrincipalBasicInfo *PrincipalBasicInfo + Unknown1 *types.PrimitiveU8 + Unknown2 *types.PrimitiveU8 +} + +// WriteTo writes the NNAInfo to the given writable +func (nnai *NNAInfo) WriteTo(writable types.Writable) { + nnai.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + nnai.PrincipalBasicInfo.WriteTo(contentWritable) + nnai.Unknown1.WriteTo(contentWritable) + nnai.Unknown2.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + nnai.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the NNAInfo from the given readable +func (nnai *NNAInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = nnai.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NNAInfo.Data. %s", err.Error()) + } + + err = nnai.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NNAInfo header. %s", err.Error()) + } + + err = nnai.PrincipalBasicInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NNAInfo.PrincipalBasicInfo. %s", err.Error()) + } + + err = nnai.Unknown1.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NNAInfo.Unknown1. %s", err.Error()) + } + + err = nnai.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NNAInfo.Unknown2. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of NNAInfo +func (nnai *NNAInfo) Copy() types.RVType { + copied := NewNNAInfo() + + copied.StructureVersion = nnai.StructureVersion + copied.Data = nnai.Data.Copy().(*types.Data) + copied.PrincipalBasicInfo = nnai.PrincipalBasicInfo.Copy().(*PrincipalBasicInfo) + copied.Unknown1 = nnai.Unknown1.Copy().(*types.PrimitiveU8) + copied.Unknown2 = nnai.Unknown2.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given NNAInfo contains the same data as the current NNAInfo +func (nnai *NNAInfo) Equals(o types.RVType) bool { + if _, ok := o.(*NNAInfo); !ok { + return false + } + + other := o.(*NNAInfo) + + if nnai.StructureVersion != other.StructureVersion { + return false + } + + if !nnai.Data.Equals(other.Data) { + return false + } + + if !nnai.PrincipalBasicInfo.Equals(other.PrincipalBasicInfo) { + return false + } + + if !nnai.Unknown1.Equals(other.Unknown1) { + return false + } + + return nnai.Unknown2.Equals(other.Unknown2) +} + +// String returns the string representation of the NNAInfo +func (nnai *NNAInfo) String() string { + return nnai.FormatToString(0) +} + +// FormatToString pretty-prints the NNAInfo using the provided indentation level +func (nnai *NNAInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("NNAInfo{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, nnai.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPrincipalBasicInfo: %s,\n", indentationValues, nnai.PrincipalBasicInfo.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUnknown1: %s,\n", indentationValues, nnai.Unknown1)) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, nnai.Unknown2)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewNNAInfo returns a new NNAInfo +func NewNNAInfo() *NNAInfo { + nnai := &NNAInfo{ + Data: types.NewData(), + PrincipalBasicInfo: NewPrincipalBasicInfo(), + Unknown1: types.NewPrimitiveU8(0), + Unknown2: types.NewPrimitiveU8(0), + } + + return nnai +} diff --git a/nex-protocols-go/friends-wiiu/types/persistent_notification.go b/nex-protocols-go/friends-wiiu/types/persistent_notification.go new file mode 100644 index 0000000..61a6753 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/types/persistent_notification.go @@ -0,0 +1,169 @@ +// Package types implements all the types used by the FriendsWiiU protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// PersistentNotification is a type within the FriendsWiiU protocol +type PersistentNotification struct { + types.Structure + *types.Data + Unknown1 *types.PrimitiveU64 + Unknown2 *types.PrimitiveU32 + Unknown3 *types.PrimitiveU32 + Unknown4 *types.PrimitiveU32 + Unknown5 *types.String +} + +// WriteTo writes the PersistentNotification to the given writable +func (pn *PersistentNotification) WriteTo(writable types.Writable) { + pn.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + pn.Unknown1.WriteTo(contentWritable) + pn.Unknown2.WriteTo(contentWritable) + pn.Unknown3.WriteTo(contentWritable) + pn.Unknown4.WriteTo(contentWritable) + pn.Unknown5.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + pn.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the PersistentNotification from the given readable +func (pn *PersistentNotification) ExtractFrom(readable types.Readable) error { + var err error + + err = pn.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentNotification.Data. %s", err.Error()) + } + + err = pn.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentNotification header. %s", err.Error()) + } + + err = pn.Unknown1.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentNotification.Unknown1. %s", err.Error()) + } + + err = pn.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentNotification.Unknown2. %s", err.Error()) + } + + err = pn.Unknown3.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentNotification.Unknown3. %s", err.Error()) + } + + err = pn.Unknown4.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentNotification.Unknown4. %s", err.Error()) + } + + err = pn.Unknown5.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentNotification.Unknown5. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of PersistentNotification +func (pn *PersistentNotification) Copy() types.RVType { + copied := NewPersistentNotification() + + copied.StructureVersion = pn.StructureVersion + copied.Data = pn.Data.Copy().(*types.Data) + copied.Unknown1 = pn.Unknown1.Copy().(*types.PrimitiveU64) + copied.Unknown2 = pn.Unknown2.Copy().(*types.PrimitiveU32) + copied.Unknown3 = pn.Unknown3.Copy().(*types.PrimitiveU32) + copied.Unknown4 = pn.Unknown4.Copy().(*types.PrimitiveU32) + copied.Unknown5 = pn.Unknown5.Copy().(*types.String) + + return copied +} + +// Equals checks if the given PersistentNotification contains the same data as the current PersistentNotification +func (pn *PersistentNotification) Equals(o types.RVType) bool { + if _, ok := o.(*PersistentNotification); !ok { + return false + } + + other := o.(*PersistentNotification) + + if pn.StructureVersion != other.StructureVersion { + return false + } + + if !pn.Data.Equals(other.Data) { + return false + } + + if !pn.Unknown1.Equals(other.Unknown1) { + return false + } + + if !pn.Unknown2.Equals(other.Unknown2) { + return false + } + + if !pn.Unknown3.Equals(other.Unknown3) { + return false + } + + if !pn.Unknown4.Equals(other.Unknown4) { + return false + } + + return pn.Unknown5.Equals(other.Unknown5) +} + +// String returns the string representation of the PersistentNotification +func (pn *PersistentNotification) String() string { + return pn.FormatToString(0) +} + +// FormatToString pretty-prints the PersistentNotification using the provided indentation level +func (pn *PersistentNotification) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("PersistentNotification{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, pn.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUnknown1: %s,\n", indentationValues, pn.Unknown1)) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, pn.Unknown2)) + b.WriteString(fmt.Sprintf("%sUnknown3: %s,\n", indentationValues, pn.Unknown3)) + b.WriteString(fmt.Sprintf("%sUnknown4: %s,\n", indentationValues, pn.Unknown4)) + b.WriteString(fmt.Sprintf("%sUnknown5: %s,\n", indentationValues, pn.Unknown5)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewPersistentNotification returns a new PersistentNotification +func NewPersistentNotification() *PersistentNotification { + pn := &PersistentNotification{ + Data: types.NewData(), + Unknown1: types.NewPrimitiveU64(0), + Unknown2: types.NewPrimitiveU32(0), + Unknown3: types.NewPrimitiveU32(0), + Unknown4: types.NewPrimitiveU32(0), + Unknown5: types.NewString(""), + } + + return pn +} diff --git a/nex-protocols-go/friends-wiiu/types/persistent_notification_list.go b/nex-protocols-go/friends-wiiu/types/persistent_notification_list.go new file mode 100644 index 0000000..38218b2 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/types/persistent_notification_list.go @@ -0,0 +1,115 @@ +// Package types implements all the types used by the FriendsWiiU protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// PersistentNotificationList is a type within the FriendsWiiU protocol +type PersistentNotificationList struct { + types.Structure + *types.Data + Notifications *types.List[*PersistentNotification] +} + +// WriteTo writes the PersistentNotificationList to the given writable +func (pnl *PersistentNotificationList) WriteTo(writable types.Writable) { + pnl.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + pnl.Notifications.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + pnl.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the PersistentNotificationList from the given readable +func (pnl *PersistentNotificationList) ExtractFrom(readable types.Readable) error { + var err error + + err = pnl.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentNotificationList.Data. %s", err.Error()) + } + + err = pnl.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentNotificationList header. %s", err.Error()) + } + + err = pnl.Notifications.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentNotificationList.Notifications. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of PersistentNotificationList +func (pnl *PersistentNotificationList) Copy() types.RVType { + copied := NewPersistentNotificationList() + + copied.StructureVersion = pnl.StructureVersion + copied.Data = pnl.Data.Copy().(*types.Data) + copied.Notifications = pnl.Notifications.Copy().(*types.List[*PersistentNotification]) + + return copied +} + +// Equals checks if the given PersistentNotificationList contains the same data as the current PersistentNotificationList +func (pnl *PersistentNotificationList) Equals(o types.RVType) bool { + if _, ok := o.(*PersistentNotificationList); !ok { + return false + } + + other := o.(*PersistentNotificationList) + + if pnl.StructureVersion != other.StructureVersion { + return false + } + + if !pnl.Data.Equals(other.Data) { + return false + } + + return pnl.Notifications.Equals(other.Notifications) +} + +// String returns the string representation of the PersistentNotificationList +func (pnl *PersistentNotificationList) String() string { + return pnl.FormatToString(0) +} + +// FormatToString pretty-prints the PersistentNotificationList using the provided indentation level +func (pnl *PersistentNotificationList) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("PersistentNotificationList{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, pnl.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sNotifications: %s,\n", indentationValues, pnl.Notifications)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewPersistentNotificationList returns a new PersistentNotificationList +func NewPersistentNotificationList() *PersistentNotificationList { + pnl := &PersistentNotificationList{ + Data: types.NewData(), + Notifications: types.NewList[*PersistentNotification](), + } + + pnl.Notifications.Type = NewPersistentNotification() + + return pnl +} diff --git a/nex-protocols-go/friends-wiiu/types/principal_basic_info.go b/nex-protocols-go/friends-wiiu/types/principal_basic_info.go new file mode 100644 index 0000000..a430ccf --- /dev/null +++ b/nex-protocols-go/friends-wiiu/types/principal_basic_info.go @@ -0,0 +1,155 @@ +// Package types implements all the types used by the FriendsWiiU protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// PrincipalBasicInfo is a type within the FriendsWiiU protocol +type PrincipalBasicInfo struct { + types.Structure + *types.Data + PID *types.PID + NNID *types.String + Mii *MiiV2 + Unknown *types.PrimitiveU8 +} + +// WriteTo writes the PrincipalBasicInfo to the given writable +func (pbi *PrincipalBasicInfo) WriteTo(writable types.Writable) { + pbi.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + pbi.PID.WriteTo(contentWritable) + pbi.NNID.WriteTo(contentWritable) + pbi.Mii.WriteTo(contentWritable) + pbi.Unknown.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + pbi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the PrincipalBasicInfo from the given readable +func (pbi *PrincipalBasicInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = pbi.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PrincipalBasicInfo.Data. %s", err.Error()) + } + + err = pbi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PrincipalBasicInfo header. %s", err.Error()) + } + + err = pbi.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PrincipalBasicInfo.PID. %s", err.Error()) + } + + err = pbi.NNID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PrincipalBasicInfo.NNID. %s", err.Error()) + } + + err = pbi.Mii.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PrincipalBasicInfo.Mii. %s", err.Error()) + } + + err = pbi.Unknown.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PrincipalBasicInfo.Unknown. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of PrincipalBasicInfo +func (pbi *PrincipalBasicInfo) Copy() types.RVType { + copied := NewPrincipalBasicInfo() + + copied.StructureVersion = pbi.StructureVersion + copied.Data = pbi.Data.Copy().(*types.Data) + copied.PID = pbi.PID.Copy().(*types.PID) + copied.NNID = pbi.NNID.Copy().(*types.String) + copied.Mii = pbi.Mii.Copy().(*MiiV2) + copied.Unknown = pbi.Unknown.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given PrincipalBasicInfo contains the same data as the current PrincipalBasicInfo +func (pbi *PrincipalBasicInfo) Equals(o types.RVType) bool { + if _, ok := o.(*PrincipalBasicInfo); !ok { + return false + } + + other := o.(*PrincipalBasicInfo) + + if pbi.StructureVersion != other.StructureVersion { + return false + } + + if !pbi.Data.Equals(other.Data) { + return false + } + + if !pbi.PID.Equals(other.PID) { + return false + } + + if !pbi.NNID.Equals(other.NNID) { + return false + } + + if !pbi.Mii.Equals(other.Mii) { + return false + } + + return pbi.Unknown.Equals(other.Unknown) +} + +// String returns the string representation of the PrincipalBasicInfo +func (pbi *PrincipalBasicInfo) String() string { + return pbi.FormatToString(0) +} + +// FormatToString pretty-prints the PrincipalBasicInfo using the provided indentation level +func (pbi *PrincipalBasicInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("PrincipalBasicInfo{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, pbi.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, pbi.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sNNID: %s,\n", indentationValues, pbi.NNID)) + b.WriteString(fmt.Sprintf("%sMii: %s,\n", indentationValues, pbi.Mii.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUnknown: %s,\n", indentationValues, pbi.Unknown)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewPrincipalBasicInfo returns a new PrincipalBasicInfo +func NewPrincipalBasicInfo() *PrincipalBasicInfo { + pbi := &PrincipalBasicInfo{ + Data: types.NewData(), + PID: types.NewPID(0), + NNID: types.NewString(""), + Mii: NewMiiV2(), + Unknown: types.NewPrimitiveU8(0), + } + + return pbi +} diff --git a/nex-protocols-go/friends-wiiu/types/principal_preference.go b/nex-protocols-go/friends-wiiu/types/principal_preference.go new file mode 100644 index 0000000..6d3fd00 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/types/principal_preference.go @@ -0,0 +1,141 @@ +// Package types implements all the types used by the FriendsWiiU protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// PrincipalPreference is a type within the FriendsWiiU protocol +type PrincipalPreference struct { + types.Structure + *types.Data + ShowOnlinePresence *types.PrimitiveBool + ShowCurrentTitle *types.PrimitiveBool + BlockFriendRequests *types.PrimitiveBool +} + +// WriteTo writes the PrincipalPreference to the given writable +func (pp *PrincipalPreference) WriteTo(writable types.Writable) { + pp.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + pp.ShowOnlinePresence.WriteTo(contentWritable) + pp.ShowCurrentTitle.WriteTo(contentWritable) + pp.BlockFriendRequests.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + pp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the PrincipalPreference from the given readable +func (pp *PrincipalPreference) ExtractFrom(readable types.Readable) error { + var err error + + err = pp.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PrincipalPreference.Data. %s", err.Error()) + } + + err = pp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PrincipalPreference header. %s", err.Error()) + } + + err = pp.ShowOnlinePresence.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PrincipalPreference.ShowOnlinePresence. %s", err.Error()) + } + + err = pp.ShowCurrentTitle.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PrincipalPreference.ShowCurrentTitle. %s", err.Error()) + } + + err = pp.BlockFriendRequests.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PrincipalPreference.BlockFriendRequests. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of PrincipalPreference +func (pp *PrincipalPreference) Copy() types.RVType { + copied := NewPrincipalPreference() + + copied.StructureVersion = pp.StructureVersion + copied.Data = pp.Data.Copy().(*types.Data) + copied.ShowOnlinePresence = pp.ShowOnlinePresence.Copy().(*types.PrimitiveBool) + copied.ShowCurrentTitle = pp.ShowCurrentTitle.Copy().(*types.PrimitiveBool) + copied.BlockFriendRequests = pp.BlockFriendRequests.Copy().(*types.PrimitiveBool) + + return copied +} + +// Equals checks if the given PrincipalPreference contains the same data as the current PrincipalPreference +func (pp *PrincipalPreference) Equals(o types.RVType) bool { + if _, ok := o.(*PrincipalPreference); !ok { + return false + } + + other := o.(*PrincipalPreference) + + if pp.StructureVersion != other.StructureVersion { + return false + } + + if !pp.Data.Equals(other.Data) { + return false + } + + if !pp.ShowOnlinePresence.Equals(other.ShowOnlinePresence) { + return false + } + + if !pp.ShowCurrentTitle.Equals(other.ShowCurrentTitle) { + return false + } + + return pp.BlockFriendRequests.Equals(other.BlockFriendRequests) +} + +// String returns the string representation of the PrincipalPreference +func (pp *PrincipalPreference) String() string { + return pp.FormatToString(0) +} + +// FormatToString pretty-prints the PrincipalPreference using the provided indentation level +func (pp *PrincipalPreference) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("PrincipalPreference{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, pp.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sShowOnlinePresence: %s,\n", indentationValues, pp.ShowOnlinePresence)) + b.WriteString(fmt.Sprintf("%sShowCurrentTitle: %s,\n", indentationValues, pp.ShowCurrentTitle)) + b.WriteString(fmt.Sprintf("%sBlockFriendRequests: %s,\n", indentationValues, pp.BlockFriendRequests)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewPrincipalPreference returns a new PrincipalPreference +func NewPrincipalPreference() *PrincipalPreference { + pp := &PrincipalPreference{ + Data: types.NewData(), + ShowOnlinePresence: types.NewPrimitiveBool(false), + ShowCurrentTitle: types.NewPrimitiveBool(false), + BlockFriendRequests: types.NewPrimitiveBool(false), + } + + return pp +} diff --git a/nex-protocols-go/friends-wiiu/types/principal_request_block_setting.go b/nex-protocols-go/friends-wiiu/types/principal_request_block_setting.go new file mode 100644 index 0000000..fb6bd99 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/types/principal_request_block_setting.go @@ -0,0 +1,127 @@ +// Package types implements all the types used by the FriendsWiiU protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// PrincipalRequestBlockSetting is a type within the FriendsWiiU protocol +type PrincipalRequestBlockSetting struct { + types.Structure + *types.Data + PID *types.PrimitiveU32 + IsBlocked *types.PrimitiveBool +} + +// WriteTo writes the PrincipalRequestBlockSetting to the given writable +func (prbs *PrincipalRequestBlockSetting) WriteTo(writable types.Writable) { + prbs.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + prbs.PID.WriteTo(contentWritable) + prbs.IsBlocked.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + prbs.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the PrincipalRequestBlockSetting from the given readable +func (prbs *PrincipalRequestBlockSetting) ExtractFrom(readable types.Readable) error { + var err error + + err = prbs.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PrincipalRequestBlockSetting.Data. %s", err.Error()) + } + + err = prbs.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PrincipalRequestBlockSetting header. %s", err.Error()) + } + + err = prbs.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PrincipalRequestBlockSetting.PID. %s", err.Error()) + } + + err = prbs.IsBlocked.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PrincipalRequestBlockSetting.IsBlocked. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of PrincipalRequestBlockSetting +func (prbs *PrincipalRequestBlockSetting) Copy() types.RVType { + copied := NewPrincipalRequestBlockSetting() + + copied.StructureVersion = prbs.StructureVersion + copied.Data = prbs.Data.Copy().(*types.Data) + copied.PID = prbs.PID.Copy().(*types.PrimitiveU32) + copied.IsBlocked = prbs.IsBlocked.Copy().(*types.PrimitiveBool) + + return copied +} + +// Equals checks if the given PrincipalRequestBlockSetting contains the same data as the current PrincipalRequestBlockSetting +func (prbs *PrincipalRequestBlockSetting) Equals(o types.RVType) bool { + if _, ok := o.(*PrincipalRequestBlockSetting); !ok { + return false + } + + other := o.(*PrincipalRequestBlockSetting) + + if prbs.StructureVersion != other.StructureVersion { + return false + } + + if !prbs.Data.Equals(other.Data) { + return false + } + + if !prbs.PID.Equals(other.PID) { + return false + } + + return prbs.IsBlocked.Equals(other.IsBlocked) +} + +// String returns the string representation of the PrincipalRequestBlockSetting +func (prbs *PrincipalRequestBlockSetting) String() string { + return prbs.FormatToString(0) +} + +// FormatToString pretty-prints the PrincipalRequestBlockSetting using the provided indentation level +func (prbs *PrincipalRequestBlockSetting) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("PrincipalRequestBlockSetting{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, prbs.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, prbs.PID)) + b.WriteString(fmt.Sprintf("%sIsBlocked: %s,\n", indentationValues, prbs.IsBlocked)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewPrincipalRequestBlockSetting returns a new PrincipalRequestBlockSetting +func NewPrincipalRequestBlockSetting() *PrincipalRequestBlockSetting { + prbs := &PrincipalRequestBlockSetting{ + Data: types.NewData(), + PID: types.NewPrimitiveU32(0), + IsBlocked: types.NewPrimitiveBool(false), + } + + return prbs +} diff --git a/nex-protocols-go/friends-wiiu/update_and_get_all_information.go b/nex-protocols-go/friends-wiiu/update_and_get_all_information.go new file mode 100644 index 0000000..f69a31a --- /dev/null +++ b/nex-protocols-go/friends-wiiu/update_and_get_all_information.go @@ -0,0 +1,72 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-wiiu/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateAndGetAllInformation(packet nex.PacketInterface) { + if protocol.UpdateAndGetAllInformation == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::UpdateAndGetAllInformation not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + nnaInfo := friends_wiiu_types.NewNNAInfo() + presence := friends_wiiu_types.NewNintendoPresenceV2() + birthday := types.NewDateTime(0) + + var err error + + err = nnaInfo.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateAndGetAllInformation(fmt.Errorf("Failed to read nnaInfo from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = presence.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateAndGetAllInformation(fmt.Errorf("Failed to read presence from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = birthday.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateAndGetAllInformation(fmt.Errorf("Failed to read birthday from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateAndGetAllInformation(nil, packet, callID, nnaInfo, presence, birthday) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/update_comment.go b/nex-protocols-go/friends-wiiu/update_comment.go new file mode 100644 index 0000000..ae686ff --- /dev/null +++ b/nex-protocols-go/friends-wiiu/update_comment.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-wiiu/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateComment(packet nex.PacketInterface) { + if protocol.UpdateComment == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::UpdateComment not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + comment := friends_wiiu_types.NewComment() + + err := comment.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateComment(fmt.Errorf("Failed to read comment from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateComment(nil, packet, callID, comment) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/update_mii.go b/nex-protocols-go/friends-wiiu/update_mii.go new file mode 100644 index 0000000..adf5d0e --- /dev/null +++ b/nex-protocols-go/friends-wiiu/update_mii.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-wiiu/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateMii(packet nex.PacketInterface) { + if protocol.UpdateMii == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::UpdateMii not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + miiV2 := friends_wiiu_types.NewMiiV2() + + err := miiV2.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateMii(fmt.Errorf("Failed to read miiV2 from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateMii(nil, packet, callID, miiV2) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/update_preference.go b/nex-protocols-go/friends-wiiu/update_preference.go new file mode 100644 index 0000000..839126d --- /dev/null +++ b/nex-protocols-go/friends-wiiu/update_preference.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-wiiu/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdatePreference(packet nex.PacketInterface) { + if protocol.UpdatePreference == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::UpdatePreference not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + principalPreference := friends_wiiu_types.NewPrincipalPreference() + + err := principalPreference.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdatePreference(fmt.Errorf("Failed to read principalPreference from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdatePreference(nil, packet, callID, principalPreference) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends-wiiu/update_presence.go b/nex-protocols-go/friends-wiiu/update_presence.go new file mode 100644 index 0000000..da61930 --- /dev/null +++ b/nex-protocols-go/friends-wiiu/update_presence.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends WiiU protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-wiiu/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdatePresence(packet nex.PacketInterface) { + if protocol.UpdatePresence == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "FriendsWiiU::UpdatePresence not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + nintendoPresenceV2 := friends_wiiu_types.NewNintendoPresenceV2() + + err := nintendoPresenceV2.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdatePresence(fmt.Errorf("Failed to read nintendoPresenceV2 from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdatePresence(nil, packet, callID, nintendoPresenceV2) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends/accept_friendship.go b/nex-protocols-go/friends/accept_friendship.go new file mode 100644 index 0000000..78a9dad --- /dev/null +++ b/nex-protocols-go/friends/accept_friendship.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends QRV protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAcceptFriendship(packet nex.PacketInterface) { + if protocol.AcceptFriendship == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends::AcceptFriendship not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiPlayer := types.NewPrimitiveU32(0) + + err := uiPlayer.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AcceptFriendship(fmt.Errorf("Failed to read uiPlayer from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AcceptFriendship(nil, packet, callID, uiPlayer) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends/add_friend.go b/nex-protocols-go/friends/add_friend.go new file mode 100644 index 0000000..5f00bac --- /dev/null +++ b/nex-protocols-go/friends/add_friend.go @@ -0,0 +1,71 @@ +// Package protocol implements the Friends QRV protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAddFriend(packet nex.PacketInterface) { + if protocol.AddFriend == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends::AddFriend not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiPlayer := types.NewPrimitiveU32(0) + uiDetails := types.NewPrimitiveU32(0) + strMessage := types.NewString("") + + var err error + + err = uiPlayer.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriend(fmt.Errorf("Failed to read uiPlayer from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uiDetails.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriend(fmt.Errorf("Failed to read uiDetails from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriend(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AddFriend(nil, packet, callID, uiPlayer, uiDetails, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends/add_friend_by_name.go b/nex-protocols-go/friends/add_friend_by_name.go new file mode 100644 index 0000000..ab52299 --- /dev/null +++ b/nex-protocols-go/friends/add_friend_by_name.go @@ -0,0 +1,71 @@ +// Package protocol implements the Friends QRV protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAddFriendByName(packet nex.PacketInterface) { + if protocol.AddFriendByName == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends::AddFriendByName not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strPlayerName := types.NewString("") + uiDetails := types.NewPrimitiveU32(0) + strMessage := types.NewString("") + + var err error + + err = strPlayerName.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendByName(fmt.Errorf("Failed to read strPlayerName from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uiDetails.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendByName(fmt.Errorf("Failed to read uiDetails from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendByName(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AddFriendByName(nil, packet, callID, strPlayerName, uiDetails, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends/add_friend_by_name_with_details.go b/nex-protocols-go/friends/add_friend_by_name_with_details.go new file mode 100644 index 0000000..fa9207d --- /dev/null +++ b/nex-protocols-go/friends/add_friend_by_name_with_details.go @@ -0,0 +1,71 @@ +// Package protocol implements the Friends QRV protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAddFriendWithDetails(packet nex.PacketInterface) { + if protocol.AddFriendWithDetails == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends::AddFriendWithDetails not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiPlayer := types.NewPrimitiveU32(0) + uiDetails := types.NewPrimitiveU32(0) + strMessage := types.NewString("") + + var err error + + err = uiPlayer.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendWithDetails(fmt.Errorf("Failed to read uiPlayer from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uiDetails.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendWithDetails(fmt.Errorf("Failed to read uiDetails from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendWithDetails(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AddFriendWithDetails(nil, packet, callID, uiPlayer, uiDetails, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends/add_friend_with_details.go b/nex-protocols-go/friends/add_friend_with_details.go new file mode 100644 index 0000000..327a6d5 --- /dev/null +++ b/nex-protocols-go/friends/add_friend_with_details.go @@ -0,0 +1,71 @@ +// Package protocol implements the Friends QRV protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAddFriendByNameWithDetails(packet nex.PacketInterface) { + if protocol.AddFriendByNameWithDetails == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends::AddFriendByNameWithDetails not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiPlayer := types.NewPrimitiveU32(0) + uiDetails := types.NewPrimitiveU32(0) + strMessage := types.NewString("") + + var err error + + err = uiPlayer.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendByNameWithDetails(fmt.Errorf("Failed to read uiPlayer from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uiDetails.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendByNameWithDetails(fmt.Errorf("Failed to read uiDetails from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriendByNameWithDetails(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AddFriendByNameWithDetails(nil, packet, callID, uiPlayer, uiDetails, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends/black_list.go b/nex-protocols-go/friends/black_list.go new file mode 100644 index 0000000..249ccff --- /dev/null +++ b/nex-protocols-go/friends/black_list.go @@ -0,0 +1,60 @@ +// Package protocol implements the Friends QRV protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleBlackList(packet nex.PacketInterface) { + if protocol.BlackList == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends::BlackList not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiPlayer := types.NewPrimitiveU32(0) + uiDetails := types.NewPrimitiveU32(0) + + var err error + + err = uiPlayer.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.BlackList(fmt.Errorf("Failed to read uiPlayer from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uiDetails.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.BlackList(fmt.Errorf("Failed to read uiDetails from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.BlackList(nil, packet, callID, uiPlayer, uiDetails) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends/black_list_by_name.go b/nex-protocols-go/friends/black_list_by_name.go new file mode 100644 index 0000000..dd24372 --- /dev/null +++ b/nex-protocols-go/friends/black_list_by_name.go @@ -0,0 +1,60 @@ +// Package protocol implements the Friends QRV protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleBlackListByName(packet nex.PacketInterface) { + if protocol.BlackListByName == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends::BlackListByName not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strPlayerName := types.NewString("") + uiDetails := types.NewPrimitiveU32(0) + + var err error + + err = strPlayerName.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.BlackListByName(fmt.Errorf("Failed to read strPlayerName from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uiDetails.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.BlackListByName(fmt.Errorf("Failed to read uiDetails from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.BlackListByName(nil, packet, callID, strPlayerName, uiDetails) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends/clear_relationship.go b/nex-protocols-go/friends/clear_relationship.go new file mode 100644 index 0000000..cb61f7c --- /dev/null +++ b/nex-protocols-go/friends/clear_relationship.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends QRV protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleClearRelationship(packet nex.PacketInterface) { + if protocol.ClearRelationship == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends::ClearRelationship not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiPlayer := types.NewPrimitiveU32(0) + + err := uiPlayer.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ClearRelationship(fmt.Errorf("Failed to read uiPlayer from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ClearRelationship(nil, packet, callID, uiPlayer) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends/decline_friendship.go b/nex-protocols-go/friends/decline_friendship.go new file mode 100644 index 0000000..896c4e8 --- /dev/null +++ b/nex-protocols-go/friends/decline_friendship.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends QRV protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeclineFriendship(packet nex.PacketInterface) { + if protocol.DeclineFriendship == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends::DeclineFriendship not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiPlayer := types.NewPrimitiveU32(0) + + err := uiPlayer.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeclineFriendship(fmt.Errorf("Failed to read uiPlayer from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeclineFriendship(nil, packet, callID, uiPlayer) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends/get_detailed_list.go b/nex-protocols-go/friends/get_detailed_list.go new file mode 100644 index 0000000..25a78f5 --- /dev/null +++ b/nex-protocols-go/friends/get_detailed_list.go @@ -0,0 +1,60 @@ +// Package protocol implements the Friends QRV protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetDetailedList(packet nex.PacketInterface) { + if protocol.GetDetailedList == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends::GetDetailedList not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + byRelationship := types.NewPrimitiveU8(0) + bReversed := types.NewPrimitiveBool(false) + + var err error + + err = byRelationship.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetDetailedList(fmt.Errorf("Failed to read byRelationship from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = bReversed.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetDetailedList(fmt.Errorf("Failed to read bReversed from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetDetailedList(nil, packet, callID, byRelationship, bReversed) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends/get_list.go b/nex-protocols-go/friends/get_list.go new file mode 100644 index 0000000..06e433e --- /dev/null +++ b/nex-protocols-go/friends/get_list.go @@ -0,0 +1,60 @@ +// Package protocol implements the Friends QRV protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetList(packet nex.PacketInterface) { + if protocol.GetList == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends::GetList not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + byRelationship := types.NewPrimitiveU8(0) + bReversed := types.NewPrimitiveBool(false) + + var err error + + err = byRelationship.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetList(fmt.Errorf("Failed to read byRelationship from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = bReversed.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetList(fmt.Errorf("Failed to read bReversed from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetList(nil, packet, callID, byRelationship, bReversed) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends/get_relationships.go b/nex-protocols-go/friends/get_relationships.go new file mode 100644 index 0000000..56aff0d --- /dev/null +++ b/nex-protocols-go/friends/get_relationships.go @@ -0,0 +1,47 @@ +// Package protocol implements the Friends QRV protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetRelationships(packet nex.PacketInterface) { + if protocol.GetRelationships == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends::GetRelationships not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + resultRange := types.NewResultRange() + + err := resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRelationships(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetRelationships(nil, packet, callID, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/friends/protocol.go b/nex-protocols-go/friends/protocol.go new file mode 100644 index 0000000..b09f1e1 --- /dev/null +++ b/nex-protocols-go/friends/protocol.go @@ -0,0 +1,223 @@ +// Package protocol implements the Friends QRV protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the Friends protocol + ProtocolID = 0x14 + + // MethodAddFriend is the method ID for method AddFriend + MethodAddFriend = 0x1 + + // MethodAddFriendByName is the method ID for method AddFriendByName + MethodAddFriendByName = 0x2 + + // MethodAddFriendWithDetails is the method ID for method AddFriendWithDetails + MethodAddFriendWithDetails = 0x3 + + // MethodAddFriendByNameWithDetails is the method ID for method AddFriendByNameWithDetails + MethodAddFriendByNameWithDetails = 0x4 + + // MethodAcceptFriendship is the method ID for method AcceptFriendship + MethodAcceptFriendship = 0x5 + + // MethodDeclineFriendship is the method ID for method DeclineFriendship + MethodDeclineFriendship = 0x6 + + // MethodBlackList is the method ID for method BlackList + MethodBlackList = 0x7 + + // MethodBlackListByName is the method ID for method BlackListByName + MethodBlackListByName = 0x8 + + // MethodClearRelationship is the method ID for method ClearRelationship + MethodClearRelationship = 0x9 + + // MethodUpdateDetails is the method ID for method UpdateDetails + MethodUpdateDetails = 0xA + + // MethodGetList is the method ID for method GetList + MethodGetList = 0xB + + // MethodGetDetailedList is the method ID for method GetDetailedList + MethodGetDetailedList = 0xC + + // MethodGetRelationships is the method ID for method GetRelationships + MethodGetRelationships = 0xD +) + +// Protocol handles the Friends QRV protocol +type Protocol struct { + endpoint nex.EndpointInterface + AddFriend func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32, uiDetails *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error) + AddFriendByName func(err error, packet nex.PacketInterface, callID uint32, strPlayerName *types.String, uiDetails *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error) + AddFriendWithDetails func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32, uiDetails *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error) + AddFriendByNameWithDetails func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32, uiDetails *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error) // TODO - Is this the right signature? + AcceptFriendship func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + DeclineFriendship func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + BlackList func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32, uiDetails *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + BlackListByName func(err error, packet nex.PacketInterface, callID uint32, strPlayerName *types.String, uiDetails *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + ClearRelationship func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + UpdateDetails func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32, uiDetails *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetList func(err error, packet nex.PacketInterface, callID uint32, byRelationship *types.PrimitiveU8, bReversed *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + GetDetailedList func(err error, packet nex.PacketInterface, callID uint32, byRelationship *types.PrimitiveU8, bReversed *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + GetRelationships func(err error, packet nex.PacketInterface, callID uint32, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Friends protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerAddFriend(handler func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32, uiDetails *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerAddFriendByName(handler func(err error, packet nex.PacketInterface, callID uint32, strPlayerName *types.String, uiDetails *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerAddFriendWithDetails(handler func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32, uiDetails *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerAddFriendByNameWithDetails(handler func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32, uiDetails *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerAcceptFriendship(handler func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeclineFriendship(handler func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerBlackList(handler func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32, uiDetails *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerBlackListByName(handler func(err error, packet nex.PacketInterface, callID uint32, strPlayerName *types.String, uiDetails *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerClearRelationship(handler func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateDetails(handler func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32, uiDetails *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetList(handler func(err error, packet nex.PacketInterface, callID uint32, byRelationship *types.PrimitiveU8, bReversed *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetDetailedList(handler func(err error, packet nex.PacketInterface, callID uint32, byRelationship *types.PrimitiveU8, bReversed *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetRelationships(handler func(err error, packet nex.PacketInterface, callID uint32, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerAddFriend sets the handler for the AddFriend method +func (protocol *Protocol) SetHandlerAddFriend(handler func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32, uiDetails *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.AddFriend = handler +} + +// SetHandlerAddFriendByName sets the handler for the AddFriendByName method +func (protocol *Protocol) SetHandlerAddFriendByName(handler func(err error, packet nex.PacketInterface, callID uint32, strPlayerName *types.String, uiDetails *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.AddFriendByName = handler +} + +// SetHandlerAddFriendWithDetails sets the handler for the AddFriendWithDetails method +func (protocol *Protocol) SetHandlerAddFriendWithDetails(handler func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32, uiDetails *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.AddFriendWithDetails = handler +} + +// SetHandlerAddFriendByNameWithDetails sets the handler for the AddFriendByNameWithDetails method +func (protocol *Protocol) SetHandlerAddFriendByNameWithDetails(handler func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32, uiDetails *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.AddFriendByNameWithDetails = handler +} + +// SetHandlerAcceptFriendship sets the handler for the AcceptFriendship method +func (protocol *Protocol) SetHandlerAcceptFriendship(handler func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.AcceptFriendship = handler +} + +// SetHandlerDeclineFriendship sets the handler for the DeclineFriendship method +func (protocol *Protocol) SetHandlerDeclineFriendship(handler func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.DeclineFriendship = handler +} + +// SetHandlerBlackList sets the handler for the BlackList method +func (protocol *Protocol) SetHandlerBlackList(handler func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32, uiDetails *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.BlackList = handler +} + +// SetHandlerBlackListByName sets the handler for the BlackListByName method +func (protocol *Protocol) SetHandlerBlackListByName(handler func(err error, packet nex.PacketInterface, callID uint32, strPlayerName *types.String, uiDetails *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.BlackListByName = handler +} + +// SetHandlerClearRelationship sets the handler for the ClearRelationship method +func (protocol *Protocol) SetHandlerClearRelationship(handler func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.ClearRelationship = handler +} + +// SetHandlerUpdateDetails sets the handler for the UpdateDetails method +func (protocol *Protocol) SetHandlerUpdateDetails(handler func(err error, packet nex.PacketInterface, callID uint32, uiPlayer *types.PrimitiveU32, uiDetails *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateDetails = handler +} + +// SetHandlerGetList sets the handler for the GetList method +func (protocol *Protocol) SetHandlerGetList(handler func(err error, packet nex.PacketInterface, callID uint32, byRelationship *types.PrimitiveU8, bReversed *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.GetList = handler +} + +// SetHandlerGetDetailedList sets the handler for the GetDetailedList method +func (protocol *Protocol) SetHandlerGetDetailedList(handler func(err error, packet nex.PacketInterface, callID uint32, byRelationship *types.PrimitiveU8, bReversed *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.GetDetailedList = handler +} + +// SetHandlerGetRelationships sets the handler for the GetRelationships method +func (protocol *Protocol) SetHandlerGetRelationships(handler func(err error, packet nex.PacketInterface, callID uint32, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.GetRelationships = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodAddFriend: + protocol.handleAddFriend(packet) + case MethodAddFriendByName: + protocol.handleAddFriendByName(packet) + case MethodAddFriendWithDetails: + protocol.handleAddFriendWithDetails(packet) + case MethodAddFriendByNameWithDetails: + protocol.handleAddFriendByNameWithDetails(packet) + case MethodAcceptFriendship: + protocol.handleAcceptFriendship(packet) + case MethodDeclineFriendship: + protocol.handleDeclineFriendship(packet) + case MethodBlackList: + protocol.handleBlackList(packet) + case MethodBlackListByName: + protocol.handleBlackListByName(packet) + case MethodClearRelationship: + protocol.handleClearRelationship(packet) + case MethodUpdateDetails: + protocol.handleUpdateDetails(packet) + case MethodGetList: + protocol.handleGetList(packet) + case MethodGetDetailedList: + protocol.handleGetDetailedList(packet) + case MethodGetRelationships: + protocol.handleGetRelationships(packet) + default: + errMessage := fmt.Sprintf("Unsupported Friends method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Friends protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/friends/types/friend_data.go b/nex-protocols-go/friends/types/friend_data.go new file mode 100644 index 0000000..0b08ac8 --- /dev/null +++ b/nex-protocols-go/friends/types/friend_data.go @@ -0,0 +1,154 @@ +// Package types implements all the types used by the Friends protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// FriendData is a type within the Friends protocol +type FriendData struct { + types.Structure + PID *types.PID + StrName *types.String + ByRelationship *types.PrimitiveU8 + UIDetails *types.PrimitiveU32 + StrStatus *types.String +} + +// WriteTo writes the FriendData to the given writable +func (fd *FriendData) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + fd.PID.WriteTo(contentWritable) + fd.StrName.WriteTo(contentWritable) + fd.ByRelationship.WriteTo(contentWritable) + fd.UIDetails.WriteTo(contentWritable) + fd.StrStatus.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + fd.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the FriendData from the given readable +func (fd *FriendData) ExtractFrom(readable types.Readable) error { + var err error + + err = fd.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendData header. %s", err.Error()) + } + + err = fd.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendData.PID. %s", err.Error()) + } + + err = fd.StrName.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendData.StrName. %s", err.Error()) + } + + err = fd.ByRelationship.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendData.ByRelationship. %s", err.Error()) + } + + err = fd.UIDetails.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendData.UIDetails. %s", err.Error()) + } + + err = fd.StrStatus.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendData.StrStatus. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of FriendData +func (fd *FriendData) Copy() types.RVType { + copied := NewFriendData() + + copied.StructureVersion = fd.StructureVersion + copied.PID = fd.PID.Copy().(*types.PID) + copied.StrName = fd.StrName.Copy().(*types.String) + copied.ByRelationship = fd.ByRelationship.Copy().(*types.PrimitiveU8) + copied.UIDetails = fd.UIDetails.Copy().(*types.PrimitiveU32) + copied.StrStatus = fd.StrStatus.Copy().(*types.String) + + return copied +} + +// Equals checks if the given FriendData contains the same data as the current FriendData +func (fd *FriendData) Equals(o types.RVType) bool { + if _, ok := o.(*FriendData); !ok { + return false + } + + other := o.(*FriendData) + + if fd.StructureVersion != other.StructureVersion { + return false + } + + if !fd.PID.Equals(other.PID) { + return false + } + + if !fd.StrName.Equals(other.StrName) { + return false + } + + if !fd.ByRelationship.Equals(other.ByRelationship) { + return false + } + + if !fd.UIDetails.Equals(other.UIDetails) { + return false + } + + return fd.StrStatus.Equals(other.StrStatus) +} + +// String returns the string representation of the FriendData +func (fd *FriendData) String() string { + return fd.FormatToString(0) +} + +// FormatToString pretty-prints the FriendData using the provided indentation level +func (fd *FriendData) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("FriendData{\n") + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, fd.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sStrName: %s,\n", indentationValues, fd.StrName)) + b.WriteString(fmt.Sprintf("%sByRelationship: %s,\n", indentationValues, fd.ByRelationship)) + b.WriteString(fmt.Sprintf("%sUIDetails: %s,\n", indentationValues, fd.UIDetails)) + b.WriteString(fmt.Sprintf("%sStrStatus: %s,\n", indentationValues, fd.StrStatus)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewFriendData returns a new FriendData +func NewFriendData() *FriendData { + fd := &FriendData{ + PID: types.NewPID(0), + StrName: types.NewString(""), + ByRelationship: types.NewPrimitiveU8(0), + UIDetails: types.NewPrimitiveU32(0), + StrStatus: types.NewString(""), + } + + return fd +} diff --git a/nex-protocols-go/friends/types/relationship_data.go b/nex-protocols-go/friends/types/relationship_data.go new file mode 100644 index 0000000..2a30d49 --- /dev/null +++ b/nex-protocols-go/friends/types/relationship_data.go @@ -0,0 +1,154 @@ +// Package types implements all the types used by the Friends protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// RelationshipData is a type within the Friends protocol +type RelationshipData struct { + types.Structure + PID *types.PrimitiveU32 + StrName *types.String + ByRelationship *types.PrimitiveU8 + UIDetails *types.PrimitiveU32 + ByStatus *types.PrimitiveU8 +} + +// WriteTo writes the RelationshipData to the given writable +func (rd *RelationshipData) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + rd.PID.WriteTo(contentWritable) + rd.StrName.WriteTo(contentWritable) + rd.ByRelationship.WriteTo(contentWritable) + rd.UIDetails.WriteTo(contentWritable) + rd.ByStatus.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + rd.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the RelationshipData from the given readable +func (rd *RelationshipData) ExtractFrom(readable types.Readable) error { + var err error + + err = rd.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RelationshipData header. %s", err.Error()) + } + + err = rd.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RelationshipData.PID. %s", err.Error()) + } + + err = rd.StrName.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RelationshipData.StrName. %s", err.Error()) + } + + err = rd.ByRelationship.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RelationshipData.ByRelationship. %s", err.Error()) + } + + err = rd.UIDetails.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RelationshipData.UIDetails. %s", err.Error()) + } + + err = rd.ByStatus.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RelationshipData.ByStatus. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of RelationshipData +func (rd *RelationshipData) Copy() types.RVType { + copied := NewRelationshipData() + + copied.StructureVersion = rd.StructureVersion + copied.PID = rd.PID.Copy().(*types.PrimitiveU32) + copied.StrName = rd.StrName.Copy().(*types.String) + copied.ByRelationship = rd.ByRelationship.Copy().(*types.PrimitiveU8) + copied.UIDetails = rd.UIDetails.Copy().(*types.PrimitiveU32) + copied.ByStatus = rd.ByStatus.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given RelationshipData contains the same data as the current RelationshipData +func (rd *RelationshipData) Equals(o types.RVType) bool { + if _, ok := o.(*RelationshipData); !ok { + return false + } + + other := o.(*RelationshipData) + + if rd.StructureVersion != other.StructureVersion { + return false + } + + if !rd.PID.Equals(other.PID) { + return false + } + + if !rd.StrName.Equals(other.StrName) { + return false + } + + if !rd.ByRelationship.Equals(other.ByRelationship) { + return false + } + + if !rd.UIDetails.Equals(other.UIDetails) { + return false + } + + return rd.ByStatus.Equals(other.ByStatus) +} + +// String returns the string representation of the RelationshipData +func (rd *RelationshipData) String() string { + return rd.FormatToString(0) +} + +// FormatToString pretty-prints the RelationshipData using the provided indentation level +func (rd *RelationshipData) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("RelationshipData{\n") + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, rd.PID)) + b.WriteString(fmt.Sprintf("%sStrName: %s,\n", indentationValues, rd.StrName)) + b.WriteString(fmt.Sprintf("%sByRelationship: %s,\n", indentationValues, rd.ByRelationship)) + b.WriteString(fmt.Sprintf("%sUIDetails: %s,\n", indentationValues, rd.UIDetails)) + b.WriteString(fmt.Sprintf("%sByStatus: %s,\n", indentationValues, rd.ByStatus)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRelationshipData returns a new RelationshipData +func NewRelationshipData() *RelationshipData { + rd := &RelationshipData{ + PID: types.NewPrimitiveU32(0), + StrName: types.NewString(""), + ByRelationship: types.NewPrimitiveU8(0), + UIDetails: types.NewPrimitiveU32(0), + ByStatus: types.NewPrimitiveU8(0), + } + + return rd +} diff --git a/nex-protocols-go/friends/update_details.go b/nex-protocols-go/friends/update_details.go new file mode 100644 index 0000000..06657a0 --- /dev/null +++ b/nex-protocols-go/friends/update_details.go @@ -0,0 +1,60 @@ +// Package protocol implements the Friends QRV protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateDetails(packet nex.PacketInterface) { + if protocol.UpdateDetails == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Friends::UpdateDetails not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiPlayer := types.NewPrimitiveU32(0) + uiDetails := types.NewPrimitiveU32(0) + + var err error + + err = uiPlayer.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateDetails(fmt.Errorf("Failed to read uiPlayer from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uiDetails.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateDetails(fmt.Errorf("Failed to read uiDetails from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateDetails(nil, packet, callID, uiPlayer, uiDetails) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/globals/logger.go b/nex-protocols-go/globals/logger.go new file mode 100644 index 0000000..55c7783 --- /dev/null +++ b/nex-protocols-go/globals/logger.go @@ -0,0 +1,7 @@ +// Package globals implements variables and functions used by all protocol packages +package globals + +import "github.com/PretendoNetwork/plogger-go" + +// Logger is an instance of the Plogger logger +var Logger = plogger.NewLogger() diff --git a/nex-protocols-go/globals/respond.go b/nex-protocols-go/globals/respond.go new file mode 100644 index 0000000..59ec608 --- /dev/null +++ b/nex-protocols-go/globals/respond.go @@ -0,0 +1,50 @@ +// Package globals implements variables and functions used by all protocol packages +package globals + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/constants" +) + +// Respond sends the client a given RMC message +func Respond(packet nex.PacketInterface, message *nex.RMCMessage) { + sender := packet.Sender() + + var responsePacket nex.PacketInterface + + switch packet := packet.(type) { + case nex.PRUDPPacketInterface: + var prudpPacket nex.PRUDPPacketInterface + + endpoint := sender.(*nex.PRUDPConnection).Endpoint() + server := endpoint.(*nex.PRUDPEndPoint).Server + if packet.Version() == 1 { + prudpPacket, _ = nex.NewPRUDPPacketV1(server, sender.(*nex.PRUDPConnection), nil) + } else { + prudpPacket, _ = nex.NewPRUDPPacketV0(server, sender.(*nex.PRUDPConnection), nil) + } + + prudpPacket.SetType(constants.DataPacket) + + if packet.HasFlag(constants.PacketFlagReliable) { + prudpPacket.AddFlag(constants.PacketFlagReliable) + } + + prudpPacket.AddFlag(constants.PacketFlagNeedsAck) + prudpPacket.SetSourceVirtualPortStreamType(packet.DestinationVirtualPortStreamType()) + prudpPacket.SetSourceVirtualPortStreamID(packet.DestinationVirtualPortStreamID()) + prudpPacket.SetDestinationVirtualPortStreamType(packet.SourceVirtualPortStreamType()) + prudpPacket.SetDestinationVirtualPortStreamID(packet.SourceVirtualPortStreamID()) + prudpPacket.SetSubstreamID(packet.SubstreamID()) + + responsePacket = prudpPacket + responsePacket.SetPayload(message.Bytes()) + case *nex.HPPPacket: + // * We reuse the same packet from input and replace + // * the RMC message so that it can be delivered back + responsePacket = packet + responsePacket.SetRMCMessage(message) + } + + sender.Endpoint().Send(responsePacket) +} diff --git a/nex-protocols-go/globals/respond_error.go b/nex-protocols-go/globals/respond_error.go new file mode 100644 index 0000000..5b053d5 --- /dev/null +++ b/nex-protocols-go/globals/respond_error.go @@ -0,0 +1,66 @@ +// Package globals implements variables and functions used by all protocol packages +package globals + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/constants" +) + +// RespondError sends the client a given error code +func RespondError(packet nex.PacketInterface, protocolID uint16, err error) { + sender := packet.Sender() + request := packet.RMCMessage() + errorCode := nex.ResultCodes.Core.Unknown + + if err, ok := err.(*nex.Error); ok { + errorCode = err.ResultCode + err.Packet = packet + + packet.Sender().Endpoint().EmitError(err) + } + + rmcResponse := nex.NewRMCError(sender.Endpoint(), errorCode) + rmcResponse.ProtocolID = request.ProtocolID + rmcResponse.CallID = request.CallID + + var responsePacket nex.PacketInterface + + switch packet := packet.(type) { + case nex.PRUDPPacketInterface: + rmcResponseBytes := rmcResponse.Bytes() + + // * Go won't type assert responsePacket in the version check below, + // * so to avoid a bunch of assertions just create a temp variable + var prudpPacket nex.PRUDPPacketInterface + + endpoint := sender.(*nex.PRUDPConnection).Endpoint() + server := endpoint.(*nex.PRUDPEndPoint).Server + if packet.Version() == 1 { + prudpPacket, _ = nex.NewPRUDPPacketV1(server, sender.(*nex.PRUDPConnection), nil) + } else { + prudpPacket, _ = nex.NewPRUDPPacketV0(server, sender.(*nex.PRUDPConnection), nil) + } + + prudpPacket.SetType(constants.DataPacket) + + if packet.HasFlag(constants.PacketFlagReliable) { + prudpPacket.AddFlag(constants.PacketFlagReliable) + } + + prudpPacket.AddFlag(constants.PacketFlagNeedsAck) + prudpPacket.SetSourceVirtualPortStreamType(packet.DestinationVirtualPortStreamType()) + prudpPacket.SetSourceVirtualPortStreamID(packet.DestinationVirtualPortStreamID()) + prudpPacket.SetDestinationVirtualPortStreamType(packet.SourceVirtualPortStreamType()) + prudpPacket.SetDestinationVirtualPortStreamID(packet.SourceVirtualPortStreamID()) + + responsePacket = prudpPacket + responsePacket.SetPayload(rmcResponseBytes) + case *nex.HPPPacket: + // * We reuse the same packet from input and replace + // * the RMC message so that it can be delivered back + responsePacket = packet + responsePacket.SetRMCMessage(rmcResponse) + } + + sender.Endpoint().Send(responsePacket) +} diff --git a/nex-protocols-go/go.mod b/nex-protocols-go/go.mod new file mode 100644 index 0000000..0ed6c88 --- /dev/null +++ b/nex-protocols-go/go.mod @@ -0,0 +1,27 @@ +module github.com/PretendoNetwork/nex-protocols-go/v2 + +go 1.21 + +require ( + github.com/PretendoNetwork/nex-go/v2 v2.0.1 + github.com/PretendoNetwork/plogger-go v1.0.4 +) + +require ( + github.com/dolthub/maphash v0.1.0 // indirect + github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e // indirect +) + +require ( + github.com/fatih/color v1.15.0 // indirect + github.com/jwalton/go-supportscolor v1.2.0 // indirect + github.com/klauspost/compress v1.17.5 // indirect + github.com/lxzan/gws v1.8.0 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + github.com/superwhiskers/crunch/v3 v3.5.7 // indirect + golang.org/x/exp v0.0.0-20230905200255-921286631fa9 + golang.org/x/mod v0.12.0 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/term v0.15.0 // indirect +) diff --git a/nex-protocols-go/go.sum b/nex-protocols-go/go.sum new file mode 100644 index 0000000..05b8374 --- /dev/null +++ b/nex-protocols-go/go.sum @@ -0,0 +1,46 @@ +github.com/PretendoNetwork/nex-go/v2 v2.0.1 h1:7UEwulBtWD+HIbwB0uaRjBK1EXFLfSnv0t5+WyQYV0s= +github.com/PretendoNetwork/nex-go/v2 v2.0.1/go.mod h1:EZNyRVr0WpPLHZQqZZvarQ8/tXsEyVqLr6zy/hKCAV4= +github.com/PretendoNetwork/plogger-go v1.0.4 h1:PF7xHw9eDRHH+RsAP9tmAE7fG0N0p6H4iPwHKnsoXwc= +github.com/PretendoNetwork/plogger-go v1.0.4/go.mod h1:7kD6M4vPq1JL4LTuPg6kuB1OvUBOwQOtAvTaUwMbwvU= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dolthub/maphash v0.1.0 h1:bsQ7JsF4FkkWyrP3oCnFJgrCUAFbFf3kOl4L/QxPDyQ= +github.com/dolthub/maphash v0.1.0/go.mod h1:gkg4Ch4CdCDu5h6PMriVLawB7koZ+5ijb9puGMV50a4= +github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= +github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/jwalton/go-supportscolor v1.2.0 h1:g6Ha4u7Vm3LIsQ5wmeBpS4gazu0UP1DRDE8y6bre4H8= +github.com/jwalton/go-supportscolor v1.2.0/go.mod h1:hFVUAZV2cWg+WFFC4v8pT2X/S2qUUBYMioBD9AINXGs= +github.com/klauspost/compress v1.17.5 h1:d4vBd+7CHydUqpFBgUEKkSdtSugf9YFmSkvUYPquI5E= +github.com/klauspost/compress v1.17.5/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= +github.com/lxzan/gws v1.8.0 h1:SqRuU6PUez/BA6CHB9BufV6n+gCnRtWHUntjLcaHA44= +github.com/lxzan/gws v1.8.0/go.mod h1:FcGeRMB7HwGuTvMLR24ku0Zx0p6RXqeKASeMc4VYgi4= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e h1:dCWirM5F3wMY+cmRda/B1BiPsFtmzXqV9b0hLWtVBMs= +github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e/go.mod h1:9leZcVcItj6m9/CfHY5Em/iBrCz7js8LcRQGTKEEv2M= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/superwhiskers/crunch/v3 v3.5.7 h1:N9RLxaR65C36i26BUIpzPXGy2f6pQ7wisu2bawbKNqg= +github.com/superwhiskers/crunch/v3 v3.5.7/go.mod h1:4ub2EKgF1MAhTjoOCTU4b9uLMsAweHEa89aRrfAypXA= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= +golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/nex-protocols-go/health/fix_sanity_errors.go b/nex-protocols-go/health/fix_sanity_errors.go new file mode 100644 index 0000000..6a39393 --- /dev/null +++ b/nex-protocols-go/health/fix_sanity_errors.go @@ -0,0 +1,29 @@ +// Package protocol implements the Health protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFixSanityErrors(packet nex.PacketInterface) { + if protocol.FixSanityErrors == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Health::FixSanityErrors not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.FixSanityErrors(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/health/ping_daemon.go b/nex-protocols-go/health/ping_daemon.go new file mode 100644 index 0000000..81b0f06 --- /dev/null +++ b/nex-protocols-go/health/ping_daemon.go @@ -0,0 +1,29 @@ +// Package protocol implements the Health protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePingDaemon(packet nex.PacketInterface) { + if protocol.PingDaemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Health::PingDaemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.PingDaemon(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/health/ping_database.go b/nex-protocols-go/health/ping_database.go new file mode 100644 index 0000000..1532641 --- /dev/null +++ b/nex-protocols-go/health/ping_database.go @@ -0,0 +1,29 @@ +// Package protocol implements the Health protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePingDatabase(packet nex.PacketInterface) { + if protocol.PingDatabase == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Health::PingDatabase not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.PingDatabase(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/health/protocol.go b/nex-protocols-go/health/protocol.go new file mode 100644 index 0000000..7715393 --- /dev/null +++ b/nex-protocols-go/health/protocol.go @@ -0,0 +1,114 @@ +// Package protocol implements the Health protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the Health protocol + ProtocolID = 0x12 + + // MethodPingDaemon is the method ID for the method PingDaemon + MethodPingDaemon = 0x1 + + // MethodPingDatabase is the method ID for the method PingDatabase + MethodPingDatabase = 0x2 + + // MethodRunSanityCheck is the method ID for the method RunSanityCheck + MethodRunSanityCheck = 0x3 + + // MethodFixSanityErrors is the method ID for the method FixSanityErrors + MethodFixSanityErrors = 0x4 +) + +// Protocol handles the Health protocol +type Protocol struct { + endpoint nex.EndpointInterface + PingDaemon func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + PingDatabase func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + RunSanityCheck func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + FixSanityErrors func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Health protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerPingDaemon(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerPingDatabase(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerRunSanityCheck(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerFixSanityErrors(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerPingDaemon sets the handler for the PingDaemon method +func (protocol *Protocol) SetHandlerPingDaemon(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.PingDaemon = handler +} + +// SetHandlerPingDatabase sets the handler for the PingDatabase method +func (protocol *Protocol) SetHandlerPingDatabase(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.PingDatabase = handler +} + +// SetHandlerRunSanityCheck sets the handler for the RunSanityCheck method +func (protocol *Protocol) SetHandlerRunSanityCheck(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.RunSanityCheck = handler +} + +// SetHandlerFixSanityErrors sets the handler for the FixSanityErrors method +func (protocol *Protocol) SetHandlerFixSanityErrors(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.FixSanityErrors = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodPingDaemon: + protocol.handlePingDaemon(packet) + case MethodPingDatabase: + protocol.handlePingDatabase(packet) + case MethodRunSanityCheck: + protocol.handleRunSanityCheck(packet) + case MethodFixSanityErrors: + protocol.handleFixSanityErrors(packet) + default: + errMessage := fmt.Sprintf("Unsupported Health method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Health protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/health/run_sanity_check.go b/nex-protocols-go/health/run_sanity_check.go new file mode 100644 index 0000000..688351b --- /dev/null +++ b/nex-protocols-go/health/run_sanity_check.go @@ -0,0 +1,29 @@ +// Package protocol implements the Health protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRunSanityCheck(packet nex.PacketInterface) { + if protocol.RunSanityCheck == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Health::RunSanityCheck not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.RunSanityCheck(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/init.go b/nex-protocols-go/init.go new file mode 100644 index 0000000..20077f2 --- /dev/null +++ b/nex-protocols-go/init.go @@ -0,0 +1,23 @@ +// Package nexproto provides all the main NEX protocols. +// +// Each folder contains a different package for that specific protocol, +// with all their types and methods needed to parse and build packets with RMC payloads +package nexproto + +import ( + "github.com/PretendoNetwork/nex-go/v2/types" + account_management_types "github.com/PretendoNetwork/nex-protocols-go/v2/account-management/types" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" + ticket_granting_types "github.com/PretendoNetwork/nex-protocols-go/v2/ticket-granting/types" + messaging_types "github.com/PretendoNetwork/nex-protocols-go/v2/messaging/types" +) + +func init() { + types.RegisterDataHolderType("NintendoCreateAccountData", account_management_types.NewNintendoCreateAccountData()) + types.RegisterDataHolderType("AccountExtraInfo", account_management_types.NewAccountExtraInfo()) + types.RegisterDataHolderType("NintendoLoginData", ticket_granting_types.NewNintendoLoginData()) + types.RegisterDataHolderType("AuthenticationInfo", ticket_granting_types.NewAuthenticationInfo()) + types.RegisterDataHolderType("Gathering", match_making_types.NewGathering()) + types.RegisterDataHolderType("MatchmakeSession", match_making_types.NewMatchmakeSession()) + types.RegisterDataHolderType("TextMessage", messaging_types.NewTextMessage()) +} diff --git a/nex-protocols-go/match-making-ext/delete_from_deletions.go b/nex-protocols-go/match-making-ext/delete_from_deletions.go new file mode 100644 index 0000000..765d20a --- /dev/null +++ b/nex-protocols-go/match-making-ext/delete_from_deletions.go @@ -0,0 +1,61 @@ +// Package protocol implements the Match Making Ext protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteFromDeletions(packet nex.PacketInterface) { + if protocol.DeleteFromDeletions == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMakingExt::DeleteFromDeletions not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lstDeletions := types.NewList[*types.PrimitiveU32]() + lstDeletions.Type = types.NewPrimitiveU32(0) + pid := types.NewPID(0) + + var err error + + err = lstDeletions.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteFromDeletions(fmt.Errorf("Failed to read lstDeletions from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = pid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteFromDeletions(fmt.Errorf("Failed to read pid from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteFromDeletions(nil, packet, callID, lstDeletions, pid) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making-ext/end_participation.go b/nex-protocols-go/match-making-ext/end_participation.go new file mode 100644 index 0000000..3d05236 --- /dev/null +++ b/nex-protocols-go/match-making-ext/end_participation.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making Ext protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleEndParticipation(packet nex.PacketInterface) { + if protocol.EndParticipation == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMakingExt::EndParticipation not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + strMessage := types.NewString("") + + var err error + + err = idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.EndParticipation(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.EndParticipation(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.EndParticipation(nil, packet, callID, idGathering, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making-ext/get_detailed_participants.go b/nex-protocols-go/match-making-ext/get_detailed_participants.go new file mode 100644 index 0000000..50bc9ac --- /dev/null +++ b/nex-protocols-go/match-making-ext/get_detailed_participants.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making Ext protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetDetailedParticipants(packet nex.PacketInterface) { + if protocol.GetDetailedParticipants == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMakingExt::GetDetailedParticipants not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + bOnlyActive := types.NewPrimitiveBool(false) + + var err error + + err = idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetDetailedParticipants(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = bOnlyActive.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetDetailedParticipants(fmt.Errorf("Failed to read bOnlyActive from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetDetailedParticipants(nil, packet, callID, idGathering, bOnlyActive) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making-ext/get_gathering_relations.go b/nex-protocols-go/match-making-ext/get_gathering_relations.go new file mode 100644 index 0000000..4a5f6e1 --- /dev/null +++ b/nex-protocols-go/match-making-ext/get_gathering_relations.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making Ext protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetGatheringRelations(packet nex.PacketInterface) { + if protocol.GetGatheringRelations == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMakingExt::GetGatheringRelations not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + id := types.NewPrimitiveU32(0) + descr := types.NewString("") + + var err error + + err = id.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetGatheringRelations(fmt.Errorf("Failed to read id from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = descr.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetGatheringRelations(fmt.Errorf("Failed to read descr from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetGatheringRelations(nil, packet, callID, id, descr) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making-ext/get_participants.go b/nex-protocols-go/match-making-ext/get_participants.go new file mode 100644 index 0000000..222d938 --- /dev/null +++ b/nex-protocols-go/match-making-ext/get_participants.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making Ext protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetParticipants(packet nex.PacketInterface) { + if protocol.GetParticipants == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMakingExt::GetParticipants not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + bOnlyActive := types.NewPrimitiveBool(false) + + var err error + + err = idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetParticipants(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = bOnlyActive.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetParticipants(fmt.Errorf("Failed to read bOnlyActive from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetParticipants(nil, packet, callID, idGathering, bOnlyActive) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making-ext/get_participants_urls.go b/nex-protocols-go/match-making-ext/get_participants_urls.go new file mode 100644 index 0000000..dee1b52 --- /dev/null +++ b/nex-protocols-go/match-making-ext/get_participants_urls.go @@ -0,0 +1,48 @@ +// Package protocol implements the Match Making Ext protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetParticipantsURLs(packet nex.PacketInterface) { + if protocol.GetParticipantsURLs == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMakingExt::GetParticipantsURLs not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lstGatherings := types.NewList[*types.PrimitiveU32]() + lstGatherings.Type = types.NewPrimitiveU32(0) + + err := lstGatherings.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetParticipantsURLs(fmt.Errorf("Failed to read lstGatherings from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetParticipantsURLs(nil, packet, callID, lstGatherings) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making-ext/protocol.go b/nex-protocols-go/match-making-ext/protocol.go new file mode 100644 index 0000000..5686731 --- /dev/null +++ b/nex-protocols-go/match-making-ext/protocol.go @@ -0,0 +1,139 @@ +// Package protocol implements the Match Making Ext protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the MatchMakingExt protocol + ProtocolID = 0x32 + + // MethodEndParticipation is the method ID for the method EndParticipation + MethodEndParticipation = 0x1 + + // MethodGetParticipants is the method ID for the method GetParticipants + MethodGetParticipants = 0x2 + + // MethodGetDetailedParticipants is the method ID for the method GetDetailedParticipants + MethodGetDetailedParticipants = 0x3 + + // MethodGetParticipantsURLs is the method ID for the method GetParticipantsURLs + MethodGetParticipantsURLs = 0x4 + + // MethodGetGatheringRelations is the method ID for the method GetGatheringRelations + MethodGetGatheringRelations = 0x5 + + // MethodDeleteFromDeletions is the method ID for the method DeleteFromDeletions + MethodDeleteFromDeletions = 0x6 +) + +// Protocol handles the MatchMakingExt protocol +type Protocol struct { + endpoint nex.EndpointInterface + EndParticipation func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error) + GetParticipants func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, bOnlyActive *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + GetDetailedParticipants func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, bOnlyActive *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + GetParticipantsURLs func(err error, packet nex.PacketInterface, callID uint32, lstGatherings *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error) + GetGatheringRelations func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU32, descr *types.String) (*nex.RMCMessage, *nex.Error) + DeleteFromDeletions func(err error, packet nex.PacketInterface, callID uint32, lstDeletions *types.List[*types.PrimitiveU32], pid *types.PID) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Match Making Ext protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerEndParticipation(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetParticipants(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, bOnlyActive *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetDetailedParticipants(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, bOnlyActive *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetParticipantsURLs(handler func(err error, packet nex.PacketInterface, callID uint32, lstGatherings *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetGatheringRelations(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU32, descr *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeleteFromDeletions(handler func(err error, packet nex.PacketInterface, callID uint32, lstDeletions *types.List[*types.PrimitiveU32], pid *types.PID) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerEndParticipation sets the handler for the EndParticipation method +func (protocol *Protocol) SetHandlerEndParticipation(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.EndParticipation = handler +} + +// SetHandlerGetParticipants sets the handler for the GetParticipants method +func (protocol *Protocol) SetHandlerGetParticipants(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, bOnlyActive *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.GetParticipants = handler +} + +// SetHandlerGetDetailedParticipants sets the handler for the GetDetailedParticipants method +func (protocol *Protocol) SetHandlerGetDetailedParticipants(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, bOnlyActive *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.GetDetailedParticipants = handler +} + +// SetHandlerGetParticipantsURLs sets the handler for the GetParticipantsURLs method +func (protocol *Protocol) SetHandlerGetParticipantsURLs(handler func(err error, packet nex.PacketInterface, callID uint32, lstGatherings *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetParticipantsURLs = handler +} + +// SetHandlerGetGatheringRelations sets the handler for the GetGatheringRelations method +func (protocol *Protocol) SetHandlerGetGatheringRelations(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU32, descr *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.GetGatheringRelations = handler +} + +// SetHandlerDeleteFromDeletions sets the handler for the DeleteFromDeletions method +func (protocol *Protocol) SetHandlerDeleteFromDeletions(handler func(err error, packet nex.PacketInterface, callID uint32, lstDeletions *types.List[*types.PrimitiveU32], pid *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.DeleteFromDeletions = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodEndParticipation: + protocol.handleEndParticipation(packet) + case MethodGetParticipants: + protocol.handleGetParticipants(packet) + case MethodGetDetailedParticipants: + protocol.handleGetDetailedParticipants(packet) + case MethodGetParticipantsURLs: + protocol.handleGetParticipantsURLs(packet) + case MethodGetGatheringRelations: + protocol.handleGetGatheringRelations(packet) + case MethodDeleteFromDeletions: + protocol.handleDeleteFromDeletions(packet) + default: + errMessage := fmt.Sprintf("Unsupported MatchMakingExt method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Match Making Ext protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/match-making/accept_invitation.go b/nex-protocols-go/match-making/accept_invitation.go new file mode 100644 index 0000000..428b160 --- /dev/null +++ b/nex-protocols-go/match-making/accept_invitation.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAcceptInvitation(packet nex.PacketInterface) { + if protocol.AcceptInvitation == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::AcceptInvitation not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + strMessage := types.NewString("") + + var err error + + err = idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AcceptInvitation(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AcceptInvitation(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AcceptInvitation(nil, packet, callID, idGathering, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/add_participants.go b/nex-protocols-go/match-making/add_participants.go new file mode 100644 index 0000000..e54524a --- /dev/null +++ b/nex-protocols-go/match-making/add_participants.go @@ -0,0 +1,72 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAddParticipants(packet nex.PacketInterface) { + if protocol.AddParticipants == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::AddParticipants not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + lstPrincipals := types.NewList[*types.PID]() + lstPrincipals.Type = types.NewPID(0) + strMessage := types.NewString("") + + var err error + + err = idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddParticipants(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = lstPrincipals.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddParticipants(fmt.Errorf("Failed to read lstPrincipals from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddParticipants(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AddParticipants(nil, packet, callID, idGathering, lstPrincipals, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/cancel_invitation.go b/nex-protocols-go/match-making/cancel_invitation.go new file mode 100644 index 0000000..c4cf4da --- /dev/null +++ b/nex-protocols-go/match-making/cancel_invitation.go @@ -0,0 +1,72 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCancelInvitation(packet nex.PacketInterface) { + if protocol.CancelInvitation == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::CancelInvitation not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + lstPrincipals := types.NewList[*types.PID]() + lstPrincipals.Type = types.NewPID(0) + strMessage := types.NewString("") + + var err error + + err = idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CancelInvitation(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = lstPrincipals.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CancelInvitation(fmt.Errorf("Failed to read lstPrincipals from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CancelInvitation(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CancelInvitation(nil, packet, callID, idGathering, lstPrincipals, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/cancel_participation.go b/nex-protocols-go/match-making/cancel_participation.go new file mode 100644 index 0000000..8c6bdf4 --- /dev/null +++ b/nex-protocols-go/match-making/cancel_participation.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCancelParticipation(packet nex.PacketInterface) { + if protocol.CancelParticipation == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::CancelParticipation not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + strMessage := types.NewString("") + + var err error + + err = idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CancelParticipation(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CancelParticipation(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CancelParticipation(nil, packet, callID, idGathering, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/decline_invitation.go b/nex-protocols-go/match-making/decline_invitation.go new file mode 100644 index 0000000..3746e51 --- /dev/null +++ b/nex-protocols-go/match-making/decline_invitation.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeclineInvitation(packet nex.PacketInterface) { + if protocol.DeclineInvitation == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::DeclineInvitation not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + strMessage := types.NewString("") + + var err error + + err = idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeclineInvitation(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeclineInvitation(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeclineInvitation(nil, packet, callID, idGathering, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/delete_from_deletions.go b/nex-protocols-go/match-making/delete_from_deletions.go new file mode 100644 index 0000000..3114cd7 --- /dev/null +++ b/nex-protocols-go/match-making/delete_from_deletions.go @@ -0,0 +1,48 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteFromDeletions(packet nex.PacketInterface) { + if protocol.DeleteFromDeletions == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::DeleteFromDeletions not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lstDeletions := types.NewList[*types.PrimitiveU32]() + lstDeletions.Type = types.NewPrimitiveU32(0) + + err := lstDeletions.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteFromDeletions(fmt.Errorf("Failed to read lstDeletions from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteFromDeletions(nil, packet, callID, lstDeletions) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/delete_gathering.go b/nex-protocols-go/match-making/delete_gathering.go new file mode 100644 index 0000000..ccf6758 --- /dev/null +++ b/nex-protocols-go/match-making/delete_gathering.go @@ -0,0 +1,47 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteGathering(packet nex.PacketInterface) { + if protocol.DeleteGathering == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::DeleteGathering not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + + err := idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteGathering(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteGathering(nil, packet, callID, idGathering) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/find_by_description.go b/nex-protocols-go/match-making/find_by_description.go new file mode 100644 index 0000000..237ebe1 --- /dev/null +++ b/nex-protocols-go/match-making/find_by_description.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindByDescription(packet nex.PacketInterface) { + if protocol.FindByDescription == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::FindByDescription not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strDescription := types.NewString("") + resultRange := types.NewResultRange() + + var err error + + err = strDescription.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByDescription(fmt.Errorf("Failed to read strDescription from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByDescription(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindByDescription(nil, packet, callID, strDescription, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/find_by_description_like.go b/nex-protocols-go/match-making/find_by_description_like.go new file mode 100644 index 0000000..9c40487 --- /dev/null +++ b/nex-protocols-go/match-making/find_by_description_like.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindByDescriptionLike(packet nex.PacketInterface) { + if protocol.FindByDescriptionLike == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::FindByDescriptionLike not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strDescriptionLike := types.NewString("") + resultRange := types.NewResultRange() + + var err error + + err = strDescriptionLike.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByDescriptionLike(fmt.Errorf("Failed to read strDescriptionLike from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByDescriptionLike(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindByDescriptionLike(nil, packet, callID, strDescriptionLike, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/find_by_description_regex.go b/nex-protocols-go/match-making/find_by_description_regex.go new file mode 100644 index 0000000..98c6c70 --- /dev/null +++ b/nex-protocols-go/match-making/find_by_description_regex.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindByDescriptionRegex(packet nex.PacketInterface) { + if protocol.FindByDescriptionRegex == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::FindByDescriptionRegex not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strDescriptionRegex := types.NewString("") + resultRange := types.NewResultRange() + + var err error + + err = strDescriptionRegex.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByDescriptionRegex(fmt.Errorf("Failed to read strDescriptionRegex from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByDescriptionRegex(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindByDescriptionRegex(nil, packet, callID, strDescriptionRegex, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/find_by_id.go b/nex-protocols-go/match-making/find_by_id.go new file mode 100644 index 0000000..ab2f63a --- /dev/null +++ b/nex-protocols-go/match-making/find_by_id.go @@ -0,0 +1,48 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindByID(packet nex.PacketInterface) { + if protocol.FindByID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::FindByID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lstID := types.NewList[*types.PrimitiveU32]() + lstID.Type = types.NewPrimitiveU32(0) + + err := lstID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByID(fmt.Errorf("Failed to read lstID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindByID(nil, packet, callID, lstID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/find_by_owner.go b/nex-protocols-go/match-making/find_by_owner.go new file mode 100644 index 0000000..f7c7740 --- /dev/null +++ b/nex-protocols-go/match-making/find_by_owner.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindByOwner(packet nex.PacketInterface) { + if protocol.FindByOwner == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::FindByOwner not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + id := types.NewPID(0) + resultRange := types.NewResultRange() + + var err error + + err = id.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByOwner(fmt.Errorf("Failed to read id from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByOwner(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindByOwner(nil, packet, callID, id, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/find_by_participants.go b/nex-protocols-go/match-making/find_by_participants.go new file mode 100644 index 0000000..9532031 --- /dev/null +++ b/nex-protocols-go/match-making/find_by_participants.go @@ -0,0 +1,48 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindByParticipants(packet nex.PacketInterface) { + if protocol.FindByParticipants == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::FindByParticipants not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pid := types.NewList[*types.PID]() + pid.Type = types.NewPID(0) + + err := pid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByParticipants(fmt.Errorf("Failed to read pid from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindByParticipants(nil, packet, callID, pid) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/find_by_single_id.go b/nex-protocols-go/match-making/find_by_single_id.go new file mode 100644 index 0000000..899734d --- /dev/null +++ b/nex-protocols-go/match-making/find_by_single_id.go @@ -0,0 +1,47 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindBySingleID(packet nex.PacketInterface) { + if protocol.FindBySingleID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::FindBySingleID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + id := types.NewPrimitiveU32(0) + + err := id.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindBySingleID(fmt.Errorf("Failed to read id from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindBySingleID(nil, packet, callID, id) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/find_by_sql_query.go b/nex-protocols-go/match-making/find_by_sql_query.go new file mode 100644 index 0000000..b832d18 --- /dev/null +++ b/nex-protocols-go/match-making/find_by_sql_query.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindBySQLQuery(packet nex.PacketInterface) { + if protocol.FindBySQLQuery == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::FindBySQLQuery not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strQuery := types.NewString("") + resultRange := types.NewResultRange() + + var err error + + err = strQuery.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindBySQLQuery(fmt.Errorf("Failed to read strQuery from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindBySQLQuery(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindBySQLQuery(nil, packet, callID, strQuery, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/find_by_type.go b/nex-protocols-go/match-making/find_by_type.go new file mode 100644 index 0000000..873e061 --- /dev/null +++ b/nex-protocols-go/match-making/find_by_type.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindByType(packet nex.PacketInterface) { + if protocol.FindByType == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::FindByType not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strType := types.NewString("") + resultRange := types.NewResultRange() + + var err error + + err = strType.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByType(fmt.Errorf("Failed to read strType from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByType(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindByType(nil, packet, callID, strType, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/find_invitations.go b/nex-protocols-go/match-making/find_invitations.go new file mode 100644 index 0000000..45fba30 --- /dev/null +++ b/nex-protocols-go/match-making/find_invitations.go @@ -0,0 +1,47 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindInvitations(packet nex.PacketInterface) { + if protocol.FindInvitations == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::FindInvitations not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + resultRange := types.NewResultRange() + + err := resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindInvitations(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindInvitations(nil, packet, callID, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/gathering_flags.go b/nex-protocols-go/match-making/gathering_flags.go new file mode 100644 index 0000000..e6b944f --- /dev/null +++ b/nex-protocols-go/match-making/gathering_flags.go @@ -0,0 +1,15 @@ +// Package protocol implements the Match Making protocol +package protocol + +type gatheringFlags struct { + DisconnectChangeOwner uint32 // TODO - Does this really only happen when a disconnect happens, or can the owner change at other times? + Unknown1 uint32 + Unknown2 uint32 +} + +// GatheringFlags is an enum of the possible flags for a gathering +var GatheringFlags = gatheringFlags{ + DisconnectChangeOwner: 0x10, + Unknown1: 0x20, + Unknown2: 0x200, +} diff --git a/nex-protocols-go/match-making/get_details_participants.go b/nex-protocols-go/match-making/get_details_participants.go new file mode 100644 index 0000000..7e7ebe5 --- /dev/null +++ b/nex-protocols-go/match-making/get_details_participants.go @@ -0,0 +1,47 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetDetailedParticipants(packet nex.PacketInterface) { + if protocol.GetDetailedParticipants == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::GetDetailedParticipants not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + + err := idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetDetailedParticipants(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetDetailedParticipants(nil, packet, callID, idGathering) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/get_invitations_received.go b/nex-protocols-go/match-making/get_invitations_received.go new file mode 100644 index 0000000..f3dcc5c --- /dev/null +++ b/nex-protocols-go/match-making/get_invitations_received.go @@ -0,0 +1,29 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetInvitationsReceived(packet nex.PacketInterface) { + if protocol.GetInvitationsReceived == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::GetInvitationsReceived not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetInvitationsReceived(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/get_invitations_sent.go b/nex-protocols-go/match-making/get_invitations_sent.go new file mode 100644 index 0000000..ba799e6 --- /dev/null +++ b/nex-protocols-go/match-making/get_invitations_sent.go @@ -0,0 +1,47 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetInvitationsSent(packet nex.PacketInterface) { + if protocol.GetInvitationsSent == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::GetInvitationsSent not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + + err := idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetInvitationsSent(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetInvitationsSent(nil, packet, callID, idGathering) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/get_participants.go b/nex-protocols-go/match-making/get_participants.go new file mode 100644 index 0000000..5056e78 --- /dev/null +++ b/nex-protocols-go/match-making/get_participants.go @@ -0,0 +1,47 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetParticipants(packet nex.PacketInterface) { + if protocol.GetParticipants == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::GetParticipants not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + + err := idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetParticipants(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetParticipants(nil, packet, callID, idGathering) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/get_participants_urls.go b/nex-protocols-go/match-making/get_participants_urls.go new file mode 100644 index 0000000..45e0f9d --- /dev/null +++ b/nex-protocols-go/match-making/get_participants_urls.go @@ -0,0 +1,47 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetParticipantsURLs(packet nex.PacketInterface) { + if protocol.GetParticipantsURLs == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::GetParticipantsURLs not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + + err := idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetParticipantsURLs(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetParticipantsURLs(nil, packet, callID, idGathering) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/get_pending_deletions.go b/nex-protocols-go/match-making/get_pending_deletions.go new file mode 100644 index 0000000..e453deb --- /dev/null +++ b/nex-protocols-go/match-making/get_pending_deletions.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetPendingDeletions(packet nex.PacketInterface) { + if protocol.GetPendingDeletions == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::GetPendingDeletions not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiReason := types.NewPrimitiveU32(0) + resultRange := types.NewResultRange() + + var err error + + err = uiReason.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPendingDeletions(fmt.Errorf("Failed to read uiReason from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPendingDeletions(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetPendingDeletions(nil, packet, callID, uiReason, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/get_session_url.go b/nex-protocols-go/match-making/get_session_url.go new file mode 100644 index 0000000..8e0dfe8 --- /dev/null +++ b/nex-protocols-go/match-making/get_session_url.go @@ -0,0 +1,47 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetSessionURL(packet nex.PacketInterface) { + if protocol.GetSessionURL == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::GetSessionURL not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + + err := idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetSessionURL(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetSessionURL(nil, packet, callID, idGathering) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/get_session_urls.go b/nex-protocols-go/match-making/get_session_urls.go new file mode 100644 index 0000000..900079f --- /dev/null +++ b/nex-protocols-go/match-making/get_session_urls.go @@ -0,0 +1,47 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetSessionURLs(packet nex.PacketInterface) { + if protocol.GetSessionURLs == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::GetSessionURLs not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + + err := gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetSessionURLs(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetSessionURLs(nil, packet, callID, gid) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/get_state.go b/nex-protocols-go/match-making/get_state.go new file mode 100644 index 0000000..da351c8 --- /dev/null +++ b/nex-protocols-go/match-making/get_state.go @@ -0,0 +1,47 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetState(packet nex.PacketInterface) { + if protocol.GetState == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::GetState not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + + err := idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetState(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetState(nil, packet, callID, idGathering) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/get_stats.go b/nex-protocols-go/match-making/get_stats.go new file mode 100644 index 0000000..36e8188 --- /dev/null +++ b/nex-protocols-go/match-making/get_stats.go @@ -0,0 +1,72 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetStats(packet nex.PacketInterface) { + if protocol.GetStats == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::GetStats not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + lstParticipants := types.NewList[*types.PID]() + lstParticipants.Type = types.NewPID(0) + lstColumns := types.NewBuffer(nil) + + var err error + + err = idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetStats(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = lstParticipants.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetStats(fmt.Errorf("Failed to read lstParticipants from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = lstColumns.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetStats(fmt.Errorf("Failed to read lstColumns from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetStats(nil, packet, callID, idGathering, lstParticipants, lstColumns) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/invite.go b/nex-protocols-go/match-making/invite.go new file mode 100644 index 0000000..fc590ec --- /dev/null +++ b/nex-protocols-go/match-making/invite.go @@ -0,0 +1,72 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleInvite(packet nex.PacketInterface) { + if protocol.Invite == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::Invite not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + lstPrincipals := types.NewList[*types.PID]() + lstPrincipals.Type = types.NewPID(0) + strMessage := types.NewString("") + + var err error + + err = idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.Invite(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = lstPrincipals.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.Invite(fmt.Errorf("Failed to read lstPrincipals from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.Invite(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.Invite(nil, packet, callID, idGathering, lstPrincipals, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/launch_session.go b/nex-protocols-go/match-making/launch_session.go new file mode 100644 index 0000000..de4062a --- /dev/null +++ b/nex-protocols-go/match-making/launch_session.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleLaunchSession(packet nex.PacketInterface) { + if protocol.LaunchSession == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::LaunchSession not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + strURL := types.NewString("") + + var err error + + err = idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.LaunchSession(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strURL.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.LaunchSession(fmt.Errorf("Failed to read strURL from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.LaunchSession(nil, packet, callID, idGathering, strURL) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/migrate_gathering_ownership.go b/nex-protocols-go/match-making/migrate_gathering_ownership.go new file mode 100644 index 0000000..f1577a0 --- /dev/null +++ b/nex-protocols-go/match-making/migrate_gathering_ownership.go @@ -0,0 +1,72 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleMigrateGatheringOwnership(packet nex.PacketInterface) { + if protocol.MigrateGatheringOwnership == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::MigrateGatheringOwnership not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + lstPotentialNewOwnersID := types.NewList[*types.PID]() + lstPotentialNewOwnersID.Type = types.NewPID(0) + participantsOnly := types.NewPrimitiveBool(false) + + var err error + + err = gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.MigrateGatheringOwnership(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = lstPotentialNewOwnersID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.MigrateGatheringOwnership(fmt.Errorf("Failed to read lstPotentialNewOwnersID from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = participantsOnly.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.MigrateGatheringOwnership(fmt.Errorf("Failed to read participantsOnly from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.MigrateGatheringOwnership(nil, packet, callID, gid, lstPotentialNewOwnersID, participantsOnly) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/migrate_gathering_ownership_v1.go b/nex-protocols-go/match-making/migrate_gathering_ownership_v1.go new file mode 100644 index 0000000..17e4549 --- /dev/null +++ b/nex-protocols-go/match-making/migrate_gathering_ownership_v1.go @@ -0,0 +1,61 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleMigrateGatheringOwnershipV1(packet nex.PacketInterface) { + if protocol.MigrateGatheringOwnershipV1 == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::MigrateGatheringOwnershipV1 not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + lstPotentialNewOwnersID := types.NewList[*types.PID]() + lstPotentialNewOwnersID.Type = types.NewPID(0) + + var err error + + err = gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.MigrateGatheringOwnershipV1(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = lstPotentialNewOwnersID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.MigrateGatheringOwnershipV1(fmt.Errorf("Failed to read lstPotentialNewOwnersID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.MigrateGatheringOwnershipV1(nil, packet, callID, gid, lstPotentialNewOwnersID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/participate.go b/nex-protocols-go/match-making/participate.go new file mode 100644 index 0000000..d57c0d0 --- /dev/null +++ b/nex-protocols-go/match-making/participate.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleParticipate(packet nex.PacketInterface) { + if protocol.Participate == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::Participate not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + strMessage := types.NewString("") + + var err error + + err = idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.Participate(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.Participate(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.Participate(nil, packet, callID, idGathering, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/protocol.go b/nex-protocols-go/match-making/protocol.go new file mode 100644 index 0000000..6d4ffc5 --- /dev/null +++ b/nex-protocols-go/match-making/protocol.go @@ -0,0 +1,596 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +const ( + // ProtocolID is the protocol ID for the Match Making protocol + ProtocolID = 0x15 + + // MethodRegisterGathering is the method ID for method RegisterGathering + MethodRegisterGathering = 0x1 + + // MethodUnregisterGathering is the method ID for method UnregisterGathering + MethodUnregisterGathering = 0x2 + + // MethodUnregisterGatherings is the method ID for method UnregisterGatherings + MethodUnregisterGatherings = 0x3 + + // MethodUpdateGathering is the method ID for method UpdateGathering + MethodUpdateGathering = 0x4 + + // MethodInvite is the method ID for method Invite + MethodInvite = 0x5 + + // MethodAcceptInvitation is the method ID for method AcceptInvitation + MethodAcceptInvitation = 0x6 + + // MethodDeclineInvitation is the method ID for method DeclineInvitation + MethodDeclineInvitation = 0x7 + + // MethodCancelInvitation is the method ID for method CancelInvitation + MethodCancelInvitation = 0x8 + + // MethodGetInvitationsSent is the method ID for method GetInvitationsSent + MethodGetInvitationsSent = 0x9 + + // MethodGetInvitationsReceived is the method ID for method GetInvitationsReceived + MethodGetInvitationsReceived = 0xA + + // MethodParticipate is the method ID for method Participate + MethodParticipate = 0xB + + // MethodCancelParticipation is the method ID for method CancelParticipation + MethodCancelParticipation = 0xC + + // MethodGetParticipants is the method ID for method GetParticipants + MethodGetParticipants = 0xD + + // MethodAddParticipants is the method ID for method AddParticipants + MethodAddParticipants = 0xE + + // MethodGetDetailedParticipants is the method ID for method GetDetailedParticipants + MethodGetDetailedParticipants = 0xF + + // MethodGetParticipantsURLs is the method ID for method GetParticipantsURLs + MethodGetParticipantsURLs = 0x10 + + // MethodFindByType is the method ID for method FindByType + MethodFindByType = 0x11 + + // MethodFindByDescription is the method ID for method FindByDescription + MethodFindByDescription = 0x12 + + // MethodFindByDescriptionRegex is the method ID for method FindByDescriptionRegex + MethodFindByDescriptionRegex = 0x13 + + // MethodFindByID is the method ID for method FindByID + MethodFindByID = 0x14 + + // MethodFindBySingleID is the method ID for method FindBySingleID + MethodFindBySingleID = 0x15 + + // MethodFindByOwner is the method ID for method FindByOwner + MethodFindByOwner = 0x16 + + // MethodFindByParticipants is the method ID for method FindByParticipants + MethodFindByParticipants = 0x17 + + // MethodFindInvitations is the method ID for method FindInvitations + MethodFindInvitations = 0x18 + + // MethodFindBySQLQuery is the method ID for method FindBySQLQuery + MethodFindBySQLQuery = 0x19 + + // MethodLaunchSession is the method ID for method LaunchSession + MethodLaunchSession = 0x1A + + // MethodUpdateSessionURL is the method ID for method UpdateSessionURL + MethodUpdateSessionURL = 0x1B + + // MethodGetSessionURL is the method ID for method GetSessionURL + MethodGetSessionURL = 0x1C + + // MethodGetState is the method ID for method GetState + MethodGetState = 0x1D + + // MethodSetState is the method ID for method SetState + MethodSetState = 0x1E + + // MethodReportStats is the method ID for method ReportStats + MethodReportStats = 0x1F + + // MethodGetStats is the method ID for method GetStats + MethodGetStats = 0x20 + + // MethodDeleteGathering is the method ID for method DeleteGathering + MethodDeleteGathering = 0x21 + + // MethodGetPendingDeletions is the method ID for method GetPendingDeletions + MethodGetPendingDeletions = 0x22 + + // MethodDeleteFromDeletions is the method ID for method DeleteFromDeletions + MethodDeleteFromDeletions = 0x23 + + // MethodMigrateGatheringOwnershipV1 is the method ID for method MigrateGatheringOwnershipV1 + MethodMigrateGatheringOwnershipV1 = 0x24 + + // MethodFindByDescriptionLike is the method ID for method FindByDescriptionLike + MethodFindByDescriptionLike = 0x25 + + // MethodRegisterLocalURL is the method ID for method RegisterLocalURL + MethodRegisterLocalURL = 0x26 + + // MethodRegisterLocalURLs is the method ID for method RegisterLocalURLs + MethodRegisterLocalURLs = 0x27 + + // MethodUpdateSessionHostV1 is the method ID for method UpdateSessionHostV1 + MethodUpdateSessionHostV1 = 0x28 + + // MethodGetSessionURLs is the method ID for method GetSessionURLs + MethodGetSessionURLs = 0x29 + + // MethodUpdateSessionHost is the method ID for method UpdateSessionHost + MethodUpdateSessionHost = 0x2A + + // MethodUpdateGatheringOwnership is the method ID for method UpdateGatheringOwnership + MethodUpdateGatheringOwnership = 0x2B + + // MethodMigrateGatheringOwnership is the method ID for method MigrateGatheringOwnership + MethodMigrateGatheringOwnership = 0x2C +) + +// Protocol stores all the RMC method handlers for the MatchMaking protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + RegisterGathering func(err error, packet nex.PacketInterface, callID uint32, anyGathering *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error) + UnregisterGathering func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + UnregisterGatherings func(err error, packet nex.PacketInterface, callID uint32, lstGatherings *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error) + UpdateGathering func(err error, packet nex.PacketInterface, callID uint32, anyGathering *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error) + Invite func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, lstPrincipals *types.List[*types.PID], strMessage *types.String) (*nex.RMCMessage, *nex.Error) + AcceptInvitation func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error) + DeclineInvitation func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error) + CancelInvitation func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, lstPrincipals *types.List[*types.PID], strMessage *types.String) (*nex.RMCMessage, *nex.Error) + GetInvitationsSent func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetInvitationsReceived func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + Participate func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error) + CancelParticipation func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error) + GetParticipants func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + AddParticipants func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, lstPrincipals *types.List[*types.PID], strMessage *types.String) (*nex.RMCMessage, *nex.Error) + GetDetailedParticipants func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetParticipantsURLs func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + FindByType func(err error, packet nex.PacketInterface, callID uint32, strType *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + FindByDescription func(err error, packet nex.PacketInterface, callID uint32, strDescription *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + FindByDescriptionRegex func(err error, packet nex.PacketInterface, callID uint32, strDescriptionRegex *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + FindByID func(err error, packet nex.PacketInterface, callID uint32, lstID *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error) + FindBySingleID func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + FindByOwner func(err error, packet nex.PacketInterface, callID uint32, id *types.PID, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + FindByParticipants func(err error, packet nex.PacketInterface, callID uint32, pid *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error) + FindInvitations func(err error, packet nex.PacketInterface, callID uint32, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + FindBySQLQuery func(err error, packet nex.PacketInterface, callID uint32, strQuery *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + LaunchSession func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strURL *types.String) (*nex.RMCMessage, *nex.Error) + UpdateSessionURL func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strURL *types.String) (*nex.RMCMessage, *nex.Error) + GetSessionURL func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetState func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + SetState func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, uiNewState *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + ReportStats func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, lstStats *types.List[*match_making_types.GatheringStats]) (*nex.RMCMessage, *nex.Error) + GetStats func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, lstParticipants *types.List[*types.PID], lstColumns *types.Buffer) (*nex.RMCMessage, *nex.Error) + DeleteGathering func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetPendingDeletions func(err error, packet nex.PacketInterface, callID uint32, uiReason *types.PrimitiveU32, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + DeleteFromDeletions func(err error, packet nex.PacketInterface, callID uint32, lstDeletions *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error) + MigrateGatheringOwnershipV1 func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, lstPotentialNewOwnersID *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error) + FindByDescriptionLike func(err error, packet nex.PacketInterface, callID uint32, strDescriptionLike *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + RegisterLocalURL func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, url *types.StationURL) (*nex.RMCMessage, *nex.Error) + RegisterLocalURLs func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, lstURLs *types.List[*types.StationURL]) (*nex.RMCMessage, *nex.Error) + UpdateSessionHostV1 func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetSessionURLs func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + UpdateSessionHost func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, isMigrateOwner *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + UpdateGatheringOwnership func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, participantsOnly *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + MigrateGatheringOwnership func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, lstPotentialNewOwnersID *types.List[*types.PID], participantsOnly *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Match Making protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerRegisterGathering(handler func(err error, packet nex.PacketInterface, callID uint32, anyGathering *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) + SetHandlerUnregisterGathering(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerUnregisterGatherings(handler func(err error, packet nex.PacketInterface, callID uint32, lstGatherings *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateGathering(handler func(err error, packet nex.PacketInterface, callID uint32, anyGathering *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) + SetHandlerInvite(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, lstPrincipals *types.List[*types.PID], strMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerAcceptInvitation(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeclineInvitation(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerCancelInvitation(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, lstPrincipals *types.List[*types.PID], strMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetInvitationsSent(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetInvitationsReceived(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerParticipate(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerCancelParticipation(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetParticipants(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerAddParticipants(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, lstPrincipals *types.List[*types.PID], strMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetDetailedParticipants(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetParticipantsURLs(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindByType(handler func(err error, packet nex.PacketInterface, callID uint32, strType *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindByDescription(handler func(err error, packet nex.PacketInterface, callID uint32, strDescription *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindByDescriptionRegex(handler func(err error, packet nex.PacketInterface, callID uint32, strDescriptionRegex *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindByID(handler func(err error, packet nex.PacketInterface, callID uint32, lstID *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindBySingleID(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindByOwner(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PID, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindByParticipants(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindInvitations(handler func(err error, packet nex.PacketInterface, callID uint32, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindBySQLQuery(handler func(err error, packet nex.PacketInterface, callID uint32, strQuery *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerLaunchSession(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strURL *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateSessionURL(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strURL *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetSessionURL(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetState(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerSetState(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, uiNewState *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerReportStats(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, lstStats *types.List[*match_making_types.GatheringStats]) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetStats(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, lstParticipants *types.List[*types.PID], lstColumns *types.Buffer) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeleteGathering(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetPendingDeletions(handler func(err error, packet nex.PacketInterface, callID uint32, uiReason *types.PrimitiveU32, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeleteFromDeletions(handler func(err error, packet nex.PacketInterface, callID uint32, lstDeletions *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) + SetHandlerMigrateGatheringOwnershipV1(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, lstPotentialNewOwnersID *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindByDescriptionLike(handler func(err error, packet nex.PacketInterface, callID uint32, strDescriptionLike *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerRegisterLocalURL(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, url *types.StationURL) (*nex.RMCMessage, *nex.Error)) + SetHandlerRegisterLocalURLs(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, lstURLs *types.List[*types.StationURL]) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateSessionHostV1(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetSessionURLs(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateSessionHost(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, isMigrateOwner *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateGatheringOwnership(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, participantsOnly *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerMigrateGatheringOwnership(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, lstPotentialNewOwnersID *types.List[*types.PID], participantsOnly *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerRegisterGathering sets the handler for the RegisterGathering method +func (protocol *Protocol) SetHandlerRegisterGathering(handler func(err error, packet nex.PacketInterface, callID uint32, anyGathering *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) { + protocol.RegisterGathering = handler +} + +// SetHandlerUnregisterGathering sets the handler for the UnregisterGathering method +func (protocol *Protocol) SetHandlerUnregisterGathering(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.UnregisterGathering = handler +} + +// SetHandlerUnregisterGatherings sets the handler for the UnregisterGatherings method +func (protocol *Protocol) SetHandlerUnregisterGatherings(handler func(err error, packet nex.PacketInterface, callID uint32, lstGatherings *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) { + protocol.UnregisterGatherings = handler +} + +// SetHandlerUpdateGathering sets the handler for the UpdateGathering method +func (protocol *Protocol) SetHandlerUpdateGathering(handler func(err error, packet nex.PacketInterface, callID uint32, anyGathering *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateGathering = handler +} + +// SetHandlerInvite sets the handler for the Invite method +func (protocol *Protocol) SetHandlerInvite(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, lstPrincipals *types.List[*types.PID], strMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.Invite = handler +} + +// SetHandlerAcceptInvitation sets the handler for the AcceptInvitation method +func (protocol *Protocol) SetHandlerAcceptInvitation(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.AcceptInvitation = handler +} + +// SetHandlerDeclineInvitation sets the handler for the DeclineInvitation method +func (protocol *Protocol) SetHandlerDeclineInvitation(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.DeclineInvitation = handler +} + +// SetHandlerCancelInvitation sets the handler for the CancelInvitation method +func (protocol *Protocol) SetHandlerCancelInvitation(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, lstPrincipals *types.List[*types.PID], strMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.CancelInvitation = handler +} + +// SetHandlerGetInvitationsSent sets the handler for the GetInvitationsSent method +func (protocol *Protocol) SetHandlerGetInvitationsSent(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetInvitationsSent = handler +} + +// SetHandlerGetInvitationsReceived sets the handler for the GetInvitationsReceived method +func (protocol *Protocol) SetHandlerGetInvitationsReceived(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetInvitationsReceived = handler +} + +// SetHandlerParticipate sets the handler for the Participate method +func (protocol *Protocol) SetHandlerParticipate(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.Participate = handler +} + +// SetHandlerCancelParticipation sets the handler for the CancelParticipation method +func (protocol *Protocol) SetHandlerCancelParticipation(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.CancelParticipation = handler +} + +// SetHandlerGetParticipants sets the handler for the GetParticipants method +func (protocol *Protocol) SetHandlerGetParticipants(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetParticipants = handler +} + +// SetHandlerAddParticipants sets the handler for the AddParticipants method +func (protocol *Protocol) SetHandlerAddParticipants(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, lstPrincipals *types.List[*types.PID], strMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.AddParticipants = handler +} + +// SetHandlerGetDetailedParticipants sets the handler for the GetDetailedParticipants method +func (protocol *Protocol) SetHandlerGetDetailedParticipants(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetDetailedParticipants = handler +} + +// SetHandlerGetParticipantsURLs sets the handler for the GetParticipantsURLs method +func (protocol *Protocol) SetHandlerGetParticipantsURLs(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetParticipantsURLs = handler +} + +// SetHandlerFindByType sets the handler for the FindByType method +func (protocol *Protocol) SetHandlerFindByType(handler func(err error, packet nex.PacketInterface, callID uint32, strType *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.FindByType = handler +} + +// SetHandlerFindByDescription sets the handler for the FindByDescription method +func (protocol *Protocol) SetHandlerFindByDescription(handler func(err error, packet nex.PacketInterface, callID uint32, strDescription *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.FindByDescription = handler +} + +// SetHandlerFindByDescriptionRegex sets the handler for the FindByDescriptionRegex method +func (protocol *Protocol) SetHandlerFindByDescriptionRegex(handler func(err error, packet nex.PacketInterface, callID uint32, strDescriptionRegex *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.FindByDescriptionRegex = handler +} + +// SetHandlerFindByID sets the handler for the FindByID method +func (protocol *Protocol) SetHandlerFindByID(handler func(err error, packet nex.PacketInterface, callID uint32, lstID *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) { + protocol.FindByID = handler +} + +// SetHandlerFindBySingleID sets the handler for the FindBySingleID method +func (protocol *Protocol) SetHandlerFindBySingleID(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.FindBySingleID = handler +} + +// SetHandlerFindByOwner sets the handler for the FindByOwner method +func (protocol *Protocol) SetHandlerFindByOwner(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PID, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.FindByOwner = handler +} + +// SetHandlerFindByParticipants sets the handler for the FindByParticipants method +func (protocol *Protocol) SetHandlerFindByParticipants(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) { + protocol.FindByParticipants = handler +} + +// SetHandlerFindInvitations sets the handler for the FindInvitations method +func (protocol *Protocol) SetHandlerFindInvitations(handler func(err error, packet nex.PacketInterface, callID uint32, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.FindInvitations = handler +} + +// SetHandlerFindBySQLQuery sets the handler for the FindBySQLQuery method +func (protocol *Protocol) SetHandlerFindBySQLQuery(handler func(err error, packet nex.PacketInterface, callID uint32, strQuery *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.FindBySQLQuery = handler +} + +// SetHandlerLaunchSession sets the handler for the LaunchSession method +func (protocol *Protocol) SetHandlerLaunchSession(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strURL *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.LaunchSession = handler +} + +// SetHandlerUpdateSessionURL sets the handler for the UpdateSessionURL method +func (protocol *Protocol) SetHandlerUpdateSessionURL(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, strURL *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateSessionURL = handler +} + +// SetHandlerGetSessionURL sets the handler for the GetSessionURL method +func (protocol *Protocol) SetHandlerGetSessionURL(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetSessionURL = handler +} + +// SetHandlerGetState sets the handler for the GetState method +func (protocol *Protocol) SetHandlerGetState(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetState = handler +} + +// SetHandlerSetState sets the handler for the SetState method +func (protocol *Protocol) SetHandlerSetState(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, uiNewState *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.SetState = handler +} + +// SetHandlerReportStats sets the handler for the ReportStats method +func (protocol *Protocol) SetHandlerReportStats(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, lstStats *types.List[*match_making_types.GatheringStats]) (*nex.RMCMessage, *nex.Error)) { + protocol.ReportStats = handler +} + +// SetHandlerGetStats sets the handler for the GetStats method +func (protocol *Protocol) SetHandlerGetStats(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32, lstParticipants *types.List[*types.PID], lstColumns *types.Buffer) (*nex.RMCMessage, *nex.Error)) { + protocol.GetStats = handler +} + +// SetHandlerDeleteGathering sets the handler for the DeleteGathering method +func (protocol *Protocol) SetHandlerDeleteGathering(handler func(err error, packet nex.PacketInterface, callID uint32, idGathering *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.DeleteGathering = handler +} + +// SetHandlerGetPendingDeletions sets the handler for the GetPendingDeletions method +func (protocol *Protocol) SetHandlerGetPendingDeletions(handler func(err error, packet nex.PacketInterface, callID uint32, uiReason *types.PrimitiveU32, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.GetPendingDeletions = handler +} + +// SetHandlerDeleteFromDeletions sets the handler for the DeleteFromDeletions method +func (protocol *Protocol) SetHandlerDeleteFromDeletions(handler func(err error, packet nex.PacketInterface, callID uint32, lstDeletions *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) { + protocol.DeleteFromDeletions = handler +} + +// SetHandlerMigrateGatheringOwnershipV1 sets the handler for the MigrateGatheringOwnershipV1 method +func (protocol *Protocol) SetHandlerMigrateGatheringOwnershipV1(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, lstPotentialNewOwnersID *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) { + protocol.MigrateGatheringOwnershipV1 = handler +} + +// SetHandlerFindByDescriptionLike sets the handler for the FindByDescriptionLike method +func (protocol *Protocol) SetHandlerFindByDescriptionLike(handler func(err error, packet nex.PacketInterface, callID uint32, strDescriptionLike *types.String, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.FindByDescriptionLike = handler +} + +// SetHandlerRegisterLocalURL sets the handler for the RegisterLocalURL method +func (protocol *Protocol) SetHandlerRegisterLocalURL(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, url *types.StationURL) (*nex.RMCMessage, *nex.Error)) { + protocol.RegisterLocalURL = handler +} + +// SetHandlerRegisterLocalURLs sets the handler for the RegisterLocalURLs method +func (protocol *Protocol) SetHandlerRegisterLocalURLs(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, lstURLs *types.List[*types.StationURL]) (*nex.RMCMessage, *nex.Error)) { + protocol.RegisterLocalURLs = handler +} + +// SetHandlerUpdateSessionHostV1 sets the handler for the UpdateSessionHostV1 method +func (protocol *Protocol) SetHandlerUpdateSessionHostV1(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateSessionHostV1 = handler +} + +// SetHandlerGetSessionURLs sets the handler for the GetSessionURLs method +func (protocol *Protocol) SetHandlerGetSessionURLs(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetSessionURLs = handler +} + +// SetHandlerUpdateSessionHost sets the handler for the UpdateSessionHost method +func (protocol *Protocol) SetHandlerUpdateSessionHost(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, isMigrateOwner *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateSessionHost = handler +} + +// SetHandlerUpdateGatheringOwnership sets the handler for the UpdateGatheringOwnership method +func (protocol *Protocol) SetHandlerUpdateGatheringOwnership(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, participantsOnly *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateGatheringOwnership = handler +} + +// SetHandlerMigrateGatheringOwnership sets the handler for the MigrateGatheringOwnership method +func (protocol *Protocol) SetHandlerMigrateGatheringOwnership(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, lstPotentialNewOwnersID *types.List[*types.PID], participantsOnly *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.MigrateGatheringOwnership = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodRegisterGathering: + protocol.handleRegisterGathering(packet) + case MethodUnregisterGathering: + protocol.handleUnregisterGathering(packet) + case MethodUnregisterGatherings: + protocol.handleUnregisterGatherings(packet) + case MethodUpdateGathering: + protocol.handleUpdateGathering(packet) + case MethodInvite: + protocol.handleInvite(packet) + case MethodAcceptInvitation: + protocol.handleAcceptInvitation(packet) + case MethodDeclineInvitation: + protocol.handleDeclineInvitation(packet) + case MethodCancelInvitation: + protocol.handleCancelInvitation(packet) + case MethodGetInvitationsSent: + protocol.handleGetInvitationsSent(packet) + case MethodGetInvitationsReceived: + protocol.handleGetInvitationsReceived(packet) + case MethodParticipate: + protocol.handleParticipate(packet) + case MethodCancelParticipation: + protocol.handleCancelParticipation(packet) + case MethodGetParticipants: + protocol.handleGetParticipants(packet) + case MethodAddParticipants: + protocol.handleAddParticipants(packet) + case MethodGetDetailedParticipants: + protocol.handleGetDetailedParticipants(packet) + case MethodGetParticipantsURLs: + protocol.handleGetParticipantsURLs(packet) + case MethodFindByType: + protocol.handleFindByType(packet) + case MethodFindByDescription: + protocol.handleFindByDescription(packet) + case MethodFindByDescriptionRegex: + protocol.handleFindByDescriptionRegex(packet) + case MethodFindByID: + protocol.handleFindByID(packet) + case MethodFindBySingleID: + protocol.handleFindBySingleID(packet) + case MethodFindByOwner: + protocol.handleFindByOwner(packet) + case MethodFindByParticipants: + protocol.handleFindByParticipants(packet) + case MethodFindInvitations: + protocol.handleFindInvitations(packet) + case MethodFindBySQLQuery: + protocol.handleFindBySQLQuery(packet) + case MethodLaunchSession: + protocol.handleLaunchSession(packet) + case MethodUpdateSessionURL: + protocol.handleUpdateSessionURL(packet) + case MethodGetSessionURL: + protocol.handleGetSessionURL(packet) + case MethodGetState: + protocol.handleGetState(packet) + case MethodSetState: + protocol.handleSetState(packet) + case MethodReportStats: + protocol.handleReportStats(packet) + case MethodGetStats: + protocol.handleGetStats(packet) + case MethodDeleteGathering: + protocol.handleDeleteGathering(packet) + case MethodGetPendingDeletions: + protocol.handleGetPendingDeletions(packet) + case MethodDeleteFromDeletions: + protocol.handleDeleteFromDeletions(packet) + case MethodMigrateGatheringOwnershipV1: + protocol.handleMigrateGatheringOwnershipV1(packet) + case MethodFindByDescriptionLike: + protocol.handleFindByDescriptionLike(packet) + case MethodRegisterLocalURL: + protocol.handleRegisterLocalURL(packet) + case MethodRegisterLocalURLs: + protocol.handleRegisterLocalURLs(packet) + case MethodUpdateSessionHostV1: + protocol.handleUpdateSessionHostV1(packet) + case MethodGetSessionURLs: + protocol.handleGetSessionURLs(packet) + case MethodUpdateSessionHost: + protocol.handleUpdateSessionHost(packet) + case MethodUpdateGatheringOwnership: + protocol.handleUpdateGatheringOwnership(packet) + case MethodMigrateGatheringOwnership: + protocol.handleMigrateGatheringOwnership(packet) + default: + errMessage := fmt.Sprintf("Unsupported MatchMaking method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Match Making protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/match-making/register_gathering.go b/nex-protocols-go/match-making/register_gathering.go new file mode 100644 index 0000000..29f5f89 --- /dev/null +++ b/nex-protocols-go/match-making/register_gathering.go @@ -0,0 +1,47 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRegisterGathering(packet nex.PacketInterface) { + if protocol.RegisterGathering == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::RegisterGathering not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + anyGathering := types.NewAnyDataHolder() + + err := anyGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RegisterGathering(fmt.Errorf("Failed to read anyGathering from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RegisterGathering(nil, packet, callID, anyGathering) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/register_local_url.go b/nex-protocols-go/match-making/register_local_url.go new file mode 100644 index 0000000..2a18b7a --- /dev/null +++ b/nex-protocols-go/match-making/register_local_url.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRegisterLocalURL(packet nex.PacketInterface) { + if protocol.RegisterLocalURL == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::RegisterLocalURL not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + url := types.NewStationURL("") + + var err error + + err = gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RegisterLocalURL(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = url.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RegisterLocalURL(fmt.Errorf("Failed to read url from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RegisterLocalURL(nil, packet, callID, gid, url) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/register_local_urls.go b/nex-protocols-go/match-making/register_local_urls.go new file mode 100644 index 0000000..050e7af --- /dev/null +++ b/nex-protocols-go/match-making/register_local_urls.go @@ -0,0 +1,61 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRegisterLocalURLs(packet nex.PacketInterface) { + if protocol.RegisterLocalURLs == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::RegisterLocalURLs not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + lstURLs := types.NewList[*types.StationURL]() + lstURLs.Type = types.NewStationURL("") + + var err error + + err = gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RegisterLocalURLs(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = lstURLs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RegisterLocalURLs(fmt.Errorf("Failed to read lstURLs from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RegisterLocalURLs(nil, packet, callID, gid, lstURLs) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/report_stats.go b/nex-protocols-go/match-making/report_stats.go new file mode 100644 index 0000000..4628976 --- /dev/null +++ b/nex-protocols-go/match-making/report_stats.go @@ -0,0 +1,62 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +func (protocol *Protocol) handleReportStats(packet nex.PacketInterface) { + if protocol.ReportStats == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::ReportStats not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + lstStats := types.NewList[*match_making_types.GatheringStats]() + lstStats.Type = match_making_types.NewGatheringStats() + + var err error + + err = idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReportStats(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = lstStats.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReportStats(fmt.Errorf("Failed to read lstStats from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ReportStats(nil, packet, callID, idGathering, lstStats) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/set_state.go b/nex-protocols-go/match-making/set_state.go new file mode 100644 index 0000000..41aa244 --- /dev/null +++ b/nex-protocols-go/match-making/set_state.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSetState(packet nex.PacketInterface) { + if protocol.SetState == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::SetState not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + uiNewState := types.NewPrimitiveU32(0) + + var err error + + err = idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SetState(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uiNewState.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SetState(fmt.Errorf("Failed to read uiNewState from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SetState(nil, packet, callID, idGathering, uiNewState) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/types/auto_matchmake_param.go b/nex-protocols-go/match-making/types/auto_matchmake_param.go new file mode 100644 index 0000000..b6a7feb --- /dev/null +++ b/nex-protocols-go/match-making/types/auto_matchmake_param.go @@ -0,0 +1,200 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// AutoMatchmakeParam is a type within the Matchmaking protocol +type AutoMatchmakeParam struct { + types.Structure + SourceMatchmakeSession *MatchmakeSession + AdditionalParticipants *types.List[*types.PID] + GIDForParticipationCheck *types.PrimitiveU32 + AutoMatchmakeOption *types.PrimitiveU32 + JoinMessage *types.String + ParticipationCount *types.PrimitiveU16 + LstSearchCriteria *types.List[*MatchmakeSessionSearchCriteria] + TargetGIDs *types.List[*types.PrimitiveU32] +} + +// WriteTo writes the AutoMatchmakeParam to the given writable +func (amp *AutoMatchmakeParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + amp.SourceMatchmakeSession.WriteTo(contentWritable) + amp.AdditionalParticipants.WriteTo(contentWritable) + amp.GIDForParticipationCheck.WriteTo(contentWritable) + amp.AutoMatchmakeOption.WriteTo(contentWritable) + amp.JoinMessage.WriteTo(contentWritable) + amp.ParticipationCount.WriteTo(contentWritable) + amp.LstSearchCriteria.WriteTo(contentWritable) + amp.TargetGIDs.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + amp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the AutoMatchmakeParam from the given readable +func (amp *AutoMatchmakeParam) ExtractFrom(readable types.Readable) error { + var err error + + err = amp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AutoMatchmakeParam header. %s", err.Error()) + } + + err = amp.SourceMatchmakeSession.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AutoMatchmakeParam.SourceMatchmakeSession. %s", err.Error()) + } + + err = amp.AdditionalParticipants.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AutoMatchmakeParam.AdditionalParticipants. %s", err.Error()) + } + + err = amp.GIDForParticipationCheck.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AutoMatchmakeParam.GIDForParticipationCheck. %s", err.Error()) + } + + err = amp.AutoMatchmakeOption.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AutoMatchmakeParam.AutoMatchmakeOption. %s", err.Error()) + } + + err = amp.JoinMessage.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AutoMatchmakeParam.JoinMessage. %s", err.Error()) + } + + err = amp.ParticipationCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AutoMatchmakeParam.ParticipationCount. %s", err.Error()) + } + + err = amp.LstSearchCriteria.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AutoMatchmakeParam.LstSearchCriteria. %s", err.Error()) + } + + err = amp.TargetGIDs.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AutoMatchmakeParam.TargetGIDs. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of AutoMatchmakeParam +func (amp *AutoMatchmakeParam) Copy() types.RVType { + copied := NewAutoMatchmakeParam() + + copied.StructureVersion = amp.StructureVersion + copied.SourceMatchmakeSession = amp.SourceMatchmakeSession.Copy().(*MatchmakeSession) + copied.AdditionalParticipants = amp.AdditionalParticipants.Copy().(*types.List[*types.PID]) + copied.GIDForParticipationCheck = amp.GIDForParticipationCheck.Copy().(*types.PrimitiveU32) + copied.AutoMatchmakeOption = amp.AutoMatchmakeOption.Copy().(*types.PrimitiveU32) + copied.JoinMessage = amp.JoinMessage.Copy().(*types.String) + copied.ParticipationCount = amp.ParticipationCount.Copy().(*types.PrimitiveU16) + copied.LstSearchCriteria = amp.LstSearchCriteria.Copy().(*types.List[*MatchmakeSessionSearchCriteria]) + copied.TargetGIDs = amp.TargetGIDs.Copy().(*types.List[*types.PrimitiveU32]) + + return copied +} + +// Equals checks if the given AutoMatchmakeParam contains the same data as the current AutoMatchmakeParam +func (amp *AutoMatchmakeParam) Equals(o types.RVType) bool { + if _, ok := o.(*AutoMatchmakeParam); !ok { + return false + } + + other := o.(*AutoMatchmakeParam) + + if amp.StructureVersion != other.StructureVersion { + return false + } + + if !amp.SourceMatchmakeSession.Equals(other.SourceMatchmakeSession) { + return false + } + + if !amp.AdditionalParticipants.Equals(other.AdditionalParticipants) { + return false + } + + if !amp.GIDForParticipationCheck.Equals(other.GIDForParticipationCheck) { + return false + } + + if !amp.AutoMatchmakeOption.Equals(other.AutoMatchmakeOption) { + return false + } + + if !amp.JoinMessage.Equals(other.JoinMessage) { + return false + } + + if !amp.ParticipationCount.Equals(other.ParticipationCount) { + return false + } + + if !amp.LstSearchCriteria.Equals(other.LstSearchCriteria) { + return false + } + + return amp.TargetGIDs.Equals(other.TargetGIDs) +} + +// String returns the string representation of the AutoMatchmakeParam +func (amp *AutoMatchmakeParam) String() string { + return amp.FormatToString(0) +} + +// FormatToString pretty-prints the AutoMatchmakeParam using the provided indentation level +func (amp *AutoMatchmakeParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("AutoMatchmakeParam{\n") + b.WriteString(fmt.Sprintf("%sSourceMatchmakeSession: %s,\n", indentationValues, amp.SourceMatchmakeSession.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sAdditionalParticipants: %s,\n", indentationValues, amp.AdditionalParticipants)) + b.WriteString(fmt.Sprintf("%sGIDForParticipationCheck: %s,\n", indentationValues, amp.GIDForParticipationCheck)) + b.WriteString(fmt.Sprintf("%sAutoMatchmakeOption: %s,\n", indentationValues, amp.AutoMatchmakeOption)) + b.WriteString(fmt.Sprintf("%sJoinMessage: %s,\n", indentationValues, amp.JoinMessage)) + b.WriteString(fmt.Sprintf("%sParticipationCount: %s,\n", indentationValues, amp.ParticipationCount)) + b.WriteString(fmt.Sprintf("%sLstSearchCriteria: %s,\n", indentationValues, amp.LstSearchCriteria)) + b.WriteString(fmt.Sprintf("%sTargetGIDs: %s,\n", indentationValues, amp.TargetGIDs)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewAutoMatchmakeParam returns a new AutoMatchmakeParam +func NewAutoMatchmakeParam() *AutoMatchmakeParam { + amp := &AutoMatchmakeParam{ + SourceMatchmakeSession: NewMatchmakeSession(), + AdditionalParticipants: types.NewList[*types.PID](), + GIDForParticipationCheck: types.NewPrimitiveU32(0), + AutoMatchmakeOption: types.NewPrimitiveU32(0), + JoinMessage: types.NewString(""), + ParticipationCount: types.NewPrimitiveU16(0), + LstSearchCriteria: types.NewList[*MatchmakeSessionSearchCriteria](), + TargetGIDs: types.NewList[*types.PrimitiveU32](), + } + + amp.AdditionalParticipants.Type = types.NewPID(0) + amp.LstSearchCriteria.Type = NewMatchmakeSessionSearchCriteria() + amp.TargetGIDs.Type = types.NewPrimitiveU32(0) + + return amp +} diff --git a/nex-protocols-go/match-making/types/create_matchmake_session_param.go b/nex-protocols-go/match-making/types/create_matchmake_session_param.go new file mode 100644 index 0000000..5dfdb97 --- /dev/null +++ b/nex-protocols-go/match-making/types/create_matchmake_session_param.go @@ -0,0 +1,170 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// CreateMatchmakeSessionParam is a type within the Matchmaking protocol +type CreateMatchmakeSessionParam struct { + types.Structure + SourceMatchmakeSession *MatchmakeSession + AdditionalParticipants *types.List[*types.PID] + GIDForParticipationCheck *types.PrimitiveU32 + CreateMatchmakeSessionOption *types.PrimitiveU32 + JoinMessage *types.String + ParticipationCount *types.PrimitiveU16 +} + +// WriteTo writes the CreateMatchmakeSessionParam to the given writable +func (cmsp *CreateMatchmakeSessionParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + cmsp.SourceMatchmakeSession.WriteTo(contentWritable) + cmsp.AdditionalParticipants.WriteTo(contentWritable) + cmsp.GIDForParticipationCheck.WriteTo(contentWritable) + cmsp.CreateMatchmakeSessionOption.WriteTo(contentWritable) + cmsp.JoinMessage.WriteTo(contentWritable) + cmsp.ParticipationCount.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + cmsp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the CreateMatchmakeSessionParam from the given readable +func (cmsp *CreateMatchmakeSessionParam) ExtractFrom(readable types.Readable) error { + var err error + + err = cmsp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CreateMatchmakeSessionParam header. %s", err.Error()) + } + + err = cmsp.SourceMatchmakeSession.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CreateMatchmakeSessionParam.SourceMatchmakeSession. %s", err.Error()) + } + + err = cmsp.AdditionalParticipants.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CreateMatchmakeSessionParam.AdditionalParticipants. %s", err.Error()) + } + + err = cmsp.GIDForParticipationCheck.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CreateMatchmakeSessionParam.GIDForParticipationCheck. %s", err.Error()) + } + + err = cmsp.CreateMatchmakeSessionOption.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CreateMatchmakeSessionParam.CreateMatchmakeSessionOption. %s", err.Error()) + } + + err = cmsp.JoinMessage.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CreateMatchmakeSessionParam.JoinMessage. %s", err.Error()) + } + + err = cmsp.ParticipationCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CreateMatchmakeSessionParam.ParticipationCount. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of CreateMatchmakeSessionParam +func (cmsp *CreateMatchmakeSessionParam) Copy() types.RVType { + copied := NewCreateMatchmakeSessionParam() + + copied.StructureVersion = cmsp.StructureVersion + copied.SourceMatchmakeSession = cmsp.SourceMatchmakeSession.Copy().(*MatchmakeSession) + copied.AdditionalParticipants = cmsp.AdditionalParticipants.Copy().(*types.List[*types.PID]) + copied.GIDForParticipationCheck = cmsp.GIDForParticipationCheck.Copy().(*types.PrimitiveU32) + copied.CreateMatchmakeSessionOption = cmsp.CreateMatchmakeSessionOption.Copy().(*types.PrimitiveU32) + copied.JoinMessage = cmsp.JoinMessage.Copy().(*types.String) + copied.ParticipationCount = cmsp.ParticipationCount.Copy().(*types.PrimitiveU16) + + return copied +} + +// Equals checks if the given CreateMatchmakeSessionParam contains the same data as the current CreateMatchmakeSessionParam +func (cmsp *CreateMatchmakeSessionParam) Equals(o types.RVType) bool { + if _, ok := o.(*CreateMatchmakeSessionParam); !ok { + return false + } + + other := o.(*CreateMatchmakeSessionParam) + + if cmsp.StructureVersion != other.StructureVersion { + return false + } + + if !cmsp.SourceMatchmakeSession.Equals(other.SourceMatchmakeSession) { + return false + } + + if !cmsp.AdditionalParticipants.Equals(other.AdditionalParticipants) { + return false + } + + if !cmsp.GIDForParticipationCheck.Equals(other.GIDForParticipationCheck) { + return false + } + + if !cmsp.CreateMatchmakeSessionOption.Equals(other.CreateMatchmakeSessionOption) { + return false + } + + if !cmsp.JoinMessage.Equals(other.JoinMessage) { + return false + } + + return cmsp.ParticipationCount.Equals(other.ParticipationCount) +} + +// String returns the string representation of the CreateMatchmakeSessionParam +func (cmsp *CreateMatchmakeSessionParam) String() string { + return cmsp.FormatToString(0) +} + +// FormatToString pretty-prints the CreateMatchmakeSessionParam using the provided indentation level +func (cmsp *CreateMatchmakeSessionParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("CreateMatchmakeSessionParam{\n") + b.WriteString(fmt.Sprintf("%sSourceMatchmakeSession: %s,\n", indentationValues, cmsp.SourceMatchmakeSession.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sAdditionalParticipants: %s,\n", indentationValues, cmsp.AdditionalParticipants)) + b.WriteString(fmt.Sprintf("%sGIDForParticipationCheck: %s,\n", indentationValues, cmsp.GIDForParticipationCheck)) + b.WriteString(fmt.Sprintf("%sCreateMatchmakeSessionOption: %s,\n", indentationValues, cmsp.CreateMatchmakeSessionOption)) + b.WriteString(fmt.Sprintf("%sJoinMessage: %s,\n", indentationValues, cmsp.JoinMessage)) + b.WriteString(fmt.Sprintf("%sParticipationCount: %s,\n", indentationValues, cmsp.ParticipationCount)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewCreateMatchmakeSessionParam returns a new CreateMatchmakeSessionParam +func NewCreateMatchmakeSessionParam() *CreateMatchmakeSessionParam { + cmsp := &CreateMatchmakeSessionParam{ + SourceMatchmakeSession: NewMatchmakeSession(), + AdditionalParticipants: types.NewList[*types.PID](), + GIDForParticipationCheck: types.NewPrimitiveU32(0), + CreateMatchmakeSessionOption: types.NewPrimitiveU32(0), + JoinMessage: types.NewString(""), + ParticipationCount: types.NewPrimitiveU16(0), + } + + cmsp.AdditionalParticipants.Type = types.NewPID(0) + + return cmsp +} diff --git a/nex-protocols-go/match-making/types/deletion_entry.go b/nex-protocols-go/match-making/types/deletion_entry.go new file mode 100644 index 0000000..c8621f8 --- /dev/null +++ b/nex-protocols-go/match-making/types/deletion_entry.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// DeletionEntry is a type within the Matchmaking protocol +type DeletionEntry struct { + types.Structure + IDGathering *types.PrimitiveU32 + PID *types.PID + UIReason *types.PrimitiveU32 +} + +// WriteTo writes the DeletionEntry to the given writable +func (de *DeletionEntry) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + de.IDGathering.WriteTo(contentWritable) + de.PID.WriteTo(contentWritable) + de.UIReason.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + de.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the DeletionEntry from the given readable +func (de *DeletionEntry) ExtractFrom(readable types.Readable) error { + var err error + + err = de.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DeletionEntry header. %s", err.Error()) + } + + err = de.IDGathering.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DeletionEntry.IDGathering. %s", err.Error()) + } + + err = de.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DeletionEntry.PID. %s", err.Error()) + } + + err = de.UIReason.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract DeletionEntry.UIReason. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of DeletionEntry +func (de *DeletionEntry) Copy() types.RVType { + copied := NewDeletionEntry() + + copied.StructureVersion = de.StructureVersion + copied.IDGathering = de.IDGathering.Copy().(*types.PrimitiveU32) + copied.PID = de.PID.Copy().(*types.PID) + copied.UIReason = de.UIReason.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given DeletionEntry contains the same data as the current DeletionEntry +func (de *DeletionEntry) Equals(o types.RVType) bool { + if _, ok := o.(*DeletionEntry); !ok { + return false + } + + other := o.(*DeletionEntry) + + if de.StructureVersion != other.StructureVersion { + return false + } + + if !de.IDGathering.Equals(other.IDGathering) { + return false + } + + if !de.PID.Equals(other.PID) { + return false + } + + return de.UIReason.Equals(other.UIReason) +} + +// String returns the string representation of the DeletionEntry +func (de *DeletionEntry) String() string { + return de.FormatToString(0) +} + +// FormatToString pretty-prints the DeletionEntry using the provided indentation level +func (de *DeletionEntry) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("DeletionEntry{\n") + b.WriteString(fmt.Sprintf("%sIDGathering: %s,\n", indentationValues, de.IDGathering)) + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, de.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUIReason: %s,\n", indentationValues, de.UIReason)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewDeletionEntry returns a new DeletionEntry +func NewDeletionEntry() *DeletionEntry { + de := &DeletionEntry{ + IDGathering: types.NewPrimitiveU32(0), + PID: types.NewPID(0), + UIReason: types.NewPrimitiveU32(0), + } + + return de +} diff --git a/nex-protocols-go/match-making/types/find_matchmake_session_by_participant_param.go b/nex-protocols-go/match-making/types/find_matchmake_session_by_participant_param.go new file mode 100644 index 0000000..efbbda0 --- /dev/null +++ b/nex-protocols-go/match-making/types/find_matchmake_session_by_participant_param.go @@ -0,0 +1,128 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// FindMatchmakeSessionByParticipantParam is a type within the Matchmaking protocol +type FindMatchmakeSessionByParticipantParam struct { + types.Structure + PrincipalIDList *types.List[*types.PID] + ResultOptions *types.PrimitiveU32 + BlockListParam *MatchmakeBlockListParam +} + +// WriteTo writes the FindMatchmakeSessionByParticipantParam to the given writable +func (fmsbpp *FindMatchmakeSessionByParticipantParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + fmsbpp.PrincipalIDList.WriteTo(contentWritable) + fmsbpp.ResultOptions.WriteTo(contentWritable) + fmsbpp.BlockListParam.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + fmsbpp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the FindMatchmakeSessionByParticipantParam from the given readable +func (fmsbpp *FindMatchmakeSessionByParticipantParam) ExtractFrom(readable types.Readable) error { + var err error + + err = fmsbpp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FindMatchmakeSessionByParticipantParam header. %s", err.Error()) + } + + err = fmsbpp.PrincipalIDList.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FindMatchmakeSessionByParticipantParam.PrincipalIDList. %s", err.Error()) + } + + err = fmsbpp.ResultOptions.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FindMatchmakeSessionByParticipantParam.ResultOptions. %s", err.Error()) + } + + err = fmsbpp.BlockListParam.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FindMatchmakeSessionByParticipantParam.BlockListParam. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of FindMatchmakeSessionByParticipantParam +func (fmsbpp *FindMatchmakeSessionByParticipantParam) Copy() types.RVType { + copied := NewFindMatchmakeSessionByParticipantParam() + + copied.StructureVersion = fmsbpp.StructureVersion + copied.PrincipalIDList = fmsbpp.PrincipalIDList.Copy().(*types.List[*types.PID]) + copied.ResultOptions = fmsbpp.ResultOptions.Copy().(*types.PrimitiveU32) + copied.BlockListParam = fmsbpp.BlockListParam.Copy().(*MatchmakeBlockListParam) + + return copied +} + +// Equals checks if the given FindMatchmakeSessionByParticipantParam contains the same data as the current FindMatchmakeSessionByParticipantParam +func (fmsbpp *FindMatchmakeSessionByParticipantParam) Equals(o types.RVType) bool { + if _, ok := o.(*FindMatchmakeSessionByParticipantParam); !ok { + return false + } + + other := o.(*FindMatchmakeSessionByParticipantParam) + + if fmsbpp.StructureVersion != other.StructureVersion { + return false + } + + if !fmsbpp.PrincipalIDList.Equals(other.PrincipalIDList) { + return false + } + + if !fmsbpp.ResultOptions.Equals(other.ResultOptions) { + return false + } + + return fmsbpp.BlockListParam.Equals(other.BlockListParam) +} + +// String returns the string representation of the FindMatchmakeSessionByParticipantParam +func (fmsbpp *FindMatchmakeSessionByParticipantParam) String() string { + return fmsbpp.FormatToString(0) +} + +// FormatToString pretty-prints the FindMatchmakeSessionByParticipantParam using the provided indentation level +func (fmsbpp *FindMatchmakeSessionByParticipantParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("FindMatchmakeSessionByParticipantParam{\n") + b.WriteString(fmt.Sprintf("%sPrincipalIDList: %s,\n", indentationValues, fmsbpp.PrincipalIDList)) + b.WriteString(fmt.Sprintf("%sResultOptions: %s,\n", indentationValues, fmsbpp.ResultOptions)) + b.WriteString(fmt.Sprintf("%sBlockListParam: %s,\n", indentationValues, fmsbpp.BlockListParam.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewFindMatchmakeSessionByParticipantParam returns a new FindMatchmakeSessionByParticipantParam +func NewFindMatchmakeSessionByParticipantParam() *FindMatchmakeSessionByParticipantParam { + fmsbpp := &FindMatchmakeSessionByParticipantParam{ + PrincipalIDList: types.NewList[*types.PID](), + ResultOptions: types.NewPrimitiveU32(0), + BlockListParam: NewMatchmakeBlockListParam(), + } + + fmsbpp.PrincipalIDList.Type = types.NewPID(0) + + return fmsbpp +} diff --git a/nex-protocols-go/match-making/types/find_matchmake_session_by_participant_result.go b/nex-protocols-go/match-making/types/find_matchmake_session_by_participant_result.go new file mode 100644 index 0000000..64777ab --- /dev/null +++ b/nex-protocols-go/match-making/types/find_matchmake_session_by_participant_result.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// FindMatchmakeSessionByParticipantResult is a type within the Matchmaking protocol +type FindMatchmakeSessionByParticipantResult struct { + types.Structure + PrincipalID *types.PID + Session *MatchmakeSession +} + +// WriteTo writes the FindMatchmakeSessionByParticipantResult to the given writable +func (fmsbpr *FindMatchmakeSessionByParticipantResult) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + fmsbpr.PrincipalID.WriteTo(contentWritable) + fmsbpr.Session.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + fmsbpr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the FindMatchmakeSessionByParticipantResult from the given readable +func (fmsbpr *FindMatchmakeSessionByParticipantResult) ExtractFrom(readable types.Readable) error { + var err error + + err = fmsbpr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FindMatchmakeSessionByParticipantResult header. %s", err.Error()) + } + + err = fmsbpr.PrincipalID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FindMatchmakeSessionByParticipantResult.PrincipalID. %s", err.Error()) + } + + err = fmsbpr.Session.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FindMatchmakeSessionByParticipantResult.Session. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of FindMatchmakeSessionByParticipantResult +func (fmsbpr *FindMatchmakeSessionByParticipantResult) Copy() types.RVType { + copied := NewFindMatchmakeSessionByParticipantResult() + + copied.StructureVersion = fmsbpr.StructureVersion + copied.PrincipalID = fmsbpr.PrincipalID.Copy().(*types.PID) + copied.Session = fmsbpr.Session.Copy().(*MatchmakeSession) + + return copied +} + +// Equals checks if the given FindMatchmakeSessionByParticipantResult contains the same data as the current FindMatchmakeSessionByParticipantResult +func (fmsbpr *FindMatchmakeSessionByParticipantResult) Equals(o types.RVType) bool { + if _, ok := o.(*FindMatchmakeSessionByParticipantResult); !ok { + return false + } + + other := o.(*FindMatchmakeSessionByParticipantResult) + + if fmsbpr.StructureVersion != other.StructureVersion { + return false + } + + if !fmsbpr.PrincipalID.Equals(other.PrincipalID) { + return false + } + + return fmsbpr.Session.Equals(other.Session) +} + +// String returns the string representation of the FindMatchmakeSessionByParticipantResult +func (fmsbpr *FindMatchmakeSessionByParticipantResult) String() string { + return fmsbpr.FormatToString(0) +} + +// FormatToString pretty-prints the FindMatchmakeSessionByParticipantResult using the provided indentation level +func (fmsbpr *FindMatchmakeSessionByParticipantResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("FindMatchmakeSessionByParticipantResult{\n") + b.WriteString(fmt.Sprintf("%sPrincipalID: %s,\n", indentationValues, fmsbpr.PrincipalID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sSession: %s,\n", indentationValues, fmsbpr.Session.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewFindMatchmakeSessionByParticipantResult returns a new FindMatchmakeSessionByParticipantResult +func NewFindMatchmakeSessionByParticipantResult() *FindMatchmakeSessionByParticipantResult { + fmsbpr := &FindMatchmakeSessionByParticipantResult{ + PrincipalID: types.NewPID(0), + Session: NewMatchmakeSession(), + } + + return fmsbpr +} diff --git a/nex-protocols-go/match-making/types/gathering.go b/nex-protocols-go/match-making/types/gathering.go new file mode 100644 index 0000000..0f9cf60 --- /dev/null +++ b/nex-protocols-go/match-making/types/gathering.go @@ -0,0 +1,224 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// Gathering is a type within the Matchmaking protocol +type Gathering struct { + types.Structure + ID *types.PrimitiveU32 + OwnerPID *types.PID + HostPID *types.PID + MinimumParticipants *types.PrimitiveU16 + MaximumParticipants *types.PrimitiveU16 + ParticipationPolicy *types.PrimitiveU32 + PolicyArgument *types.PrimitiveU32 + Flags *types.PrimitiveU32 + State *types.PrimitiveU32 + Description *types.String +} + +// WriteTo writes the Gathering to the given writable +func (g *Gathering) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + g.ID.WriteTo(contentWritable) + g.OwnerPID.WriteTo(contentWritable) + g.HostPID.WriteTo(contentWritable) + g.MinimumParticipants.WriteTo(contentWritable) + g.MaximumParticipants.WriteTo(contentWritable) + g.ParticipationPolicy.WriteTo(contentWritable) + g.PolicyArgument.WriteTo(contentWritable) + g.Flags.WriteTo(contentWritable) + g.State.WriteTo(contentWritable) + g.Description.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + g.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the Gathering from the given readable +func (g *Gathering) ExtractFrom(readable types.Readable) error { + var err error + + err = g.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Gathering header. %s", err.Error()) + } + + err = g.ID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Gathering.ID. %s", err.Error()) + } + + err = g.OwnerPID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Gathering.OwnerPID. %s", err.Error()) + } + + err = g.HostPID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Gathering.HostPID. %s", err.Error()) + } + + err = g.MinimumParticipants.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Gathering.MinimumParticipants. %s", err.Error()) + } + + err = g.MaximumParticipants.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Gathering.MaximumParticipants. %s", err.Error()) + } + + err = g.ParticipationPolicy.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Gathering.ParticipationPolicy. %s", err.Error()) + } + + err = g.PolicyArgument.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Gathering.PolicyArgument. %s", err.Error()) + } + + err = g.Flags.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Gathering.Flags. %s", err.Error()) + } + + err = g.State.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Gathering.State. %s", err.Error()) + } + + err = g.Description.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Gathering.Description. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of Gathering +func (g *Gathering) Copy() types.RVType { + copied := NewGathering() + + copied.StructureVersion = g.StructureVersion + copied.ID = g.ID.Copy().(*types.PrimitiveU32) + copied.OwnerPID = g.OwnerPID.Copy().(*types.PID) + copied.HostPID = g.HostPID.Copy().(*types.PID) + copied.MinimumParticipants = g.MinimumParticipants.Copy().(*types.PrimitiveU16) + copied.MaximumParticipants = g.MaximumParticipants.Copy().(*types.PrimitiveU16) + copied.ParticipationPolicy = g.ParticipationPolicy.Copy().(*types.PrimitiveU32) + copied.PolicyArgument = g.PolicyArgument.Copy().(*types.PrimitiveU32) + copied.Flags = g.Flags.Copy().(*types.PrimitiveU32) + copied.State = g.State.Copy().(*types.PrimitiveU32) + copied.Description = g.Description.Copy().(*types.String) + + return copied +} + +// Equals checks if the given Gathering contains the same data as the current Gathering +func (g *Gathering) Equals(o types.RVType) bool { + if _, ok := o.(*Gathering); !ok { + return false + } + + other := o.(*Gathering) + + if g.StructureVersion != other.StructureVersion { + return false + } + + if !g.ID.Equals(other.ID) { + return false + } + + if !g.OwnerPID.Equals(other.OwnerPID) { + return false + } + + if !g.HostPID.Equals(other.HostPID) { + return false + } + + if !g.MinimumParticipants.Equals(other.MinimumParticipants) { + return false + } + + if !g.MaximumParticipants.Equals(other.MaximumParticipants) { + return false + } + + if !g.ParticipationPolicy.Equals(other.ParticipationPolicy) { + return false + } + + if !g.PolicyArgument.Equals(other.PolicyArgument) { + return false + } + + if !g.Flags.Equals(other.Flags) { + return false + } + + if !g.State.Equals(other.State) { + return false + } + + return g.Description.Equals(other.Description) +} + +// String returns the string representation of the Gathering +func (g *Gathering) String() string { + return g.FormatToString(0) +} + +// FormatToString pretty-prints the Gathering using the provided indentation level +func (g *Gathering) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("Gathering{\n") + b.WriteString(fmt.Sprintf("%sID: %s,\n", indentationValues, g.ID)) + b.WriteString(fmt.Sprintf("%sOwnerPID: %s,\n", indentationValues, g.OwnerPID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sHostPID: %s,\n", indentationValues, g.HostPID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sMinimumParticipants: %s,\n", indentationValues, g.MinimumParticipants)) + b.WriteString(fmt.Sprintf("%sMaximumParticipants: %s,\n", indentationValues, g.MaximumParticipants)) + b.WriteString(fmt.Sprintf("%sParticipationPolicy: %s,\n", indentationValues, g.ParticipationPolicy)) + b.WriteString(fmt.Sprintf("%sPolicyArgument: %s,\n", indentationValues, g.PolicyArgument)) + b.WriteString(fmt.Sprintf("%sFlags: %s,\n", indentationValues, g.Flags)) + b.WriteString(fmt.Sprintf("%sState: %s,\n", indentationValues, g.State)) + b.WriteString(fmt.Sprintf("%sDescription: %s,\n", indentationValues, g.Description)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGathering returns a new Gathering +func NewGathering() *Gathering { + g := &Gathering{ + ID: types.NewPrimitiveU32(0), + OwnerPID: types.NewPID(0), + HostPID: types.NewPID(0), + MinimumParticipants: types.NewPrimitiveU16(0), + MaximumParticipants: types.NewPrimitiveU16(0), + ParticipationPolicy: types.NewPrimitiveU32(0), + PolicyArgument: types.NewPrimitiveU32(0), + Flags: types.NewPrimitiveU32(0), + State: types.NewPrimitiveU32(0), + Description: types.NewString(""), + } + + return g +} diff --git a/nex-protocols-go/match-making/types/gathering_stats.go b/nex-protocols-go/match-making/types/gathering_stats.go new file mode 100644 index 0000000..426180b --- /dev/null +++ b/nex-protocols-go/match-making/types/gathering_stats.go @@ -0,0 +1,128 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GatheringStats is a type within the Matchmaking protocol +type GatheringStats struct { + types.Structure + PIDParticipant *types.PID + UIFlags *types.PrimitiveU32 + LstValues *types.List[*types.PrimitiveF32] +} + +// WriteTo writes the GatheringStats to the given writable +func (gs *GatheringStats) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gs.PIDParticipant.WriteTo(contentWritable) + gs.UIFlags.WriteTo(contentWritable) + gs.LstValues.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gs.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GatheringStats from the given readable +func (gs *GatheringStats) ExtractFrom(readable types.Readable) error { + var err error + + err = gs.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GatheringStats header. %s", err.Error()) + } + + err = gs.PIDParticipant.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GatheringStats.PIDParticipant. %s", err.Error()) + } + + err = gs.UIFlags.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GatheringStats.UIFlags. %s", err.Error()) + } + + err = gs.LstValues.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GatheringStats.LstValues. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GatheringStats +func (gs *GatheringStats) Copy() types.RVType { + copied := NewGatheringStats() + + copied.StructureVersion = gs.StructureVersion + copied.PIDParticipant = gs.PIDParticipant.Copy().(*types.PID) + copied.UIFlags = gs.UIFlags.Copy().(*types.PrimitiveU32) + copied.LstValues = gs.LstValues.Copy().(*types.List[*types.PrimitiveF32]) + + return copied +} + +// Equals checks if the given GatheringStats contains the same data as the current GatheringStats +func (gs *GatheringStats) Equals(o types.RVType) bool { + if _, ok := o.(*GatheringStats); !ok { + return false + } + + other := o.(*GatheringStats) + + if gs.StructureVersion != other.StructureVersion { + return false + } + + if !gs.PIDParticipant.Equals(other.PIDParticipant) { + return false + } + + if !gs.UIFlags.Equals(other.UIFlags) { + return false + } + + return gs.LstValues.Equals(other.LstValues) +} + +// String returns the string representation of the GatheringStats +func (gs *GatheringStats) String() string { + return gs.FormatToString(0) +} + +// FormatToString pretty-prints the GatheringStats using the provided indentation level +func (gs *GatheringStats) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GatheringStats{\n") + b.WriteString(fmt.Sprintf("%sPIDParticipant: %s,\n", indentationValues, gs.PIDParticipant.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUIFlags: %s,\n", indentationValues, gs.UIFlags)) + b.WriteString(fmt.Sprintf("%sLstValues: %s,\n", indentationValues, gs.LstValues)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGatheringStats returns a new GatheringStats +func NewGatheringStats() *GatheringStats { + gs := &GatheringStats{ + PIDParticipant: types.NewPID(0), + UIFlags: types.NewPrimitiveU32(0), + LstValues: types.NewList[*types.PrimitiveF32](), + } + + gs.LstValues.Type = types.NewPrimitiveF32(0) + + return gs +} diff --git a/nex-protocols-go/match-making/types/gathering_urls.go b/nex-protocols-go/match-making/types/gathering_urls.go new file mode 100644 index 0000000..f4c6e62 --- /dev/null +++ b/nex-protocols-go/match-making/types/gathering_urls.go @@ -0,0 +1,114 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// GatheringURLs is a type within the Matchmaking protocol +type GatheringURLs struct { + types.Structure + GID *types.PrimitiveU32 + LstStationURLs *types.List[*types.StationURL] +} + +// WriteTo writes the GatheringURLs to the given writable +func (gurl *GatheringURLs) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + gurl.GID.WriteTo(contentWritable) + gurl.LstStationURLs.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + gurl.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the GatheringURLs from the given readable +func (gurl *GatheringURLs) ExtractFrom(readable types.Readable) error { + var err error + + err = gurl.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GatheringURLs header. %s", err.Error()) + } + + err = gurl.GID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GatheringURLs.GID. %s", err.Error()) + } + + err = gurl.LstStationURLs.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract GatheringURLs.LstStationURLs. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of GatheringURLs +func (gurl *GatheringURLs) Copy() types.RVType { + copied := NewGatheringURLs() + + copied.StructureVersion = gurl.StructureVersion + copied.GID = gurl.GID.Copy().(*types.PrimitiveU32) + copied.LstStationURLs = gurl.LstStationURLs.Copy().(*types.List[*types.StationURL]) + + return copied +} + +// Equals checks if the given GatheringURLs contains the same data as the current GatheringURLs +func (gurl *GatheringURLs) Equals(o types.RVType) bool { + if _, ok := o.(*GatheringURLs); !ok { + return false + } + + other := o.(*GatheringURLs) + + if gurl.StructureVersion != other.StructureVersion { + return false + } + + if !gurl.GID.Equals(other.GID) { + return false + } + + return gurl.LstStationURLs.Equals(other.LstStationURLs) +} + +// String returns the string representation of the GatheringURLs +func (gurl *GatheringURLs) String() string { + return gurl.FormatToString(0) +} + +// FormatToString pretty-prints the GatheringURLs using the provided indentation level +func (gurl *GatheringURLs) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("GatheringURLs{\n") + b.WriteString(fmt.Sprintf("%sGID: %s,\n", indentationValues, gurl.GID)) + b.WriteString(fmt.Sprintf("%sLstStationURLs: %s,\n", indentationValues, gurl.LstStationURLs)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewGatheringURLs returns a new GatheringURLs +func NewGatheringURLs() *GatheringURLs { + gurl := &GatheringURLs{ + GID: types.NewPrimitiveU32(0), + LstStationURLs: types.NewList[*types.StationURL](), + } + + gurl.LstStationURLs.Type = types.NewStationURL("") + + return gurl +} diff --git a/nex-protocols-go/match-making/types/invitation.go b/nex-protocols-go/match-making/types/invitation.go new file mode 100644 index 0000000..8f7b760 --- /dev/null +++ b/nex-protocols-go/match-making/types/invitation.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// Invitation is a type within the Matchmaking protocol +type Invitation struct { + types.Structure + IDGathering *types.PrimitiveU32 + IDGuest *types.PrimitiveU32 + StrMessage *types.String +} + +// WriteTo writes the Invitation to the given writable +func (i *Invitation) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + i.IDGathering.WriteTo(contentWritable) + i.IDGuest.WriteTo(contentWritable) + i.StrMessage.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + i.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the Invitation from the given readable +func (i *Invitation) ExtractFrom(readable types.Readable) error { + var err error + + err = i.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Invitation header. %s", err.Error()) + } + + err = i.IDGathering.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Invitation.IDGathering. %s", err.Error()) + } + + err = i.IDGuest.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Invitation.IDGuest. %s", err.Error()) + } + + err = i.StrMessage.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Invitation.StrMessage. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of Invitation +func (i *Invitation) Copy() types.RVType { + copied := NewInvitation() + + copied.StructureVersion = i.StructureVersion + copied.IDGathering = i.IDGathering.Copy().(*types.PrimitiveU32) + copied.IDGuest = i.IDGuest.Copy().(*types.PrimitiveU32) + copied.StrMessage = i.StrMessage.Copy().(*types.String) + + return copied +} + +// Equals checks if the given Invitation contains the same data as the current Invitation +func (i *Invitation) Equals(o types.RVType) bool { + if _, ok := o.(*Invitation); !ok { + return false + } + + other := o.(*Invitation) + + if i.StructureVersion != other.StructureVersion { + return false + } + + if !i.IDGathering.Equals(other.IDGathering) { + return false + } + + if !i.IDGuest.Equals(other.IDGuest) { + return false + } + + return i.StrMessage.Equals(other.StrMessage) +} + +// String returns the string representation of the Invitation +func (i *Invitation) String() string { + return i.FormatToString(0) +} + +// FormatToString pretty-prints the Invitation using the provided indentation level +func (i *Invitation) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("Invitation{\n") + b.WriteString(fmt.Sprintf("%sIDGathering: %s,\n", indentationValues, i.IDGathering)) + b.WriteString(fmt.Sprintf("%sIDGuest: %s,\n", indentationValues, i.IDGuest)) + b.WriteString(fmt.Sprintf("%sStrMessage: %s,\n", indentationValues, i.StrMessage)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewInvitation returns a new Invitation +func NewInvitation() *Invitation { + i := &Invitation{ + IDGathering: types.NewPrimitiveU32(0), + IDGuest: types.NewPrimitiveU32(0), + StrMessage: types.NewString(""), + } + + return i +} diff --git a/nex-protocols-go/match-making/types/join_matchmake_session_param.go b/nex-protocols-go/match-making/types/join_matchmake_session_param.go new file mode 100644 index 0000000..53d43f4 --- /dev/null +++ b/nex-protocols-go/match-making/types/join_matchmake_session_param.go @@ -0,0 +1,252 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// JoinMatchmakeSessionParam is a type within the Matchmaking protocol +type JoinMatchmakeSessionParam struct { + types.Structure + GID *types.PrimitiveU32 + AdditionalParticipants *types.List[*types.PID] + GIDForParticipationCheck *types.PrimitiveU32 + JoinMatchmakeSessionOption *types.PrimitiveU32 + JoinMatchmakeSessionBehavior *types.PrimitiveU8 + StrUserPassword *types.String + StrSystemPassword *types.String + JoinMessage *types.String + ParticipationCount *types.PrimitiveU16 + ExtraParticipants *types.PrimitiveU16 + BlockListParam *MatchmakeBlockListParam // * NEX v4.0 +} + +// WriteTo writes the JoinMatchmakeSessionParam to the given writable +func (jmsp *JoinMatchmakeSessionParam) WriteTo(writable types.Writable) { + stream := writable.(*nex.ByteStreamOut) + libraryVersion := stream.LibraryVersions.MatchMaking + + contentWritable := writable.CopyNew() + + jmsp.GID.WriteTo(contentWritable) + jmsp.AdditionalParticipants.WriteTo(contentWritable) + jmsp.GIDForParticipationCheck.WriteTo(contentWritable) + jmsp.JoinMatchmakeSessionOption.WriteTo(contentWritable) + jmsp.JoinMatchmakeSessionBehavior.WriteTo(contentWritable) + jmsp.StrUserPassword.WriteTo(contentWritable) + jmsp.StrSystemPassword.WriteTo(contentWritable) + jmsp.JoinMessage.WriteTo(contentWritable) + jmsp.ParticipationCount.WriteTo(contentWritable) + jmsp.ExtraParticipants.WriteTo(contentWritable) + + if libraryVersion.GreaterOrEqual("4.0") { + jmsp.BlockListParam.WriteTo(contentWritable) + } + + content := contentWritable.Bytes() + + jmsp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the JoinMatchmakeSessionParam from the given readable +func (jmsp *JoinMatchmakeSessionParam) ExtractFrom(readable types.Readable) error { + stream := readable.(*nex.ByteStreamIn) + libraryVersion := stream.LibraryVersions.MatchMaking + + var err error + + err = jmsp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract JoinMatchmakeSessionParam header. %s", err.Error()) + } + + err = jmsp.GID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract JoinMatchmakeSessionParam.GID. %s", err.Error()) + } + + err = jmsp.AdditionalParticipants.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract JoinMatchmakeSessionParam.AdditionalParticipants. %s", err.Error()) + } + + err = jmsp.GIDForParticipationCheck.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract JoinMatchmakeSessionParam.GIDForParticipationCheck. %s", err.Error()) + } + + err = jmsp.JoinMatchmakeSessionOption.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract JoinMatchmakeSessionParam.JoinMatchmakeSessionOption. %s", err.Error()) + } + + err = jmsp.JoinMatchmakeSessionBehavior.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract JoinMatchmakeSessionParam.JoinMatchmakeSessionBehavior. %s", err.Error()) + } + + err = jmsp.StrUserPassword.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract JoinMatchmakeSessionParam.StrUserPassword. %s", err.Error()) + } + + err = jmsp.StrSystemPassword.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract JoinMatchmakeSessionParam.StrSystemPassword. %s", err.Error()) + } + + err = jmsp.JoinMessage.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract JoinMatchmakeSessionParam.JoinMessage. %s", err.Error()) + } + + err = jmsp.ParticipationCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract JoinMatchmakeSessionParam.ParticipationCount. %s", err.Error()) + } + + err = jmsp.ExtraParticipants.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract JoinMatchmakeSessionParam.ExtraParticipants. %s", err.Error()) + } + + if libraryVersion.GreaterOrEqual("4.0") { + err = jmsp.BlockListParam.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract JoinMatchmakeSessionParam.BlockListParam. %s", err.Error()) + } + } + + return nil +} + +// Copy returns a new copied instance of JoinMatchmakeSessionParam +func (jmsp *JoinMatchmakeSessionParam) Copy() types.RVType { + copied := NewJoinMatchmakeSessionParam() + + copied.StructureVersion = jmsp.StructureVersion + copied.GID = jmsp.GID.Copy().(*types.PrimitiveU32) + copied.AdditionalParticipants = jmsp.AdditionalParticipants.Copy().(*types.List[*types.PID]) + copied.GIDForParticipationCheck = jmsp.GIDForParticipationCheck.Copy().(*types.PrimitiveU32) + copied.JoinMatchmakeSessionOption = jmsp.JoinMatchmakeSessionOption.Copy().(*types.PrimitiveU32) + copied.JoinMatchmakeSessionBehavior = jmsp.JoinMatchmakeSessionBehavior.Copy().(*types.PrimitiveU8) + copied.StrUserPassword = jmsp.StrUserPassword.Copy().(*types.String) + copied.StrSystemPassword = jmsp.StrSystemPassword.Copy().(*types.String) + copied.JoinMessage = jmsp.JoinMessage.Copy().(*types.String) + copied.ParticipationCount = jmsp.ParticipationCount.Copy().(*types.PrimitiveU16) + copied.ExtraParticipants = jmsp.ExtraParticipants.Copy().(*types.PrimitiveU16) + copied.BlockListParam = jmsp.BlockListParam.Copy().(*MatchmakeBlockListParam) + + return copied +} + +// Equals checks if the given JoinMatchmakeSessionParam contains the same data as the current JoinMatchmakeSessionParam +func (jmsp *JoinMatchmakeSessionParam) Equals(o types.RVType) bool { + if _, ok := o.(*JoinMatchmakeSessionParam); !ok { + return false + } + + other := o.(*JoinMatchmakeSessionParam) + + if jmsp.StructureVersion != other.StructureVersion { + return false + } + + if !jmsp.GID.Equals(other.GID) { + return false + } + + if !jmsp.AdditionalParticipants.Equals(other.AdditionalParticipants) { + return false + } + + if !jmsp.GIDForParticipationCheck.Equals(other.GIDForParticipationCheck) { + return false + } + + if !jmsp.JoinMatchmakeSessionOption.Equals(other.JoinMatchmakeSessionOption) { + return false + } + + if !jmsp.JoinMatchmakeSessionBehavior.Equals(other.JoinMatchmakeSessionBehavior) { + return false + } + + if !jmsp.StrUserPassword.Equals(other.StrUserPassword) { + return false + } + + if !jmsp.StrSystemPassword.Equals(other.StrSystemPassword) { + return false + } + + if !jmsp.JoinMessage.Equals(other.JoinMessage) { + return false + } + + if !jmsp.ParticipationCount.Equals(other.ParticipationCount) { + return false + } + + if !jmsp.ExtraParticipants.Equals(other.ExtraParticipants) { + return false + } + + return jmsp.BlockListParam.Equals(other.BlockListParam) +} + +// String returns the string representation of the JoinMatchmakeSessionParam +func (jmsp *JoinMatchmakeSessionParam) String() string { + return jmsp.FormatToString(0) +} + +// FormatToString pretty-prints the JoinMatchmakeSessionParam using the provided indentation level +func (jmsp *JoinMatchmakeSessionParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("JoinMatchmakeSessionParam{\n") + b.WriteString(fmt.Sprintf("%sGID: %s,\n", indentationValues, jmsp.GID)) + b.WriteString(fmt.Sprintf("%sAdditionalParticipants: %s,\n", indentationValues, jmsp.AdditionalParticipants)) + b.WriteString(fmt.Sprintf("%sGIDForParticipationCheck: %s,\n", indentationValues, jmsp.GIDForParticipationCheck)) + b.WriteString(fmt.Sprintf("%sJoinMatchmakeSessionOption: %s,\n", indentationValues, jmsp.JoinMatchmakeSessionOption)) + b.WriteString(fmt.Sprintf("%sJoinMatchmakeSessionBehavior: %s,\n", indentationValues, jmsp.JoinMatchmakeSessionBehavior)) + b.WriteString(fmt.Sprintf("%sStrUserPassword: %s,\n", indentationValues, jmsp.StrUserPassword)) + b.WriteString(fmt.Sprintf("%sStrSystemPassword: %s,\n", indentationValues, jmsp.StrSystemPassword)) + b.WriteString(fmt.Sprintf("%sJoinMessage: %s,\n", indentationValues, jmsp.JoinMessage)) + b.WriteString(fmt.Sprintf("%sParticipationCount: %s,\n", indentationValues, jmsp.ParticipationCount)) + b.WriteString(fmt.Sprintf("%sExtraParticipants: %s,\n", indentationValues, jmsp.ExtraParticipants)) + b.WriteString(fmt.Sprintf("%sBlockListParam: %s,\n", indentationValues, jmsp.BlockListParam.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewJoinMatchmakeSessionParam returns a new JoinMatchmakeSessionParam +func NewJoinMatchmakeSessionParam() *JoinMatchmakeSessionParam { + jmsp := &JoinMatchmakeSessionParam{ + GID: types.NewPrimitiveU32(0), + AdditionalParticipants: types.NewList[*types.PID](), + GIDForParticipationCheck: types.NewPrimitiveU32(0), + JoinMatchmakeSessionOption: types.NewPrimitiveU32(0), + JoinMatchmakeSessionBehavior: types.NewPrimitiveU8(0), + StrUserPassword: types.NewString(""), + StrSystemPassword: types.NewString(""), + JoinMessage: types.NewString(""), + ParticipationCount: types.NewPrimitiveU16(0), + ExtraParticipants: types.NewPrimitiveU16(0), + BlockListParam: NewMatchmakeBlockListParam(), + } + + jmsp.AdditionalParticipants.Type = types.NewPID(0) + + return jmsp +} diff --git a/nex-protocols-go/match-making/types/matchmake_block_list_param.go b/nex-protocols-go/match-making/types/matchmake_block_list_param.go new file mode 100644 index 0000000..c691d66 --- /dev/null +++ b/nex-protocols-go/match-making/types/matchmake_block_list_param.go @@ -0,0 +1,98 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// MatchmakeBlockListParam is a type within the Matchmaking protocol +type MatchmakeBlockListParam struct { + types.Structure + OptionFlag *types.PrimitiveU32 +} + +// WriteTo writes the MatchmakeBlockListParam to the given writable +func (mblp *MatchmakeBlockListParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + mblp.OptionFlag.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + mblp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MatchmakeBlockListParam from the given readable +func (mblp *MatchmakeBlockListParam) ExtractFrom(readable types.Readable) error { + var err error + + err = mblp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeBlockListParam header. %s", err.Error()) + } + + err = mblp.OptionFlag.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeBlockListParam.OptionFlag. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of MatchmakeBlockListParam +func (mblp *MatchmakeBlockListParam) Copy() types.RVType { + copied := NewMatchmakeBlockListParam() + + copied.StructureVersion = mblp.StructureVersion + copied.OptionFlag = mblp.OptionFlag.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given MatchmakeBlockListParam contains the same data as the current MatchmakeBlockListParam +func (mblp *MatchmakeBlockListParam) Equals(o types.RVType) bool { + if _, ok := o.(*MatchmakeBlockListParam); !ok { + return false + } + + other := o.(*MatchmakeBlockListParam) + + if mblp.StructureVersion != other.StructureVersion { + return false + } + + return mblp.OptionFlag.Equals(other.OptionFlag) +} + +// String returns the string representation of the MatchmakeBlockListParam +func (mblp *MatchmakeBlockListParam) String() string { + return mblp.FormatToString(0) +} + +// FormatToString pretty-prints the MatchmakeBlockListParam using the provided indentation level +func (mblp *MatchmakeBlockListParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MatchmakeBlockListParam{\n") + b.WriteString(fmt.Sprintf("%sOptionFlag: %s,\n", indentationValues, mblp.OptionFlag)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMatchmakeBlockListParam returns a new MatchmakeBlockListParam +func NewMatchmakeBlockListParam() *MatchmakeBlockListParam { + mblp := &MatchmakeBlockListParam{ + OptionFlag: types.NewPrimitiveU32(0), + } + + return mblp +} diff --git a/nex-protocols-go/match-making/types/matchmake_param.go b/nex-protocols-go/match-making/types/matchmake_param.go new file mode 100644 index 0000000..b105e07 --- /dev/null +++ b/nex-protocols-go/match-making/types/matchmake_param.go @@ -0,0 +1,101 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// MatchmakeParam is a type within the Matchmaking protocol +type MatchmakeParam struct { + types.Structure + Params *types.Map[*types.String, *types.Variant] +} + +// WriteTo writes the MatchmakeParam to the given writable +func (mp *MatchmakeParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + mp.Params.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + mp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MatchmakeParam from the given readable +func (mp *MatchmakeParam) ExtractFrom(readable types.Readable) error { + var err error + + err = mp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeParam header. %s", err.Error()) + } + + err = mp.Params.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeParam.Params. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of MatchmakeParam +func (mp *MatchmakeParam) Copy() types.RVType { + copied := NewMatchmakeParam() + + copied.StructureVersion = mp.StructureVersion + copied.Params = mp.Params.Copy().(*types.Map[*types.String, *types.Variant]) + + return copied +} + +// Equals checks if the given MatchmakeParam contains the same data as the current MatchmakeParam +func (mp *MatchmakeParam) Equals(o types.RVType) bool { + if _, ok := o.(*MatchmakeParam); !ok { + return false + } + + other := o.(*MatchmakeParam) + + if mp.StructureVersion != other.StructureVersion { + return false + } + + return mp.Params.Equals(other.Params) +} + +// String returns the string representation of the MatchmakeParam +func (mp *MatchmakeParam) String() string { + return mp.FormatToString(0) +} + +// FormatToString pretty-prints the MatchmakeParam using the provided indentation level +func (mp *MatchmakeParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MatchmakeParam{\n") + b.WriteString(fmt.Sprintf("%sParams: %s,\n", indentationValues, mp.Params.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMatchmakeParam returns a new MatchmakeParam +func NewMatchmakeParam() *MatchmakeParam { + mp := &MatchmakeParam{ + Params: types.NewMap[*types.String, *types.Variant](), + } + + mp.Params.KeyType = types.NewString("") + mp.Params.ValueType = types.NewVariant() + + return mp +} diff --git a/nex-protocols-go/match-making/types/matchmake_session.go b/nex-protocols-go/match-making/types/matchmake_session.go new file mode 100644 index 0000000..6507332 --- /dev/null +++ b/nex-protocols-go/match-making/types/matchmake_session.go @@ -0,0 +1,382 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// MatchmakeSession is a type within the Matchmaking protocol +type MatchmakeSession struct { + types.Structure + *Gathering + GameMode *types.PrimitiveU32 + Attributes *types.List[*types.PrimitiveU32] + OpenParticipation *types.PrimitiveBool + MatchmakeSystemType *types.PrimitiveU32 + ApplicationBuffer *types.Buffer + ParticipationCount *types.PrimitiveU32 + ProgressScore *types.PrimitiveU8 // * NEX v3.4.0 + SessionKey *types.Buffer // * NEX v3.0.0 + Option *types.PrimitiveU32 // * NEX v3.5.0 + MatchmakeParam *MatchmakeParam // * NEX v3.6.0 + StartedTime *types.DateTime // * NEX v3.6.0 + UserPassword *types.String // * NEX v3.7.0 + ReferGID *types.PrimitiveU32 // * NEX v3.8.0 + UserPasswordEnabled *types.PrimitiveBool // * NEX v3.8.0 + SystemPasswordEnabled *types.PrimitiveBool // * NEX v3.8.0 + CodeWord *types.String // * NEX v4.0.0 +} + +// WriteTo writes the MatchmakeSession to the given writable +func (ms *MatchmakeSession) WriteTo(writable types.Writable) { + stream := writable.(*nex.ByteStreamOut) + libraryVersion := stream.LibraryVersions.MatchMaking + + ms.Gathering.WriteTo(writable) + + contentWritable := writable.CopyNew() + + ms.GameMode.WriteTo(contentWritable) + ms.Attributes.WriteTo(contentWritable) + ms.OpenParticipation.WriteTo(contentWritable) + ms.MatchmakeSystemType.WriteTo(contentWritable) + ms.ApplicationBuffer.WriteTo(contentWritable) + ms.ParticipationCount.WriteTo(contentWritable) + + if libraryVersion.GreaterOrEqual("3.4.0") { + ms.ProgressScore.WriteTo(contentWritable) + } + + if libraryVersion.GreaterOrEqual("3.0.0") { + ms.SessionKey.WriteTo(contentWritable) + } + + if libraryVersion.GreaterOrEqual("3.5.0") { + ms.Option.WriteTo(contentWritable) + } + + if libraryVersion.GreaterOrEqual("3.6.0") { + ms.MatchmakeParam.WriteTo(contentWritable) + } + + if libraryVersion.GreaterOrEqual("3.6.0") { + ms.StartedTime.WriteTo(contentWritable) + } + + if libraryVersion.GreaterOrEqual("3.7.0") { + ms.UserPassword.WriteTo(contentWritable) + } + + if libraryVersion.GreaterOrEqual("3.8.0") { + ms.ReferGID.WriteTo(contentWritable) + } + + if libraryVersion.GreaterOrEqual("3.8.0") { + ms.UserPasswordEnabled.WriteTo(contentWritable) + } + + if libraryVersion.GreaterOrEqual("3.8.0") { + ms.SystemPasswordEnabled.WriteTo(contentWritable) + } + + if libraryVersion.GreaterOrEqual("4.0.0") { + ms.CodeWord.WriteTo(contentWritable) + } + + content := contentWritable.Bytes() + + ms.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MatchmakeSession from the given readable +func (ms *MatchmakeSession) ExtractFrom(readable types.Readable) error { + stream := readable.(*nex.ByteStreamIn) + libraryVersion := stream.LibraryVersions.MatchMaking + + var err error + + err = ms.Gathering.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession.Gathering. %s", err.Error()) + } + + err = ms.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession header. %s", err.Error()) + } + + err = ms.GameMode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession.GameMode. %s", err.Error()) + } + + err = ms.Attributes.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession.Attributes. %s", err.Error()) + } + + err = ms.OpenParticipation.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession.OpenParticipation. %s", err.Error()) + } + + err = ms.MatchmakeSystemType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession.MatchmakeSystemType. %s", err.Error()) + } + + err = ms.ApplicationBuffer.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession.ApplicationBuffer. %s", err.Error()) + } + + err = ms.ParticipationCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession.ParticipationCount. %s", err.Error()) + } + + if libraryVersion.GreaterOrEqual("3.4.0") { + err = ms.ProgressScore.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession.ProgressScore. %s", err.Error()) + } + } + + if libraryVersion.GreaterOrEqual("3.0.0") { + err = ms.SessionKey.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession.SessionKey. %s", err.Error()) + } + } + + if libraryVersion.GreaterOrEqual("3.5.0") { + err = ms.Option.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession.Option. %s", err.Error()) + } + } + + if libraryVersion.GreaterOrEqual("3.6.0") { + err = ms.MatchmakeParam.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession.MatchmakeParam. %s", err.Error()) + } + } + + if libraryVersion.GreaterOrEqual("3.6.0") { + err = ms.StartedTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession.StartedTime. %s", err.Error()) + } + } + + if libraryVersion.GreaterOrEqual("3.7.0") { + err = ms.UserPassword.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession.UserPassword. %s", err.Error()) + } + } + + if libraryVersion.GreaterOrEqual("3.8.0") { + err = ms.ReferGID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession.ReferGID. %s", err.Error()) + } + } + + if libraryVersion.GreaterOrEqual("3.8.0") { + err = ms.UserPasswordEnabled.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession.UserPasswordEnabled. %s", err.Error()) + } + } + + if libraryVersion.GreaterOrEqual("3.8.0") { + err = ms.SystemPasswordEnabled.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession.SystemPasswordEnabled. %s", err.Error()) + } + } + + if libraryVersion.GreaterOrEqual("4.0.0") { + err = ms.CodeWord.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSession.CodeWord. %s", err.Error()) + } + } + + return nil +} + +// Copy returns a new copied instance of MatchmakeSession +func (ms *MatchmakeSession) Copy() types.RVType { + copied := NewMatchmakeSession() + + copied.StructureVersion = ms.StructureVersion + copied.Gathering = ms.Gathering.Copy().(*Gathering) + copied.GameMode = ms.GameMode.Copy().(*types.PrimitiveU32) + copied.Attributes = ms.Attributes.Copy().(*types.List[*types.PrimitiveU32]) + copied.OpenParticipation = ms.OpenParticipation.Copy().(*types.PrimitiveBool) + copied.MatchmakeSystemType = ms.MatchmakeSystemType.Copy().(*types.PrimitiveU32) + copied.ApplicationBuffer = ms.ApplicationBuffer.Copy().(*types.Buffer) + copied.ParticipationCount = ms.ParticipationCount.Copy().(*types.PrimitiveU32) + copied.ProgressScore = ms.ProgressScore.Copy().(*types.PrimitiveU8) + copied.SessionKey = ms.SessionKey.Copy().(*types.Buffer) + copied.Option = ms.Option.Copy().(*types.PrimitiveU32) + copied.MatchmakeParam = ms.MatchmakeParam.Copy().(*MatchmakeParam) + copied.StartedTime = ms.StartedTime.Copy().(*types.DateTime) + copied.UserPassword = ms.UserPassword.Copy().(*types.String) + copied.ReferGID = ms.ReferGID.Copy().(*types.PrimitiveU32) + copied.UserPasswordEnabled = ms.UserPasswordEnabled.Copy().(*types.PrimitiveBool) + copied.SystemPasswordEnabled = ms.SystemPasswordEnabled.Copy().(*types.PrimitiveBool) + copied.CodeWord = ms.CodeWord.Copy().(*types.String) + + return copied +} + +// Equals checks if the given MatchmakeSession contains the same data as the current MatchmakeSession +func (ms *MatchmakeSession) Equals(o types.RVType) bool { + if _, ok := o.(*MatchmakeSession); !ok { + return false + } + + other := o.(*MatchmakeSession) + + if ms.StructureVersion != other.StructureVersion { + return false + } + + if !ms.Gathering.Equals(other.Gathering) { + return false + } + + if !ms.GameMode.Equals(other.GameMode) { + return false + } + + if !ms.Attributes.Equals(other.Attributes) { + return false + } + + if !ms.OpenParticipation.Equals(other.OpenParticipation) { + return false + } + + if !ms.MatchmakeSystemType.Equals(other.MatchmakeSystemType) { + return false + } + + if !ms.ApplicationBuffer.Equals(other.ApplicationBuffer) { + return false + } + + if !ms.ParticipationCount.Equals(other.ParticipationCount) { + return false + } + + if !ms.ProgressScore.Equals(other.ProgressScore) { + return false + } + + if !ms.SessionKey.Equals(other.SessionKey) { + return false + } + + if !ms.Option.Equals(other.Option) { + return false + } + + if !ms.MatchmakeParam.Equals(other.MatchmakeParam) { + return false + } + + if !ms.StartedTime.Equals(other.StartedTime) { + return false + } + + if !ms.UserPassword.Equals(other.UserPassword) { + return false + } + + if !ms.ReferGID.Equals(other.ReferGID) { + return false + } + + if !ms.UserPasswordEnabled.Equals(other.UserPasswordEnabled) { + return false + } + + if !ms.SystemPasswordEnabled.Equals(other.SystemPasswordEnabled) { + return false + } + + return ms.CodeWord.Equals(other.CodeWord) +} + +// String returns the string representation of the MatchmakeSession +func (ms *MatchmakeSession) String() string { + return ms.FormatToString(0) +} + +// FormatToString pretty-prints the MatchmakeSession using the provided indentation level +func (ms *MatchmakeSession) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MatchmakeSession{\n") + b.WriteString(fmt.Sprintf("%sGathering (parent): %s,\n", indentationValues, ms.Gathering.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sGameMode: %s,\n", indentationValues, ms.GameMode)) + b.WriteString(fmt.Sprintf("%sAttributes: %s,\n", indentationValues, ms.Attributes)) + b.WriteString(fmt.Sprintf("%sOpenParticipation: %s,\n", indentationValues, ms.OpenParticipation)) + b.WriteString(fmt.Sprintf("%sMatchmakeSystemType: %s,\n", indentationValues, ms.MatchmakeSystemType)) + b.WriteString(fmt.Sprintf("%sApplicationBuffer: %s,\n", indentationValues, ms.ApplicationBuffer)) + b.WriteString(fmt.Sprintf("%sParticipationCount: %s,\n", indentationValues, ms.ParticipationCount)) + b.WriteString(fmt.Sprintf("%sProgressScore: %s,\n", indentationValues, ms.ProgressScore)) + b.WriteString(fmt.Sprintf("%sSessionKey: %s,\n", indentationValues, ms.SessionKey)) + b.WriteString(fmt.Sprintf("%sOption: %s,\n", indentationValues, ms.Option)) + b.WriteString(fmt.Sprintf("%sMatchmakeParam: %s,\n", indentationValues, ms.MatchmakeParam.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sStartedTime: %s,\n", indentationValues, ms.StartedTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUserPassword: %s,\n", indentationValues, ms.UserPassword)) + b.WriteString(fmt.Sprintf("%sReferGID: %s,\n", indentationValues, ms.ReferGID)) + b.WriteString(fmt.Sprintf("%sUserPasswordEnabled: %s,\n", indentationValues, ms.UserPasswordEnabled)) + b.WriteString(fmt.Sprintf("%sSystemPasswordEnabled: %s,\n", indentationValues, ms.SystemPasswordEnabled)) + b.WriteString(fmt.Sprintf("%sCodeWord: %s,\n", indentationValues, ms.CodeWord)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMatchmakeSession returns a new MatchmakeSession +func NewMatchmakeSession() *MatchmakeSession { + ms := &MatchmakeSession{ + Gathering: NewGathering(), + GameMode: types.NewPrimitiveU32(0), + Attributes: types.NewList[*types.PrimitiveU32](), + OpenParticipation: types.NewPrimitiveBool(false), + MatchmakeSystemType: types.NewPrimitiveU32(0), + ApplicationBuffer: types.NewBuffer(nil), + ParticipationCount: types.NewPrimitiveU32(0), + ProgressScore: types.NewPrimitiveU8(0), + SessionKey: types.NewBuffer(nil), + Option: types.NewPrimitiveU32(0), + MatchmakeParam: NewMatchmakeParam(), + StartedTime: types.NewDateTime(0), + UserPassword: types.NewString(""), + ReferGID: types.NewPrimitiveU32(0), + UserPasswordEnabled: types.NewPrimitiveBool(false), + SystemPasswordEnabled: types.NewPrimitiveBool(false), + CodeWord: types.NewString(""), + } + + ms.Attributes.Type = types.NewPrimitiveU32(0) + + return ms +} diff --git a/nex-protocols-go/match-making/types/matchmake_session_search_criteria.go b/nex-protocols-go/match-making/types/matchmake_session_search_criteria.go new file mode 100644 index 0000000..961e76d --- /dev/null +++ b/nex-protocols-go/match-making/types/matchmake_session_search_criteria.go @@ -0,0 +1,357 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// MatchmakeSessionSearchCriteria is a type within the Matchmaking protocol +type MatchmakeSessionSearchCriteria struct { + types.Structure + Attribs *types.List[*types.String] + GameMode *types.String + MinParticipants *types.String + MaxParticipants *types.String + MatchmakeSystemType *types.String + VacantOnly *types.PrimitiveBool + ExcludeLocked *types.PrimitiveBool + ExcludeNonHostPID *types.PrimitiveBool + SelectionMethod *types.PrimitiveU32 // * NEX v3.0.0 + VacantParticipants *types.PrimitiveU16 // * NEX v3.4.0 + MatchmakeParam *MatchmakeParam // * NEX v3.6.0 + ExcludeUserPasswordSet *types.PrimitiveBool // * NEX v3.7.0 + ExcludeSystemPasswordSet *types.PrimitiveBool // * NEX v3.7.0 + ReferGID *types.PrimitiveU32 // * NEX v3.8.0 + CodeWord *types.String // * NEX v4.0.0 + ResultRange *types.ResultRange // * NEX v4.0.0 +} + +// WriteTo writes the MatchmakeSessionSearchCriteria to the given writable +func (mssc *MatchmakeSessionSearchCriteria) WriteTo(writable types.Writable) { + stream := writable.(*nex.ByteStreamOut) + libraryVersion := stream.LibraryVersions.MatchMaking + + contentWritable := writable.CopyNew() + + mssc.Attribs.WriteTo(contentWritable) + mssc.GameMode.WriteTo(contentWritable) + mssc.MinParticipants.WriteTo(contentWritable) + mssc.MaxParticipants.WriteTo(contentWritable) + mssc.MatchmakeSystemType.WriteTo(contentWritable) + mssc.VacantOnly.WriteTo(contentWritable) + mssc.ExcludeLocked.WriteTo(contentWritable) + mssc.ExcludeNonHostPID.WriteTo(contentWritable) + + if libraryVersion.GreaterOrEqual("3.0.0") { + mssc.SelectionMethod.WriteTo(contentWritable) + } + + if libraryVersion.GreaterOrEqual("3.4.0") { + mssc.VacantParticipants.WriteTo(contentWritable) + } + + if libraryVersion.GreaterOrEqual("3.6.0") { + mssc.MatchmakeParam.WriteTo(contentWritable) + } + + if libraryVersion.GreaterOrEqual("3.7.0") { + mssc.ExcludeUserPasswordSet.WriteTo(contentWritable) + } + + if libraryVersion.GreaterOrEqual("3.7.0") { + mssc.ExcludeSystemPasswordSet.WriteTo(contentWritable) + } + + if libraryVersion.GreaterOrEqual("3.8.0") { + mssc.ReferGID.WriteTo(contentWritable) + } + + if libraryVersion.GreaterOrEqual("4.0.0") { + mssc.CodeWord.WriteTo(contentWritable) + } + + if libraryVersion.GreaterOrEqual("4.0.0") { + mssc.ResultRange.WriteTo(contentWritable) + } + + content := contentWritable.Bytes() + + mssc.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MatchmakeSessionSearchCriteria from the given readable +func (mssc *MatchmakeSessionSearchCriteria) ExtractFrom(readable types.Readable) error { + stream := readable.(*nex.ByteStreamIn) + libraryVersion := stream.LibraryVersions.MatchMaking + + var err error + + err = mssc.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSessionSearchCriteria header. %s", err.Error()) + } + + err = mssc.Attribs.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSessionSearchCriteria.Attribs. %s", err.Error()) + } + + err = mssc.GameMode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSessionSearchCriteria.GameMode. %s", err.Error()) + } + + err = mssc.MinParticipants.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSessionSearchCriteria.MinParticipants. %s", err.Error()) + } + + err = mssc.MaxParticipants.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSessionSearchCriteria.MaxParticipants. %s", err.Error()) + } + + err = mssc.MatchmakeSystemType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSessionSearchCriteria.MatchmakeSystemType. %s", err.Error()) + } + + err = mssc.VacantOnly.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSessionSearchCriteria.VacantOnly. %s", err.Error()) + } + + err = mssc.ExcludeLocked.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSessionSearchCriteria.ExcludeLocked. %s", err.Error()) + } + + err = mssc.ExcludeNonHostPID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSessionSearchCriteria.ExcludeNonHostPID. %s", err.Error()) + } + + if libraryVersion.GreaterOrEqual("3.0.0") { + err = mssc.SelectionMethod.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSessionSearchCriteria.SelectionMethod. %s", err.Error()) + } + } + + if libraryVersion.GreaterOrEqual("3.4.0") { + err = mssc.VacantParticipants.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSessionSearchCriteria.VacantParticipants. %s", err.Error()) + } + } + + if libraryVersion.GreaterOrEqual("3.6.0") { + err = mssc.MatchmakeParam.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSessionSearchCriteria.MatchmakeParam. %s", err.Error()) + } + } + + if libraryVersion.GreaterOrEqual("3.7.0") { + err = mssc.ExcludeUserPasswordSet.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSessionSearchCriteria.ExcludeUserPasswordSet. %s", err.Error()) + } + } + + if libraryVersion.GreaterOrEqual("3.7.0") { + err = mssc.ExcludeSystemPasswordSet.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSessionSearchCriteria.ExcludeSystemPasswordSet. %s", err.Error()) + } + } + + if libraryVersion.GreaterOrEqual("3.8.0") { + err = mssc.ReferGID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSessionSearchCriteria.ReferGID. %s", err.Error()) + } + } + + if libraryVersion.GreaterOrEqual("4.0.0") { + err = mssc.CodeWord.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSessionSearchCriteria.CodeWord. %s", err.Error()) + } + } + + if libraryVersion.GreaterOrEqual("4.0.0") { + err = mssc.ResultRange.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeSessionSearchCriteria.ResultRange. %s", err.Error()) + } + } + + return nil +} + +// Copy returns a new copied instance of MatchmakeSessionSearchCriteria +func (mssc *MatchmakeSessionSearchCriteria) Copy() types.RVType { + copied := NewMatchmakeSessionSearchCriteria() + + copied.StructureVersion = mssc.StructureVersion + copied.Attribs = mssc.Attribs.Copy().(*types.List[*types.String]) + copied.GameMode = mssc.GameMode.Copy().(*types.String) + copied.MinParticipants = mssc.MinParticipants.Copy().(*types.String) + copied.MaxParticipants = mssc.MaxParticipants.Copy().(*types.String) + copied.MatchmakeSystemType = mssc.MatchmakeSystemType.Copy().(*types.String) + copied.VacantOnly = mssc.VacantOnly.Copy().(*types.PrimitiveBool) + copied.ExcludeLocked = mssc.ExcludeLocked.Copy().(*types.PrimitiveBool) + copied.ExcludeNonHostPID = mssc.ExcludeNonHostPID.Copy().(*types.PrimitiveBool) + copied.SelectionMethod = mssc.SelectionMethod.Copy().(*types.PrimitiveU32) + copied.VacantParticipants = mssc.VacantParticipants.Copy().(*types.PrimitiveU16) + copied.MatchmakeParam = mssc.MatchmakeParam.Copy().(*MatchmakeParam) + copied.ExcludeUserPasswordSet = mssc.ExcludeUserPasswordSet.Copy().(*types.PrimitiveBool) + copied.ExcludeSystemPasswordSet = mssc.ExcludeSystemPasswordSet.Copy().(*types.PrimitiveBool) + copied.ReferGID = mssc.ReferGID.Copy().(*types.PrimitiveU32) + copied.CodeWord = mssc.CodeWord.Copy().(*types.String) + copied.ResultRange = mssc.ResultRange.Copy().(*types.ResultRange) + + return copied +} + +// Equals checks if the given MatchmakeSessionSearchCriteria contains the same data as the current MatchmakeSessionSearchCriteria +func (mssc *MatchmakeSessionSearchCriteria) Equals(o types.RVType) bool { + if _, ok := o.(*MatchmakeSessionSearchCriteria); !ok { + return false + } + + other := o.(*MatchmakeSessionSearchCriteria) + + if mssc.StructureVersion != other.StructureVersion { + return false + } + + if !mssc.Attribs.Equals(other.Attribs) { + return false + } + + if !mssc.GameMode.Equals(other.GameMode) { + return false + } + + if !mssc.MinParticipants.Equals(other.MinParticipants) { + return false + } + + if !mssc.MaxParticipants.Equals(other.MaxParticipants) { + return false + } + + if !mssc.MatchmakeSystemType.Equals(other.MatchmakeSystemType) { + return false + } + + if !mssc.VacantOnly.Equals(other.VacantOnly) { + return false + } + + if !mssc.ExcludeLocked.Equals(other.ExcludeLocked) { + return false + } + + if !mssc.ExcludeNonHostPID.Equals(other.ExcludeNonHostPID) { + return false + } + + if !mssc.SelectionMethod.Equals(other.SelectionMethod) { + return false + } + + if !mssc.VacantParticipants.Equals(other.VacantParticipants) { + return false + } + + if !mssc.MatchmakeParam.Equals(other.MatchmakeParam) { + return false + } + + if !mssc.ExcludeUserPasswordSet.Equals(other.ExcludeUserPasswordSet) { + return false + } + + if !mssc.ExcludeSystemPasswordSet.Equals(other.ExcludeSystemPasswordSet) { + return false + } + + if !mssc.ReferGID.Equals(other.ReferGID) { + return false + } + + if !mssc.CodeWord.Equals(other.CodeWord) { + return false + } + + return mssc.ResultRange.Equals(other.ResultRange) +} + +// String returns the string representation of the MatchmakeSessionSearchCriteria +func (mssc *MatchmakeSessionSearchCriteria) String() string { + return mssc.FormatToString(0) +} + +// FormatToString pretty-prints the MatchmakeSessionSearchCriteria using the provided indentation level +func (mssc *MatchmakeSessionSearchCriteria) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MatchmakeSessionSearchCriteria{\n") + b.WriteString(fmt.Sprintf("%sAttribs: %s,\n", indentationValues, mssc.Attribs)) + b.WriteString(fmt.Sprintf("%sGameMode: %s,\n", indentationValues, mssc.GameMode)) + b.WriteString(fmt.Sprintf("%sMinParticipants: %s,\n", indentationValues, mssc.MinParticipants)) + b.WriteString(fmt.Sprintf("%sMaxParticipants: %s,\n", indentationValues, mssc.MaxParticipants)) + b.WriteString(fmt.Sprintf("%sMatchmakeSystemType: %s,\n", indentationValues, mssc.MatchmakeSystemType)) + b.WriteString(fmt.Sprintf("%sVacantOnly: %s,\n", indentationValues, mssc.VacantOnly)) + b.WriteString(fmt.Sprintf("%sExcludeLocked: %s,\n", indentationValues, mssc.ExcludeLocked)) + b.WriteString(fmt.Sprintf("%sExcludeNonHostPID: %s,\n", indentationValues, mssc.ExcludeNonHostPID)) + b.WriteString(fmt.Sprintf("%sSelectionMethod: %s,\n", indentationValues, mssc.SelectionMethod)) + b.WriteString(fmt.Sprintf("%sVacantParticipants: %s,\n", indentationValues, mssc.VacantParticipants)) + b.WriteString(fmt.Sprintf("%sMatchmakeParam: %s,\n", indentationValues, mssc.MatchmakeParam.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sExcludeUserPasswordSet: %s,\n", indentationValues, mssc.ExcludeUserPasswordSet)) + b.WriteString(fmt.Sprintf("%sExcludeSystemPasswordSet: %s,\n", indentationValues, mssc.ExcludeSystemPasswordSet)) + b.WriteString(fmt.Sprintf("%sReferGID: %s,\n", indentationValues, mssc.ReferGID)) + b.WriteString(fmt.Sprintf("%sCodeWord: %s,\n", indentationValues, mssc.CodeWord)) + b.WriteString(fmt.Sprintf("%sResultRange: %s,\n", indentationValues, mssc.ResultRange.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMatchmakeSessionSearchCriteria returns a new MatchmakeSessionSearchCriteria +func NewMatchmakeSessionSearchCriteria() *MatchmakeSessionSearchCriteria { + mssc := &MatchmakeSessionSearchCriteria{ + Attribs: types.NewList[*types.String](), + GameMode: types.NewString(""), + MinParticipants: types.NewString(""), + MaxParticipants: types.NewString(""), + MatchmakeSystemType: types.NewString(""), + VacantOnly: types.NewPrimitiveBool(false), + ExcludeLocked: types.NewPrimitiveBool(false), + ExcludeNonHostPID: types.NewPrimitiveBool(false), + SelectionMethod: types.NewPrimitiveU32(0), + VacantParticipants: types.NewPrimitiveU16(0), + MatchmakeParam: NewMatchmakeParam(), + ExcludeUserPasswordSet: types.NewPrimitiveBool(false), + ExcludeSystemPasswordSet: types.NewPrimitiveBool(false), + ReferGID: types.NewPrimitiveU32(0), + CodeWord: types.NewString(""), + ResultRange: types.NewResultRange(), + } + + mssc.Attribs.Type = types.NewString("") + + return mssc +} diff --git a/nex-protocols-go/match-making/types/participant_details.go b/nex-protocols-go/match-making/types/participant_details.go new file mode 100644 index 0000000..6569e9b --- /dev/null +++ b/nex-protocols-go/match-making/types/participant_details.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ParticipantDetails is a type within the Matchmaking protocol +type ParticipantDetails struct { + types.Structure + IDParticipant *types.PID + StrName *types.String + StrMessage *types.String + UIParticipants *types.PrimitiveU16 +} + +// WriteTo writes the ParticipantDetails to the given writable +func (pd *ParticipantDetails) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + pd.IDParticipant.WriteTo(contentWritable) + pd.StrName.WriteTo(contentWritable) + pd.StrMessage.WriteTo(contentWritable) + pd.UIParticipants.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + pd.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ParticipantDetails from the given readable +func (pd *ParticipantDetails) ExtractFrom(readable types.Readable) error { + var err error + + err = pd.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ParticipantDetails header. %s", err.Error()) + } + + err = pd.IDParticipant.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ParticipantDetails.IDParticipant. %s", err.Error()) + } + + err = pd.StrName.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ParticipantDetails.StrName. %s", err.Error()) + } + + err = pd.StrMessage.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ParticipantDetails.StrMessage. %s", err.Error()) + } + + err = pd.UIParticipants.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ParticipantDetails.UIParticipants. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ParticipantDetails +func (pd *ParticipantDetails) Copy() types.RVType { + copied := NewParticipantDetails() + + copied.StructureVersion = pd.StructureVersion + copied.IDParticipant = pd.IDParticipant.Copy().(*types.PID) + copied.StrName = pd.StrName.Copy().(*types.String) + copied.StrMessage = pd.StrMessage.Copy().(*types.String) + copied.UIParticipants = pd.UIParticipants.Copy().(*types.PrimitiveU16) + + return copied +} + +// Equals checks if the given ParticipantDetails contains the same data as the current ParticipantDetails +func (pd *ParticipantDetails) Equals(o types.RVType) bool { + if _, ok := o.(*ParticipantDetails); !ok { + return false + } + + other := o.(*ParticipantDetails) + + if pd.StructureVersion != other.StructureVersion { + return false + } + + if !pd.IDParticipant.Equals(other.IDParticipant) { + return false + } + + if !pd.StrName.Equals(other.StrName) { + return false + } + + if !pd.StrMessage.Equals(other.StrMessage) { + return false + } + + return pd.UIParticipants.Equals(other.UIParticipants) +} + +// String returns the string representation of the ParticipantDetails +func (pd *ParticipantDetails) String() string { + return pd.FormatToString(0) +} + +// FormatToString pretty-prints the ParticipantDetails using the provided indentation level +func (pd *ParticipantDetails) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ParticipantDetails{\n") + b.WriteString(fmt.Sprintf("%sIDParticipant: %s,\n", indentationValues, pd.IDParticipant.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sStrName: %s,\n", indentationValues, pd.StrName)) + b.WriteString(fmt.Sprintf("%sStrMessage: %s,\n", indentationValues, pd.StrMessage)) + b.WriteString(fmt.Sprintf("%sUIParticipants: %s,\n", indentationValues, pd.UIParticipants)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewParticipantDetails returns a new ParticipantDetails +func NewParticipantDetails() *ParticipantDetails { + pd := &ParticipantDetails{ + IDParticipant: types.NewPID(0), + StrName: types.NewString(""), + StrMessage: types.NewString(""), + UIParticipants: types.NewPrimitiveU16(0), + } + + return pd +} diff --git a/nex-protocols-go/match-making/types/persistent_gathering.go b/nex-protocols-go/match-making/types/persistent_gathering.go new file mode 100644 index 0000000..b623500 --- /dev/null +++ b/nex-protocols-go/match-making/types/persistent_gathering.go @@ -0,0 +1,213 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// PersistentGathering is a type within the Matchmaking protocol +type PersistentGathering struct { + types.Structure + *Gathering + CommunityType *types.PrimitiveU32 + Password *types.String + Attribs *types.List[*types.PrimitiveU32] + ApplicationBuffer *types.Buffer + ParticipationStartDate *types.DateTime + ParticipationEndDate *types.DateTime + MatchmakeSessionCount *types.PrimitiveU32 + ParticipationCount *types.PrimitiveU32 +} + +// WriteTo writes the PersistentGathering to the given writable +func (pg *PersistentGathering) WriteTo(writable types.Writable) { + pg.Gathering.WriteTo(writable) + + contentWritable := writable.CopyNew() + + pg.CommunityType.WriteTo(contentWritable) + pg.Password.WriteTo(contentWritable) + pg.Attribs.WriteTo(contentWritable) + pg.ApplicationBuffer.WriteTo(contentWritable) + pg.ParticipationStartDate.WriteTo(contentWritable) + pg.ParticipationEndDate.WriteTo(contentWritable) + pg.MatchmakeSessionCount.WriteTo(contentWritable) + pg.ParticipationCount.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + pg.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the PersistentGathering from the given readable +func (pg *PersistentGathering) ExtractFrom(readable types.Readable) error { + var err error + + err = pg.Gathering.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentGathering.Gathering. %s", err.Error()) + } + + err = pg.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentGathering header. %s", err.Error()) + } + + err = pg.CommunityType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentGathering.CommunityType. %s", err.Error()) + } + + err = pg.Password.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentGathering.Password. %s", err.Error()) + } + + err = pg.Attribs.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentGathering.Attribs. %s", err.Error()) + } + + err = pg.ApplicationBuffer.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentGathering.ApplicationBuffer. %s", err.Error()) + } + + err = pg.ParticipationStartDate.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentGathering.ParticipationStartDate. %s", err.Error()) + } + + err = pg.ParticipationEndDate.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentGathering.ParticipationEndDate. %s", err.Error()) + } + + err = pg.MatchmakeSessionCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentGathering.MatchmakeSessionCount. %s", err.Error()) + } + + err = pg.ParticipationCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PersistentGathering.ParticipationCount. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of PersistentGathering +func (pg *PersistentGathering) Copy() types.RVType { + copied := NewPersistentGathering() + + copied.StructureVersion = pg.StructureVersion + copied.Gathering = pg.Gathering.Copy().(*Gathering) + copied.CommunityType = pg.CommunityType.Copy().(*types.PrimitiveU32) + copied.Password = pg.Password.Copy().(*types.String) + copied.Attribs = pg.Attribs.Copy().(*types.List[*types.PrimitiveU32]) + copied.ApplicationBuffer = pg.ApplicationBuffer.Copy().(*types.Buffer) + copied.ParticipationStartDate = pg.ParticipationStartDate.Copy().(*types.DateTime) + copied.ParticipationEndDate = pg.ParticipationEndDate.Copy().(*types.DateTime) + copied.MatchmakeSessionCount = pg.MatchmakeSessionCount.Copy().(*types.PrimitiveU32) + copied.ParticipationCount = pg.ParticipationCount.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given PersistentGathering contains the same data as the current PersistentGathering +func (pg *PersistentGathering) Equals(o types.RVType) bool { + if _, ok := o.(*PersistentGathering); !ok { + return false + } + + other := o.(*PersistentGathering) + + if pg.StructureVersion != other.StructureVersion { + return false + } + + if !pg.Gathering.Equals(other.Gathering) { + return false + } + + if !pg.CommunityType.Equals(other.CommunityType) { + return false + } + + if !pg.Password.Equals(other.Password) { + return false + } + + if !pg.Attribs.Equals(other.Attribs) { + return false + } + + if !pg.ApplicationBuffer.Equals(other.ApplicationBuffer) { + return false + } + + if !pg.ParticipationStartDate.Equals(other.ParticipationStartDate) { + return false + } + + if !pg.ParticipationEndDate.Equals(other.ParticipationEndDate) { + return false + } + + if !pg.MatchmakeSessionCount.Equals(other.MatchmakeSessionCount) { + return false + } + + return pg.ParticipationCount.Equals(other.ParticipationCount) +} + +// String returns the string representation of the PersistentGathering +func (pg *PersistentGathering) String() string { + return pg.FormatToString(0) +} + +// FormatToString pretty-prints the PersistentGathering using the provided indentation level +func (pg *PersistentGathering) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("PersistentGathering{\n") + b.WriteString(fmt.Sprintf("%sGathering (parent): %s,\n", indentationValues, pg.Gathering.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sCommunityType: %s,\n", indentationValues, pg.CommunityType)) + b.WriteString(fmt.Sprintf("%sPassword: %s,\n", indentationValues, pg.Password)) + b.WriteString(fmt.Sprintf("%sAttribs: %s,\n", indentationValues, pg.Attribs)) + b.WriteString(fmt.Sprintf("%sApplicationBuffer: %s,\n", indentationValues, pg.ApplicationBuffer)) + b.WriteString(fmt.Sprintf("%sParticipationStartDate: %s,\n", indentationValues, pg.ParticipationStartDate.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sParticipationEndDate: %s,\n", indentationValues, pg.ParticipationEndDate.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sMatchmakeSessionCount: %s,\n", indentationValues, pg.MatchmakeSessionCount)) + b.WriteString(fmt.Sprintf("%sParticipationCount: %s,\n", indentationValues, pg.ParticipationCount)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewPersistentGathering returns a new PersistentGathering +func NewPersistentGathering() *PersistentGathering { + pg := &PersistentGathering{ + Gathering: NewGathering(), + CommunityType: types.NewPrimitiveU32(0), + Password: types.NewString(""), + Attribs: types.NewList[*types.PrimitiveU32](), + ApplicationBuffer: types.NewBuffer(nil), + ParticipationStartDate: types.NewDateTime(0), + ParticipationEndDate: types.NewDateTime(0), + MatchmakeSessionCount: types.NewPrimitiveU32(0), + ParticipationCount: types.NewPrimitiveU32(0), + } + + pg.Attribs.Type = types.NewPrimitiveU32(0) + + return pg +} diff --git a/nex-protocols-go/match-making/types/playing_session.go b/nex-protocols-go/match-making/types/playing_session.go new file mode 100644 index 0000000..25a1fa2 --- /dev/null +++ b/nex-protocols-go/match-making/types/playing_session.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// PlayingSession is a type within the Matchmaking protocol +type PlayingSession struct { + types.Structure + PrincipalID *types.PID + Gathering *types.AnyDataHolder +} + +// WriteTo writes the PlayingSession to the given writable +func (ps *PlayingSession) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + ps.PrincipalID.WriteTo(contentWritable) + ps.Gathering.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + ps.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the PlayingSession from the given readable +func (ps *PlayingSession) ExtractFrom(readable types.Readable) error { + var err error + + err = ps.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PlayingSession header. %s", err.Error()) + } + + err = ps.PrincipalID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PlayingSession.PrincipalID. %s", err.Error()) + } + + err = ps.Gathering.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract PlayingSession.Gathering. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of PlayingSession +func (ps *PlayingSession) Copy() types.RVType { + copied := NewPlayingSession() + + copied.StructureVersion = ps.StructureVersion + copied.PrincipalID = ps.PrincipalID.Copy().(*types.PID) + copied.Gathering = ps.Gathering.Copy().(*types.AnyDataHolder) + + return copied +} + +// Equals checks if the given PlayingSession contains the same data as the current PlayingSession +func (ps *PlayingSession) Equals(o types.RVType) bool { + if _, ok := o.(*PlayingSession); !ok { + return false + } + + other := o.(*PlayingSession) + + if ps.StructureVersion != other.StructureVersion { + return false + } + + if !ps.PrincipalID.Equals(other.PrincipalID) { + return false + } + + return ps.Gathering.Equals(other.Gathering) +} + +// String returns the string representation of the PlayingSession +func (ps *PlayingSession) String() string { + return ps.FormatToString(0) +} + +// FormatToString pretty-prints the PlayingSession using the provided indentation level +func (ps *PlayingSession) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("PlayingSession{\n") + b.WriteString(fmt.Sprintf("%sPrincipalID: %s,\n", indentationValues, ps.PrincipalID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sGathering: %s,\n", indentationValues, ps.Gathering.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewPlayingSession returns a new PlayingSession +func NewPlayingSession() *PlayingSession { + ps := &PlayingSession{ + PrincipalID: types.NewPID(0), + Gathering: types.NewAnyDataHolder(), + } + + return ps +} diff --git a/nex-protocols-go/match-making/types/simple_community.go b/nex-protocols-go/match-making/types/simple_community.go new file mode 100644 index 0000000..4a71ce9 --- /dev/null +++ b/nex-protocols-go/match-making/types/simple_community.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// SimpleCommunity is a type within the Matchmaking protocol +type SimpleCommunity struct { + types.Structure + GatheringID *types.PrimitiveU32 + MatchmakeSessionCount *types.PrimitiveU32 +} + +// WriteTo writes the SimpleCommunity to the given writable +func (sc *SimpleCommunity) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sc.GatheringID.WriteTo(contentWritable) + sc.MatchmakeSessionCount.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sc.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the SimpleCommunity from the given readable +func (sc *SimpleCommunity) ExtractFrom(readable types.Readable) error { + var err error + + err = sc.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleCommunity header. %s", err.Error()) + } + + err = sc.GatheringID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleCommunity.GatheringID. %s", err.Error()) + } + + err = sc.MatchmakeSessionCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleCommunity.MatchmakeSessionCount. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of SimpleCommunity +func (sc *SimpleCommunity) Copy() types.RVType { + copied := NewSimpleCommunity() + + copied.StructureVersion = sc.StructureVersion + copied.GatheringID = sc.GatheringID.Copy().(*types.PrimitiveU32) + copied.MatchmakeSessionCount = sc.MatchmakeSessionCount.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given SimpleCommunity contains the same data as the current SimpleCommunity +func (sc *SimpleCommunity) Equals(o types.RVType) bool { + if _, ok := o.(*SimpleCommunity); !ok { + return false + } + + other := o.(*SimpleCommunity) + + if sc.StructureVersion != other.StructureVersion { + return false + } + + if !sc.GatheringID.Equals(other.GatheringID) { + return false + } + + return sc.MatchmakeSessionCount.Equals(other.MatchmakeSessionCount) +} + +// String returns the string representation of the SimpleCommunity +func (sc *SimpleCommunity) String() string { + return sc.FormatToString(0) +} + +// FormatToString pretty-prints the SimpleCommunity using the provided indentation level +func (sc *SimpleCommunity) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("SimpleCommunity{\n") + b.WriteString(fmt.Sprintf("%sGatheringID: %s,\n", indentationValues, sc.GatheringID)) + b.WriteString(fmt.Sprintf("%sMatchmakeSessionCount: %s,\n", indentationValues, sc.MatchmakeSessionCount)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewSimpleCommunity returns a new SimpleCommunity +func NewSimpleCommunity() *SimpleCommunity { + sc := &SimpleCommunity{ + GatheringID: types.NewPrimitiveU32(0), + MatchmakeSessionCount: types.NewPrimitiveU32(0), + } + + return sc +} diff --git a/nex-protocols-go/match-making/types/simple_playing_session.go b/nex-protocols-go/match-making/types/simple_playing_session.go new file mode 100644 index 0000000..964dfab --- /dev/null +++ b/nex-protocols-go/match-making/types/simple_playing_session.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// SimplePlayingSession is a type within the Matchmaking protocol +type SimplePlayingSession struct { + types.Structure + PrincipalID *types.PID + GatheringID *types.PrimitiveU32 + GameMode *types.PrimitiveU32 + Attribute0 *types.PrimitiveU32 +} + +// WriteTo writes the SimplePlayingSession to the given writable +func (sps *SimplePlayingSession) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sps.PrincipalID.WriteTo(contentWritable) + sps.GatheringID.WriteTo(contentWritable) + sps.GameMode.WriteTo(contentWritable) + sps.Attribute0.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sps.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the SimplePlayingSession from the given readable +func (sps *SimplePlayingSession) ExtractFrom(readable types.Readable) error { + var err error + + err = sps.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimplePlayingSession header. %s", err.Error()) + } + + err = sps.PrincipalID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimplePlayingSession.PrincipalID. %s", err.Error()) + } + + err = sps.GatheringID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimplePlayingSession.GatheringID. %s", err.Error()) + } + + err = sps.GameMode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimplePlayingSession.GameMode. %s", err.Error()) + } + + err = sps.Attribute0.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimplePlayingSession.Attribute0. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of SimplePlayingSession +func (sps *SimplePlayingSession) Copy() types.RVType { + copied := NewSimplePlayingSession() + + copied.StructureVersion = sps.StructureVersion + copied.PrincipalID = sps.PrincipalID.Copy().(*types.PID) + copied.GatheringID = sps.GatheringID.Copy().(*types.PrimitiveU32) + copied.GameMode = sps.GameMode.Copy().(*types.PrimitiveU32) + copied.Attribute0 = sps.Attribute0.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given SimplePlayingSession contains the same data as the current SimplePlayingSession +func (sps *SimplePlayingSession) Equals(o types.RVType) bool { + if _, ok := o.(*SimplePlayingSession); !ok { + return false + } + + other := o.(*SimplePlayingSession) + + if sps.StructureVersion != other.StructureVersion { + return false + } + + if !sps.PrincipalID.Equals(other.PrincipalID) { + return false + } + + if !sps.GatheringID.Equals(other.GatheringID) { + return false + } + + if !sps.GameMode.Equals(other.GameMode) { + return false + } + + return sps.Attribute0.Equals(other.Attribute0) +} + +// String returns the string representation of the SimplePlayingSession +func (sps *SimplePlayingSession) String() string { + return sps.FormatToString(0) +} + +// FormatToString pretty-prints the SimplePlayingSession using the provided indentation level +func (sps *SimplePlayingSession) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("SimplePlayingSession{\n") + b.WriteString(fmt.Sprintf("%sPrincipalID: %s,\n", indentationValues, sps.PrincipalID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sGatheringID: %s,\n", indentationValues, sps.GatheringID)) + b.WriteString(fmt.Sprintf("%sGameMode: %s,\n", indentationValues, sps.GameMode)) + b.WriteString(fmt.Sprintf("%sAttribute0: %s,\n", indentationValues, sps.Attribute0)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewSimplePlayingSession returns a new SimplePlayingSession +func NewSimplePlayingSession() *SimplePlayingSession { + sps := &SimplePlayingSession{ + PrincipalID: types.NewPID(0), + GatheringID: types.NewPrimitiveU32(0), + GameMode: types.NewPrimitiveU32(0), + Attribute0: types.NewPrimitiveU32(0), + } + + return sps +} diff --git a/nex-protocols-go/match-making/types/update_matchmake_session_param.go b/nex-protocols-go/match-making/types/update_matchmake_session_param.go new file mode 100644 index 0000000..1e1950f --- /dev/null +++ b/nex-protocols-go/match-making/types/update_matchmake_session_param.go @@ -0,0 +1,324 @@ +// Package types implements all the types used by the Matchmaking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// UpdateMatchmakeSessionParam is a type within the Matchmaking protocol +type UpdateMatchmakeSessionParam struct { + types.Structure + GID *types.PrimitiveU32 + ModificationFlag *types.PrimitiveU32 + Attributes *types.List[*types.PrimitiveU32] + OpenParticipation *types.PrimitiveBool + ApplicationBuffer *types.Buffer + ProgressScore *types.PrimitiveU8 + MatchmakeParam *MatchmakeParam + StartedTime *types.DateTime + UserPassword *types.String + GameMode *types.PrimitiveU32 + Description *types.String + MinParticipants *types.PrimitiveU16 + MaxParticipants *types.PrimitiveU16 + MatchmakeSystemType *types.PrimitiveU32 + ParticipationPolicy *types.PrimitiveU32 + PolicyArgument *types.PrimitiveU32 + Codeword *types.String +} + +// WriteTo writes the UpdateMatchmakeSessionParam to the given writable +func (umsp *UpdateMatchmakeSessionParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + umsp.GID.WriteTo(contentWritable) + umsp.ModificationFlag.WriteTo(contentWritable) + umsp.Attributes.WriteTo(contentWritable) + umsp.OpenParticipation.WriteTo(contentWritable) + umsp.ApplicationBuffer.WriteTo(contentWritable) + umsp.ProgressScore.WriteTo(contentWritable) + umsp.MatchmakeParam.WriteTo(contentWritable) + umsp.StartedTime.WriteTo(contentWritable) + umsp.UserPassword.WriteTo(contentWritable) + umsp.GameMode.WriteTo(contentWritable) + umsp.Description.WriteTo(contentWritable) + umsp.MinParticipants.WriteTo(contentWritable) + umsp.MaxParticipants.WriteTo(contentWritable) + umsp.MatchmakeSystemType.WriteTo(contentWritable) + umsp.ParticipationPolicy.WriteTo(contentWritable) + umsp.PolicyArgument.WriteTo(contentWritable) + umsp.Codeword.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + umsp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the UpdateMatchmakeSessionParam from the given readable +func (umsp *UpdateMatchmakeSessionParam) ExtractFrom(readable types.Readable) error { + var err error + + err = umsp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam header. %s", err.Error()) + } + + err = umsp.GID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam.GID. %s", err.Error()) + } + + err = umsp.ModificationFlag.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam.ModificationFlag. %s", err.Error()) + } + + err = umsp.Attributes.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam.Attributes. %s", err.Error()) + } + + err = umsp.OpenParticipation.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam.OpenParticipation. %s", err.Error()) + } + + err = umsp.ApplicationBuffer.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam.ApplicationBuffer. %s", err.Error()) + } + + err = umsp.ProgressScore.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam.ProgressScore. %s", err.Error()) + } + + err = umsp.MatchmakeParam.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam.MatchmakeParam. %s", err.Error()) + } + + err = umsp.StartedTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam.StartedTime. %s", err.Error()) + } + + err = umsp.UserPassword.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam.UserPassword. %s", err.Error()) + } + + err = umsp.GameMode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam.GameMode. %s", err.Error()) + } + + err = umsp.Description.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam.Description. %s", err.Error()) + } + + err = umsp.MinParticipants.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam.MinParticipants. %s", err.Error()) + } + + err = umsp.MaxParticipants.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam.MaxParticipants. %s", err.Error()) + } + + err = umsp.MatchmakeSystemType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam.MatchmakeSystemType. %s", err.Error()) + } + + err = umsp.ParticipationPolicy.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam.ParticipationPolicy. %s", err.Error()) + } + + err = umsp.PolicyArgument.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam.PolicyArgument. %s", err.Error()) + } + + err = umsp.Codeword.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UpdateMatchmakeSessionParam.Codeword. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of UpdateMatchmakeSessionParam +func (umsp *UpdateMatchmakeSessionParam) Copy() types.RVType { + copied := NewUpdateMatchmakeSessionParam() + + copied.StructureVersion = umsp.StructureVersion + copied.GID = umsp.GID.Copy().(*types.PrimitiveU32) + copied.ModificationFlag = umsp.ModificationFlag.Copy().(*types.PrimitiveU32) + copied.Attributes = umsp.Attributes.Copy().(*types.List[*types.PrimitiveU32]) + copied.OpenParticipation = umsp.OpenParticipation.Copy().(*types.PrimitiveBool) + copied.ApplicationBuffer = umsp.ApplicationBuffer.Copy().(*types.Buffer) + copied.ProgressScore = umsp.ProgressScore.Copy().(*types.PrimitiveU8) + copied.MatchmakeParam = umsp.MatchmakeParam.Copy().(*MatchmakeParam) + copied.StartedTime = umsp.StartedTime.Copy().(*types.DateTime) + copied.UserPassword = umsp.UserPassword.Copy().(*types.String) + copied.GameMode = umsp.GameMode.Copy().(*types.PrimitiveU32) + copied.Description = umsp.Description.Copy().(*types.String) + copied.MinParticipants = umsp.MinParticipants.Copy().(*types.PrimitiveU16) + copied.MaxParticipants = umsp.MaxParticipants.Copy().(*types.PrimitiveU16) + copied.MatchmakeSystemType = umsp.MatchmakeSystemType.Copy().(*types.PrimitiveU32) + copied.ParticipationPolicy = umsp.ParticipationPolicy.Copy().(*types.PrimitiveU32) + copied.PolicyArgument = umsp.PolicyArgument.Copy().(*types.PrimitiveU32) + copied.Codeword = umsp.Codeword.Copy().(*types.String) + + return copied +} + +// Equals checks if the given UpdateMatchmakeSessionParam contains the same data as the current UpdateMatchmakeSessionParam +func (umsp *UpdateMatchmakeSessionParam) Equals(o types.RVType) bool { + if _, ok := o.(*UpdateMatchmakeSessionParam); !ok { + return false + } + + other := o.(*UpdateMatchmakeSessionParam) + + if umsp.StructureVersion != other.StructureVersion { + return false + } + + if !umsp.GID.Equals(other.GID) { + return false + } + + if !umsp.ModificationFlag.Equals(other.ModificationFlag) { + return false + } + + if !umsp.Attributes.Equals(other.Attributes) { + return false + } + + if !umsp.OpenParticipation.Equals(other.OpenParticipation) { + return false + } + + if !umsp.ApplicationBuffer.Equals(other.ApplicationBuffer) { + return false + } + + if !umsp.ProgressScore.Equals(other.ProgressScore) { + return false + } + + if !umsp.MatchmakeParam.Equals(other.MatchmakeParam) { + return false + } + + if !umsp.StartedTime.Equals(other.StartedTime) { + return false + } + + if !umsp.UserPassword.Equals(other.UserPassword) { + return false + } + + if !umsp.GameMode.Equals(other.GameMode) { + return false + } + + if !umsp.Description.Equals(other.Description) { + return false + } + + if !umsp.MinParticipants.Equals(other.MinParticipants) { + return false + } + + if !umsp.MaxParticipants.Equals(other.MaxParticipants) { + return false + } + + if !umsp.MatchmakeSystemType.Equals(other.MatchmakeSystemType) { + return false + } + + if !umsp.ParticipationPolicy.Equals(other.ParticipationPolicy) { + return false + } + + if !umsp.PolicyArgument.Equals(other.PolicyArgument) { + return false + } + + return umsp.Codeword.Equals(other.Codeword) +} + +// String returns the string representation of the UpdateMatchmakeSessionParam +func (umsp *UpdateMatchmakeSessionParam) String() string { + return umsp.FormatToString(0) +} + +// FormatToString pretty-prints the UpdateMatchmakeSessionParam using the provided indentation level +func (umsp *UpdateMatchmakeSessionParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("UpdateMatchmakeSessionParam{\n") + b.WriteString(fmt.Sprintf("%sGID: %s,\n", indentationValues, umsp.GID)) + b.WriteString(fmt.Sprintf("%sModificationFlag: %s,\n", indentationValues, umsp.ModificationFlag)) + b.WriteString(fmt.Sprintf("%sAttributes: %s,\n", indentationValues, umsp.Attributes)) + b.WriteString(fmt.Sprintf("%sOpenParticipation: %s,\n", indentationValues, umsp.OpenParticipation)) + b.WriteString(fmt.Sprintf("%sApplicationBuffer: %s,\n", indentationValues, umsp.ApplicationBuffer)) + b.WriteString(fmt.Sprintf("%sProgressScore: %s,\n", indentationValues, umsp.ProgressScore)) + b.WriteString(fmt.Sprintf("%sMatchmakeParam: %s,\n", indentationValues, umsp.MatchmakeParam.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sStartedTime: %s,\n", indentationValues, umsp.StartedTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUserPassword: %s,\n", indentationValues, umsp.UserPassword)) + b.WriteString(fmt.Sprintf("%sGameMode: %s,\n", indentationValues, umsp.GameMode)) + b.WriteString(fmt.Sprintf("%sDescription: %s,\n", indentationValues, umsp.Description)) + b.WriteString(fmt.Sprintf("%sMinParticipants: %s,\n", indentationValues, umsp.MinParticipants)) + b.WriteString(fmt.Sprintf("%sMaxParticipants: %s,\n", indentationValues, umsp.MaxParticipants)) + b.WriteString(fmt.Sprintf("%sMatchmakeSystemType: %s,\n", indentationValues, umsp.MatchmakeSystemType)) + b.WriteString(fmt.Sprintf("%sParticipationPolicy: %s,\n", indentationValues, umsp.ParticipationPolicy)) + b.WriteString(fmt.Sprintf("%sPolicyArgument: %s,\n", indentationValues, umsp.PolicyArgument)) + b.WriteString(fmt.Sprintf("%sCodeword: %s,\n", indentationValues, umsp.Codeword)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewUpdateMatchmakeSessionParam returns a new UpdateMatchmakeSessionParam +func NewUpdateMatchmakeSessionParam() *UpdateMatchmakeSessionParam { + umsp := &UpdateMatchmakeSessionParam{ + GID: types.NewPrimitiveU32(0), + ModificationFlag: types.NewPrimitiveU32(0), + Attributes: types.NewList[*types.PrimitiveU32](), + OpenParticipation: types.NewPrimitiveBool(false), + ApplicationBuffer: types.NewBuffer(nil), + ProgressScore: types.NewPrimitiveU8(0), + MatchmakeParam: NewMatchmakeParam(), + StartedTime: types.NewDateTime(0), + UserPassword: types.NewString(""), + GameMode: types.NewPrimitiveU32(0), + Description: types.NewString(""), + MinParticipants: types.NewPrimitiveU16(0), + MaxParticipants: types.NewPrimitiveU16(0), + MatchmakeSystemType: types.NewPrimitiveU32(0), + ParticipationPolicy: types.NewPrimitiveU32(0), + PolicyArgument: types.NewPrimitiveU32(0), + Codeword: types.NewString(""), + } + + umsp.Attributes.Type = types.NewPrimitiveU32(0) + + return umsp +} diff --git a/nex-protocols-go/match-making/unregister_gathering.go b/nex-protocols-go/match-making/unregister_gathering.go new file mode 100644 index 0000000..3d0b70e --- /dev/null +++ b/nex-protocols-go/match-making/unregister_gathering.go @@ -0,0 +1,47 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUnregisterGathering(packet nex.PacketInterface) { + if protocol.UnregisterGathering == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::UnregisterGathering not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + + err := idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UnregisterGathering(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UnregisterGathering(nil, packet, callID, idGathering) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/unregister_gatherings.go b/nex-protocols-go/match-making/unregister_gatherings.go new file mode 100644 index 0000000..77cb8ed --- /dev/null +++ b/nex-protocols-go/match-making/unregister_gatherings.go @@ -0,0 +1,48 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUnregisterGatherings(packet nex.PacketInterface) { + if protocol.UnregisterGatherings == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::UnregisterGatherings not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lstGatherings := types.NewList[*types.PrimitiveU32]() + lstGatherings.Type = types.NewPrimitiveU32(0) + + err := lstGatherings.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UnregisterGatherings(fmt.Errorf("Failed to read lstGatherings from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UnregisterGatherings(nil, packet, callID, lstGatherings) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/update_gathering.go b/nex-protocols-go/match-making/update_gathering.go new file mode 100644 index 0000000..c771445 --- /dev/null +++ b/nex-protocols-go/match-making/update_gathering.go @@ -0,0 +1,47 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateGathering(packet nex.PacketInterface) { + if protocol.UpdateGathering == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::UpdateGathering not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + anyGathering := types.NewAnyDataHolder() + + err := anyGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateGathering(fmt.Errorf("Failed to read anyGathering from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateGathering(nil, packet, callID, anyGathering) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/update_gathering_ownership.go b/nex-protocols-go/match-making/update_gathering_ownership.go new file mode 100644 index 0000000..1f643fc --- /dev/null +++ b/nex-protocols-go/match-making/update_gathering_ownership.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateGatheringOwnership(packet nex.PacketInterface) { + if protocol.UpdateGatheringOwnership == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::UpdateGatheringOwnership not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + participantsOnly := types.NewPrimitiveBool(false) + + var err error + + err = gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateGatheringOwnership(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = participantsOnly.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateGatheringOwnership(fmt.Errorf("Failed to read participantsOnly from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateGatheringOwnership(nil, packet, callID, gid, participantsOnly) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/update_session_host.go b/nex-protocols-go/match-making/update_session_host.go new file mode 100644 index 0000000..13c8850 --- /dev/null +++ b/nex-protocols-go/match-making/update_session_host.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateSessionHost(packet nex.PacketInterface) { + if protocol.UpdateSessionHost == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::UpdateSessionHost not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + isMigrateOwner := types.NewPrimitiveBool(false) + + var err error + + err = gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateSessionHost(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = isMigrateOwner.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateSessionHost(fmt.Errorf("Failed to read isMigrateOwner from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateSessionHost(nil, packet, callID, gid, isMigrateOwner) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/update_session_host_v1.go b/nex-protocols-go/match-making/update_session_host_v1.go new file mode 100644 index 0000000..b137c40 --- /dev/null +++ b/nex-protocols-go/match-making/update_session_host_v1.go @@ -0,0 +1,47 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateSessionHostV1(packet nex.PacketInterface) { + if protocol.UpdateSessionHostV1 == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::UpdateSessionHostV1 not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + + err := gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateSessionHostV1(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateSessionHostV1(nil, packet, callID, gid) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/match-making/update_session_url.go b/nex-protocols-go/match-making/update_session_url.go new file mode 100644 index 0000000..8866772 --- /dev/null +++ b/nex-protocols-go/match-making/update_session_url.go @@ -0,0 +1,60 @@ +// Package protocol implements the Match Making protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateSessionURL(packet nex.PacketInterface) { + if protocol.UpdateSessionURL == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchMaking::UpdateSessionURL not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idGathering := types.NewPrimitiveU32(0) + strURL := types.NewString("") + + var err error + + err = idGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateSessionURL(fmt.Errorf("Failed to read idGathering from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strURL.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateSessionURL(fmt.Errorf("Failed to read strURL from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateSessionURL(nil, packet, callID, idGathering, strURL) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/add_to_block_list.go b/nex-protocols-go/matchmake-extension/add_to_block_list.go new file mode 100644 index 0000000..b65e0df --- /dev/null +++ b/nex-protocols-go/matchmake-extension/add_to_block_list.go @@ -0,0 +1,48 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAddToBlockList(packet nex.PacketInterface) { + if protocol.AddToBlockList == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::AddToBlockList not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lstPrincipalID := types.NewList[*types.PID]() + lstPrincipalID.Type = types.NewPID(0) + + err := lstPrincipalID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddToBlockList(fmt.Errorf("Failed to read lstPrincipalID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AddToBlockList(nil, packet, callID, lstPrincipalID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/auto_matchmake_postpone.go b/nex-protocols-go/matchmake-extension/auto_matchmake_postpone.go new file mode 100644 index 0000000..36a5c23 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/auto_matchmake_postpone.go @@ -0,0 +1,60 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAutoMatchmakePostpone(packet nex.PacketInterface) { + if protocol.AutoMatchmakePostpone == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::AutoMatchmakePostpone not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + anyGathering := types.NewAnyDataHolder() + strMessage := types.NewString("") + + var err error + + err = anyGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AutoMatchmakePostpone(fmt.Errorf("Failed to read anyGathering from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AutoMatchmakePostpone(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AutoMatchmakePostpone(nil, packet, callID, anyGathering, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/auto_matchmake_with_gathering_id_postpone.go b/nex-protocols-go/matchmake-extension/auto_matchmake_with_gathering_id_postpone.go new file mode 100644 index 0000000..625f9d4 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/auto_matchmake_with_gathering_id_postpone.go @@ -0,0 +1,72 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAutoMatchmakeWithGatheringIDPostpone(packet nex.PacketInterface) { + if protocol.AutoMatchmakeWithGatheringIDPostpone == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::AutoMatchmakeWithGatheringIDPostpone not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lstGID := types.NewList[*types.PrimitiveU32]() + lstGID.Type = types.NewPrimitiveU32(0) + anyGathering := types.NewAnyDataHolder() + strMessage := types.NewString("") + + var err error + + err = lstGID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AutoMatchmakeWithGatheringIDPostpone(fmt.Errorf("Failed to read lstGID from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = anyGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AutoMatchmakeWithGatheringIDPostpone(fmt.Errorf("Failed to read anyGathering from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AutoMatchmakeWithGatheringIDPostpone(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AutoMatchmakeWithGatheringIDPostpone(nil, packet, callID, lstGID, anyGathering, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/auto_matchmake_with_param_postpone.go b/nex-protocols-go/matchmake-extension/auto_matchmake_with_param_postpone.go new file mode 100644 index 0000000..093b66b --- /dev/null +++ b/nex-protocols-go/matchmake-extension/auto_matchmake_with_param_postpone.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +func (protocol *Protocol) handleAutoMatchmakeWithParamPostpone(packet nex.PacketInterface) { + if protocol.AutoMatchmakeWithParamPostpone == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::AutoMatchmakeWithParamPostpone not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + autoMatchmakeParam := match_making_types.NewAutoMatchmakeParam() + + err := autoMatchmakeParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AutoMatchmakeWithParamPostpone(fmt.Errorf("Failed to read autoMatchmakeParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AutoMatchmakeWithParamPostpone(nil, packet, callID, autoMatchmakeParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go b/nex-protocols-go/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go new file mode 100644 index 0000000..4a644b5 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/auto_matchmake_with_search_criteria_postpone.go @@ -0,0 +1,73 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +func (protocol *Protocol) handleAutoMatchmakeWithSearchCriteriaPostpone(packet nex.PacketInterface) { + if protocol.AutoMatchmakeWithSearchCriteriaPostpone == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::AutoMatchmakeWithSearchCriteriaPostpone not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lstSearchCriteria := types.NewList[*match_making_types.MatchmakeSessionSearchCriteria]() + lstSearchCriteria.Type = match_making_types.NewMatchmakeSessionSearchCriteria() + anyGathering := types.NewAnyDataHolder() + strMessage := types.NewString("") + + var err error + + err = lstSearchCriteria.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AutoMatchmakeWithSearchCriteriaPostpone(fmt.Errorf("Failed to read lstSearchCriteria from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = anyGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AutoMatchmakeWithSearchCriteriaPostpone(fmt.Errorf("Failed to read anyGathering from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AutoMatchmakeWithSearchCriteriaPostpone(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AutoMatchmakeWithSearchCriteriaPostpone(nil, packet, callID, lstSearchCriteria, anyGathering, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/browse_matchmake_session.go b/nex-protocols-go/matchmake-extension/browse_matchmake_session.go new file mode 100644 index 0000000..58c0a3f --- /dev/null +++ b/nex-protocols-go/matchmake-extension/browse_matchmake_session.go @@ -0,0 +1,61 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +func (protocol *Protocol) handleBrowseMatchmakeSession(packet nex.PacketInterface) { + if protocol.BrowseMatchmakeSession == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::BrowseMatchmakeSession not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + searchCriteria := match_making_types.NewMatchmakeSessionSearchCriteria() + resultRange := types.NewResultRange() + + var err error + + err = searchCriteria.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.BrowseMatchmakeSession(fmt.Errorf("Failed to read searchCriteria from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.BrowseMatchmakeSession(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.BrowseMatchmakeSession(nil, packet, callID, searchCriteria, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/browse_matchmake_session_no_holder.go b/nex-protocols-go/matchmake-extension/browse_matchmake_session_no_holder.go new file mode 100644 index 0000000..3b12382 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/browse_matchmake_session_no_holder.go @@ -0,0 +1,61 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +func (protocol *Protocol) handleBrowseMatchmakeSessionNoHolder(packet nex.PacketInterface) { + if protocol.BrowseMatchmakeSessionNoHolder == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::BrowseMatchmakeSessionNoHolder not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + searchCriteria := match_making_types.NewMatchmakeSessionSearchCriteria() + resultRange := types.NewResultRange() + + var err error + + err = searchCriteria.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.BrowseMatchmakeSessionNoHolder(fmt.Errorf("Failed to read searchCriteria from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.BrowseMatchmakeSessionNoHolder(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.BrowseMatchmakeSessionNoHolder(nil, packet, callID, searchCriteria, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/browse_matchmake_session_no_holder_no_result_range.go b/nex-protocols-go/matchmake-extension/browse_matchmake_session_no_holder_no_result_range.go new file mode 100644 index 0000000..a402af9 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/browse_matchmake_session_no_holder_no_result_range.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +func (protocol *Protocol) handleBrowseMatchmakeSessionNoHolderNoResultRange(packet nex.PacketInterface) { + if protocol.BrowseMatchmakeSessionNoHolderNoResultRange == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::BrowseMatchmakeSessionNoHolderNoResultRange not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + searchCriteria := match_making_types.NewMatchmakeSessionSearchCriteria() + + err := searchCriteria.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.BrowseMatchmakeSessionNoHolderNoResultRange(fmt.Errorf("Failed to read searchCriteria from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.BrowseMatchmakeSessionNoHolderNoResultRange(nil, packet, callID, searchCriteria) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/browse_matchmake_session_with_host_urls.go b/nex-protocols-go/matchmake-extension/browse_matchmake_session_with_host_urls.go new file mode 100644 index 0000000..0c58d73 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/browse_matchmake_session_with_host_urls.go @@ -0,0 +1,61 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +func (protocol *Protocol) handleBrowseMatchmakeSessionWithHostURLs(packet nex.PacketInterface) { + if protocol.BrowseMatchmakeSessionWithHostURLs == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::BrowseMatchmakeSessionWithHostURLs not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + searchCriteria := match_making_types.NewMatchmakeSessionSearchCriteria() + resultRange := types.NewResultRange() + + var err error + + err = searchCriteria.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.BrowseMatchmakeSessionWithHostURLs(fmt.Errorf("Failed to read searchCriteria from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.BrowseMatchmakeSessionWithHostURLs(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.BrowseMatchmakeSessionWithHostURLs(nil, packet, callID, searchCriteria, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/browse_matchmake_session_with_host_urls_no_holder.go b/nex-protocols-go/matchmake-extension/browse_matchmake_session_with_host_urls_no_holder.go new file mode 100644 index 0000000..f6c4571 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/browse_matchmake_session_with_host_urls_no_holder.go @@ -0,0 +1,61 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +func (protocol *Protocol) handleBrowseMatchmakeSessionWithHostURLsNoHolder(packet nex.PacketInterface) { + if protocol.BrowseMatchmakeSessionWithHostURLsNoHolder == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::BrowseMatchmakeSessionWithHostURLsNoHolder not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + searchCriteria := match_making_types.NewMatchmakeSessionSearchCriteria() + resultRange := types.NewResultRange() + + var err error + + err = searchCriteria.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.BrowseMatchmakeSessionWithHostURLsNoHolder(fmt.Errorf("Failed to read searchCriteria from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.BrowseMatchmakeSessionWithHostURLsNoHolder(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.BrowseMatchmakeSessionWithHostURLsNoHolder(nil, packet, callID, searchCriteria, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/browse_matchmake_session_with_host_urls_no_holder_no_result_range.go b/nex-protocols-go/matchmake-extension/browse_matchmake_session_with_host_urls_no_holder_no_result_range.go new file mode 100644 index 0000000..c9c5a35 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/browse_matchmake_session_with_host_urls_no_holder_no_result_range.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +func (protocol *Protocol) handleBrowseMatchmakeSessionWithHostURLsNoHolderNoResultRange(packet nex.PacketInterface) { + if protocol.BrowseMatchmakeSessionWithHostURLsNoHolderNoResultRange == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::BrowseMatchmakeSessionWithHostURLsNoHolderNoResultRange not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + searchCriteria := match_making_types.NewMatchmakeSessionSearchCriteria() + + err := searchCriteria.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.BrowseMatchmakeSessionWithHostURLsNoHolderNoResultRange(fmt.Errorf("Failed to read searchCriteria from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.BrowseMatchmakeSessionWithHostURLsNoHolderNoResultRange(nil, packet, callID, searchCriteria) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/clear_matchmake_session_system_password.go b/nex-protocols-go/matchmake-extension/clear_matchmake_session_system_password.go new file mode 100644 index 0000000..be1ceb5 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/clear_matchmake_session_system_password.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleClearMatchmakeSessionSystemPassword(packet nex.PacketInterface) { + if protocol.ClearMatchmakeSessionSystemPassword == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::ClearMatchmakeSessionSystemPassword not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + + err := gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ClearMatchmakeSessionSystemPassword(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ClearMatchmakeSessionSystemPassword(nil, packet, callID, gid) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/clear_my_block_list.go b/nex-protocols-go/matchmake-extension/clear_my_block_list.go new file mode 100644 index 0000000..2c37526 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/clear_my_block_list.go @@ -0,0 +1,29 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleClearMyBlockList(packet nex.PacketInterface) { + if protocol.ClearMyBlockList == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::ClearMyBlockList not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.ClearMyBlockList(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/close_participation.go b/nex-protocols-go/matchmake-extension/close_participation.go new file mode 100644 index 0000000..9457c01 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/close_participation.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCloseParticipation(packet nex.PacketInterface) { + if protocol.CloseParticipation == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::CloseParticipation not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + + err := gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CloseParticipation(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CloseParticipation(nil, packet, callID, gid) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/create_community.go b/nex-protocols-go/matchmake-extension/create_community.go new file mode 100644 index 0000000..9546de0 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/create_community.go @@ -0,0 +1,61 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +func (protocol *Protocol) handleCreateCommunity(packet nex.PacketInterface) { + if protocol.CreateCommunity == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::CreateCommunity not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + community := match_making_types.NewPersistentGathering() + strMessage := types.NewString("") + + var err error + + err = community.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateCommunity(fmt.Errorf("Failed to read community from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateCommunity(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CreateCommunity(nil, packet, callID, community, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/create_matchmake_session.go b/nex-protocols-go/matchmake-extension/create_matchmake_session.go new file mode 100644 index 0000000..38fb2f9 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/create_matchmake_session.go @@ -0,0 +1,75 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCreateMatchmakeSession(packet nex.PacketInterface) { + if protocol.CreateMatchmakeSession == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::CreateMatchmakeSession not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + endpoint := packet.Sender().Endpoint() + matchmakingVersion := endpoint.LibraryVersions().MatchMaking + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + anyGathering := types.NewAnyDataHolder() + strMessage := types.NewString("") + participationCount := types.NewPrimitiveU16(0) + + var err error + + err = anyGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateMatchmakeSession(fmt.Errorf("Failed to read anyGathering from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateMatchmakeSession(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + if matchmakingVersion.GreaterOrEqual("3.4.0") { + err = participationCount.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateMatchmakeSession(fmt.Errorf("Failed to read participationCount from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + } + + rmcMessage, rmcError := protocol.CreateMatchmakeSession(nil, packet, callID, anyGathering, strMessage, participationCount) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/create_matchmake_session_with_param.go b/nex-protocols-go/matchmake-extension/create_matchmake_session_with_param.go new file mode 100644 index 0000000..2adf807 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/create_matchmake_session_with_param.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +func (protocol *Protocol) handleCreateMatchmakeSessionWithParam(packet nex.PacketInterface) { + if protocol.CreateMatchmakeSessionWithParam == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::CreateMatchmakeSessionWithParam not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + createMatchmakeSessionParam := match_making_types.NewCreateMatchmakeSessionParam() + + err := createMatchmakeSessionParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateMatchmakeSessionWithParam(fmt.Errorf("Failed to read createMatchmakeSessionParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CreateMatchmakeSessionWithParam(nil, packet, callID, createMatchmakeSessionParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/debug_notify_event.go b/nex-protocols-go/matchmake-extension/debug_notify_event.go new file mode 100644 index 0000000..2000812 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/debug_notify_event.go @@ -0,0 +1,104 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDebugNotifyEvent(packet nex.PacketInterface) { + if protocol.DebugNotifyEvent == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::DebugNotifyEvent not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pid := types.NewPID(0) + mainType := types.NewPrimitiveU32(0) + subType := types.NewPrimitiveU32(0) + param1 := types.NewPrimitiveU64(0) + param2 := types.NewPrimitiveU64(0) + stringParam := types.NewString("") + + var err error + + err = pid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DebugNotifyEvent(fmt.Errorf("Failed to read pid from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = mainType.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DebugNotifyEvent(fmt.Errorf("Failed to read mainType from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = subType.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DebugNotifyEvent(fmt.Errorf("Failed to read subType from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = param1.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DebugNotifyEvent(fmt.Errorf("Failed to read param1 from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = param2.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DebugNotifyEvent(fmt.Errorf("Failed to read param2 from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = stringParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DebugNotifyEvent(fmt.Errorf("Failed to read stringParam from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DebugNotifyEvent(nil, packet, callID, pid, mainType, subType, param1, param2, stringParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/find_comminuty_by_owner.go b/nex-protocols-go/matchmake-extension/find_comminuty_by_owner.go new file mode 100644 index 0000000..51a104e --- /dev/null +++ b/nex-protocols-go/matchmake-extension/find_comminuty_by_owner.go @@ -0,0 +1,31 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindCommunityByOwner(packet nex.PacketInterface) { + if protocol.FindCommunityByOwner == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::FindCommunityByOwner not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtension::FindCommunityByOwner STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.FindCommunityByOwner(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/find_community_by_gathering_id.go b/nex-protocols-go/matchmake-extension/find_community_by_gathering_id.go new file mode 100644 index 0000000..4606451 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/find_community_by_gathering_id.go @@ -0,0 +1,48 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindCommunityByGatheringID(packet nex.PacketInterface) { + if protocol.FindCommunityByGatheringID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::FindCommunityByGatheringID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lstGID := types.NewList[*types.PrimitiveU32]() + lstGID.Type = types.NewPrimitiveU32(0) + + err := lstGID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindCommunityByGatheringID(fmt.Errorf("Failed to read lstGID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindCommunityByGatheringID(nil, packet, callID, lstGID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/find_community_by_participant.go b/nex-protocols-go/matchmake-extension/find_community_by_participant.go new file mode 100644 index 0000000..dd35631 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/find_community_by_participant.go @@ -0,0 +1,60 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindCommunityByParticipant(packet nex.PacketInterface) { + if protocol.FindCommunityByParticipant == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::FindCommunityByParticipant not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pid := types.NewPID(0) + resultRange := types.NewResultRange() + + var err error + + err = pid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindCommunityByParticipant(fmt.Errorf("Failed to read pid from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindCommunityByParticipant(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindCommunityByParticipant(nil, packet, callID, pid, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/find_matchmake_session_by_gathering_id.go b/nex-protocols-go/matchmake-extension/find_matchmake_session_by_gathering_id.go new file mode 100644 index 0000000..2e5fa6f --- /dev/null +++ b/nex-protocols-go/matchmake-extension/find_matchmake_session_by_gathering_id.go @@ -0,0 +1,48 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindMatchmakeSessionByGatheringID(packet nex.PacketInterface) { + if protocol.FindMatchmakeSessionByGatheringID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::FindMatchmakeSessionByGatheringID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lstGID := types.NewList[*types.PrimitiveU32]() + lstGID.Type = types.NewPrimitiveU32(0) + + err := lstGID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindMatchmakeSessionByGatheringID(fmt.Errorf("Failed to read lstGID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindMatchmakeSessionByGatheringID(nil, packet, callID, lstGID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/find_matchmake_session_by_gathering_id_detail.go b/nex-protocols-go/matchmake-extension/find_matchmake_session_by_gathering_id_detail.go new file mode 100644 index 0000000..52bc34c --- /dev/null +++ b/nex-protocols-go/matchmake-extension/find_matchmake_session_by_gathering_id_detail.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindMatchmakeSessionByGatheringIDDetail(packet nex.PacketInterface) { + if protocol.FindMatchmakeSessionByGatheringIDDetail == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::FindMatchmakeSessionByGatheringIDDetail not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + + err := gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindMatchmakeSessionByGatheringIDDetail(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindMatchmakeSessionByGatheringIDDetail(nil, packet, callID, gid) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/find_matchmake_session_by_owner.go b/nex-protocols-go/matchmake-extension/find_matchmake_session_by_owner.go new file mode 100644 index 0000000..99a726a --- /dev/null +++ b/nex-protocols-go/matchmake-extension/find_matchmake_session_by_owner.go @@ -0,0 +1,60 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindMatchmakeSessionByOwner(packet nex.PacketInterface) { + if protocol.FindMatchmakeSessionByOwner == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::FindMatchmakeSessionByOwner not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + id := types.NewPrimitiveU32(0) + resultRange := types.NewResultRange() + + var err error + + err = id.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindMatchmakeSessionByOwner(fmt.Errorf("Failed to read id from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindMatchmakeSessionByOwner(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindMatchmakeSessionByOwner(nil, packet, callID, id, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/find_matchmake_session_by_participant.go b/nex-protocols-go/matchmake-extension/find_matchmake_session_by_participant.go new file mode 100644 index 0000000..949fa83 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/find_matchmake_session_by_participant.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +func (protocol *Protocol) handleFindMatchmakeSessionByParticipant(packet nex.PacketInterface) { + if protocol.FindMatchmakeSessionByParticipant == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::FindMatchmakeSessionByParticipant not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := match_making_types.NewFindMatchmakeSessionByParticipantParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindMatchmakeSessionByParticipant(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindMatchmakeSessionByParticipant(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/find_matchmake_session_by_single_gathering_id.go b/nex-protocols-go/matchmake-extension/find_matchmake_session_by_single_gathering_id.go new file mode 100644 index 0000000..37dae40 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/find_matchmake_session_by_single_gathering_id.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindMatchmakeSessionBySingleGatheringID(packet nex.PacketInterface) { + if protocol.FindMatchmakeSessionBySingleGatheringID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::FindMatchmakeSessionBySingleGatheringID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + + err := gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindMatchmakeSessionBySingleGatheringID(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindMatchmakeSessionBySingleGatheringID(nil, packet, callID, gid) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/find_official_community.go b/nex-protocols-go/matchmake-extension/find_official_community.go new file mode 100644 index 0000000..6fe2b34 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/find_official_community.go @@ -0,0 +1,60 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindOfficialCommunity(packet nex.PacketInterface) { + if protocol.FindOfficialCommunity == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::FindOfficialCommunity not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + isAvailableOnly := types.NewPrimitiveBool(false) + resultRange := types.NewResultRange() + + var err error + + err = isAvailableOnly.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindOfficialCommunity(fmt.Errorf("Failed to read isAvailableOnly from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindOfficialCommunity(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindOfficialCommunity(nil, packet, callID, isAvailableOnly, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/generate_matchmake_session_system_password.go b/nex-protocols-go/matchmake-extension/generate_matchmake_session_system_password.go new file mode 100644 index 0000000..2081947 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/generate_matchmake_session_system_password.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGenerateMatchmakeSessionSystemPassword(packet nex.PacketInterface) { + if protocol.GenerateMatchmakeSessionSystemPassword == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::GenerateMatchmakeSessionSystemPassword not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + + err := gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GenerateMatchmakeSessionSystemPassword(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GenerateMatchmakeSessionSystemPassword(nil, packet, callID, gid) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/get_friend_notification_data.go b/nex-protocols-go/matchmake-extension/get_friend_notification_data.go new file mode 100644 index 0000000..4a6352b --- /dev/null +++ b/nex-protocols-go/matchmake-extension/get_friend_notification_data.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetFriendNotificationData(packet nex.PacketInterface) { + if protocol.GetFriendNotificationData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::GetFriendNotificationData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiType := types.NewPrimitiveS32(0) + + err := uiType.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetFriendNotificationData(fmt.Errorf("Failed to read uiType from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetFriendNotificationData(nil, packet, callID, uiType) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/get_lst_friend_notification_data.go b/nex-protocols-go/matchmake-extension/get_lst_friend_notification_data.go new file mode 100644 index 0000000..a17e938 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/get_lst_friend_notification_data.go @@ -0,0 +1,48 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetlstFriendNotificationData(packet nex.PacketInterface) { + if protocol.GetlstFriendNotificationData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::GetlstFriendNotificationData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lstTypes := types.NewList[*types.PrimitiveU32]() + lstTypes.Type = types.NewPrimitiveU32(0) + + err := lstTypes.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetlstFriendNotificationData(fmt.Errorf("Failed to read lstTypes from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetlstFriendNotificationData(nil, packet, callID, lstTypes) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/get_my_block_list.go b/nex-protocols-go/matchmake-extension/get_my_block_list.go new file mode 100644 index 0000000..29d9b6f --- /dev/null +++ b/nex-protocols-go/matchmake-extension/get_my_block_list.go @@ -0,0 +1,29 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetMyBlockList(packet nex.PacketInterface) { + if protocol.GetMyBlockList == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::GetMyBlockList not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetMyBlockList(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/get_playing_session.go b/nex-protocols-go/matchmake-extension/get_playing_session.go new file mode 100644 index 0000000..31c1522 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/get_playing_session.go @@ -0,0 +1,48 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetPlayingSession(packet nex.PacketInterface) { + if protocol.GetPlayingSession == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::GetPlayingSession not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lstPID := types.NewList[*types.PID]() + lstPID.Type = types.NewPID(0) + + err := lstPID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPlayingSession(fmt.Errorf("Failed to read lstPID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetPlayingSession(nil, packet, callID, lstPID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/get_simple_community.go b/nex-protocols-go/matchmake-extension/get_simple_community.go new file mode 100644 index 0000000..5a9dbbb --- /dev/null +++ b/nex-protocols-go/matchmake-extension/get_simple_community.go @@ -0,0 +1,48 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetSimpleCommunity(packet nex.PacketInterface) { + if protocol.GetSimpleCommunity == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::GetSimpleCommunity not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gatheringIDList := types.NewList[*types.PrimitiveU32]() + gatheringIDList.Type = types.NewPrimitiveU32(0) + + err := gatheringIDList.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetSimpleCommunity(fmt.Errorf("Failed to read gatheringIDList from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetSimpleCommunity(nil, packet, callID, gatheringIDList) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/get_simple_playing_session.go b/nex-protocols-go/matchmake-extension/get_simple_playing_session.go new file mode 100644 index 0000000..d80bb57 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/get_simple_playing_session.go @@ -0,0 +1,61 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetSimplePlayingSession(packet nex.PacketInterface) { + if protocol.GetSimplePlayingSession == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::GetSimplePlayingSession not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + listPID := types.NewList[*types.PID]() + listPID.Type = types.NewPID(0) + includeLoginUser := types.NewPrimitiveBool(false) + + var err error + + err = listPID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetSimplePlayingSession(fmt.Errorf("Failed to read listPID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = includeLoginUser.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetSimplePlayingSession(fmt.Errorf("Failed to read includeLoginUser from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetSimplePlayingSession(nil, packet, callID, listPID, includeLoginUser) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/is_violation_user.go b/nex-protocols-go/matchmake-extension/is_violation_user.go new file mode 100644 index 0000000..13350e9 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/is_violation_user.go @@ -0,0 +1,29 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleIsViolationUser(packet nex.PacketInterface) { + if protocol.IsViolationUser == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::IsViolationUser not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.IsViolationUser(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/join_community.go b/nex-protocols-go/matchmake-extension/join_community.go new file mode 100644 index 0000000..b6bfec8 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/join_community.go @@ -0,0 +1,71 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleJoinCommunity(packet nex.PacketInterface) { + if protocol.JoinCommunity == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::JoinCommunity not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + strMessage := types.NewString("") + strPassword := types.NewString("") + + var err error + + err = gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.JoinCommunity(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.JoinCommunity(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strPassword.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.JoinCommunity(fmt.Errorf("Failed to read strPassword from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.JoinCommunity(nil, packet, callID, gid, strMessage, strPassword) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/join_matchmake_session.go b/nex-protocols-go/matchmake-extension/join_matchmake_session.go new file mode 100644 index 0000000..b8045f1 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/join_matchmake_session.go @@ -0,0 +1,60 @@ +// Package protocol implements the Matchmake tension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleJoinMatchmakeSession(packet nex.PacketInterface) { + if protocol.JoinMatchmakeSession == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::JoinMatchmakeSession not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + strMessage := types.NewString("") + + var err error + + err = gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.JoinMatchmakeSession(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.JoinMatchmakeSession(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.JoinMatchmakeSession(nil, packet, callID, gid, strMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/join_matchmake_session_ex.go b/nex-protocols-go/matchmake-extension/join_matchmake_session_ex.go new file mode 100644 index 0000000..3f2522b --- /dev/null +++ b/nex-protocols-go/matchmake-extension/join_matchmake_session_ex.go @@ -0,0 +1,85 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleJoinMatchmakeSessionEx(packet nex.PacketInterface) { + if protocol.JoinMatchmakeSessionEx == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::JoinMatchmakeSessionEx not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + matchmakingVersion := endpoint.LibraryVersions().MatchMaking + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + strMessage := types.NewString("") + dontCareMyBlockList := types.NewPrimitiveBool(false) + participationCount := types.NewPrimitiveU16(0) + + var err error + + err = gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.JoinMatchmakeSessionEx(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.JoinMatchmakeSessionEx(fmt.Errorf("Failed to read strMessage from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = dontCareMyBlockList.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.JoinMatchmakeSessionEx(fmt.Errorf("Failed to read dontCareMyBlockList from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + if matchmakingVersion.GreaterOrEqual("3.4.0") { + err = participationCount.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.JoinMatchmakeSessionEx(fmt.Errorf("Failed to read participationCount from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + } + + rmcMessage, rmcError := protocol.JoinMatchmakeSessionEx(nil, packet, callID, gid, strMessage, dontCareMyBlockList, participationCount) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/join_matchmake_session_with_param.go b/nex-protocols-go/matchmake-extension/join_matchmake_session_with_param.go new file mode 100644 index 0000000..23c730c --- /dev/null +++ b/nex-protocols-go/matchmake-extension/join_matchmake_session_with_param.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +func (protocol *Protocol) handleJoinMatchmakeSessionWithParam(packet nex.PacketInterface) { + if protocol.JoinMatchmakeSessionWithParam == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::JoinMatchmakeSessionWithParam not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + joinMatchmakeSessionParam := match_making_types.NewJoinMatchmakeSessionParam() + + err := joinMatchmakeSessionParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.JoinMatchmakeSessionWithParam(fmt.Errorf("Failed to read joinMatchmakeSessionParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.JoinMatchmakeSessionWithParam(nil, packet, callID, joinMatchmakeSessionParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/mario-kart-8/create_simple_search_object.go b/nex-protocols-go/matchmake-extension/mario-kart-8/create_simple_search_object.go new file mode 100644 index 0000000..a2a07ca --- /dev/null +++ b/nex-protocols-go/matchmake-extension/mario-kart-8/create_simple_search_object.go @@ -0,0 +1,47 @@ +// Package protocol implements the MatchmakeExtensionMarioKart8 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + matchmake_extension_mario_kart8_types "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension/mario-kart-8/types" +) + +func (protocol *Protocol) handleCreateSimpleSearchObject(packet nex.PacketInterface) { + if protocol.CreateSimpleSearchObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionMarioKart8::CreateSimpleSearchObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + object := matchmake_extension_mario_kart8_types.NewSimpleSearchObject() + + err := object.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateSimpleSearchObject(fmt.Errorf("Failed to read object from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CreateSimpleSearchObject(nil, packet, callID, object) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/mario-kart-8/delete_simple_search_object.go b/nex-protocols-go/matchmake-extension/mario-kart-8/delete_simple_search_object.go new file mode 100644 index 0000000..d1a2777 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/mario-kart-8/delete_simple_search_object.go @@ -0,0 +1,47 @@ +// Package protocol implements the MatchmakeExtensionMarioKart8 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteSimpleSearchObject(packet nex.PacketInterface) { + if protocol.DeleteSimpleSearchObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionMarioKart8::DeleteSimpleSearchObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + objectID := types.NewPrimitiveU32(0) + + err := objectID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteSimpleSearchObject(fmt.Errorf("Failed to read objectID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteSimpleSearchObject(nil, packet, callID, objectID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/mario-kart-8/join_matchmake_session_with_extra_participants.go b/nex-protocols-go/matchmake-extension/mario-kart-8/join_matchmake_session_with_extra_participants.go new file mode 100644 index 0000000..802b0e5 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/mario-kart-8/join_matchmake_session_with_extra_participants.go @@ -0,0 +1,93 @@ +// Package protocol implements the MatchmakeExtensionMarioKart8 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleJoinMatchmakeSessionWithExtraParticipants(packet nex.PacketInterface) { + if protocol.JoinMatchmakeSessionWithExtraParticipants == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionMarioKart8::JoinMatchmakeSessionWithExtraParticipants not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + joinMessage := types.NewString("") + ignoreBlacklist := types.NewPrimitiveBool(false) + participationCount := types.NewPrimitiveU16(0) + extraParticipants := types.NewPrimitiveU32(0) + + var err error + + err = gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.JoinMatchmakeSessionWithExtraParticipants(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = joinMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.JoinMatchmakeSessionWithExtraParticipants(fmt.Errorf("Failed to read joinMessage from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = ignoreBlacklist.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.JoinMatchmakeSessionWithExtraParticipants(fmt.Errorf("Failed to read ignoreBlacklist from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = participationCount.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.JoinMatchmakeSessionWithExtraParticipants(fmt.Errorf("Failed to read participationCount from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = extraParticipants.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.JoinMatchmakeSessionWithExtraParticipants(fmt.Errorf("Failed to read extraParticipants from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.JoinMatchmakeSessionWithExtraParticipants(nil, packet, callID, gid, joinMessage, ignoreBlacklist, participationCount, extraParticipants) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/mario-kart-8/protocol.go b/nex-protocols-go/matchmake-extension/mario-kart-8/protocol.go new file mode 100644 index 0000000..1b95193 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/mario-kart-8/protocol.go @@ -0,0 +1,103 @@ +// Package protocol implements the MatchmakeExtensionMarioKart8 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" + matchmake_extension_mario_kart8_types "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension/mario-kart-8/types" + "golang.org/x/exp/slices" +) + +const ( + // ProtocolID is the Protocol ID for the Matchmake Extension (Mario Kart 8) protocol + ProtocolID = 0x6D + + // MethodCreateSimpleSearchObject is the method ID for the CreateSimpleSearchObject method + MethodCreateSimpleSearchObject = 0x24 + + // MethodUpdateSimpleSearchObject is the method ID for the UpdateSimpleSearchObject method + MethodUpdateSimpleSearchObject = 0x25 + + // MethodDeleteSimpleSearchObject is the method ID for the DeleteSimpleSearchObject method + MethodDeleteSimpleSearchObject = 0x26 + + // MethodSearchSimpleSearchObject is the method ID for the SearchSimpleSearchObject method + MethodSearchSimpleSearchObject = 0x27 + + // MethodJoinMatchmakeSessionWithExtraParticipants is the method ID for the JoinMatchmakeSessionWithExtraParticipants method + MethodJoinMatchmakeSessionWithExtraParticipants = 0x28 + + // MethodSearchSimpleSearchObjectByObjectIDs is the method ID for the SearchSimpleSearchObjectByObjectIDs method + MethodSearchSimpleSearchObjectByObjectIDs = 0x29 +) + +var patchedMethods = []uint32{ + MethodCreateSimpleSearchObject, + MethodUpdateSimpleSearchObject, + MethodDeleteSimpleSearchObject, + MethodSearchSimpleSearchObject, + MethodJoinMatchmakeSessionWithExtraParticipants, + MethodSearchSimpleSearchObjectByObjectIDs, +} + +type matchmakeExtensionProtocol = matchmake_extension.Protocol + +// Protocol stores all the RMC method handlers for the Matchmake Extension (Mario Kart 8) protocol and listens for requests +// Embeds the Matchmake Extension protocol +type Protocol struct { + endpoint nex.EndpointInterface + matchmakeExtensionProtocol + CreateSimpleSearchObject func(err error, packet nex.PacketInterface, callID uint32, object *matchmake_extension_mario_kart8_types.SimpleSearchObject) (*nex.RMCMessage, *nex.Error) + UpdateSimpleSearchObject func(err error, packet nex.PacketInterface, callID uint32, objectID *types.PrimitiveU32, newObject *matchmake_extension_mario_kart8_types.SimpleSearchObject) (*nex.RMCMessage, *nex.Error) + DeleteSimpleSearchObject func(err error, packet nex.PacketInterface, callID uint32, objectID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + SearchSimpleSearchObject func(err error, packet nex.PacketInterface, callID uint32, param *matchmake_extension_mario_kart8_types.SimpleSearchParam) (*nex.RMCMessage, *nex.Error) + JoinMatchmakeSessionWithExtraParticipants func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, joinMessage *types.String, ignoreBlacklist *types.PrimitiveBool, participationCount *types.PrimitiveU16, extraParticipants *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + SearchSimpleSearchObjectByObjectIDs func(err error, packet nex.PacketInterface, callID uint32, objectIDs *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error) +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if !slices.Contains(patchedMethods, message.MethodID) { + protocol.matchmakeExtensionProtocol.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodCreateSimpleSearchObject: + protocol.handleCreateSimpleSearchObject(packet) + case MethodUpdateSimpleSearchObject: + protocol.handleUpdateSimpleSearchObject(packet) + case MethodDeleteSimpleSearchObject: + protocol.handleDeleteSimpleSearchObject(packet) + case MethodSearchSimpleSearchObject: + protocol.handleSearchSimpleSearchObject(packet) + case MethodJoinMatchmakeSessionWithExtraParticipants: + protocol.handleJoinMatchmakeSessionWithExtraParticipants(packet) + case MethodSearchSimpleSearchObjectByObjectIDs: + protocol.handleSearchSimpleSearchObjectByObjectIDs(packet) + default: + errMessage := fmt.Sprintf("Unsupported Matchmake Extension (Mario Kart 8) method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new MatchmakeExtensionMarioKart8 protocol +func NewProtocol(endpoint nex.EndpointInterface) *Protocol { + protocol := &Protocol{endpoint: endpoint} + protocol.matchmakeExtensionProtocol.SetEndpoint(endpoint) + + return protocol +} diff --git a/nex-protocols-go/matchmake-extension/mario-kart-8/search_simple_search_object.go b/nex-protocols-go/matchmake-extension/mario-kart-8/search_simple_search_object.go new file mode 100644 index 0000000..254da7e --- /dev/null +++ b/nex-protocols-go/matchmake-extension/mario-kart-8/search_simple_search_object.go @@ -0,0 +1,47 @@ +// Package protocol implements the MatchmakeExtensionMarioKart8 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + matchmake_extension_mario_kart8_types "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension/mario-kart-8/types" +) + +func (protocol *Protocol) handleSearchSimpleSearchObject(packet nex.PacketInterface) { + if protocol.SearchSimpleSearchObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionMarioKart8::SearchSimpleSearchObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := matchmake_extension_mario_kart8_types.NewSimpleSearchParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SearchSimpleSearchObject(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SearchSimpleSearchObject(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/mario-kart-8/search_simple_search_object_by_object_ids.go b/nex-protocols-go/matchmake-extension/mario-kart-8/search_simple_search_object_by_object_ids.go new file mode 100644 index 0000000..77a1c25 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/mario-kart-8/search_simple_search_object_by_object_ids.go @@ -0,0 +1,48 @@ +// Package protocol implements the MatchmakeExtensionMarioKart8 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSearchSimpleSearchObjectByObjectIDs(packet nex.PacketInterface) { + if protocol.SearchSimpleSearchObjectByObjectIDs == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionMarioKart8::SearchSimpleSearchObjectByObjectIDs not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + objectIDs := types.NewList[*types.PrimitiveU32]() + objectIDs.Type = types.NewPrimitiveU32(0) + + err := objectIDs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SearchSimpleSearchObjectByObjectIDs(fmt.Errorf("Failed to read objectIDs from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SearchSimpleSearchObjectByObjectIDs(nil, packet, callID, objectIDs) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/mario-kart-8/types/simple_search_condition.go b/nex-protocols-go/matchmake-extension/mario-kart-8/types/simple_search_condition.go new file mode 100644 index 0000000..a0d41b8 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/mario-kart-8/types/simple_search_condition.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the MatchmakeExtension protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// SimpleSearchCondition is a type within the MatchmakeExtension protocol +type SimpleSearchCondition struct { + types.Structure + Value *types.PrimitiveU32 + ComparisonOperator *types.PrimitiveU32 +} + +// WriteTo writes the SimpleSearchCondition to the given writable +func (ssc *SimpleSearchCondition) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + ssc.Value.WriteTo(contentWritable) + ssc.ComparisonOperator.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + ssc.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the SimpleSearchCondition from the given readable +func (ssc *SimpleSearchCondition) ExtractFrom(readable types.Readable) error { + var err error + + err = ssc.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchCondition header. %s", err.Error()) + } + + err = ssc.Value.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchCondition.Value. %s", err.Error()) + } + + err = ssc.ComparisonOperator.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchCondition.ComparisonOperator. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of SimpleSearchCondition +func (ssc *SimpleSearchCondition) Copy() types.RVType { + copied := NewSimpleSearchCondition() + + copied.StructureVersion = ssc.StructureVersion + copied.Value = ssc.Value.Copy().(*types.PrimitiveU32) + copied.ComparisonOperator = ssc.ComparisonOperator.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given SimpleSearchCondition contains the same data as the current SimpleSearchCondition +func (ssc *SimpleSearchCondition) Equals(o types.RVType) bool { + if _, ok := o.(*SimpleSearchCondition); !ok { + return false + } + + other := o.(*SimpleSearchCondition) + + if ssc.StructureVersion != other.StructureVersion { + return false + } + + if !ssc.Value.Equals(other.Value) { + return false + } + + return ssc.ComparisonOperator.Equals(other.ComparisonOperator) +} + +// String returns the string representation of the SimpleSearchCondition +func (ssc *SimpleSearchCondition) String() string { + return ssc.FormatToString(0) +} + +// FormatToString pretty-prints the SimpleSearchCondition using the provided indentation level +func (ssc *SimpleSearchCondition) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("SimpleSearchCondition{\n") + b.WriteString(fmt.Sprintf("%sValue: %s,\n", indentationValues, ssc.Value)) + b.WriteString(fmt.Sprintf("%sComparisonOperator: %s,\n", indentationValues, ssc.ComparisonOperator)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewSimpleSearchCondition returns a new SimpleSearchCondition +func NewSimpleSearchCondition() *SimpleSearchCondition { + ssc := &SimpleSearchCondition{ + Value: types.NewPrimitiveU32(0), + ComparisonOperator: types.NewPrimitiveU32(0), + } + + return ssc +} diff --git a/nex-protocols-go/matchmake-extension/mario-kart-8/types/simple_search_date_time_attribute.go b/nex-protocols-go/matchmake-extension/mario-kart-8/types/simple_search_date_time_attribute.go new file mode 100644 index 0000000..4f5888a --- /dev/null +++ b/nex-protocols-go/matchmake-extension/mario-kart-8/types/simple_search_date_time_attribute.go @@ -0,0 +1,168 @@ +// Package types implements all the types used by the MatchmakeExtension protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// SimpleSearchDateTimeAttribute is a type within the MatchmakeExtension protocol +type SimpleSearchDateTimeAttribute struct { + types.Structure + Unknown *types.PrimitiveU32 + Unknown2 *types.PrimitiveU32 + Unknown3 *types.PrimitiveU32 + Unknown4 *types.PrimitiveU32 + StartTime *types.DateTime + EndTime *types.DateTime +} + +// WriteTo writes the SimpleSearchDateTimeAttribute to the given writable +func (ssdta *SimpleSearchDateTimeAttribute) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + ssdta.Unknown.WriteTo(contentWritable) + ssdta.Unknown2.WriteTo(contentWritable) + ssdta.Unknown3.WriteTo(contentWritable) + ssdta.Unknown4.WriteTo(contentWritable) + ssdta.StartTime.WriteTo(contentWritable) + ssdta.EndTime.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + ssdta.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the SimpleSearchDateTimeAttribute from the given readable +func (ssdta *SimpleSearchDateTimeAttribute) ExtractFrom(readable types.Readable) error { + var err error + + err = ssdta.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchDateTimeAttribute header. %s", err.Error()) + } + + err = ssdta.Unknown.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchDateTimeAttribute.Unknown. %s", err.Error()) + } + + err = ssdta.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchDateTimeAttribute.Unknown2. %s", err.Error()) + } + + err = ssdta.Unknown3.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchDateTimeAttribute.Unknown3. %s", err.Error()) + } + + err = ssdta.Unknown4.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchDateTimeAttribute.Unknown4. %s", err.Error()) + } + + err = ssdta.StartTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchDateTimeAttribute.StartTime. %s", err.Error()) + } + + err = ssdta.EndTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchDateTimeAttribute.EndTime. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of SimpleSearchDateTimeAttribute +func (ssdta *SimpleSearchDateTimeAttribute) Copy() types.RVType { + copied := NewSimpleSearchDateTimeAttribute() + + copied.StructureVersion = ssdta.StructureVersion + copied.Unknown = ssdta.Unknown.Copy().(*types.PrimitiveU32) + copied.Unknown2 = ssdta.Unknown2.Copy().(*types.PrimitiveU32) + copied.Unknown3 = ssdta.Unknown3.Copy().(*types.PrimitiveU32) + copied.Unknown4 = ssdta.Unknown4.Copy().(*types.PrimitiveU32) + copied.StartTime = ssdta.StartTime.Copy().(*types.DateTime) + copied.EndTime = ssdta.EndTime.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given SimpleSearchDateTimeAttribute contains the same data as the current SimpleSearchDateTimeAttribute +func (ssdta *SimpleSearchDateTimeAttribute) Equals(o types.RVType) bool { + if _, ok := o.(*SimpleSearchDateTimeAttribute); !ok { + return false + } + + other := o.(*SimpleSearchDateTimeAttribute) + + if ssdta.StructureVersion != other.StructureVersion { + return false + } + + if !ssdta.Unknown.Equals(other.Unknown) { + return false + } + + if !ssdta.Unknown2.Equals(other.Unknown2) { + return false + } + + if !ssdta.Unknown3.Equals(other.Unknown3) { + return false + } + + if !ssdta.Unknown4.Equals(other.Unknown4) { + return false + } + + if !ssdta.StartTime.Equals(other.StartTime) { + return false + } + + return ssdta.EndTime.Equals(other.EndTime) +} + +// String returns the string representation of the SimpleSearchDateTimeAttribute +func (ssdta *SimpleSearchDateTimeAttribute) String() string { + return ssdta.FormatToString(0) +} + +// FormatToString pretty-prints the SimpleSearchDateTimeAttribute using the provided indentation level +func (ssdta *SimpleSearchDateTimeAttribute) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("SimpleSearchDateTimeAttribute{\n") + b.WriteString(fmt.Sprintf("%sUnknown: %s,\n", indentationValues, ssdta.Unknown)) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, ssdta.Unknown2)) + b.WriteString(fmt.Sprintf("%sUnknown3: %s,\n", indentationValues, ssdta.Unknown3)) + b.WriteString(fmt.Sprintf("%sUnknown4: %s,\n", indentationValues, ssdta.Unknown4)) + b.WriteString(fmt.Sprintf("%sStartTime: %s,\n", indentationValues, ssdta.StartTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sEndTime: %s,\n", indentationValues, ssdta.EndTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewSimpleSearchDateTimeAttribute returns a new SimpleSearchDateTimeAttribute +func NewSimpleSearchDateTimeAttribute() *SimpleSearchDateTimeAttribute { + ssdta := &SimpleSearchDateTimeAttribute{ + Unknown: types.NewPrimitiveU32(0), + Unknown2: types.NewPrimitiveU32(0), + Unknown3: types.NewPrimitiveU32(0), + Unknown4: types.NewPrimitiveU32(0), + StartTime: types.NewDateTime(0), + EndTime: types.NewDateTime(0), + } + + return ssdta +} diff --git a/nex-protocols-go/matchmake-extension/mario-kart-8/types/simple_search_object.go b/nex-protocols-go/matchmake-extension/mario-kart-8/types/simple_search_object.go new file mode 100644 index 0000000..0be7e3a --- /dev/null +++ b/nex-protocols-go/matchmake-extension/mario-kart-8/types/simple_search_object.go @@ -0,0 +1,184 @@ +// Package types implements all the types used by the MatchmakeExtension protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// SimpleSearchObject is a type within the MatchmakeExtension protocol +type SimpleSearchObject struct { + types.Structure + ObjectID *types.PrimitiveU32 + OwnerPID *types.PID + Attributes *types.List[*types.PrimitiveU32] + Metadata *types.QBuffer + CommunityIDMiiverse *types.PrimitiveU32 + CommunityCode *types.String + DatetimeAttribute *SimpleSearchDateTimeAttribute +} + +// WriteTo writes the SimpleSearchObject to the given writable +func (sso *SimpleSearchObject) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sso.ObjectID.WriteTo(contentWritable) + sso.OwnerPID.WriteTo(contentWritable) + sso.Attributes.WriteTo(contentWritable) + sso.Metadata.WriteTo(contentWritable) + sso.CommunityIDMiiverse.WriteTo(contentWritable) + sso.CommunityCode.WriteTo(contentWritable) + sso.DatetimeAttribute.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sso.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the SimpleSearchObject from the given readable +func (sso *SimpleSearchObject) ExtractFrom(readable types.Readable) error { + var err error + + err = sso.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchObject header. %s", err.Error()) + } + + err = sso.ObjectID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchObject.ObjectID. %s", err.Error()) + } + + err = sso.OwnerPID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchObject.OwnerPID. %s", err.Error()) + } + + err = sso.Attributes.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchObject.Attributes. %s", err.Error()) + } + + err = sso.Metadata.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchObject.Metadata. %s", err.Error()) + } + + err = sso.CommunityIDMiiverse.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchObject.CommunityIDMiiverse. %s", err.Error()) + } + + err = sso.CommunityCode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchObject.CommunityCode. %s", err.Error()) + } + + err = sso.DatetimeAttribute.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchObject.DatetimeAttribute. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of SimpleSearchObject +func (sso *SimpleSearchObject) Copy() types.RVType { + copied := NewSimpleSearchObject() + + copied.StructureVersion = sso.StructureVersion + copied.ObjectID = sso.ObjectID.Copy().(*types.PrimitiveU32) + copied.OwnerPID = sso.OwnerPID.Copy().(*types.PID) + copied.Attributes = sso.Attributes.Copy().(*types.List[*types.PrimitiveU32]) + copied.Metadata = sso.Metadata.Copy().(*types.QBuffer) + copied.CommunityIDMiiverse = sso.CommunityIDMiiverse.Copy().(*types.PrimitiveU32) + copied.CommunityCode = sso.CommunityCode.Copy().(*types.String) + copied.DatetimeAttribute = sso.DatetimeAttribute.Copy().(*SimpleSearchDateTimeAttribute) + + return copied +} + +// Equals checks if the given SimpleSearchObject contains the same data as the current SimpleSearchObject +func (sso *SimpleSearchObject) Equals(o types.RVType) bool { + if _, ok := o.(*SimpleSearchObject); !ok { + return false + } + + other := o.(*SimpleSearchObject) + + if sso.StructureVersion != other.StructureVersion { + return false + } + + if !sso.ObjectID.Equals(other.ObjectID) { + return false + } + + if !sso.OwnerPID.Equals(other.OwnerPID) { + return false + } + + if !sso.Attributes.Equals(other.Attributes) { + return false + } + + if !sso.Metadata.Equals(other.Metadata) { + return false + } + + if !sso.CommunityIDMiiverse.Equals(other.CommunityIDMiiverse) { + return false + } + + if !sso.CommunityCode.Equals(other.CommunityCode) { + return false + } + + return sso.DatetimeAttribute.Equals(other.DatetimeAttribute) +} + +// String returns the string representation of the SimpleSearchObject +func (sso *SimpleSearchObject) String() string { + return sso.FormatToString(0) +} + +// FormatToString pretty-prints the SimpleSearchObject using the provided indentation level +func (sso *SimpleSearchObject) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("SimpleSearchObject{\n") + b.WriteString(fmt.Sprintf("%sObjectID: %s,\n", indentationValues, sso.ObjectID)) + b.WriteString(fmt.Sprintf("%sOwnerPID: %s,\n", indentationValues, sso.OwnerPID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sAttributes: %s,\n", indentationValues, sso.Attributes)) + b.WriteString(fmt.Sprintf("%sMetadata: %s,\n", indentationValues, sso.Metadata)) + b.WriteString(fmt.Sprintf("%sCommunityIDMiiverse: %s,\n", indentationValues, sso.CommunityIDMiiverse)) + b.WriteString(fmt.Sprintf("%sCommunityCode: %s,\n", indentationValues, sso.CommunityCode)) + b.WriteString(fmt.Sprintf("%sDatetimeAttribute: %s,\n", indentationValues, sso.DatetimeAttribute.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewSimpleSearchObject returns a new SimpleSearchObject +func NewSimpleSearchObject() *SimpleSearchObject { + sso := &SimpleSearchObject{ + ObjectID: types.NewPrimitiveU32(0), + OwnerPID: types.NewPID(0), + Attributes: types.NewList[*types.PrimitiveU32](), + Metadata: types.NewQBuffer(nil), + CommunityIDMiiverse: types.NewPrimitiveU32(0), + CommunityCode: types.NewString(""), + DatetimeAttribute: NewSimpleSearchDateTimeAttribute(), + } + + sso.Attributes.Type = types.NewPrimitiveU32(0) + + return sso +} diff --git a/nex-protocols-go/matchmake-extension/mario-kart-8/types/simple_search_param.go b/nex-protocols-go/matchmake-extension/mario-kart-8/types/simple_search_param.go new file mode 100644 index 0000000..71886c3 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/mario-kart-8/types/simple_search_param.go @@ -0,0 +1,170 @@ +// Package types implements all the types used by the MatchmakeExtension protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// SimpleSearchParam is a type within the MatchmakeExtension protocol +type SimpleSearchParam struct { + types.Structure + Unknown *types.PrimitiveU32 + Unknown2 *types.PID + Conditions *types.List[*SimpleSearchCondition] + Unknown3 *types.String + ResultRange *types.ResultRange + Unknown4 *types.DateTime +} + +// WriteTo writes the SimpleSearchParam to the given writable +func (ssp *SimpleSearchParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + ssp.Unknown.WriteTo(contentWritable) + ssp.Unknown2.WriteTo(contentWritable) + ssp.Conditions.WriteTo(contentWritable) + ssp.Unknown3.WriteTo(contentWritable) + ssp.ResultRange.WriteTo(contentWritable) + ssp.Unknown4.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + ssp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the SimpleSearchParam from the given readable +func (ssp *SimpleSearchParam) ExtractFrom(readable types.Readable) error { + var err error + + err = ssp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchParam header. %s", err.Error()) + } + + err = ssp.Unknown.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchParam.Unknown. %s", err.Error()) + } + + err = ssp.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchParam.Unknown2. %s", err.Error()) + } + + err = ssp.Conditions.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchParam.Conditions. %s", err.Error()) + } + + err = ssp.Unknown3.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchParam.Unknown3. %s", err.Error()) + } + + err = ssp.ResultRange.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchParam.ResultRange. %s", err.Error()) + } + + err = ssp.Unknown4.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SimpleSearchParam.Unknown4. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of SimpleSearchParam +func (ssp *SimpleSearchParam) Copy() types.RVType { + copied := NewSimpleSearchParam() + + copied.StructureVersion = ssp.StructureVersion + copied.Unknown = ssp.Unknown.Copy().(*types.PrimitiveU32) + copied.Unknown2 = ssp.Unknown2.Copy().(*types.PID) + copied.Conditions = ssp.Conditions.Copy().(*types.List[*SimpleSearchCondition]) + copied.Unknown3 = ssp.Unknown3.Copy().(*types.String) + copied.ResultRange = ssp.ResultRange.Copy().(*types.ResultRange) + copied.Unknown4 = ssp.Unknown4.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given SimpleSearchParam contains the same data as the current SimpleSearchParam +func (ssp *SimpleSearchParam) Equals(o types.RVType) bool { + if _, ok := o.(*SimpleSearchParam); !ok { + return false + } + + other := o.(*SimpleSearchParam) + + if ssp.StructureVersion != other.StructureVersion { + return false + } + + if !ssp.Unknown.Equals(other.Unknown) { + return false + } + + if !ssp.Unknown2.Equals(other.Unknown2) { + return false + } + + if !ssp.Conditions.Equals(other.Conditions) { + return false + } + + if !ssp.Unknown3.Equals(other.Unknown3) { + return false + } + + if !ssp.ResultRange.Equals(other.ResultRange) { + return false + } + + return ssp.Unknown4.Equals(other.Unknown4) +} + +// String returns the string representation of the SimpleSearchParam +func (ssp *SimpleSearchParam) String() string { + return ssp.FormatToString(0) +} + +// FormatToString pretty-prints the SimpleSearchParam using the provided indentation level +func (ssp *SimpleSearchParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("SimpleSearchParam{\n") + b.WriteString(fmt.Sprintf("%sUnknown: %s,\n", indentationValues, ssp.Unknown)) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, ssp.Unknown2.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sConditions: %s,\n", indentationValues, ssp.Conditions)) + b.WriteString(fmt.Sprintf("%sUnknown3: %s,\n", indentationValues, ssp.Unknown3)) + b.WriteString(fmt.Sprintf("%sResultRange: %s,\n", indentationValues, ssp.ResultRange.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUnknown4: %s,\n", indentationValues, ssp.Unknown4.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewSimpleSearchParam returns a new SimpleSearchParam +func NewSimpleSearchParam() *SimpleSearchParam { + ssp := &SimpleSearchParam{ + Unknown: types.NewPrimitiveU32(0), + Unknown2: types.NewPID(0), + Conditions: types.NewList[*SimpleSearchCondition](), + Unknown3: types.NewString(""), + ResultRange: types.NewResultRange(), + Unknown4: types.NewDateTime(0), + } + + ssp.Conditions.Type = NewSimpleSearchCondition() + + return ssp +} diff --git a/nex-protocols-go/matchmake-extension/mario-kart-8/update_simple_search_object.go b/nex-protocols-go/matchmake-extension/mario-kart-8/update_simple_search_object.go new file mode 100644 index 0000000..9ddf973 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/mario-kart-8/update_simple_search_object.go @@ -0,0 +1,61 @@ +// Package protocol implements the MatchmakeExtensionMarioKart8 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + matchmake_extension_mario_kart8_types "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension/mario-kart-8/types" +) + +func (protocol *Protocol) handleUpdateSimpleSearchObject(packet nex.PacketInterface) { + if protocol.UpdateSimpleSearchObject == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionMarioKart8::UpdateSimpleSearchObject not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + objectID := types.NewPrimitiveU32(0) + newObject := matchmake_extension_mario_kart8_types.NewSimpleSearchObject() + + var err error + + err = objectID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateSimpleSearchObject(fmt.Errorf("Failed to read objectID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = newObject.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateSimpleSearchObject(fmt.Errorf("Failed to read newObject from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateSimpleSearchObject(nil, packet, callID, objectID, newObject) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/modify_current_game_attribute.go b/nex-protocols-go/matchmake-extension/modify_current_game_attribute.go new file mode 100644 index 0000000..2266fa6 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/modify_current_game_attribute.go @@ -0,0 +1,71 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleModifyCurrentGameAttribute(packet nex.PacketInterface) { + if protocol.ModifyCurrentGameAttribute == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::ModifyCurrentGameAttribute not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + attribIndex := types.NewPrimitiveU32(0) + newValue := types.NewPrimitiveU32(0) + + var err error + + err = gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ModifyCurrentGameAttribute(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = attribIndex.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ModifyCurrentGameAttribute(fmt.Errorf("Failed to read attribIndex from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = newValue.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ModifyCurrentGameAttribute(fmt.Errorf("Failed to read newValue from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ModifyCurrentGameAttribute(nil, packet, callID, gid, attribIndex, newValue) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/monster-hunter-xx/add_friends.go b/nex-protocols-go/matchmake-extension/monster-hunter-xx/add_friends.go new file mode 100644 index 0000000..6bc32e9 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/monster-hunter-xx/add_friends.go @@ -0,0 +1,48 @@ +// Package protocol implements the MatchmakeExtensionMonsterHunterXX protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAddFriends(packet nex.PacketInterface) { + if protocol.AddFriends == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionMonsterHunterXX::AddFriends not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pids := types.NewList[*types.PID]() + pids.Type = types.NewPID(0) + + err := pids.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AddFriends(fmt.Errorf("Failed to read pids from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AddFriends(nil, packet, callID, pids) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/monster-hunter-xx/find_community_by_owner.go b/nex-protocols-go/matchmake-extension/monster-hunter-xx/find_community_by_owner.go new file mode 100644 index 0000000..6373aa8 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/monster-hunter-xx/find_community_by_owner.go @@ -0,0 +1,60 @@ +// Package protocol implements the MatchmakeExtensionMonsterHunterXX protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindCommunityByOwner(packet nex.PacketInterface) { + if protocol.FindCommunityByOwner == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionMonsterHunterXX::FindCommunityByOwner not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + id := types.NewPrimitiveU64(0) + resultRange := types.NewResultRange() + + var err error + + err = id.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindCommunityByOwner(fmt.Errorf("Failed to read id from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindCommunityByOwner(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindCommunityByOwner(nil, packet, callID, id, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/monster-hunter-xx/get_friend_user_profiles.go b/nex-protocols-go/matchmake-extension/monster-hunter-xx/get_friend_user_profiles.go new file mode 100644 index 0000000..7a5bbb0 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/monster-hunter-xx/get_friend_user_profiles.go @@ -0,0 +1,48 @@ +// Package protocol implements the MatchmakeExtensionMonsterHunterXX protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetFriendUserProfiles(packet nex.PacketInterface) { + if protocol.GetFriendUserProfiles == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionMonsterHunterXX::GetFriendUserProfiles not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pids := types.NewList[*types.PID]() + pids.Type = types.NewPID(0) + + err := pids.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetFriendUserProfiles(fmt.Errorf("Failed to read pids from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetFriendUserProfiles(nil, packet, callID, pids) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/monster-hunter-xx/protocol.go b/nex-protocols-go/matchmake-extension/monster-hunter-xx/protocol.go new file mode 100644 index 0000000..ca38749 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/monster-hunter-xx/protocol.go @@ -0,0 +1,96 @@ +// Package protocol implements the MatchmakeExtensionMonsterHunterXX protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" + matchmake_extension_monster_hunter_x_x_types "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension/monster-hunter-xx/types" + "golang.org/x/exp/slices" +) + +const ( + // ProtocolID is the Protocol ID for the Matchmake Extension (Monster Hunter XX) protocol + ProtocolID = 0x6D + + // MethodUpdateFriendUserProfile is the method ID for the UpdateFriendUserProfile method + MethodUpdateFriendUserProfile = 0x36 + + // MethodGetFriendUserProfiles is the method ID for the GetFriendUserProfiles method + MethodGetFriendUserProfiles = 0x37 + + // MethodAddFriends is the method ID for the AddFriends method + MethodAddFriends = 0x39 + + // MethodRemoveFriend is the method ID for the RemoveFriend method + MethodRemoveFriend = 0x3A + + // MethodFindCommunityByOwner is the method ID for the FindCommunityByOwner method + MethodFindCommunityByOwner = 0x3B +) + +var patchedMethods = []uint32{ + MethodUpdateFriendUserProfile, + MethodGetFriendUserProfiles, + MethodAddFriends, + MethodRemoveFriend, + MethodFindCommunityByOwner, +} + +type matchmakeExtensionProtocol = matchmake_extension.Protocol + +// Protocol stores all the RMC method handlers for the Matchmake Extension (Monster Hunter XX) protocol and listens for requests +// Embeds the Matchmake Extension protocol +type Protocol struct { + endpoint nex.EndpointInterface + matchmakeExtensionProtocol + UpdateFriendUserProfile func(err error, packet nex.PacketInterface, callID uint32, param *matchmake_extension_monster_hunter_x_x_types.FriendUserParam) (*nex.RMCMessage, *nex.Error) + GetFriendUserProfiles func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error) + AddFriends func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error) + RemoveFriend func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID) (*nex.RMCMessage, *nex.Error) + FindCommunityByOwner func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU64, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if !slices.Contains(patchedMethods, message.MethodID) { + protocol.matchmakeExtensionProtocol.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodUpdateFriendUserProfile: + protocol.handleUpdateFriendUserProfile(packet) + case MethodGetFriendUserProfiles: + protocol.handleGetFriendUserProfiles(packet) + case MethodAddFriends: + protocol.handleAddFriends(packet) + case MethodRemoveFriend: + protocol.handleRemoveFriend(packet) + case MethodFindCommunityByOwner: + protocol.handleFindCommunityByOwner(packet) + default: + errMessage := fmt.Sprintf("Unsupported Matchmake Extension (Monster Hunter XX) method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new MatchmakeExtensionMonsterHunterXX protocol +func NewProtocol(endpoint nex.EndpointInterface) *Protocol { + protocol := &Protocol{endpoint: endpoint} + protocol.matchmakeExtensionProtocol.SetEndpoint(endpoint) + + return protocol +} diff --git a/nex-protocols-go/matchmake-extension/monster-hunter-xx/remove_friend.go b/nex-protocols-go/matchmake-extension/monster-hunter-xx/remove_friend.go new file mode 100644 index 0000000..de392a2 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/monster-hunter-xx/remove_friend.go @@ -0,0 +1,47 @@ +// Package protocol implements the MatchmakeExtensionMonsterHunterXX protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRemoveFriend(packet nex.PacketInterface) { + if protocol.RemoveFriend == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionMonsterHunterXX::RemoveFriend not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pid := types.NewPID(0) + + err := pid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RemoveFriend(fmt.Errorf("Failed to read pid from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RemoveFriend(nil, packet, callID, pid) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/monster-hunter-xx/types/friend_user_info.go b/nex-protocols-go/matchmake-extension/monster-hunter-xx/types/friend_user_info.go new file mode 100644 index 0000000..06472da --- /dev/null +++ b/nex-protocols-go/matchmake-extension/monster-hunter-xx/types/friend_user_info.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the MatchmakeExtension protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// FriendUserInfo is a type within the MatchmakeExtension protocol +type FriendUserInfo struct { + types.Structure + PID *types.PID + Name *types.String + Presence *types.PrimitiveU32 +} + +// WriteTo writes the FriendUserInfo to the given writable +func (fui *FriendUserInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + fui.PID.WriteTo(contentWritable) + fui.Name.WriteTo(contentWritable) + fui.Presence.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + fui.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the FriendUserInfo from the given readable +func (fui *FriendUserInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = fui.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendUserInfo header. %s", err.Error()) + } + + err = fui.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendUserInfo.PID. %s", err.Error()) + } + + err = fui.Name.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendUserInfo.Name. %s", err.Error()) + } + + err = fui.Presence.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendUserInfo.Presence. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of FriendUserInfo +func (fui *FriendUserInfo) Copy() types.RVType { + copied := NewFriendUserInfo() + + copied.StructureVersion = fui.StructureVersion + copied.PID = fui.PID.Copy().(*types.PID) + copied.Name = fui.Name.Copy().(*types.String) + copied.Presence = fui.Presence.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given FriendUserInfo contains the same data as the current FriendUserInfo +func (fui *FriendUserInfo) Equals(o types.RVType) bool { + if _, ok := o.(*FriendUserInfo); !ok { + return false + } + + other := o.(*FriendUserInfo) + + if fui.StructureVersion != other.StructureVersion { + return false + } + + if !fui.PID.Equals(other.PID) { + return false + } + + if !fui.Name.Equals(other.Name) { + return false + } + + return fui.Presence.Equals(other.Presence) +} + +// String returns the string representation of the FriendUserInfo +func (fui *FriendUserInfo) String() string { + return fui.FormatToString(0) +} + +// FormatToString pretty-prints the FriendUserInfo using the provided indentation level +func (fui *FriendUserInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("FriendUserInfo{\n") + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, fui.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sName: %s,\n", indentationValues, fui.Name)) + b.WriteString(fmt.Sprintf("%sPresence: %s,\n", indentationValues, fui.Presence)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewFriendUserInfo returns a new FriendUserInfo +func NewFriendUserInfo() *FriendUserInfo { + fui := &FriendUserInfo{ + PID: types.NewPID(0), + Name: types.NewString(""), + Presence: types.NewPrimitiveU32(0), + } + + return fui +} diff --git a/nex-protocols-go/matchmake-extension/monster-hunter-xx/types/friend_user_param.go b/nex-protocols-go/matchmake-extension/monster-hunter-xx/types/friend_user_param.go new file mode 100644 index 0000000..13dd03b --- /dev/null +++ b/nex-protocols-go/matchmake-extension/monster-hunter-xx/types/friend_user_param.go @@ -0,0 +1,98 @@ +// Package types implements all the types used by the MatchmakeExtension protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// FriendUserParam is a type within the MatchmakeExtension protocol +type FriendUserParam struct { + types.Structure + Name *types.String +} + +// WriteTo writes the FriendUserParam to the given writable +func (fup *FriendUserParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + fup.Name.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + fup.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the FriendUserParam from the given readable +func (fup *FriendUserParam) ExtractFrom(readable types.Readable) error { + var err error + + err = fup.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendUserParam header. %s", err.Error()) + } + + err = fup.Name.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract FriendUserParam.Name. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of FriendUserParam +func (fup *FriendUserParam) Copy() types.RVType { + copied := NewFriendUserParam() + + copied.StructureVersion = fup.StructureVersion + copied.Name = fup.Name.Copy().(*types.String) + + return copied +} + +// Equals checks if the given FriendUserParam contains the same data as the current FriendUserParam +func (fup *FriendUserParam) Equals(o types.RVType) bool { + if _, ok := o.(*FriendUserParam); !ok { + return false + } + + other := o.(*FriendUserParam) + + if fup.StructureVersion != other.StructureVersion { + return false + } + + return fup.Name.Equals(other.Name) +} + +// String returns the string representation of the FriendUserParam +func (fup *FriendUserParam) String() string { + return fup.FormatToString(0) +} + +// FormatToString pretty-prints the FriendUserParam using the provided indentation level +func (fup *FriendUserParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("FriendUserParam{\n") + b.WriteString(fmt.Sprintf("%sName: %s,\n", indentationValues, fup.Name)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewFriendUserParam returns a new FriendUserParam +func NewFriendUserParam() *FriendUserParam { + fup := &FriendUserParam{ + Name: types.NewString(""), + } + + return fup +} diff --git a/nex-protocols-go/matchmake-extension/monster-hunter-xx/update_friend_user_profile.go b/nex-protocols-go/matchmake-extension/monster-hunter-xx/update_friend_user_profile.go new file mode 100644 index 0000000..174017d --- /dev/null +++ b/nex-protocols-go/matchmake-extension/monster-hunter-xx/update_friend_user_profile.go @@ -0,0 +1,47 @@ +// Package protocol implements the MatchmakeExtensionMonsterHunterXX protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + matchmake_extension_monster_hunter_xx_types "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension/monster-hunter-xx/types" +) + +func (protocol *Protocol) handleUpdateFriendUserProfile(packet nex.PacketInterface) { + if protocol.UpdateFriendUserProfile == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionMonsterHunterXX::UpdateFriendUserProfile not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := matchmake_extension_monster_hunter_xx_types.NewFriendUserParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateFriendUserProfile(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateFriendUserProfile(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/open_participation.go b/nex-protocols-go/matchmake-extension/open_participation.go new file mode 100644 index 0000000..b7d4fdb --- /dev/null +++ b/nex-protocols-go/matchmake-extension/open_participation.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleOpenParticipation(packet nex.PacketInterface) { + if protocol.OpenParticipation == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::OpenParticipation not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + + err := gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.OpenParticipation(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.OpenParticipation(nil, packet, callID, gid) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/pokemon-gen6/clear_my_previously_matched_user_cache.go b/nex-protocols-go/matchmake-extension/pokemon-gen6/clear_my_previously_matched_user_cache.go new file mode 100644 index 0000000..c14661d --- /dev/null +++ b/nex-protocols-go/matchmake-extension/pokemon-gen6/clear_my_previously_matched_user_cache.go @@ -0,0 +1,29 @@ +// Package protocol implements the Pokemon GEN 6 Matchmake Extension protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleClearMyPreviouslyMatchedUserCache(packet nex.PacketInterface) { + if protocol.ClearMyPreviouslyMatchedUserCache == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::ClearMyPreviouslyMatchedUserCache not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.ClearMyPreviouslyMatchedUserCache(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/pokemon-gen6/protocol.go b/nex-protocols-go/matchmake-extension/pokemon-gen6/protocol.go new file mode 100644 index 0000000..966feef --- /dev/null +++ b/nex-protocols-go/matchmake-extension/pokemon-gen6/protocol.go @@ -0,0 +1,66 @@ +// Package protocol implements the Pokemon GEN 6 Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" + "golang.org/x/exp/slices" +) + +const ( + // ProtocolID is the protocol ID for the Matchmake Extension (Pokemon GEN 6) protocol. ID is the same as the Matchmake Extension protocol + ProtocolID = 0x6D + + // MethodClearMyPreviouslyMatchedUserCache is the method ID for the method ClearMyPreviouslyMatchedUserCache + MethodClearMyPreviouslyMatchedUserCache = 0x22 +) + +var patchedMethods = []uint32{ + MethodClearMyPreviouslyMatchedUserCache, +} + +type matchmakeExtensionProtocol = matchmake_extension.Protocol + +// Protocol stores all the RMC method handlers for the Matchmake Extension (Pokemon GEN 6) protocol and listens for requests +// Embeds the Matchmake Extension protocol +type Protocol struct { + endpoint nex.EndpointInterface + matchmakeExtensionProtocol + ClearMyPreviouslyMatchedUserCache func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if !slices.Contains(patchedMethods, message.MethodID) { + protocol.matchmakeExtensionProtocol.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodClearMyPreviouslyMatchedUserCache: + protocol.handleClearMyPreviouslyMatchedUserCache(packet) + default: + errMessage := fmt.Sprintf("Unsupported MatchmakeExtension (Pokemon GEN 6) method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Matchmake Extension (Pokemon GEN 6) protocol +func NewProtocol(endpoint nex.EndpointInterface) *Protocol { + protocol := &Protocol{endpoint: endpoint} + protocol.matchmakeExtensionProtocol.SetEndpoint(endpoint) + + return protocol +} diff --git a/nex-protocols-go/matchmake-extension/protocol.go b/nex-protocols-go/matchmake-extension/protocol.go new file mode 100644 index 0000000..53f719c --- /dev/null +++ b/nex-protocols-go/matchmake-extension/protocol.go @@ -0,0 +1,716 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +const ( + // ProtocolID is the protocol ID for the Matchmake Extension protocol + ProtocolID = 0x6D + + // MethodCloseParticipation is the method ID for method CloseParticipation + MethodCloseParticipation = 0x1 + + // MethodOpenParticipation is the method ID for method OpenParticipation + MethodOpenParticipation = 0x2 + + // MethodAutoMatchmakePostpone is the method ID for method AutoMatchmakePostpone + MethodAutoMatchmakePostpone = 0x3 + + // MethodBrowseMatchmakeSession is the method ID for method BrowseMatchmakeSession + MethodBrowseMatchmakeSession = 0x4 + + // MethodBrowseMatchmakeSessionWithHostURLs is the method ID for method BrowseMatchmakeSessionWithHostURLs + MethodBrowseMatchmakeSessionWithHostURLs = 0x5 + + // MethodCreateMatchmakeSession is the method ID for method CreateMatchmakeSession + MethodCreateMatchmakeSession = 0x6 + + // MethodJoinMatchmakeSession is the method ID for method JoinMatchmakeSession + MethodJoinMatchmakeSession = 0x7 + + // MethodModifyCurrentGameAttribute is the method ID for method ModifyCurrentGameAttribute + MethodModifyCurrentGameAttribute = 0x8 + + // MethodUpdateNotificationData is the method ID for method UpdateNotificationData + MethodUpdateNotificationData = 0x9 + + // MethodGetFriendNotificationData is the method ID for method GetFriendNotificationData + MethodGetFriendNotificationData = 0xA + + // MethodUpdateApplicationBuffer is the method ID for method UpdateApplicationBuffer + MethodUpdateApplicationBuffer = 0xB + + // MethodUpdateMatchmakeSessionAttribute is the method ID for method UpdateMatchmakeSessionAttribute + MethodUpdateMatchmakeSessionAttribute = 0xC + + // MethodGetlstFriendNotificationData is the method ID for method GetlstFriendNotificationData + MethodGetlstFriendNotificationData = 0xD + + // MethodUpdateMatchmakeSession is the method ID for method UpdateMatchmakeSession + MethodUpdateMatchmakeSession = 0xE + + // MethodAutoMatchmakeWithSearchCriteriaPostpone is the method ID for method AutoMatchmakeWithSearchCriteriaPostpone + MethodAutoMatchmakeWithSearchCriteriaPostpone = 0xF + + // MethodGetPlayingSession is the method ID for method GetPlayingSession + MethodGetPlayingSession = 0x10 + + // MethodCreateCommunity is the method ID for method CreateCommunity + MethodCreateCommunity = 0x11 + + // MethodUpdateCommunity is the method ID for method UpdateCommunity + MethodUpdateCommunity = 0x12 + + // MethodJoinCommunity is the method ID for method JoinCommunity + MethodJoinCommunity = 0x13 + + // MethodFindCommunityByGatheringID is the method ID for method FindCommunityByGatheringID + MethodFindCommunityByGatheringID = 0x14 + + // MethodFindOfficialCommunity is the method ID for method FindOfficialCommunity + MethodFindOfficialCommunity = 0x15 + + // MethodFindCommunityByParticipant is the method ID for method FindCommunityByParticipant + MethodFindCommunityByParticipant = 0x16 + + // MethodUpdatePrivacySetting is the method ID for method UpdatePrivacySetting + MethodUpdatePrivacySetting = 0x17 + + // MethodGetMyBlockList is the method ID for method GetMyBlockList + MethodGetMyBlockList = 0x18 + + // MethodAddToBlockList is the method ID for method AddToBlockList + MethodAddToBlockList = 0x19 + + // MethodRemoveFromBlockList is the method ID for method RemoveFromBlockList + MethodRemoveFromBlockList = 0x1A + + // MethodClearMyBlockList is the method ID for method ClearMyBlockList + MethodClearMyBlockList = 0x1B + + // MethodReportViolation is the method ID for method ReportViolation + MethodReportViolation = 0x1C + + // MethodIsViolationUser is the method ID for method IsViolationUser + MethodIsViolationUser = 0x1D + + // MethodJoinMatchmakeSessionEx is the method ID for method JoinMatchmakeSessionEx + MethodJoinMatchmakeSessionEx = 0x1E + + // MethodGetSimplePlayingSession is the method ID for method GetSimplePlayingSession + MethodGetSimplePlayingSession = 0x1F + + // MethodGetSimpleCommunity is the method ID for method GetSimpleCommunity + MethodGetSimpleCommunity = 0x20 + + // MethodAutoMatchmakeWithGatheringIDPostpone is the method ID for method AutoMatchmakeWithGatheringIDPostpone + MethodAutoMatchmakeWithGatheringIDPostpone = 0x21 + + // MethodUpdateProgressScore is the method ID for method UpdateProgressScore + MethodUpdateProgressScore = 0x22 + + // MethodDebugNotifyEvent is the method ID for method DebugNotifyEvent + MethodDebugNotifyEvent = 0x23 + + // MethodGenerateMatchmakeSessionSystemPassword is the method ID for method GenerateMatchmakeSessionSystemPassword + MethodGenerateMatchmakeSessionSystemPassword = 0x24 + + // MethodClearMatchmakeSessionSystemPassword is the method ID for method ClearMatchmakeSessionSystemPassword + MethodClearMatchmakeSessionSystemPassword = 0x25 + + // MethodCreateMatchmakeSessionWithParam is the method ID for method CreateMatchmakeSessionWithParam + MethodCreateMatchmakeSessionWithParam = 0x26 + + // MethodJoinMatchmakeSessionWithParam is the method ID for method JoinMatchmakeSessionWithParam + MethodJoinMatchmakeSessionWithParam = 0x27 + + // MethodAutoMatchmakeWithParamPostpone is the method ID for method AutoMatchmakeWithParamPostpone + MethodAutoMatchmakeWithParamPostpone = 0x28 + + // MethodFindMatchmakeSessionByGatheringIDDetail is the method ID for method FindMatchmakeSessionByGatheringIDDetail + MethodFindMatchmakeSessionByGatheringIDDetail = 0x29 + + // MethodBrowseMatchmakeSessionNoHolder is the method ID for method BrowseMatchmakeSessionNoHolder + MethodBrowseMatchmakeSessionNoHolder = 0x2A + + // MethodBrowseMatchmakeSessionWithHostURLsNoHolder is the method ID for method BrowseMatchmakeSessionWithHostURLsNoHolder + MethodBrowseMatchmakeSessionWithHostURLsNoHolder = 0x2B + + // MethodUpdateMatchmakeSessionPart is the method ID for method UpdateMatchmakeSessionPart + MethodUpdateMatchmakeSessionPart = 0x2C + + // MethodRequestMatchmaking is the method ID for method RequestMatchmaking + MethodRequestMatchmaking = 0x2D + + // MethodWithdrawMatchmaking is the method ID for method WithdrawMatchmaking + MethodWithdrawMatchmaking = 0x2E + + // MethodWithdrawMatchmakingAll is the method ID for method WithdrawMatchmakingAll + MethodWithdrawMatchmakingAll = 0x2F + + // MethodFindMatchmakeSessionByGatheringID is the method ID for method FindMatchmakeSessionByGatheringID + MethodFindMatchmakeSessionByGatheringID = 0x30 + + // MethodFindMatchmakeSessionBySingleGatheringID is the method ID for method FindMatchmakeSessionBySingleGatheringID + MethodFindMatchmakeSessionBySingleGatheringID = 0x31 + + // MethodFindMatchmakeSessionByOwner is the method ID for method FindMatchmakeSessionByOwner + MethodFindMatchmakeSessionByOwner = 0x32 + + // MethodFindMatchmakeSessionByParticipant is the method ID for method FindMatchmakeSessionByParticipant + MethodFindMatchmakeSessionByParticipant = 0x33 + + // MethodBrowseMatchmakeSessionNoHolderNoResultRange is the method ID for method BrowseMatchmakeSessionNoHolderNoResultRange + MethodBrowseMatchmakeSessionNoHolderNoResultRange = 0x34 + + // MethodBrowseMatchmakeSessionWithHostURLsNoHolderNoResultRange is the method ID for method BrowseMatchmakeSessionWithHostURLsNoHolderNoResultRange + MethodBrowseMatchmakeSessionWithHostURLsNoHolderNoResultRange = 0x35 + + // MethodFindCommunityByOwner is the method ID for method FindCommunityByOwner + MethodFindCommunityByOwner = 0x36 +) + +// Protocol stores all the RMC method handlers for the Matchmake Extension protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + CloseParticipation func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + OpenParticipation func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + AutoMatchmakePostpone func(err error, packet nex.PacketInterface, callID uint32, anyGathering *types.AnyDataHolder, message *types.String) (*nex.RMCMessage, *nex.Error) + BrowseMatchmakeSession func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + BrowseMatchmakeSessionWithHostURLs func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + CreateMatchmakeSession func(err error, packet nex.PacketInterface, callID uint32, anyGathering *types.AnyDataHolder, message *types.String, participationCount *types.PrimitiveU16) (*nex.RMCMessage, *nex.Error) + JoinMatchmakeSession func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error) + ModifyCurrentGameAttribute func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, attribIndex *types.PrimitiveU32, newValue *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + UpdateNotificationData func(err error, packet nex.PacketInterface, callID uint32, uiType *types.PrimitiveU32, uiParam1 *types.PrimitiveU32, uiParam2 *types.PrimitiveU32, strParam *types.String) (*nex.RMCMessage, *nex.Error) + GetFriendNotificationData func(err error, packet nex.PacketInterface, callID uint32, uiType *types.PrimitiveS32) (*nex.RMCMessage, *nex.Error) + UpdateApplicationBuffer func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, applicationBuffer *types.Buffer) (*nex.RMCMessage, *nex.Error) + UpdateMatchmakeSessionAttribute func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, attribs *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error) + GetlstFriendNotificationData func(err error, packet nex.PacketInterface, callID uint32, lstTypes *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error) + UpdateMatchmakeSession func(err error, packet nex.PacketInterface, callID uint32, anyGathering *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error) + AutoMatchmakeWithSearchCriteriaPostpone func(err error, packet nex.PacketInterface, callID uint32, lstSearchCriteria *types.List[*match_making_types.MatchmakeSessionSearchCriteria], anyGathering *types.AnyDataHolder, strMessage *types.String) (*nex.RMCMessage, *nex.Error) + GetPlayingSession func(err error, packet nex.PacketInterface, callID uint32, lstPID *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error) + CreateCommunity func(err error, packet nex.PacketInterface, callID uint32, community *match_making_types.PersistentGathering, strMessage *types.String) (*nex.RMCMessage, *nex.Error) + UpdateCommunity func(err error, packet nex.PacketInterface, callID uint32, community *match_making_types.PersistentGathering) (*nex.RMCMessage, *nex.Error) + JoinCommunity func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, strMessage *types.String, strPassword *types.String) (*nex.RMCMessage, *nex.Error) + FindCommunityByGatheringID func(err error, packet nex.PacketInterface, callID uint32, lstGID *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error) + FindOfficialCommunity func(err error, packet nex.PacketInterface, callID uint32, isAvailableOnly *types.PrimitiveBool, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + FindCommunityByParticipant func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + UpdatePrivacySetting func(err error, packet nex.PacketInterface, callID uint32, onlineStatus *types.PrimitiveBool, participationCommunity *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + GetMyBlockList func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + AddToBlockList func(err error, packet nex.PacketInterface, callID uint32, lstPrincipalID *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error) + RemoveFromBlockList func(err error, packet nex.PacketInterface, callID uint32, lstPrincipalID *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error) + ClearMyBlockList func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + ReportViolation func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID, userName *types.String, violationCode *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + IsViolationUser func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + JoinMatchmakeSessionEx func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, strMessage *types.String, dontCareMyBlockList *types.PrimitiveBool, participationCount *types.PrimitiveU16) (*nex.RMCMessage, *nex.Error) + GetSimplePlayingSession func(err error, packet nex.PacketInterface, callID uint32, listPID *types.List[*types.PID], includeLoginUser *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + GetSimpleCommunity func(err error, packet nex.PacketInterface, callID uint32, gatheringIDList *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error) + AutoMatchmakeWithGatheringIDPostpone func(err error, packet nex.PacketInterface, callID uint32, lstGID *types.List[*types.PrimitiveU32], anyGathering *types.AnyDataHolder, strMessage *types.String) (*nex.RMCMessage, *nex.Error) + UpdateProgressScore func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, progressScore *types.PrimitiveU8) (*nex.RMCMessage, *nex.Error) + DebugNotifyEvent func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID, mainType *types.PrimitiveU32, subType *types.PrimitiveU32, param1 *types.PrimitiveU64, param2 *types.PrimitiveU64, stringParam *types.String) (*nex.RMCMessage, *nex.Error) + GenerateMatchmakeSessionSystemPassword func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + ClearMatchmakeSessionSystemPassword func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + CreateMatchmakeSessionWithParam func(err error, packet nex.PacketInterface, callID uint32, createMatchmakeSessionParam *match_making_types.CreateMatchmakeSessionParam) (*nex.RMCMessage, *nex.Error) + JoinMatchmakeSessionWithParam func(err error, packet nex.PacketInterface, callID uint32, joinMatchmakeSessionParam *match_making_types.JoinMatchmakeSessionParam) (*nex.RMCMessage, *nex.Error) + AutoMatchmakeWithParamPostpone func(err error, packet nex.PacketInterface, callID uint32, autoMatchmakeParam *match_making_types.AutoMatchmakeParam) (*nex.RMCMessage, *nex.Error) + FindMatchmakeSessionByGatheringIDDetail func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + BrowseMatchmakeSessionNoHolder func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + BrowseMatchmakeSessionWithHostURLsNoHolder func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + UpdateMatchmakeSessionPart func(err error, packet nex.PacketInterface, callID uint32, updateMatchmakeSessionParam *match_making_types.UpdateMatchmakeSessionParam) (*nex.RMCMessage, *nex.Error) + RequestMatchmaking func(err error, packet nex.PacketInterface, callID uint32, autoMatchmakeParam *match_making_types.AutoMatchmakeParam) (*nex.RMCMessage, *nex.Error) + WithdrawMatchmaking func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + WithdrawMatchmakingAll func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + FindMatchmakeSessionByGatheringID func(err error, packet nex.PacketInterface, callID uint32, lstGID *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error) + FindMatchmakeSessionBySingleGatheringID func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + FindMatchmakeSessionByOwner func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU32, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + FindMatchmakeSessionByParticipant func(err error, packet nex.PacketInterface, callID uint32, param *match_making_types.FindMatchmakeSessionByParticipantParam) (*nex.RMCMessage, *nex.Error) + BrowseMatchmakeSessionNoHolderNoResultRange func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria) (*nex.RMCMessage, *nex.Error) + BrowseMatchmakeSessionWithHostURLsNoHolderNoResultRange func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria) (*nex.RMCMessage, *nex.Error) + FindCommunityByOwner func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) // TODO - Unknown request/response format + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Matchmake Extension protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerCloseParticipation(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerOpenParticipation(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerAutoMatchmakePostpone(handler func(err error, packet nex.PacketInterface, callID uint32, anyGathering *types.AnyDataHolder, message *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerBrowseMatchmakeSession(handler func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerBrowseMatchmakeSessionWithHostURLs(handler func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerCreateMatchmakeSession(handler func(err error, packet nex.PacketInterface, callID uint32, anyGathering *types.AnyDataHolder, message *types.String, participationCount *types.PrimitiveU16) (*nex.RMCMessage, *nex.Error)) + SetHandlerJoinMatchmakeSession(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerModifyCurrentGameAttribute(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, attribIndex *types.PrimitiveU32, newValue *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateNotificationData(handler func(err error, packet nex.PacketInterface, callID uint32, uiType *types.PrimitiveU32, uiParam1 *types.PrimitiveU32, uiParam2 *types.PrimitiveU32, strParam *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetFriendNotificationData(handler func(err error, packet nex.PacketInterface, callID uint32, uiType *types.PrimitiveS32) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateApplicationBuffer(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, applicationBuffer *types.Buffer) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateMatchmakeSessionAttribute(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, attribs *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetlstFriendNotificationData(handler func(err error, packet nex.PacketInterface, callID uint32, lstTypes *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateMatchmakeSession(handler func(err error, packet nex.PacketInterface, callID uint32, anyGathering *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) + SetHandlerAutoMatchmakeWithSearchCriteriaPostpone(handler func(err error, packet nex.PacketInterface, callID uint32, lstSearchCriteria *types.List[*match_making_types.MatchmakeSessionSearchCriteria], anyGathering *types.AnyDataHolder, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetPlayingSession(handler func(err error, packet nex.PacketInterface, callID uint32, lstPID *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) + SetHandlerCreateCommunity(handler func(err error, packet nex.PacketInterface, callID uint32, community *match_making_types.PersistentGathering, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateCommunity(handler func(err error, packet nex.PacketInterface, callID uint32, community *match_making_types.PersistentGathering) (*nex.RMCMessage, *nex.Error)) + SetHandlerJoinCommunity(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, strMessage *types.String, strPassword *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindCommunityByGatheringID(handler func(err error, packet nex.PacketInterface, callID uint32, lstGID *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindOfficialCommunity(handler func(err error, packet nex.PacketInterface, callID uint32, isAvailableOnly *types.PrimitiveBool, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindCommunityByParticipant(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdatePrivacySetting(handler func(err error, packet nex.PacketInterface, callID uint32, onlineStatus *types.PrimitiveBool, participationCommunity *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetMyBlockList(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerAddToBlockList(handler func(err error, packet nex.PacketInterface, callID uint32, lstPrincipalID *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) + SetHandlerRemoveFromBlockList(handler func(err error, packet nex.PacketInterface, callID uint32, lstPrincipalID *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) + SetHandlerClearMyBlockList(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerReportViolation(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID, userName *types.String, violationCode *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerIsViolationUser(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerJoinMatchmakeSessionEx(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, strMessage *types.String, dontCareMyBlockList *types.PrimitiveBool, participationCount *types.PrimitiveU16) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetSimplePlayingSession(handler func(err error, packet nex.PacketInterface, callID uint32, listPID *types.List[*types.PID], includeLoginUser *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetSimpleCommunity(handler func(err error, packet nex.PacketInterface, callID uint32, gatheringIDList *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) + SetHandlerAutoMatchmakeWithGatheringIDPostpone(handler func(err error, packet nex.PacketInterface, callID uint32, lstGID *types.List[*types.PrimitiveU32], anyGathering *types.AnyDataHolder, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateProgressScore(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, progressScore *types.PrimitiveU8) (*nex.RMCMessage, *nex.Error)) + SetHandlerDebugNotifyEvent(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID, mainType *types.PrimitiveU32, subType *types.PrimitiveU32, param1 *types.PrimitiveU64, param2 *types.PrimitiveU64, stringParam *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerGenerateMatchmakeSessionSystemPassword(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerClearMatchmakeSessionSystemPassword(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerCreateMatchmakeSessionWithParam(handler func(err error, packet nex.PacketInterface, callID uint32, createMatchmakeSessionParam *match_making_types.CreateMatchmakeSessionParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerJoinMatchmakeSessionWithParam(handler func(err error, packet nex.PacketInterface, callID uint32, joinMatchmakeSessionParam *match_making_types.JoinMatchmakeSessionParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerAutoMatchmakeWithParamPostpone(handler func(err error, packet nex.PacketInterface, callID uint32, autoMatchmakeParam *match_making_types.AutoMatchmakeParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindMatchmakeSessionByGatheringIDDetail(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerBrowseMatchmakeSessionNoHolder(handler func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerBrowseMatchmakeSessionWithHostURLsNoHolder(handler func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateMatchmakeSessionPart(handler func(err error, packet nex.PacketInterface, callID uint32, updateMatchmakeSessionParam *match_making_types.UpdateMatchmakeSessionParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerRequestMatchmaking(handler func(err error, packet nex.PacketInterface, callID uint32, autoMatchmakeParam *match_making_types.AutoMatchmakeParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerWithdrawMatchmaking(handler func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerWithdrawMatchmakingAll(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindMatchmakeSessionByGatheringID(handler func(err error, packet nex.PacketInterface, callID uint32, lstGID *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindMatchmakeSessionBySingleGatheringID(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindMatchmakeSessionByOwner(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU32, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindMatchmakeSessionByParticipant(handler func(err error, packet nex.PacketInterface, callID uint32, param *match_making_types.FindMatchmakeSessionByParticipantParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerBrowseMatchmakeSessionNoHolderNoResultRange(handler func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria) (*nex.RMCMessage, *nex.Error)) + SetHandlerBrowseMatchmakeSessionWithHostURLsNoHolderNoResultRange(handler func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindCommunityByOwner(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerCloseParticipation sets the handler for the CloseParticipation method +func (protocol *Protocol) SetHandlerCloseParticipation(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.CloseParticipation = handler +} + +// SetHandlerOpenParticipation sets the handler for the OpenParticipation method +func (protocol *Protocol) SetHandlerOpenParticipation(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.OpenParticipation = handler +} + +// SetHandlerAutoMatchmakePostpone sets the handler for the AutoMatchmakePostpone method +func (protocol *Protocol) SetHandlerAutoMatchmakePostpone(handler func(err error, packet nex.PacketInterface, callID uint32, anyGathering *types.AnyDataHolder, message *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.AutoMatchmakePostpone = handler +} + +// SetHandlerBrowseMatchmakeSession sets the handler for the BrowseMatchmakeSession method +func (protocol *Protocol) SetHandlerBrowseMatchmakeSession(handler func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.BrowseMatchmakeSession = handler +} + +// SetHandlerBrowseMatchmakeSessionWithHostURLs sets the handler for the BrowseMatchmakeSessionWithHostURLs method +func (protocol *Protocol) SetHandlerBrowseMatchmakeSessionWithHostURLs(handler func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.BrowseMatchmakeSessionWithHostURLs = handler +} + +// SetHandlerCreateMatchmakeSession sets the handler for the CreateMatchmakeSession method +func (protocol *Protocol) SetHandlerCreateMatchmakeSession(handler func(err error, packet nex.PacketInterface, callID uint32, anyGathering *types.AnyDataHolder, message *types.String, participationCount *types.PrimitiveU16) (*nex.RMCMessage, *nex.Error)) { + protocol.CreateMatchmakeSession = handler +} + +// SetHandlerJoinMatchmakeSession sets the handler for the JoinMatchmakeSession method +func (protocol *Protocol) SetHandlerJoinMatchmakeSession(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.JoinMatchmakeSession = handler +} + +// SetHandlerModifyCurrentGameAttribute sets the handler for the ModifyCurrentGameAttribute method +func (protocol *Protocol) SetHandlerModifyCurrentGameAttribute(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, attribIndex *types.PrimitiveU32, newValue *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.ModifyCurrentGameAttribute = handler +} + +// SetHandlerUpdateNotificationData sets the handler for the UpdateNotificationData method +func (protocol *Protocol) SetHandlerUpdateNotificationData(handler func(err error, packet nex.PacketInterface, callID uint32, uiType *types.PrimitiveU32, uiParam1 *types.PrimitiveU32, uiParam2 *types.PrimitiveU32, strParam *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateNotificationData = handler +} + +// SetHandlerGetFriendNotificationData sets the handler for the GetFriendNotificationData method +func (protocol *Protocol) SetHandlerGetFriendNotificationData(handler func(err error, packet nex.PacketInterface, callID uint32, uiType *types.PrimitiveS32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetFriendNotificationData = handler +} + +// SetHandlerUpdateApplicationBuffer sets the handler for the UpdateApplicationBuffer method +func (protocol *Protocol) SetHandlerUpdateApplicationBuffer(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, applicationBuffer *types.Buffer) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateApplicationBuffer = handler +} + +// SetHandlerUpdateMatchmakeSessionAttribute sets the handler for the UpdateMatchmakeSessionAttribute method +func (protocol *Protocol) SetHandlerUpdateMatchmakeSessionAttribute(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, attribs *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateMatchmakeSessionAttribute = handler +} + +// SetHandlerGetlstFriendNotificationData sets the handler for the GetlstFriendNotificationData method +func (protocol *Protocol) SetHandlerGetlstFriendNotificationData(handler func(err error, packet nex.PacketInterface, callID uint32, lstTypes *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetlstFriendNotificationData = handler +} + +// SetHandlerUpdateMatchmakeSession sets the handler for the UpdateMatchmakeSession method +func (protocol *Protocol) SetHandlerUpdateMatchmakeSession(handler func(err error, packet nex.PacketInterface, callID uint32, anyGathering *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateMatchmakeSession = handler +} + +// SetHandlerAutoMatchmakeWithSearchCriteriaPostpone sets the handler for the AutoMatchmakeWithSearchCriteriaPostpone method +func (protocol *Protocol) SetHandlerAutoMatchmakeWithSearchCriteriaPostpone(handler func(err error, packet nex.PacketInterface, callID uint32, lstSearchCriteria *types.List[*match_making_types.MatchmakeSessionSearchCriteria], anyGathering *types.AnyDataHolder, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.AutoMatchmakeWithSearchCriteriaPostpone = handler +} + +// SetHandlerGetPlayingSession sets the handler for the GetPlayingSession method +func (protocol *Protocol) SetHandlerGetPlayingSession(handler func(err error, packet nex.PacketInterface, callID uint32, lstPID *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetPlayingSession = handler +} + +// SetHandlerCreateCommunity sets the handler for the CreateCommunity method +func (protocol *Protocol) SetHandlerCreateCommunity(handler func(err error, packet nex.PacketInterface, callID uint32, community *match_making_types.PersistentGathering, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.CreateCommunity = handler +} + +// SetHandlerUpdateCommunity sets the handler for the UpdateCommunity method +func (protocol *Protocol) SetHandlerUpdateCommunity(handler func(err error, packet nex.PacketInterface, callID uint32, community *match_making_types.PersistentGathering) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateCommunity = handler +} + +// SetHandlerJoinCommunity sets the handler for the JoinCommunity method +func (protocol *Protocol) SetHandlerJoinCommunity(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, strMessage *types.String, strPassword *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.JoinCommunity = handler +} + +// SetHandlerFindCommunityByGatheringID sets the handler for the FindCommunityByGatheringID method +func (protocol *Protocol) SetHandlerFindCommunityByGatheringID(handler func(err error, packet nex.PacketInterface, callID uint32, lstGID *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) { + protocol.FindCommunityByGatheringID = handler +} + +// SetHandlerFindOfficialCommunity sets the handler for the FindOfficialCommunity method +func (protocol *Protocol) SetHandlerFindOfficialCommunity(handler func(err error, packet nex.PacketInterface, callID uint32, isAvailableOnly *types.PrimitiveBool, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.FindOfficialCommunity = handler +} + +// SetHandlerFindCommunityByParticipant sets the handler for the FindCommunityByParticipant method +func (protocol *Protocol) SetHandlerFindCommunityByParticipant(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.FindCommunityByParticipant = handler +} + +// SetHandlerUpdatePrivacySetting sets the handler for the UpdatePrivacySetting method +func (protocol *Protocol) SetHandlerUpdatePrivacySetting(handler func(err error, packet nex.PacketInterface, callID uint32, onlineStatus *types.PrimitiveBool, participationCommunity *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdatePrivacySetting = handler +} + +// SetHandlerGetMyBlockList sets the handler for the GetMyBlockList method +func (protocol *Protocol) SetHandlerGetMyBlockList(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetMyBlockList = handler +} + +// SetHandlerAddToBlockList sets the handler for the AddToBlockList method +func (protocol *Protocol) SetHandlerAddToBlockList(handler func(err error, packet nex.PacketInterface, callID uint32, lstPrincipalID *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) { + protocol.AddToBlockList = handler +} + +// SetHandlerRemoveFromBlockList sets the handler for the RemoveFromBlockList method +func (protocol *Protocol) SetHandlerRemoveFromBlockList(handler func(err error, packet nex.PacketInterface, callID uint32, lstPrincipalID *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) { + protocol.RemoveFromBlockList = handler +} + +// SetHandlerClearMyBlockList sets the handler for the ClearMyBlockList method +func (protocol *Protocol) SetHandlerClearMyBlockList(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.ClearMyBlockList = handler +} + +// SetHandlerReportViolation sets the handler for the ReportViolation method +func (protocol *Protocol) SetHandlerReportViolation(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID, userName *types.String, violationCode *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.ReportViolation = handler +} + +// SetHandlerIsViolationUser sets the handler for the IsViolationUser method +func (protocol *Protocol) SetHandlerIsViolationUser(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.IsViolationUser = handler +} + +// SetHandlerJoinMatchmakeSessionEx sets the handler for the JoinMatchmakeSessionEx method +func (protocol *Protocol) SetHandlerJoinMatchmakeSessionEx(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, strMessage *types.String, dontCareMyBlockList *types.PrimitiveBool, participationCount *types.PrimitiveU16) (*nex.RMCMessage, *nex.Error)) { + protocol.JoinMatchmakeSessionEx = handler +} + +// SetHandlerGetSimplePlayingSession sets the handler for the GetSimplePlayingSession method +func (protocol *Protocol) SetHandlerGetSimplePlayingSession(handler func(err error, packet nex.PacketInterface, callID uint32, listPID *types.List[*types.PID], includeLoginUser *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.GetSimplePlayingSession = handler +} + +// SetHandlerGetSimpleCommunity sets the handler for the GetSimpleCommunity method +func (protocol *Protocol) SetHandlerGetSimpleCommunity(handler func(err error, packet nex.PacketInterface, callID uint32, gatheringIDList *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetSimpleCommunity = handler +} + +// SetHandlerAutoMatchmakeWithGatheringIDPostpone sets the handler for the AutoMatchmakeWithGatheringIDPostpone method +func (protocol *Protocol) SetHandlerAutoMatchmakeWithGatheringIDPostpone(handler func(err error, packet nex.PacketInterface, callID uint32, lstGID *types.List[*types.PrimitiveU32], anyGathering *types.AnyDataHolder, strMessage *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.AutoMatchmakeWithGatheringIDPostpone = handler +} + +// SetHandlerUpdateProgressScore sets the handler for the UpdateProgressScore method +func (protocol *Protocol) SetHandlerUpdateProgressScore(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32, progressScore *types.PrimitiveU8) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateProgressScore = handler +} + +// SetHandlerDebugNotifyEvent sets the handler for the DebugNotifyEvent method +func (protocol *Protocol) SetHandlerDebugNotifyEvent(handler func(err error, packet nex.PacketInterface, callID uint32, pid *types.PID, mainType *types.PrimitiveU32, subType *types.PrimitiveU32, param1 *types.PrimitiveU64, param2 *types.PrimitiveU64, stringParam *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.DebugNotifyEvent = handler +} + +// SetHandlerGenerateMatchmakeSessionSystemPassword sets the handler for the GenerateMatchmakeSessionSystemPassword method +func (protocol *Protocol) SetHandlerGenerateMatchmakeSessionSystemPassword(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.GenerateMatchmakeSessionSystemPassword = handler +} + +// SetHandlerClearMatchmakeSessionSystemPassword sets the handler for the ClearMatchmakeSessionSystemPassword method +func (protocol *Protocol) SetHandlerClearMatchmakeSessionSystemPassword(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.ClearMatchmakeSessionSystemPassword = handler +} + +// SetHandlerCreateMatchmakeSessionWithParam sets the handler for the CreateMatchmakeSessionWithParam method +func (protocol *Protocol) SetHandlerCreateMatchmakeSessionWithParam(handler func(err error, packet nex.PacketInterface, callID uint32, createMatchmakeSessionParam *match_making_types.CreateMatchmakeSessionParam) (*nex.RMCMessage, *nex.Error)) { + protocol.CreateMatchmakeSessionWithParam = handler +} + +// SetHandlerJoinMatchmakeSessionWithParam sets the handler for the JoinMatchmakeSessionWithParam method +func (protocol *Protocol) SetHandlerJoinMatchmakeSessionWithParam(handler func(err error, packet nex.PacketInterface, callID uint32, joinMatchmakeSessionParam *match_making_types.JoinMatchmakeSessionParam) (*nex.RMCMessage, *nex.Error)) { + protocol.JoinMatchmakeSessionWithParam = handler +} + +// SetHandlerAutoMatchmakeWithParamPostpone sets the handler for the AutoMatchmakeWithParamPostpone method +func (protocol *Protocol) SetHandlerAutoMatchmakeWithParamPostpone(handler func(err error, packet nex.PacketInterface, callID uint32, autoMatchmakeParam *match_making_types.AutoMatchmakeParam) (*nex.RMCMessage, *nex.Error)) { + protocol.AutoMatchmakeWithParamPostpone = handler +} + +// SetHandlerFindMatchmakeSessionByGatheringIDDetail sets the handler for the FindMatchmakeSessionByGatheringIDDetail method +func (protocol *Protocol) SetHandlerFindMatchmakeSessionByGatheringIDDetail(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.FindMatchmakeSessionByGatheringIDDetail = handler +} + +// SetHandlerBrowseMatchmakeSessionNoHolder sets the handler for the BrowseMatchmakeSessionNoHolder method +func (protocol *Protocol) SetHandlerBrowseMatchmakeSessionNoHolder(handler func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.BrowseMatchmakeSessionNoHolder = handler +} + +// SetHandlerBrowseMatchmakeSessionWithHostURLsNoHolder sets the handler for the BrowseMatchmakeSessionWithHostURLsNoHolder method +func (protocol *Protocol) SetHandlerBrowseMatchmakeSessionWithHostURLsNoHolder(handler func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.BrowseMatchmakeSessionWithHostURLsNoHolder = handler +} + +// SetHandlerUpdateMatchmakeSessionPart sets the handler for the UpdateMatchmakeSessionPart method +func (protocol *Protocol) SetHandlerUpdateMatchmakeSessionPart(handler func(err error, packet nex.PacketInterface, callID uint32, updateMatchmakeSessionParam *match_making_types.UpdateMatchmakeSessionParam) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateMatchmakeSessionPart = handler +} + +// SetHandlerRequestMatchmaking sets the handler for the RequestMatchmaking method +func (protocol *Protocol) SetHandlerRequestMatchmaking(handler func(err error, packet nex.PacketInterface, callID uint32, autoMatchmakeParam *match_making_types.AutoMatchmakeParam) (*nex.RMCMessage, *nex.Error)) { + protocol.RequestMatchmaking = handler +} + +// SetHandlerWithdrawMatchmaking sets the handler for the WithdrawMatchmaking method +func (protocol *Protocol) SetHandlerWithdrawMatchmaking(handler func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.WithdrawMatchmaking = handler +} + +// SetHandlerWithdrawMatchmakingAll sets the handler for the WithdrawMatchmakingAll method +func (protocol *Protocol) SetHandlerWithdrawMatchmakingAll(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.WithdrawMatchmakingAll = handler +} + +// SetHandlerFindMatchmakeSessionByGatheringID sets the handler for the FindMatchmakeSessionByGatheringID method +func (protocol *Protocol) SetHandlerFindMatchmakeSessionByGatheringID(handler func(err error, packet nex.PacketInterface, callID uint32, lstGID *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) { + protocol.FindMatchmakeSessionByGatheringID = handler +} + +// SetHandlerFindMatchmakeSessionBySingleGatheringID sets the handler for the FindMatchmakeSessionBySingleGatheringID method +func (protocol *Protocol) SetHandlerFindMatchmakeSessionBySingleGatheringID(handler func(err error, packet nex.PacketInterface, callID uint32, gid *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.FindMatchmakeSessionBySingleGatheringID = handler +} + +// SetHandlerFindMatchmakeSessionByOwner sets the handler for the FindMatchmakeSessionByOwner method +func (protocol *Protocol) SetHandlerFindMatchmakeSessionByOwner(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PrimitiveU32, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.FindMatchmakeSessionByOwner = handler +} + +// SetHandlerFindMatchmakeSessionByParticipant sets the handler for the FindMatchmakeSessionByParticipant method +func (protocol *Protocol) SetHandlerFindMatchmakeSessionByParticipant(handler func(err error, packet nex.PacketInterface, callID uint32, param *match_making_types.FindMatchmakeSessionByParticipantParam) (*nex.RMCMessage, *nex.Error)) { + protocol.FindMatchmakeSessionByParticipant = handler +} + +// SetHandlerBrowseMatchmakeSessionNoHolderNoResultRange sets the handler for the BrowseMatchmakeSessionNoHolderNoResultRange method +func (protocol *Protocol) SetHandlerBrowseMatchmakeSessionNoHolderNoResultRange(handler func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria) (*nex.RMCMessage, *nex.Error)) { + protocol.BrowseMatchmakeSessionNoHolderNoResultRange = handler +} + +// SetHandlerBrowseMatchmakeSessionWithHostURLsNoHolderNoResultRange sets the handler for the BrowseMatchmakeSessionWithHostURLsNoHolderNoResultRange method +func (protocol *Protocol) SetHandlerBrowseMatchmakeSessionWithHostURLsNoHolderNoResultRange(handler func(err error, packet nex.PacketInterface, callID uint32, searchCriteria *match_making_types.MatchmakeSessionSearchCriteria) (*nex.RMCMessage, *nex.Error)) { + protocol.BrowseMatchmakeSessionWithHostURLsNoHolderNoResultRange = handler +} + +// SetHandlerFindCommunityByOwner sets the handler for the FindCommunityByOwner method +func (protocol *Protocol) SetHandlerFindCommunityByOwner(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) { + protocol.FindCommunityByOwner = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodCloseParticipation: + protocol.handleCloseParticipation(packet) + case MethodOpenParticipation: + protocol.handleOpenParticipation(packet) + case MethodAutoMatchmakePostpone: + protocol.handleAutoMatchmakePostpone(packet) + case MethodBrowseMatchmakeSession: + protocol.handleBrowseMatchmakeSession(packet) + case MethodBrowseMatchmakeSessionWithHostURLs: + protocol.handleBrowseMatchmakeSessionWithHostURLs(packet) + case MethodCreateMatchmakeSession: + protocol.handleCreateMatchmakeSession(packet) + case MethodJoinMatchmakeSession: + protocol.handleJoinMatchmakeSession(packet) + case MethodModifyCurrentGameAttribute: + protocol.handleModifyCurrentGameAttribute(packet) + case MethodUpdateNotificationData: + protocol.handleUpdateNotificationData(packet) + case MethodGetFriendNotificationData: + protocol.handleGetFriendNotificationData(packet) + case MethodUpdateApplicationBuffer: + protocol.handleUpdateApplicationBuffer(packet) + case MethodUpdateMatchmakeSessionAttribute: + protocol.handleUpdateMatchmakeSessionAttribute(packet) + case MethodGetlstFriendNotificationData: + protocol.handleGetlstFriendNotificationData(packet) + case MethodUpdateMatchmakeSession: + protocol.handleUpdateMatchmakeSession(packet) + case MethodAutoMatchmakeWithSearchCriteriaPostpone: + protocol.handleAutoMatchmakeWithSearchCriteriaPostpone(packet) + case MethodGetPlayingSession: + protocol.handleGetPlayingSession(packet) + case MethodCreateCommunity: + protocol.handleCreateCommunity(packet) + case MethodUpdateCommunity: + protocol.handleUpdateCommunity(packet) + case MethodJoinCommunity: + protocol.handleJoinCommunity(packet) + case MethodFindCommunityByGatheringID: + protocol.handleFindCommunityByGatheringID(packet) + case MethodFindOfficialCommunity: + protocol.handleFindOfficialCommunity(packet) + case MethodFindCommunityByParticipant: + protocol.handleFindCommunityByParticipant(packet) + case MethodUpdatePrivacySetting: + protocol.handleUpdatePrivacySetting(packet) + case MethodGetMyBlockList: + protocol.handleGetMyBlockList(packet) + case MethodAddToBlockList: + protocol.handleAddToBlockList(packet) + case MethodRemoveFromBlockList: + protocol.handleRemoveFromBlockList(packet) + case MethodClearMyBlockList: + protocol.handleClearMyBlockList(packet) + case MethodReportViolation: + protocol.handleReportViolation(packet) + case MethodIsViolationUser: + protocol.handleIsViolationUser(packet) + case MethodJoinMatchmakeSessionEx: + protocol.handleJoinMatchmakeSessionEx(packet) + case MethodGetSimplePlayingSession: + protocol.handleGetSimplePlayingSession(packet) + case MethodGetSimpleCommunity: + protocol.handleGetSimpleCommunity(packet) + case MethodAutoMatchmakeWithGatheringIDPostpone: + protocol.handleAutoMatchmakeWithGatheringIDPostpone(packet) + case MethodUpdateProgressScore: + protocol.handleUpdateProgressScore(packet) + case MethodDebugNotifyEvent: + protocol.handleDebugNotifyEvent(packet) + case MethodGenerateMatchmakeSessionSystemPassword: + protocol.handleGenerateMatchmakeSessionSystemPassword(packet) + case MethodClearMatchmakeSessionSystemPassword: + protocol.handleClearMatchmakeSessionSystemPassword(packet) + case MethodCreateMatchmakeSessionWithParam: + protocol.handleCreateMatchmakeSessionWithParam(packet) + case MethodJoinMatchmakeSessionWithParam: + protocol.handleJoinMatchmakeSessionWithParam(packet) + case MethodAutoMatchmakeWithParamPostpone: + protocol.handleAutoMatchmakeWithParamPostpone(packet) + case MethodFindMatchmakeSessionByGatheringIDDetail: + protocol.handleFindMatchmakeSessionByGatheringIDDetail(packet) + case MethodBrowseMatchmakeSessionNoHolder: + protocol.handleBrowseMatchmakeSessionNoHolder(packet) + case MethodBrowseMatchmakeSessionWithHostURLsNoHolder: + protocol.handleBrowseMatchmakeSessionWithHostURLsNoHolder(packet) + case MethodUpdateMatchmakeSessionPart: + protocol.handleUpdateMatchmakeSessionPart(packet) + case MethodRequestMatchmaking: + protocol.handleRequestMatchmaking(packet) + case MethodWithdrawMatchmaking: + protocol.handleWithdrawMatchmaking(packet) + case MethodWithdrawMatchmakingAll: + protocol.handleWithdrawMatchmakingAll(packet) + case MethodFindMatchmakeSessionByGatheringID: + protocol.handleFindMatchmakeSessionByGatheringID(packet) + case MethodFindMatchmakeSessionBySingleGatheringID: + protocol.handleFindMatchmakeSessionBySingleGatheringID(packet) + case MethodFindMatchmakeSessionByOwner: + protocol.handleFindMatchmakeSessionByOwner(packet) + case MethodFindMatchmakeSessionByParticipant: + protocol.handleFindMatchmakeSessionByParticipant(packet) + case MethodBrowseMatchmakeSessionNoHolderNoResultRange: + protocol.handleBrowseMatchmakeSessionNoHolderNoResultRange(packet) + case MethodBrowseMatchmakeSessionWithHostURLsNoHolderNoResultRange: + protocol.handleBrowseMatchmakeSessionWithHostURLsNoHolderNoResultRange(packet) + case MethodFindCommunityByOwner: + protocol.handleFindCommunityByOwner(packet) + default: + errMessage := fmt.Sprintf("Unsupported Matchmake Extension method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Matchmake Extension protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/matchmake-extension/remove_from_block_list.go b/nex-protocols-go/matchmake-extension/remove_from_block_list.go new file mode 100644 index 0000000..2db439e --- /dev/null +++ b/nex-protocols-go/matchmake-extension/remove_from_block_list.go @@ -0,0 +1,48 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRemoveFromBlockList(packet nex.PacketInterface) { + if protocol.RemoveFromBlockList == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::RemoveFromBlockList not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + lstPrincipalID := types.NewList[*types.PID]() + lstPrincipalID.Type = types.NewPID(0) + + err := lstPrincipalID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RemoveFromBlockList(fmt.Errorf("Failed to read lstPrincipalID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RemoveFromBlockList(nil, packet, callID, lstPrincipalID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/report_violation.go b/nex-protocols-go/matchmake-extension/report_violation.go new file mode 100644 index 0000000..1aba708 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/report_violation.go @@ -0,0 +1,71 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleReportViolation(packet nex.PacketInterface) { + if protocol.ReportViolation == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::ReportViolation not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pid := types.NewPID(0) + userName := types.NewString("") + violationCode := types.NewPrimitiveU32(0) + + var err error + + err = pid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReportViolation(fmt.Errorf("Failed to read pid from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = userName.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReportViolation(fmt.Errorf("Failed to read userName from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = violationCode.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReportViolation(fmt.Errorf("Failed to read violationCode from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ReportViolation(nil, packet, callID, pid, userName, violationCode) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/request_matchmaking.go b/nex-protocols-go/matchmake-extension/request_matchmaking.go new file mode 100644 index 0000000..ddba277 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/request_matchmaking.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +func (protocol *Protocol) handleRequestMatchmaking(packet nex.PacketInterface) { + if protocol.RequestMatchmaking == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::RequestMatchmaking not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + autoMatchmakeParam := match_making_types.NewAutoMatchmakeParam() + + err := autoMatchmakeParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RequestMatchmaking(fmt.Errorf("Failed to read autoMatchmakeParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RequestMatchmaking(nil, packet, callID, autoMatchmakeParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/auto_tournament_matchmake.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/auto_tournament_matchmake.go new file mode 100644 index 0000000..0ee55c1 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/auto_tournament_matchmake.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAutoTournamentMatchmake(packet nex.PacketInterface) { + if protocol.AutoTournamentMatchmake == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::AutoTournamentMatchmake not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::AutoTournamentMatchmake STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.AutoTournamentMatchmake(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_end_community_competition_participation.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_end_community_competition_participation.go new file mode 100644 index 0000000..f465b79 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_end_community_competition_participation.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDebugEndCommunityCompetitionParticipation(packet nex.PacketInterface) { + if protocol.DebugEndCommunityCompetitionParticipation == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::DebugEndCommunityCompetitionParticipation not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::DebugEndCommunityCompetitionParticipation STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.DebugEndCommunityCompetitionParticipation(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_join_community_competition.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_join_community_competition.go new file mode 100644 index 0000000..6c5dc7f --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_join_community_competition.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDebugJoinCommunityCompetition(packet nex.PacketInterface) { + if protocol.DebugJoinCommunityCompetition == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::DebugJoinCommunityCompetition not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::DebugJoinCommunityCompetition STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.DebugJoinCommunityCompetition(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_post_community_competition_match_result.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_post_community_competition_match_result.go new file mode 100644 index 0000000..e9bb5c9 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_post_community_competition_match_result.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDebugPostCommunityCompetitionMatchResult(packet nex.PacketInterface) { + if protocol.DebugPostCommunityCompetitionMatchResult == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::DebugPostCommunityCompetitionMatchResult not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::DebugPostCommunityCompetitionMatchResult STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.DebugPostCommunityCompetitionMatchResult(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_register_community_competition.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_register_community_competition.go new file mode 100644 index 0000000..21e3a35 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_register_community_competition.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDebugRegisterCommunityCompetition(packet nex.PacketInterface) { + if protocol.DebugRegisterCommunityCompetition == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::DebugRegisterCommunityCompetition not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::DebugRegisterCommunityCompetition STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.DebugRegisterCommunityCompetition(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_unregister_community_competition.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_unregister_community_competition.go new file mode 100644 index 0000000..3eeb7e3 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/debug_unregister_community_competition.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDebugUnregisterCommunityCompetition(packet nex.PacketInterface) { + if protocol.DebugUnregisterCommunityCompetition == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::DebugUnregisterCommunityCompetition not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::DebugUnregisterCommunityCompetition STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.DebugUnregisterCommunityCompetition(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/end_community_competition_participation.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/end_community_competition_participation.go new file mode 100644 index 0000000..8e52d4d --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/end_community_competition_participation.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleEndCommunityCompetitionParticipation(packet nex.PacketInterface) { + if protocol.EndCommunityCompetitionParticipation == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::EndCommunityCompetitionParticipation not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::EndCommunityCompetitionParticipation STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.EndCommunityCompetitionParticipation(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/end_community_competition_participation_by_gathering_id.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/end_community_competition_participation_by_gathering_id.go new file mode 100644 index 0000000..5102905 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/end_community_competition_participation_by_gathering_id.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleEndCommunityCompetitionParticipationByGatheringID(packet nex.PacketInterface) { + if protocol.EndCommunityCompetitionParticipationByGatheringID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::EndCommunityCompetitionParticipationByGatheringID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::EndCommunityCompetitionParticipationByGatheringID STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.EndCommunityCompetitionParticipationByGatheringID(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/find_community_competitions_by_gathering_id.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/find_community_competitions_by_gathering_id.go new file mode 100644 index 0000000..f23bbbc --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/find_community_competitions_by_gathering_id.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindCommunityCompetitionsByGatheringID(packet nex.PacketInterface) { + if protocol.FindCommunityCompetitionsByGatheringID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::FindCommunityCompetitionsByGatheringID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::FindCommunityCompetitionsByGatheringID STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.FindCommunityCompetitionsByGatheringID(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/find_community_competitions_by_participant.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/find_community_competitions_by_participant.go new file mode 100644 index 0000000..dd399d5 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/find_community_competitions_by_participant.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindCommunityCompetitionsByParticipant(packet nex.PacketInterface) { + if protocol.FindCommunityCompetitionsByParticipant == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::FindCommunityCompetitionsByParticipant not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::FindCommunityCompetitionsByParticipant STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.FindCommunityCompetitionsByParticipant(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_community_competition_by_id.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_community_competition_by_id.go new file mode 100644 index 0000000..76c128b --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_community_competition_by_id.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetCommunityCompetitionByID(packet nex.PacketInterface) { + if protocol.GetCommunityCompetitionByID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::GetCommunityCompetitionByID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::GetCommunityCompetitionByID STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetCommunityCompetitionByID(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_community_competition_ranking.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_community_competition_ranking.go new file mode 100644 index 0000000..b8df3c1 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_community_competition_ranking.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetCommunityCompetitionRanking(packet nex.PacketInterface) { + if protocol.GetCommunityCompetitionRanking == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::GetCommunityCompetitionRanking not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::GetCommunityCompetitionRanking STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetCommunityCompetitionRanking(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_community_competitions.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_community_competitions.go new file mode 100644 index 0000000..5fe8649 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_community_competitions.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetCommunityCompetitions(packet nex.PacketInterface) { + if protocol.GetCommunityCompetitions == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::GetCommunityCompetitions not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::GetCommunityCompetitions STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetCommunityCompetitions(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament.go new file mode 100644 index 0000000..d741537 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetTournament(packet nex.PacketInterface) { + if protocol.GetTournament == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::GetTournament not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::GetTournament STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetTournament(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_competition.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_competition.go new file mode 100644 index 0000000..bf926ac --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_competition.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetTournamentCompetition(packet nex.PacketInterface) { + if protocol.GetTournamentCompetition == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::GetTournamentCompetition not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::GetTournamentCompetition STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetTournamentCompetition(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_competitions.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_competitions.go new file mode 100644 index 0000000..f585d67 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_competitions.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetTournamentCompetitions(packet nex.PacketInterface) { + if protocol.GetTournamentCompetitions == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::GetTournamentCompetitions not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::GetTournamentCompetitions STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetTournamentCompetitions(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_profiles.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_profiles.go new file mode 100644 index 0000000..41b06c8 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_profiles.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetTournamentProfiles(packet nex.PacketInterface) { + if protocol.GetTournamentProfiles == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::GetTournamentProfiles not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::GetTournamentProfiles STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetTournamentProfiles(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_replay_id.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_replay_id.go new file mode 100644 index 0000000..ae79302 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_replay_id.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetTournamentReplayID(packet nex.PacketInterface) { + if protocol.GetTournamentReplayID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::GetTournamentReplayID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::GetTournamentReplayID STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetTournamentReplayID(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_replay_ids.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_replay_ids.go new file mode 100644 index 0000000..95fbb98 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_replay_ids.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetTournamentReplayIDs(packet nex.PacketInterface) { + if protocol.GetTournamentReplayIDs == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::GetTournamentReplayIDs not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::GetTournamentReplayIDs STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetTournamentReplayIDs(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_result.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_result.go new file mode 100644 index 0000000..39bb7ed --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/get_tournament_result.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetTournamentResult(packet nex.PacketInterface) { + if protocol.GetTournamentResult == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::GetTournamentResult not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::GetTournamentResult STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetTournamentResult(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/join_community_competition.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/join_community_competition.go new file mode 100644 index 0000000..efd7e88 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/join_community_competition.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleJoinCommunityCompetition(packet nex.PacketInterface) { + if protocol.JoinCommunityCompetition == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::JoinCommunityCompetition not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::JoinCommunityCompetition STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.JoinCommunityCompetition(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/join_community_competition_by_gathering_id.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/join_community_competition_by_gathering_id.go new file mode 100644 index 0000000..e0afe3d --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/join_community_competition_by_gathering_id.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleJoinCommunityCompetitionByGatheringID(packet nex.PacketInterface) { + if protocol.JoinCommunityCompetitionByGatheringID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::JoinCommunityCompetitionByGatheringID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::JoinCommunityCompetitionByGatheringID STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.JoinCommunityCompetitionByGatheringID(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/join_or_create_matchmake_session.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/join_or_create_matchmake_session.go new file mode 100644 index 0000000..a2e05d8 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/join_or_create_matchmake_session.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleJoinOrCreateMatchmakeSession(packet nex.PacketInterface) { + if protocol.JoinOrCreateMatchmakeSession == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::JoinOrCreateMatchmakeSession not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::JoinOrCreateMatchmakeSession STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.JoinOrCreateMatchmakeSession(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/post_community_competition_match_result.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/post_community_competition_match_result.go new file mode 100644 index 0000000..a5863d7 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/post_community_competition_match_result.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePostCommunityCompetitionMatchResult(packet nex.PacketInterface) { + if protocol.PostCommunityCompetitionMatchResult == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::PostCommunityCompetitionMatchResult not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::PostCommunityCompetitionMatchResult STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.PostCommunityCompetitionMatchResult(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/protocol.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/protocol.go new file mode 100644 index 0000000..9e22a07 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/protocol.go @@ -0,0 +1,311 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" + "golang.org/x/exp/slices" +) + +const ( + // ProtocolID is the Protocol ID for the Matchmake Extension (Super Smash Bros. 4) protocol + ProtocolID = 0x6D + + // MethodGetTournament is the method ID for the GetTournament method + MethodGetTournament = 0x24 + + // MethodGetTournamentReplayID is the method ID for the GetTournamentReplayID method + MethodGetTournamentReplayID = 0x25 + + // MethodGetTournamentResult is the method ID for the GetTournamentResult method + MethodGetTournamentResult = 0x26 + + // MethodSetTournamentReplayID is the method ID for the SetTournamentReplayID method + MethodSetTournamentReplayID = 0x27 + + // MethodGetTournamentProfiles is the method ID for the GetTournamentProfiles method + MethodGetTournamentProfiles = 0x28 + + // MethodJoinOrCreateMatchmakeSession is the method ID for the JoinOrCreateMatchmakeSession method + MethodJoinOrCreateMatchmakeSession = 0x29 + + // MethodRegisterTournamentPlayerInfo is the method ID for the RegisterTournamentPlayerInfo method + MethodRegisterTournamentPlayerInfo = 0x2A + + // MethodRegisterTournamentBot is the method ID for the RegisterTournamentBot method + MethodRegisterTournamentBot = 0x2B + + // MethodReportTournamentBotRoundResult is the method ID for the ReportTournamentBotRoundResult method + MethodReportTournamentBotRoundResult = 0x2C + + // MethodReplaceTournamentLeafNode is the method ID for the ReplaceTournamentLeafNode method + MethodReplaceTournamentLeafNode = 0x2D + + // MethodStartTournament is the method ID for the StartTournament method + MethodStartTournament = 0x2E + + // MethodAutoTournamentMatchmake is the method ID for the AutoTournamentMatchmake method + MethodAutoTournamentMatchmake = 0x2F + + // MethodSimpleFindByID is the method ID for the SimpleFindByID method + MethodSimpleFindByID = 0x30 + + // MethodGetTournamentCompetitions is the method ID for the GetTournamentCompetitions method + MethodGetTournamentCompetitions = 0x31 + + // MethodGetTournamentCompetition is the method ID for the GetTournamentCompetition method + MethodGetTournamentCompetition = 0x32 + + // MethodGetTournamentReplayIDs is the method ID for the GetTournamentReplayIDs method + MethodGetTournamentReplayIDs = 0x33 + + // MethodRegisterCommunityCompetition is the method ID for the RegisterCommunityCompetition method + MethodRegisterCommunityCompetition = 0x34 + + // MethodUnregisterCommunityCompetition is the method ID for the UnregisterCommunityCompetition method + MethodUnregisterCommunityCompetition = 0x35 + + // MethodUnregisterCommunityCompetitionByID is the method ID for the UnregisterCommunityCompetitionByID method + MethodUnregisterCommunityCompetitionByID = 0x36 + + // MethodGetCommunityCompetitions is the method ID for the GetCommunityCompetitions method + MethodGetCommunityCompetitions = 0x37 + + // MethodGetCommunityCompetitionByID is the method ID for the GetCommunityCompetitionByID method + MethodGetCommunityCompetitionByID = 0x38 + + // MethodFindCommunityCompetitionsByParticipant is the method ID for the FindCommunityCompetitionsByParticipant method + MethodFindCommunityCompetitionsByParticipant = 0x39 + + // MethodFindCommunityCompetitionsByGatheringID is the method ID for the FindCommunityCompetitionsByGatheringID method + MethodFindCommunityCompetitionsByGatheringID = 0x3A + + // MethodSelectCommunityCompetitionByOwner is the method ID for the SelectCommunityCompetitionByOwner method + MethodSelectCommunityCompetitionByOwner = 0x3B + + // MethodJoinCommunityCompetition is the method ID for the JoinCommunityCompetition method + MethodJoinCommunityCompetition = 0x3C + + // MethodJoinCommunityCompetitionByGatheringID is the method ID for the JoinCommunityCompetitionByGatheringID method + MethodJoinCommunityCompetitionByGatheringID = 0x3D + + // MethodEndCommunityCompetitionParticipation is the method ID for the EndCommunityCompetitionParticipation method + MethodEndCommunityCompetitionParticipation = 0x3E + + // MethodEndCommunityCompetitionParticipationByGatheringID is the method ID for the EndCommunityCompetitionParticipationByGatheringID method + MethodEndCommunityCompetitionParticipationByGatheringID = 0x3F + + // MethodSearchCommunityCompetition is the method ID for the SearchCommunityCompetition method + MethodSearchCommunityCompetition = 0x40 + + // MethodPostCommunityCompetitionMatchResult is the method ID for the PostCommunityCompetitionMatchResult method + MethodPostCommunityCompetitionMatchResult = 0x41 + + // MethodGetCommunityCompetitionRanking is the method ID for the GetCommunityCompetitionRanking method + MethodGetCommunityCompetitionRanking = 0x42 + + // MethodDebugRegisterCommunityCompetition is the method ID for the DebugRegisterCommunityCompetition method + MethodDebugRegisterCommunityCompetition = 0x43 + + // MethodDebugUnregisterCommunityCompetition is the method ID for the DebugUnregisterCommunityCompetition method + MethodDebugUnregisterCommunityCompetition = 0x44 + + // MethodDebugJoinCommunityCompetition is the method ID for the DebugJoinCommunityCompetition method + MethodDebugJoinCommunityCompetition = 0x45 + + // MethodDebugEndCommunityCompetitionParticipation is the method ID for the DebugEndCommunityCompetitionParticipation method + MethodDebugEndCommunityCompetitionParticipation = 0x46 + + // MethodDebugPostCommunityCompetitionMatchResult is the method ID for the DebugPostCommunityCompetitionMatchResult method + MethodDebugPostCommunityCompetitionMatchResult = 0x47 +) + +var patchedMethods = []uint32{ + MethodGetTournament, + MethodGetTournamentReplayID, + MethodGetTournamentResult, + MethodSetTournamentReplayID, + MethodGetTournamentProfiles, + MethodJoinOrCreateMatchmakeSession, + MethodRegisterTournamentPlayerInfo, + MethodRegisterTournamentBot, + MethodReportTournamentBotRoundResult, + MethodReplaceTournamentLeafNode, + MethodStartTournament, + MethodAutoTournamentMatchmake, + MethodSimpleFindByID, + MethodGetTournamentCompetitions, + MethodGetTournamentCompetition, + MethodGetTournamentReplayIDs, + MethodRegisterCommunityCompetition, + MethodUnregisterCommunityCompetition, + MethodUnregisterCommunityCompetitionByID, + MethodGetCommunityCompetitions, + MethodGetCommunityCompetitionByID, + MethodFindCommunityCompetitionsByParticipant, + MethodFindCommunityCompetitionsByGatheringID, + MethodSelectCommunityCompetitionByOwner, + MethodJoinCommunityCompetition, + MethodJoinCommunityCompetitionByGatheringID, + MethodEndCommunityCompetitionParticipation, + MethodEndCommunityCompetitionParticipationByGatheringID, + MethodSearchCommunityCompetition, + MethodPostCommunityCompetitionMatchResult, + MethodGetCommunityCompetitionRanking, + MethodDebugRegisterCommunityCompetition, + MethodDebugUnregisterCommunityCompetition, + MethodDebugJoinCommunityCompetition, + MethodDebugEndCommunityCompetitionParticipation, + MethodDebugPostCommunityCompetitionMatchResult, +} + +type matchmakeExtensionProtocol = matchmake_extension.Protocol + +// Protocol stores all the RMC method handlers for the Matchmake Extension (Super Smash Bros. 4) protocol and listens for requests +// Embeds the Matchmake Extension protocol +type Protocol struct { + endpoint nex.EndpointInterface + matchmakeExtensionProtocol + GetTournament func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + GetTournamentReplayID func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + GetTournamentResult func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + SetTournamentReplayID func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + GetTournamentProfiles func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + JoinOrCreateMatchmakeSession func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + RegisterTournamentPlayerInfo func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + RegisterTournamentBot func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + ReportTournamentBotRoundResult func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + ReplaceTournamentLeafNode func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + StartTournament func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + AutoTournamentMatchmake func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + SimpleFindByID func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + GetTournamentCompetitions func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + GetTournamentCompetition func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + GetTournamentReplayIDs func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + RegisterCommunityCompetition func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + UnregisterCommunityCompetition func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + UnregisterCommunityCompetitionByID func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + GetCommunityCompetitions func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + GetCommunityCompetitionByID func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + FindCommunityCompetitionsByParticipant func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + FindCommunityCompetitionsByGatheringID func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + SelectCommunityCompetitionByOwner func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + JoinCommunityCompetition func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + JoinCommunityCompetitionByGatheringID func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + EndCommunityCompetitionParticipation func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + EndCommunityCompetitionParticipationByGatheringID func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + SearchCommunityCompetition func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + PostCommunityCompetitionMatchResult func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + GetCommunityCompetitionRanking func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + DebugRegisterCommunityCompetition func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + DebugUnregisterCommunityCompetition func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + DebugJoinCommunityCompetition func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + DebugEndCommunityCompetitionParticipation func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + DebugPostCommunityCompetitionMatchResult func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if !slices.Contains(patchedMethods, message.MethodID) { + protocol.matchmakeExtensionProtocol.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodGetTournament: + protocol.handleGetTournament(packet) + case MethodGetTournamentReplayID: + protocol.handleGetTournamentReplayID(packet) + case MethodGetTournamentResult: + protocol.handleGetTournamentResult(packet) + case MethodSetTournamentReplayID: + protocol.handleSetTournamentReplayID(packet) + case MethodGetTournamentProfiles: + protocol.handleGetTournamentProfiles(packet) + case MethodJoinOrCreateMatchmakeSession: + protocol.handleJoinOrCreateMatchmakeSession(packet) + case MethodRegisterTournamentPlayerInfo: + protocol.handleRegisterTournamentPlayerInfo(packet) + case MethodRegisterTournamentBot: + protocol.handleRegisterTournamentBot(packet) + case MethodReportTournamentBotRoundResult: + protocol.handleReportTournamentBotRoundResult(packet) + case MethodReplaceTournamentLeafNode: + protocol.handleReplaceTournamentLeafNode(packet) + case MethodStartTournament: + protocol.handleStartTournament(packet) + case MethodAutoTournamentMatchmake: + protocol.handleAutoTournamentMatchmake(packet) + case MethodSimpleFindByID: + protocol.handleSimpleFindByID(packet) + case MethodGetTournamentCompetitions: + protocol.handleGetTournamentCompetitions(packet) + case MethodGetTournamentCompetition: + protocol.handleGetTournamentCompetition(packet) + case MethodGetTournamentReplayIDs: + protocol.handleGetTournamentReplayIDs(packet) + case MethodRegisterCommunityCompetition: + protocol.handleRegisterCommunityCompetition(packet) + case MethodUnregisterCommunityCompetition: + protocol.handleUnregisterCommunityCompetition(packet) + case MethodUnregisterCommunityCompetitionByID: + protocol.handleUnregisterCommunityCompetitionByID(packet) + case MethodGetCommunityCompetitions: + protocol.handleGetCommunityCompetitions(packet) + case MethodGetCommunityCompetitionByID: + protocol.handleGetCommunityCompetitionByID(packet) + case MethodFindCommunityCompetitionsByParticipant: + protocol.handleFindCommunityCompetitionsByParticipant(packet) + case MethodFindCommunityCompetitionsByGatheringID: + protocol.handleFindCommunityCompetitionsByGatheringID(packet) + case MethodSelectCommunityCompetitionByOwner: + protocol.handleSelectCommunityCompetitionByOwner(packet) + case MethodJoinCommunityCompetition: + protocol.handleJoinCommunityCompetition(packet) + case MethodJoinCommunityCompetitionByGatheringID: + protocol.handleJoinCommunityCompetitionByGatheringID(packet) + case MethodEndCommunityCompetitionParticipation: + protocol.handleEndCommunityCompetitionParticipation(packet) + case MethodEndCommunityCompetitionParticipationByGatheringID: + protocol.handleEndCommunityCompetitionParticipationByGatheringID(packet) + case MethodSearchCommunityCompetition: + protocol.handleSearchCommunityCompetition(packet) + case MethodPostCommunityCompetitionMatchResult: + protocol.handlePostCommunityCompetitionMatchResult(packet) + case MethodGetCommunityCompetitionRanking: + protocol.handleGetCommunityCompetitionRanking(packet) + case MethodDebugRegisterCommunityCompetition: + protocol.handleDebugRegisterCommunityCompetition(packet) + case MethodDebugUnregisterCommunityCompetition: + protocol.handleDebugUnregisterCommunityCompetition(packet) + case MethodDebugJoinCommunityCompetition: + protocol.handleDebugJoinCommunityCompetition(packet) + case MethodDebugEndCommunityCompetitionParticipation: + protocol.handleDebugEndCommunityCompetitionParticipation(packet) + case MethodDebugPostCommunityCompetitionMatchResult: + protocol.handleDebugPostCommunityCompetitionMatchResult(packet) + default: + errMessage := fmt.Sprintf("Unsupported Matchmake Extension (Super Smash Bros. 4) method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new MatchmakeExtensionSuperSmashBros4 protocol +func NewProtocol(endpoint nex.EndpointInterface) *Protocol { + protocol := &Protocol{endpoint: endpoint} + protocol.matchmakeExtensionProtocol.SetEndpoint(endpoint) + + return protocol +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/register_community_competition.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/register_community_competition.go new file mode 100644 index 0000000..33eb101 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/register_community_competition.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRegisterCommunityCompetition(packet nex.PacketInterface) { + if protocol.RegisterCommunityCompetition == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::RegisterCommunityCompetition not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::RegisterCommunityCompetition STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.RegisterCommunityCompetition(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/register_tournament_bot.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/register_tournament_bot.go new file mode 100644 index 0000000..ec8f1f9 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/register_tournament_bot.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRegisterTournamentBot(packet nex.PacketInterface) { + if protocol.RegisterTournamentBot == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::RegisterTournamentBot not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::RegisterTournamentBot STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.RegisterTournamentBot(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/register_tournament_player_info.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/register_tournament_player_info.go new file mode 100644 index 0000000..b888511 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/register_tournament_player_info.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRegisterTournamentPlayerInfo(packet nex.PacketInterface) { + if protocol.RegisterTournamentPlayerInfo == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::RegisterTournamentPlayerInfo not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::RegisterTournamentPlayerInfo STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.RegisterTournamentPlayerInfo(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/replace_tournament_leaf_node.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/replace_tournament_leaf_node.go new file mode 100644 index 0000000..3d700dc --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/replace_tournament_leaf_node.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleReplaceTournamentLeafNode(packet nex.PacketInterface) { + if protocol.ReplaceTournamentLeafNode == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::ReplaceTournamentLeafNode not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::ReplaceTournamentLeafNode STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.ReplaceTournamentLeafNode(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/report_tournament_bot_round_result.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/report_tournament_bot_round_result.go new file mode 100644 index 0000000..55ee9bd --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/report_tournament_bot_round_result.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleReportTournamentBotRoundResult(packet nex.PacketInterface) { + if protocol.ReportTournamentBotRoundResult == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::ReportTournamentBotRoundResult not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::ReportTournamentBotRoundResult STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.ReportTournamentBotRoundResult(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/search_community_competition.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/search_community_competition.go new file mode 100644 index 0000000..d6824a8 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/search_community_competition.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSearchCommunityCompetition(packet nex.PacketInterface) { + if protocol.SearchCommunityCompetition == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::SearchCommunityCompetition not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::SearchCommunityCompetition STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.SearchCommunityCompetition(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/select_community_competition_by_owner.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/select_community_competition_by_owner.go new file mode 100644 index 0000000..5f37bcd --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/select_community_competition_by_owner.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSelectCommunityCompetitionByOwner(packet nex.PacketInterface) { + if protocol.SelectCommunityCompetitionByOwner == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::SelectCommunityCompetitionByOwner not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::SelectCommunityCompetitionByOwner STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.SelectCommunityCompetitionByOwner(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/set_tournament_replay_id.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/set_tournament_replay_id.go new file mode 100644 index 0000000..8d99736 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/set_tournament_replay_id.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSetTournamentReplayID(packet nex.PacketInterface) { + if protocol.SetTournamentReplayID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::SetTournamentReplayID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::SetTournamentReplayID STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.SetTournamentReplayID(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/simple_find_by_i_d.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/simple_find_by_i_d.go new file mode 100644 index 0000000..97741d4 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/simple_find_by_i_d.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSimpleFindByID(packet nex.PacketInterface) { + if protocol.SimpleFindByID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::SimpleFindByID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::SimpleFindByID STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.SimpleFindByID(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/start_tournament.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/start_tournament.go new file mode 100644 index 0000000..bed753b --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/start_tournament.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleStartTournament(packet nex.PacketInterface) { + if protocol.StartTournament == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::StartTournament not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::StartTournament STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.StartTournament(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/unregister_community_competition.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/unregister_community_competition.go new file mode 100644 index 0000000..7af845d --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/unregister_community_competition.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUnregisterCommunityCompetition(packet nex.PacketInterface) { + if protocol.UnregisterCommunityCompetition == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::UnregisterCommunityCompetition not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::UnregisterCommunityCompetition STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.UnregisterCommunityCompetition(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/super-smash-bros-4/unregister_community_competition_by_id.go b/nex-protocols-go/matchmake-extension/super-smash-bros-4/unregister_community_competition_by_id.go new file mode 100644 index 0000000..1039da7 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/super-smash-bros-4/unregister_community_competition_by_id.go @@ -0,0 +1,31 @@ +// Package protocol implements the MatchmakeExtensionSuperSmashBros4 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUnregisterCommunityCompetitionByID(packet nex.PacketInterface) { + if protocol.UnregisterCommunityCompetitionByID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtensionSuperSmashBros4::UnregisterCommunityCompetitionByID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("MatchmakeExtensionSuperSmashBros4::UnregisterCommunityCompetitionByID STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.UnregisterCommunityCompetitionByID(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/update_application_buffer.go b/nex-protocols-go/matchmake-extension/update_application_buffer.go new file mode 100644 index 0000000..90556ee --- /dev/null +++ b/nex-protocols-go/matchmake-extension/update_application_buffer.go @@ -0,0 +1,60 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateApplicationBuffer(packet nex.PacketInterface) { + if protocol.UpdateApplicationBuffer == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::UpdateApplicationBuffer not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + applicationBuffer := types.NewBuffer(nil) + + var err error + + err = gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateApplicationBuffer(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = applicationBuffer.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateApplicationBuffer(fmt.Errorf("Failed to read applicationBuffer from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateApplicationBuffer(nil, packet, callID, gid, applicationBuffer) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/update_community.go b/nex-protocols-go/matchmake-extension/update_community.go new file mode 100644 index 0000000..07f7b46 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/update_community.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +func (protocol *Protocol) handleUpdateCommunity(packet nex.PacketInterface) { + if protocol.UpdateCommunity == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::UpdateCommunity not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + community := match_making_types.NewPersistentGathering() + + err := community.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateCommunity(fmt.Errorf("Failed to read community from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateCommunity(nil, packet, callID, community) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/update_matchmake_session.go b/nex-protocols-go/matchmake-extension/update_matchmake_session.go new file mode 100644 index 0000000..e24975d --- /dev/null +++ b/nex-protocols-go/matchmake-extension/update_matchmake_session.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateMatchmakeSession(packet nex.PacketInterface) { + if protocol.UpdateMatchmakeSession == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::UpdateMatchmakeSession not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + anyGathering := types.NewAnyDataHolder() + + err := anyGathering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateMatchmakeSession(fmt.Errorf("Failed to read anyGathering from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateMatchmakeSession(nil, packet, callID, anyGathering) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/update_matchmake_session_attribute.go b/nex-protocols-go/matchmake-extension/update_matchmake_session_attribute.go new file mode 100644 index 0000000..b4b3741 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/update_matchmake_session_attribute.go @@ -0,0 +1,61 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateMatchmakeSessionAttribute(packet nex.PacketInterface) { + if protocol.UpdateMatchmakeSessionAttribute == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::UpdateMatchmakeSessionAttribute not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + attribs := types.NewList[*types.PrimitiveU32]() + attribs.Type = types.NewPrimitiveU32(0) + + var err error + + err = gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateMatchmakeSessionAttribute(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = attribs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateMatchmakeSessionAttribute(fmt.Errorf("Failed to read attribs from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateMatchmakeSessionAttribute(nil, packet, callID, gid, attribs) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/update_matchmake_session_part.go b/nex-protocols-go/matchmake-extension/update_matchmake_session_part.go new file mode 100644 index 0000000..13f8201 --- /dev/null +++ b/nex-protocols-go/matchmake-extension/update_matchmake_session_part.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +func (protocol *Protocol) handleUpdateMatchmakeSessionPart(packet nex.PacketInterface) { + if protocol.UpdateMatchmakeSessionPart == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::UpdateMatchmakeSessionPart not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + updateMatchmakeSessionParam := match_making_types.NewUpdateMatchmakeSessionParam() + + err := updateMatchmakeSessionParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateMatchmakeSessionPart(fmt.Errorf("Failed to read updateMatchmakeSessionParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateMatchmakeSessionPart(nil, packet, callID, updateMatchmakeSessionParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/update_notification_data.go b/nex-protocols-go/matchmake-extension/update_notification_data.go new file mode 100644 index 0000000..969bd4c --- /dev/null +++ b/nex-protocols-go/matchmake-extension/update_notification_data.go @@ -0,0 +1,82 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateNotificationData(packet nex.PacketInterface) { + if protocol.UpdateNotificationData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::UpdateNotificationData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiType := types.NewPrimitiveU32(0) + uiParam1 := types.NewPrimitiveU32(0) + uiParam2 := types.NewPrimitiveU32(0) + strParam := types.NewString("") + + var err error + + err = uiType.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateNotificationData(fmt.Errorf("Failed to read uiType from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uiParam1.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateNotificationData(fmt.Errorf("Failed to read uiParam1 from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uiParam2.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateNotificationData(fmt.Errorf("Failed to read uiParam2 from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateNotificationData(fmt.Errorf("Failed to read strParam from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateNotificationData(nil, packet, callID, uiType, uiParam1, uiParam2, strParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/update_privacy_setting.go b/nex-protocols-go/matchmake-extension/update_privacy_setting.go new file mode 100644 index 0000000..8fb352b --- /dev/null +++ b/nex-protocols-go/matchmake-extension/update_privacy_setting.go @@ -0,0 +1,60 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdatePrivacySetting(packet nex.PacketInterface) { + if protocol.UpdatePrivacySetting == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::UpdatePrivacySetting not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + onlineStatus := types.NewPrimitiveBool(false) + participationCommunity := types.NewPrimitiveBool(false) + + var err error + + err = onlineStatus.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdatePrivacySetting(fmt.Errorf("Failed to read onlineStatus from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = participationCommunity.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdatePrivacySetting(fmt.Errorf("Failed to read participationCommunity from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdatePrivacySetting(nil, packet, callID, onlineStatus, participationCommunity) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/update_progress_score.go b/nex-protocols-go/matchmake-extension/update_progress_score.go new file mode 100644 index 0000000..85e389a --- /dev/null +++ b/nex-protocols-go/matchmake-extension/update_progress_score.go @@ -0,0 +1,60 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateProgressScore(packet nex.PacketInterface) { + if protocol.UpdateProgressScore == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::UpdateProgressScore not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + gid := types.NewPrimitiveU32(0) + progressScore := types.NewPrimitiveU8(0) + + var err error + + err = gid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateProgressScore(fmt.Errorf("Failed to read gid from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = progressScore.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateProgressScore(fmt.Errorf("Failed to read progressScore from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateProgressScore(nil, packet, callID, gid, progressScore) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/withdraw_matchmaking.go b/nex-protocols-go/matchmake-extension/withdraw_matchmaking.go new file mode 100644 index 0000000..c6df39b --- /dev/null +++ b/nex-protocols-go/matchmake-extension/withdraw_matchmaking.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleWithdrawMatchmaking(packet nex.PacketInterface) { + if protocol.WithdrawMatchmaking == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::WithdrawMatchmaking not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestID := types.NewPrimitiveU64(0) + + err := requestID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.WithdrawMatchmaking(fmt.Errorf("Failed to read requestID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.WithdrawMatchmaking(nil, packet, callID, requestID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-extension/withdraw_matchmaking_all.go b/nex-protocols-go/matchmake-extension/withdraw_matchmaking_all.go new file mode 100644 index 0000000..3bc662f --- /dev/null +++ b/nex-protocols-go/matchmake-extension/withdraw_matchmaking_all.go @@ -0,0 +1,29 @@ +// Package protocol implements the Matchmake Extension protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleWithdrawMatchmakingAll(packet nex.PacketInterface) { + if protocol.WithdrawMatchmakingAll == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeExtension::WithdrawMatchmakingAll not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.WithdrawMatchmakingAll(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-referee/create_stats.go b/nex-protocols-go/matchmake-referee/create_stats.go new file mode 100644 index 0000000..7ea7723 --- /dev/null +++ b/nex-protocols-go/matchmake-referee/create_stats.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Referee protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + matchmake_referee_types "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-referee/types" +) + +func (protocol *Protocol) handleCreateStats(packet nex.PacketInterface) { + if protocol.CreateStats == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeReferee::CreateStats not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := matchmake_referee_types.NewMatchmakeRefereeStatsInitParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateStats(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.CreateStats(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-referee/end_round.go b/nex-protocols-go/matchmake-referee/end_round.go new file mode 100644 index 0000000..9991b00 --- /dev/null +++ b/nex-protocols-go/matchmake-referee/end_round.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Referee protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + matchmake_referee_types "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-referee/types" +) + +func (protocol *Protocol) handleEndRound(packet nex.PacketInterface) { + if protocol.EndRound == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeReferee::EndRound not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + endRoundParam := matchmake_referee_types.NewMatchmakeRefereeEndRoundParam() + + err := endRoundParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.EndRound(fmt.Errorf("Failed to read endRoundParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.EndRound(nil, packet, callID, endRoundParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-referee/end_round_without_report.go b/nex-protocols-go/matchmake-referee/end_round_without_report.go new file mode 100644 index 0000000..aab58fc --- /dev/null +++ b/nex-protocols-go/matchmake-referee/end_round_without_report.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Referee protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleEndRoundWithoutReport(packet nex.PacketInterface) { + if protocol.EndRoundWithoutReport == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeReferee::EndRoundWithoutReport not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + roundID := types.NewPrimitiveU64(0) + + err := roundID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.EndRoundWithoutReport(fmt.Errorf("Failed to read roundID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.EndRoundWithoutReport(nil, packet, callID, roundID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-referee/get_not_summarized_round.go b/nex-protocols-go/matchmake-referee/get_not_summarized_round.go new file mode 100644 index 0000000..68f5df3 --- /dev/null +++ b/nex-protocols-go/matchmake-referee/get_not_summarized_round.go @@ -0,0 +1,29 @@ +// Package protocol implements the Matchmake Referee protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetNotSummarizedRound(packet nex.PacketInterface) { + if protocol.GetNotSummarizedRound == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeReferee::GetNotSummarizedRound not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetNotSummarizedRound(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-referee/get_or_create_stats.go b/nex-protocols-go/matchmake-referee/get_or_create_stats.go new file mode 100644 index 0000000..7e59f50 --- /dev/null +++ b/nex-protocols-go/matchmake-referee/get_or_create_stats.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Referee protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + matchmake_referee_types "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-referee/types" +) + +func (protocol *Protocol) handleGetOrCreateStats(packet nex.PacketInterface) { + if protocol.GetOrCreateStats == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeReferee::GetOrCreateStats not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := matchmake_referee_types.NewMatchmakeRefereeStatsInitParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetOrCreateStats(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetOrCreateStats(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-referee/get_round.go b/nex-protocols-go/matchmake-referee/get_round.go new file mode 100644 index 0000000..90f63e8 --- /dev/null +++ b/nex-protocols-go/matchmake-referee/get_round.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Referee protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetRound(packet nex.PacketInterface) { + if protocol.GetRound == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeReferee::GetRound not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + roundID := types.NewPrimitiveU64(0) + + err := roundID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRound(fmt.Errorf("Failed to read roundID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetRound(nil, packet, callID, roundID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-referee/get_round_participants.go b/nex-protocols-go/matchmake-referee/get_round_participants.go new file mode 100644 index 0000000..3c65bb0 --- /dev/null +++ b/nex-protocols-go/matchmake-referee/get_round_participants.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Referee protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetRoundParticipants(packet nex.PacketInterface) { + if protocol.GetRoundParticipants == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeReferee::GetRoundParticipants not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + roundID := types.NewPrimitiveU64(0) + + err := roundID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRoundParticipants(fmt.Errorf("Failed to read roundID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetRoundParticipants(nil, packet, callID, roundID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-referee/get_start_round_param.go b/nex-protocols-go/matchmake-referee/get_start_round_param.go new file mode 100644 index 0000000..ec03d1e --- /dev/null +++ b/nex-protocols-go/matchmake-referee/get_start_round_param.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Referee protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetStartRoundParam(packet nex.PacketInterface) { + if protocol.GetStartRoundParam == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeReferee::GetStartRoundParam not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + roundID := types.NewPrimitiveU64(0) + + err := roundID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetStartRoundParam(fmt.Errorf("Failed to read roundID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetStartRoundParam(nil, packet, callID, roundID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-referee/get_stats_all.go b/nex-protocols-go/matchmake-referee/get_stats_all.go new file mode 100644 index 0000000..e5ee11a --- /dev/null +++ b/nex-protocols-go/matchmake-referee/get_stats_all.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Referee protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + matchmake_referee_types "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-referee/types" +) + +func (protocol *Protocol) handleGetStatsAll(packet nex.PacketInterface) { + if protocol.GetStatsAll == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeReferee::GetStatsAll not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + target := matchmake_referee_types.NewMatchmakeRefereeStatsTarget() + + err := target.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetStatsAll(fmt.Errorf("Failed to read target from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetStatsAll(nil, packet, callID, target) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-referee/get_stats_primaries.go b/nex-protocols-go/matchmake-referee/get_stats_primaries.go new file mode 100644 index 0000000..e76af27 --- /dev/null +++ b/nex-protocols-go/matchmake-referee/get_stats_primaries.go @@ -0,0 +1,49 @@ +// Package protocol implements the Matchmake Referee protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + matchmake_referee_types "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-referee/types" +) + +func (protocol *Protocol) handleGetStatsPrimaries(packet nex.PacketInterface) { + if protocol.GetStatsPrimaries == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeReferee::GetStatsPrimaries not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + targets := types.NewList[*matchmake_referee_types.MatchmakeRefereeStatsTarget]() + targets.Type = matchmake_referee_types.NewMatchmakeRefereeStatsTarget() + + err := targets.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetStatsPrimaries(fmt.Errorf("Failed to read targets from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetStatsPrimaries(nil, packet, callID, targets) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-referee/get_stats_primary.go b/nex-protocols-go/matchmake-referee/get_stats_primary.go new file mode 100644 index 0000000..2390bcf --- /dev/null +++ b/nex-protocols-go/matchmake-referee/get_stats_primary.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Referee protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + matchmake_referee_types "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-referee/types" +) + +func (protocol *Protocol) handleGetStatsPrimary(packet nex.PacketInterface) { + if protocol.GetStatsPrimary == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeReferee::GetStatsPrimary not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + target := matchmake_referee_types.NewMatchmakeRefereeStatsTarget() + + err := target.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetStatsPrimary(fmt.Errorf("Failed to read target from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetStatsPrimary(nil, packet, callID, target) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-referee/protocol.go b/nex-protocols-go/matchmake-referee/protocol.go new file mode 100644 index 0000000..10cb996 --- /dev/null +++ b/nex-protocols-go/matchmake-referee/protocol.go @@ -0,0 +1,224 @@ +// Package protocol implements the Matchmake Referee protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + matchmake_referee_types "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-referee/types" +) + +const ( + // ProtocolID is the protocol ID for the Message Delivery protocol + ProtocolID = 0x78 + + // MethodStartRound is the method ID for the method StartRound + MethodStartRound = 0x1 + + // MethodGetStartRoundParam is the method ID for the method GetStartRoundParam + MethodGetStartRoundParam = 0x2 + + // MethodEndRound is the method ID for the method EndRound + MethodEndRound = 0x3 + + // MethodEndRoundWithoutReport is the method ID for the method EndRoundWithoutReport + MethodEndRoundWithoutReport = 0x4 + + // MethodGetRoundParticipants is the method ID for the method GetRoundParticipants + MethodGetRoundParticipants = 0x5 + + // MethodGetNotSummarizedRound is the method ID for the method GetNotSummarizedRound + MethodGetNotSummarizedRound = 0x6 + + // MethodGetRound is the method ID for the method GetRound + MethodGetRound = 0x7 + + // MethodGetStatsPrimary is the method ID for the method GetStatsPrimary + MethodGetStatsPrimary = 0x8 + + // MethodGetStatsPrimaries is the method ID for the method GetStatsPrimaries + MethodGetStatsPrimaries = 0x9 + + // MethodGetStatsAll is the method ID for the method GetStatsAll + MethodGetStatsAll = 0xA + + // MethodCreateStats is the method ID for the method CreateStats + MethodCreateStats = 0xB + + // MethodGetOrCreateStats is the method ID for the method GetOrCreateStats + MethodGetOrCreateStats = 0xC + + // MethodResetStats is the method ID for the method ResetStats + MethodResetStats = 0xD +) + +// Protocol stores all the RMC method handlers for the Matchmake Referee protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + StartRound func(err error, packet nex.PacketInterface, callID uint32, param *matchmake_referee_types.MatchmakeRefereeStartRoundParam) (*nex.RMCMessage, *nex.Error) + GetStartRoundParam func(err error, packet nex.PacketInterface, callID uint32, roundID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + EndRound func(err error, packet nex.PacketInterface, callID uint32, endRoundParam *matchmake_referee_types.MatchmakeRefereeEndRoundParam) (*nex.RMCMessage, *nex.Error) + EndRoundWithoutReport func(err error, packet nex.PacketInterface, callID uint32, roundID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + GetRoundParticipants func(err error, packet nex.PacketInterface, callID uint32, roundID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + GetNotSummarizedRound func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + GetRound func(err error, packet nex.PacketInterface, callID uint32, roundID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + GetStatsPrimary func(err error, packet nex.PacketInterface, callID uint32, target *matchmake_referee_types.MatchmakeRefereeStatsTarget) (*nex.RMCMessage, *nex.Error) + GetStatsPrimaries func(err error, packet nex.PacketInterface, callID uint32, targets *types.List[*matchmake_referee_types.MatchmakeRefereeStatsTarget]) (*nex.RMCMessage, *nex.Error) + GetStatsAll func(err error, packet nex.PacketInterface, callID uint32, target *matchmake_referee_types.MatchmakeRefereeStatsTarget) (*nex.RMCMessage, *nex.Error) + CreateStats func(err error, packet nex.PacketInterface, callID uint32, param *matchmake_referee_types.MatchmakeRefereeStatsInitParam) (*nex.RMCMessage, *nex.Error) + GetOrCreateStats func(err error, packet nex.PacketInterface, callID uint32, param *matchmake_referee_types.MatchmakeRefereeStatsInitParam) (*nex.RMCMessage, *nex.Error) + ResetStats func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Matchmake Referee protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerStartRound(handler func(err error, packet nex.PacketInterface, callID uint32, param *matchmake_referee_types.MatchmakeRefereeStartRoundParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetStartRoundParam(handler func(err error, packet nex.PacketInterface, callID uint32, roundID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerEndRound(handler func(err error, packet nex.PacketInterface, callID uint32, endRoundParam *matchmake_referee_types.MatchmakeRefereeEndRoundParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerEndRoundWithoutReport(handler func(err error, packet nex.PacketInterface, callID uint32, roundID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetRoundParticipants(handler func(err error, packet nex.PacketInterface, callID uint32, roundID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetNotSummarizedRound(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetRound(handler func(err error, packet nex.PacketInterface, callID uint32, roundID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetStatsPrimary(handler func(err error, packet nex.PacketInterface, callID uint32, target *matchmake_referee_types.MatchmakeRefereeStatsTarget) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetStatsPrimaries(handler func(err error, packet nex.PacketInterface, callID uint32, targets *types.List[*matchmake_referee_types.MatchmakeRefereeStatsTarget]) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetStatsAll(handler func(err error, packet nex.PacketInterface, callID uint32, target *matchmake_referee_types.MatchmakeRefereeStatsTarget) (*nex.RMCMessage, *nex.Error)) + SetHandlerCreateStats(handler func(err error, packet nex.PacketInterface, callID uint32, param *matchmake_referee_types.MatchmakeRefereeStatsInitParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetOrCreateStats(handler func(err error, packet nex.PacketInterface, callID uint32, param *matchmake_referee_types.MatchmakeRefereeStatsInitParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerResetStats(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerStartRound sets the handler for the StartRound method +func (protocol *Protocol) SetHandlerStartRound(handler func(err error, packet nex.PacketInterface, callID uint32, param *matchmake_referee_types.MatchmakeRefereeStartRoundParam) (*nex.RMCMessage, *nex.Error)) { + protocol.StartRound = handler +} + +// SetHandlerGetStartRoundParam sets the handler for the GetStartRoundParam method +func (protocol *Protocol) SetHandlerGetStartRoundParam(handler func(err error, packet nex.PacketInterface, callID uint32, roundID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.GetStartRoundParam = handler +} + +// SetHandlerEndRound sets the handler for the EndRound method +func (protocol *Protocol) SetHandlerEndRound(handler func(err error, packet nex.PacketInterface, callID uint32, endRoundParam *matchmake_referee_types.MatchmakeRefereeEndRoundParam) (*nex.RMCMessage, *nex.Error)) { + protocol.EndRound = handler +} + +// SetHandlerEndRoundWithoutReport sets the handler for the EndRoundWithoutReport method +func (protocol *Protocol) SetHandlerEndRoundWithoutReport(handler func(err error, packet nex.PacketInterface, callID uint32, roundID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.EndRoundWithoutReport = handler +} + +// SetHandlerGetRoundParticipants sets the handler for the GetRoundParticipants method +func (protocol *Protocol) SetHandlerGetRoundParticipants(handler func(err error, packet nex.PacketInterface, callID uint32, roundID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.GetRoundParticipants = handler +} + +// SetHandlerGetNotSummarizedRound sets the handler for the GetNotSummarizedRound method +func (protocol *Protocol) SetHandlerGetNotSummarizedRound(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetNotSummarizedRound = handler +} + +// SetHandlerGetRound sets the handler for the GetRound method +func (protocol *Protocol) SetHandlerGetRound(handler func(err error, packet nex.PacketInterface, callID uint32, roundID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.GetRound = handler +} + +// SetHandlerGetStatsPrimary sets the handler for the GetStatsPrimary method +func (protocol *Protocol) SetHandlerGetStatsPrimary(handler func(err error, packet nex.PacketInterface, callID uint32, target *matchmake_referee_types.MatchmakeRefereeStatsTarget) (*nex.RMCMessage, *nex.Error)) { + protocol.GetStatsPrimary = handler +} + +// SetHandlerGetStatsPrimaries sets the handler for the GetStatsPrimaries method +func (protocol *Protocol) SetHandlerGetStatsPrimaries(handler func(err error, packet nex.PacketInterface, callID uint32, targets *types.List[*matchmake_referee_types.MatchmakeRefereeStatsTarget]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetStatsPrimaries = handler +} + +// SetHandlerGetStatsAll sets the handler for the GetStatsAll method +func (protocol *Protocol) SetHandlerGetStatsAll(handler func(err error, packet nex.PacketInterface, callID uint32, target *matchmake_referee_types.MatchmakeRefereeStatsTarget) (*nex.RMCMessage, *nex.Error)) { + protocol.GetStatsAll = handler +} + +// SetHandlerCreateStats sets the handler for the CreateStats method +func (protocol *Protocol) SetHandlerCreateStats(handler func(err error, packet nex.PacketInterface, callID uint32, param *matchmake_referee_types.MatchmakeRefereeStatsInitParam) (*nex.RMCMessage, *nex.Error)) { + protocol.CreateStats = handler +} + +// SetHandlerGetOrCreateStats sets the handler for the GetOrCreateStats method +func (protocol *Protocol) SetHandlerGetOrCreateStats(handler func(err error, packet nex.PacketInterface, callID uint32, param *matchmake_referee_types.MatchmakeRefereeStatsInitParam) (*nex.RMCMessage, *nex.Error)) { + protocol.GetOrCreateStats = handler +} + +// SetHandlerResetStats sets the handler for the ResetStats method +func (protocol *Protocol) SetHandlerResetStats(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.ResetStats = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodStartRound: + protocol.handleStartRound(packet) + case MethodGetStartRoundParam: + protocol.handleGetStartRoundParam(packet) + case MethodEndRound: + protocol.handleEndRound(packet) + case MethodEndRoundWithoutReport: + protocol.handleEndRoundWithoutReport(packet) + case MethodGetRoundParticipants: + protocol.handleGetRoundParticipants(packet) + case MethodGetNotSummarizedRound: + protocol.handleGetNotSummarizedRound(packet) + case MethodGetRound: + protocol.handleGetRound(packet) + case MethodGetStatsPrimary: + protocol.handleGetStatsPrimary(packet) + case MethodGetStatsPrimaries: + protocol.handleGetStatsPrimaries(packet) + case MethodGetStatsAll: + protocol.handleGetStatsAll(packet) + case MethodCreateStats: + protocol.handleCreateStats(packet) + case MethodGetOrCreateStats: + protocol.handleGetOrCreateStats(packet) + case MethodResetStats: + protocol.handleResetStats(packet) + default: + errMessage := fmt.Sprintf("Unsupported MatchmakeReferee method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Matchmake Referee protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/matchmake-referee/reset_stats.go b/nex-protocols-go/matchmake-referee/reset_stats.go new file mode 100644 index 0000000..37d097c --- /dev/null +++ b/nex-protocols-go/matchmake-referee/reset_stats.go @@ -0,0 +1,29 @@ +// Package protocol implements the Matchmake Referee protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleResetStats(packet nex.PacketInterface) { + if protocol.ResetStats == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeReferee::ResetStats not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.ResetStats(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-referee/start_round.go b/nex-protocols-go/matchmake-referee/start_round.go new file mode 100644 index 0000000..14cc1f3 --- /dev/null +++ b/nex-protocols-go/matchmake-referee/start_round.go @@ -0,0 +1,47 @@ +// Package protocol implements the Matchmake Referee protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + matchmake_referee_types "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-referee/types" +) + +func (protocol *Protocol) handleStartRound(packet nex.PacketInterface) { + if protocol.StartRound == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MatchmakeReferee::StartRound not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := matchmake_referee_types.NewMatchmakeRefereeStartRoundParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.StartRound(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.StartRound(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/matchmake-referee/types/matchmake_referee_end_round_param.go b/nex-protocols-go/matchmake-referee/types/matchmake_referee_end_round_param.go new file mode 100644 index 0000000..0c9c984 --- /dev/null +++ b/nex-protocols-go/matchmake-referee/types/matchmake_referee_end_round_param.go @@ -0,0 +1,129 @@ +// Package types implements all the types used by the MatchmakeReferee protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// MatchmakeRefereeEndRoundParam is a type within the MatchmakeReferee protocol +type MatchmakeRefereeEndRoundParam struct { + types.Structure + *types.Data + RoundID *types.PrimitiveU64 + PersonalRoundResults *types.List[*MatchmakeRefereePersonalRoundResult] +} + +// WriteTo writes the MatchmakeRefereeEndRoundParam to the given writable +func (mrerp *MatchmakeRefereeEndRoundParam) WriteTo(writable types.Writable) { + mrerp.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + mrerp.RoundID.WriteTo(contentWritable) + mrerp.PersonalRoundResults.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + mrerp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MatchmakeRefereeEndRoundParam from the given readable +func (mrerp *MatchmakeRefereeEndRoundParam) ExtractFrom(readable types.Readable) error { + var err error + + err = mrerp.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeEndRoundParam.Data. %s", err.Error()) + } + + err = mrerp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeEndRoundParam header. %s", err.Error()) + } + + err = mrerp.RoundID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeEndRoundParam.RoundID. %s", err.Error()) + } + + err = mrerp.PersonalRoundResults.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeEndRoundParam.PersonalRoundResults. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of MatchmakeRefereeEndRoundParam +func (mrerp *MatchmakeRefereeEndRoundParam) Copy() types.RVType { + copied := NewMatchmakeRefereeEndRoundParam() + + copied.StructureVersion = mrerp.StructureVersion + copied.Data = mrerp.Data.Copy().(*types.Data) + copied.RoundID = mrerp.RoundID.Copy().(*types.PrimitiveU64) + copied.PersonalRoundResults = mrerp.PersonalRoundResults.Copy().(*types.List[*MatchmakeRefereePersonalRoundResult]) + + return copied +} + +// Equals checks if the given MatchmakeRefereeEndRoundParam contains the same data as the current MatchmakeRefereeEndRoundParam +func (mrerp *MatchmakeRefereeEndRoundParam) Equals(o types.RVType) bool { + if _, ok := o.(*MatchmakeRefereeEndRoundParam); !ok { + return false + } + + other := o.(*MatchmakeRefereeEndRoundParam) + + if mrerp.StructureVersion != other.StructureVersion { + return false + } + + if !mrerp.Data.Equals(other.Data) { + return false + } + + if !mrerp.RoundID.Equals(other.RoundID) { + return false + } + + return mrerp.PersonalRoundResults.Equals(other.PersonalRoundResults) +} + +// String returns the string representation of the MatchmakeRefereeEndRoundParam +func (mrerp *MatchmakeRefereeEndRoundParam) String() string { + return mrerp.FormatToString(0) +} + +// FormatToString pretty-prints the MatchmakeRefereeEndRoundParam using the provided indentation level +func (mrerp *MatchmakeRefereeEndRoundParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MatchmakeRefereeEndRoundParam{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, mrerp.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sRoundID: %s,\n", indentationValues, mrerp.RoundID)) + b.WriteString(fmt.Sprintf("%sPersonalRoundResults: %s,\n", indentationValues, mrerp.PersonalRoundResults)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMatchmakeRefereeEndRoundParam returns a new MatchmakeRefereeEndRoundParam +func NewMatchmakeRefereeEndRoundParam() *MatchmakeRefereeEndRoundParam { + mrerp := &MatchmakeRefereeEndRoundParam{ + Data: types.NewData(), + RoundID: types.NewPrimitiveU64(0), + PersonalRoundResults: types.NewList[*MatchmakeRefereePersonalRoundResult](), + } + + mrerp.PersonalRoundResults.Type = NewMatchmakeRefereePersonalRoundResult() + + return mrerp +} diff --git a/nex-protocols-go/matchmake-referee/types/matchmake_referee_personal_round_result.go b/nex-protocols-go/matchmake-referee/types/matchmake_referee_personal_round_result.go new file mode 100644 index 0000000..e56ac27 --- /dev/null +++ b/nex-protocols-go/matchmake-referee/types/matchmake_referee_personal_round_result.go @@ -0,0 +1,169 @@ +// Package types implements all the types used by the MatchmakeReferee protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// MatchmakeRefereePersonalRoundResult is a type within the MatchmakeReferee protocol +type MatchmakeRefereePersonalRoundResult struct { + types.Structure + *types.Data + PID *types.PID + PersonalRoundResultFlag *types.PrimitiveU32 + RoundWinLoss *types.PrimitiveU32 + RatingValueChange *types.PrimitiveS32 + Buffer *types.QBuffer +} + +// WriteTo writes the MatchmakeRefereePersonalRoundResult to the given writable +func (mrprr *MatchmakeRefereePersonalRoundResult) WriteTo(writable types.Writable) { + mrprr.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + mrprr.PID.WriteTo(contentWritable) + mrprr.PersonalRoundResultFlag.WriteTo(contentWritable) + mrprr.RoundWinLoss.WriteTo(contentWritable) + mrprr.RatingValueChange.WriteTo(contentWritable) + mrprr.Buffer.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + mrprr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MatchmakeRefereePersonalRoundResult from the given readable +func (mrprr *MatchmakeRefereePersonalRoundResult) ExtractFrom(readable types.Readable) error { + var err error + + err = mrprr.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereePersonalRoundResult.Data. %s", err.Error()) + } + + err = mrprr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereePersonalRoundResult header. %s", err.Error()) + } + + err = mrprr.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereePersonalRoundResult.PID. %s", err.Error()) + } + + err = mrprr.PersonalRoundResultFlag.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereePersonalRoundResult.PersonalRoundResultFlag. %s", err.Error()) + } + + err = mrprr.RoundWinLoss.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereePersonalRoundResult.RoundWinLoss. %s", err.Error()) + } + + err = mrprr.RatingValueChange.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereePersonalRoundResult.RatingValueChange. %s", err.Error()) + } + + err = mrprr.Buffer.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereePersonalRoundResult.Buffer. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of MatchmakeRefereePersonalRoundResult +func (mrprr *MatchmakeRefereePersonalRoundResult) Copy() types.RVType { + copied := NewMatchmakeRefereePersonalRoundResult() + + copied.StructureVersion = mrprr.StructureVersion + copied.Data = mrprr.Data.Copy().(*types.Data) + copied.PID = mrprr.PID.Copy().(*types.PID) + copied.PersonalRoundResultFlag = mrprr.PersonalRoundResultFlag.Copy().(*types.PrimitiveU32) + copied.RoundWinLoss = mrprr.RoundWinLoss.Copy().(*types.PrimitiveU32) + copied.RatingValueChange = mrprr.RatingValueChange.Copy().(*types.PrimitiveS32) + copied.Buffer = mrprr.Buffer.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given MatchmakeRefereePersonalRoundResult contains the same data as the current MatchmakeRefereePersonalRoundResult +func (mrprr *MatchmakeRefereePersonalRoundResult) Equals(o types.RVType) bool { + if _, ok := o.(*MatchmakeRefereePersonalRoundResult); !ok { + return false + } + + other := o.(*MatchmakeRefereePersonalRoundResult) + + if mrprr.StructureVersion != other.StructureVersion { + return false + } + + if !mrprr.Data.Equals(other.Data) { + return false + } + + if !mrprr.PID.Equals(other.PID) { + return false + } + + if !mrprr.PersonalRoundResultFlag.Equals(other.PersonalRoundResultFlag) { + return false + } + + if !mrprr.RoundWinLoss.Equals(other.RoundWinLoss) { + return false + } + + if !mrprr.RatingValueChange.Equals(other.RatingValueChange) { + return false + } + + return mrprr.Buffer.Equals(other.Buffer) +} + +// String returns the string representation of the MatchmakeRefereePersonalRoundResult +func (mrprr *MatchmakeRefereePersonalRoundResult) String() string { + return mrprr.FormatToString(0) +} + +// FormatToString pretty-prints the MatchmakeRefereePersonalRoundResult using the provided indentation level +func (mrprr *MatchmakeRefereePersonalRoundResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MatchmakeRefereePersonalRoundResult{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, mrprr.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, mrprr.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPersonalRoundResultFlag: %s,\n", indentationValues, mrprr.PersonalRoundResultFlag)) + b.WriteString(fmt.Sprintf("%sRoundWinLoss: %s,\n", indentationValues, mrprr.RoundWinLoss)) + b.WriteString(fmt.Sprintf("%sRatingValueChange: %s,\n", indentationValues, mrprr.RatingValueChange)) + b.WriteString(fmt.Sprintf("%sBuffer: %s,\n", indentationValues, mrprr.Buffer)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMatchmakeRefereePersonalRoundResult returns a new MatchmakeRefereePersonalRoundResult +func NewMatchmakeRefereePersonalRoundResult() *MatchmakeRefereePersonalRoundResult { + mrprr := &MatchmakeRefereePersonalRoundResult{ + Data: types.NewData(), + PID: types.NewPID(0), + PersonalRoundResultFlag: types.NewPrimitiveU32(0), + RoundWinLoss: types.NewPrimitiveU32(0), + RatingValueChange: types.NewPrimitiveS32(0), + Buffer: types.NewQBuffer(nil), + } + + return mrprr +} diff --git a/nex-protocols-go/matchmake-referee/types/matchmake_referee_round.go b/nex-protocols-go/matchmake-referee/types/matchmake_referee_round.go new file mode 100644 index 0000000..aa4a02b --- /dev/null +++ b/nex-protocols-go/matchmake-referee/types/matchmake_referee_round.go @@ -0,0 +1,171 @@ +// Package types implements all the types used by the MatchmakeReferee protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// MatchmakeRefereeRound is a type within the MatchmakeReferee protocol +type MatchmakeRefereeRound struct { + types.Structure + *types.Data + RoundID *types.PrimitiveU64 + GID *types.PrimitiveU32 + State *types.PrimitiveU32 + PersonalDataCategory *types.PrimitiveU32 + NormalizedPersonalRoundResults *types.List[*MatchmakeRefereePersonalRoundResult] +} + +// WriteTo writes the MatchmakeRefereeRound to the given writable +func (mrr *MatchmakeRefereeRound) WriteTo(writable types.Writable) { + mrr.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + mrr.RoundID.WriteTo(contentWritable) + mrr.GID.WriteTo(contentWritable) + mrr.State.WriteTo(contentWritable) + mrr.PersonalDataCategory.WriteTo(contentWritable) + mrr.NormalizedPersonalRoundResults.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + mrr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MatchmakeRefereeRound from the given readable +func (mrr *MatchmakeRefereeRound) ExtractFrom(readable types.Readable) error { + var err error + + err = mrr.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeRound.Data. %s", err.Error()) + } + + err = mrr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeRound header. %s", err.Error()) + } + + err = mrr.RoundID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeRound.RoundID. %s", err.Error()) + } + + err = mrr.GID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeRound.GID. %s", err.Error()) + } + + err = mrr.State.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeRound.State. %s", err.Error()) + } + + err = mrr.PersonalDataCategory.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeRound.PersonalDataCategory. %s", err.Error()) + } + + err = mrr.NormalizedPersonalRoundResults.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeRound.NormalizedPersonalRoundResults. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of MatchmakeRefereeRound +func (mrr *MatchmakeRefereeRound) Copy() types.RVType { + copied := NewMatchmakeRefereeRound() + + copied.StructureVersion = mrr.StructureVersion + copied.Data = mrr.Data.Copy().(*types.Data) + copied.RoundID = mrr.RoundID.Copy().(*types.PrimitiveU64) + copied.GID = mrr.GID.Copy().(*types.PrimitiveU32) + copied.State = mrr.State.Copy().(*types.PrimitiveU32) + copied.PersonalDataCategory = mrr.PersonalDataCategory.Copy().(*types.PrimitiveU32) + copied.NormalizedPersonalRoundResults = mrr.NormalizedPersonalRoundResults.Copy().(*types.List[*MatchmakeRefereePersonalRoundResult]) + + return copied +} + +// Equals checks if the given MatchmakeRefereeRound contains the same data as the current MatchmakeRefereeRound +func (mrr *MatchmakeRefereeRound) Equals(o types.RVType) bool { + if _, ok := o.(*MatchmakeRefereeRound); !ok { + return false + } + + other := o.(*MatchmakeRefereeRound) + + if mrr.StructureVersion != other.StructureVersion { + return false + } + + if !mrr.Data.Equals(other.Data) { + return false + } + + if !mrr.RoundID.Equals(other.RoundID) { + return false + } + + if !mrr.GID.Equals(other.GID) { + return false + } + + if !mrr.State.Equals(other.State) { + return false + } + + if !mrr.PersonalDataCategory.Equals(other.PersonalDataCategory) { + return false + } + + return mrr.NormalizedPersonalRoundResults.Equals(other.NormalizedPersonalRoundResults) +} + +// String returns the string representation of the MatchmakeRefereeRound +func (mrr *MatchmakeRefereeRound) String() string { + return mrr.FormatToString(0) +} + +// FormatToString pretty-prints the MatchmakeRefereeRound using the provided indentation level +func (mrr *MatchmakeRefereeRound) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MatchmakeRefereeRound{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, mrr.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sRoundID: %s,\n", indentationValues, mrr.RoundID)) + b.WriteString(fmt.Sprintf("%sGID: %s,\n", indentationValues, mrr.GID)) + b.WriteString(fmt.Sprintf("%sState: %s,\n", indentationValues, mrr.State)) + b.WriteString(fmt.Sprintf("%sPersonalDataCategory: %s,\n", indentationValues, mrr.PersonalDataCategory)) + b.WriteString(fmt.Sprintf("%sNormalizedPersonalRoundResults: %s,\n", indentationValues, mrr.NormalizedPersonalRoundResults)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMatchmakeRefereeRound returns a new MatchmakeRefereeRound +func NewMatchmakeRefereeRound() *MatchmakeRefereeRound { + mrr := &MatchmakeRefereeRound{ + Data: types.NewData(), + RoundID: types.NewPrimitiveU64(0), + GID: types.NewPrimitiveU32(0), + State: types.NewPrimitiveU32(0), + PersonalDataCategory: types.NewPrimitiveU32(0), + NormalizedPersonalRoundResults: types.NewList[*MatchmakeRefereePersonalRoundResult](), + } + + mrr.NormalizedPersonalRoundResults.Type = NewMatchmakeRefereePersonalRoundResult() + + return mrr +} diff --git a/nex-protocols-go/matchmake-referee/types/matchmake_referee_start_round_param.go b/nex-protocols-go/matchmake-referee/types/matchmake_referee_start_round_param.go new file mode 100644 index 0000000..4aa12a1 --- /dev/null +++ b/nex-protocols-go/matchmake-referee/types/matchmake_referee_start_round_param.go @@ -0,0 +1,143 @@ +// Package types implements all the types used by the MatchmakeReferee protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// MatchmakeRefereeStartRoundParam is a type within the MatchmakeReferee protocol +type MatchmakeRefereeStartRoundParam struct { + types.Structure + *types.Data + PersonalDataCategory *types.PrimitiveU32 + GID *types.PrimitiveU32 + PIDs *types.List[*types.PID] +} + +// WriteTo writes the MatchmakeRefereeStartRoundParam to the given writable +func (mrsrp *MatchmakeRefereeStartRoundParam) WriteTo(writable types.Writable) { + mrsrp.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + mrsrp.PersonalDataCategory.WriteTo(contentWritable) + mrsrp.GID.WriteTo(contentWritable) + mrsrp.PIDs.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + mrsrp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MatchmakeRefereeStartRoundParam from the given readable +func (mrsrp *MatchmakeRefereeStartRoundParam) ExtractFrom(readable types.Readable) error { + var err error + + err = mrsrp.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStartRoundParam.Data. %s", err.Error()) + } + + err = mrsrp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStartRoundParam header. %s", err.Error()) + } + + err = mrsrp.PersonalDataCategory.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStartRoundParam.PersonalDataCategory. %s", err.Error()) + } + + err = mrsrp.GID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStartRoundParam.GID. %s", err.Error()) + } + + err = mrsrp.PIDs.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStartRoundParam.PIDs. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of MatchmakeRefereeStartRoundParam +func (mrsrp *MatchmakeRefereeStartRoundParam) Copy() types.RVType { + copied := NewMatchmakeRefereeStartRoundParam() + + copied.StructureVersion = mrsrp.StructureVersion + copied.Data = mrsrp.Data.Copy().(*types.Data) + copied.PersonalDataCategory = mrsrp.PersonalDataCategory.Copy().(*types.PrimitiveU32) + copied.GID = mrsrp.GID.Copy().(*types.PrimitiveU32) + copied.PIDs = mrsrp.PIDs.Copy().(*types.List[*types.PID]) + + return copied +} + +// Equals checks if the given MatchmakeRefereeStartRoundParam contains the same data as the current MatchmakeRefereeStartRoundParam +func (mrsrp *MatchmakeRefereeStartRoundParam) Equals(o types.RVType) bool { + if _, ok := o.(*MatchmakeRefereeStartRoundParam); !ok { + return false + } + + other := o.(*MatchmakeRefereeStartRoundParam) + + if mrsrp.StructureVersion != other.StructureVersion { + return false + } + + if !mrsrp.Data.Equals(other.Data) { + return false + } + + if !mrsrp.PersonalDataCategory.Equals(other.PersonalDataCategory) { + return false + } + + if !mrsrp.GID.Equals(other.GID) { + return false + } + + return mrsrp.PIDs.Equals(other.PIDs) +} + +// String returns the string representation of the MatchmakeRefereeStartRoundParam +func (mrsrp *MatchmakeRefereeStartRoundParam) String() string { + return mrsrp.FormatToString(0) +} + +// FormatToString pretty-prints the MatchmakeRefereeStartRoundParam using the provided indentation level +func (mrsrp *MatchmakeRefereeStartRoundParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MatchmakeRefereeStartRoundParam{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, mrsrp.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPersonalDataCategory: %s,\n", indentationValues, mrsrp.PersonalDataCategory)) + b.WriteString(fmt.Sprintf("%sGID: %s,\n", indentationValues, mrsrp.GID)) + b.WriteString(fmt.Sprintf("%sPIDs: %s,\n", indentationValues, mrsrp.PIDs)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMatchmakeRefereeStartRoundParam returns a new MatchmakeRefereeStartRoundParam +func NewMatchmakeRefereeStartRoundParam() *MatchmakeRefereeStartRoundParam { + mrsrp := &MatchmakeRefereeStartRoundParam{ + Data: types.NewData(), + PersonalDataCategory: types.NewPrimitiveU32(0), + GID: types.NewPrimitiveU32(0), + PIDs: types.NewList[*types.PID](), + } + + mrsrp.PIDs.Type = types.NewPID(0) + + return mrsrp +} diff --git a/nex-protocols-go/matchmake-referee/types/matchmake_referee_stats.go b/nex-protocols-go/matchmake-referee/types/matchmake_referee_stats.go new file mode 100644 index 0000000..87de5f7 --- /dev/null +++ b/nex-protocols-go/matchmake-referee/types/matchmake_referee_stats.go @@ -0,0 +1,323 @@ +// Package types implements all the types used by the MatchmakeReferee protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// MatchmakeRefereeStats is a type within the MatchmakeReferee protocol +type MatchmakeRefereeStats struct { + types.Structure + *types.Data + UniqueID *types.PrimitiveU64 + Category *types.PrimitiveU32 + PID *types.PID + RecentDisconnection *types.PrimitiveU32 + RecentViolation *types.PrimitiveU32 + RecentMismatch *types.PrimitiveU32 + RecentWin *types.PrimitiveU32 + RecentLoss *types.PrimitiveU32 + RecentDraw *types.PrimitiveU32 + TotalDisconnect *types.PrimitiveU32 + TotalViolation *types.PrimitiveU32 + TotalMismatch *types.PrimitiveU32 + TotalWin *types.PrimitiveU32 + TotalLoss *types.PrimitiveU32 + TotalDraw *types.PrimitiveU32 + RatingValue *types.PrimitiveU32 +} + +// WriteTo writes the MatchmakeRefereeStats to the given writable +func (mrs *MatchmakeRefereeStats) WriteTo(writable types.Writable) { + mrs.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + mrs.UniqueID.WriteTo(contentWritable) + mrs.Category.WriteTo(contentWritable) + mrs.PID.WriteTo(contentWritable) + mrs.RecentDisconnection.WriteTo(contentWritable) + mrs.RecentViolation.WriteTo(contentWritable) + mrs.RecentMismatch.WriteTo(contentWritable) + mrs.RecentWin.WriteTo(contentWritable) + mrs.RecentLoss.WriteTo(contentWritable) + mrs.RecentDraw.WriteTo(contentWritable) + mrs.TotalDisconnect.WriteTo(contentWritable) + mrs.TotalViolation.WriteTo(contentWritable) + mrs.TotalMismatch.WriteTo(contentWritable) + mrs.TotalWin.WriteTo(contentWritable) + mrs.TotalLoss.WriteTo(contentWritable) + mrs.TotalDraw.WriteTo(contentWritable) + mrs.RatingValue.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + mrs.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MatchmakeRefereeStats from the given readable +func (mrs *MatchmakeRefereeStats) ExtractFrom(readable types.Readable) error { + var err error + + err = mrs.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats.Data. %s", err.Error()) + } + + err = mrs.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats header. %s", err.Error()) + } + + err = mrs.UniqueID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats.UniqueID. %s", err.Error()) + } + + err = mrs.Category.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats.Category. %s", err.Error()) + } + + err = mrs.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats.PID. %s", err.Error()) + } + + err = mrs.RecentDisconnection.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats.RecentDisconnection. %s", err.Error()) + } + + err = mrs.RecentViolation.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats.RecentViolation. %s", err.Error()) + } + + err = mrs.RecentMismatch.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats.RecentMismatch. %s", err.Error()) + } + + err = mrs.RecentWin.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats.RecentWin. %s", err.Error()) + } + + err = mrs.RecentLoss.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats.RecentLoss. %s", err.Error()) + } + + err = mrs.RecentDraw.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats.RecentDraw. %s", err.Error()) + } + + err = mrs.TotalDisconnect.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats.TotalDisconnect. %s", err.Error()) + } + + err = mrs.TotalViolation.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats.TotalViolation. %s", err.Error()) + } + + err = mrs.TotalMismatch.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats.TotalMismatch. %s", err.Error()) + } + + err = mrs.TotalWin.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats.TotalWin. %s", err.Error()) + } + + err = mrs.TotalLoss.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats.TotalLoss. %s", err.Error()) + } + + err = mrs.TotalDraw.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats.TotalDraw. %s", err.Error()) + } + + err = mrs.RatingValue.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStats.RatingValue. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of MatchmakeRefereeStats +func (mrs *MatchmakeRefereeStats) Copy() types.RVType { + copied := NewMatchmakeRefereeStats() + + copied.StructureVersion = mrs.StructureVersion + copied.Data = mrs.Data.Copy().(*types.Data) + copied.UniqueID = mrs.UniqueID.Copy().(*types.PrimitiveU64) + copied.Category = mrs.Category.Copy().(*types.PrimitiveU32) + copied.PID = mrs.PID.Copy().(*types.PID) + copied.RecentDisconnection = mrs.RecentDisconnection.Copy().(*types.PrimitiveU32) + copied.RecentViolation = mrs.RecentViolation.Copy().(*types.PrimitiveU32) + copied.RecentMismatch = mrs.RecentMismatch.Copy().(*types.PrimitiveU32) + copied.RecentWin = mrs.RecentWin.Copy().(*types.PrimitiveU32) + copied.RecentLoss = mrs.RecentLoss.Copy().(*types.PrimitiveU32) + copied.RecentDraw = mrs.RecentDraw.Copy().(*types.PrimitiveU32) + copied.TotalDisconnect = mrs.TotalDisconnect.Copy().(*types.PrimitiveU32) + copied.TotalViolation = mrs.TotalViolation.Copy().(*types.PrimitiveU32) + copied.TotalMismatch = mrs.TotalMismatch.Copy().(*types.PrimitiveU32) + copied.TotalWin = mrs.TotalWin.Copy().(*types.PrimitiveU32) + copied.TotalLoss = mrs.TotalLoss.Copy().(*types.PrimitiveU32) + copied.TotalDraw = mrs.TotalDraw.Copy().(*types.PrimitiveU32) + copied.RatingValue = mrs.RatingValue.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given MatchmakeRefereeStats contains the same data as the current MatchmakeRefereeStats +func (mrs *MatchmakeRefereeStats) Equals(o types.RVType) bool { + if _, ok := o.(*MatchmakeRefereeStats); !ok { + return false + } + + other := o.(*MatchmakeRefereeStats) + + if mrs.StructureVersion != other.StructureVersion { + return false + } + + if !mrs.Data.Equals(other.Data) { + return false + } + + if !mrs.UniqueID.Equals(other.UniqueID) { + return false + } + + if !mrs.Category.Equals(other.Category) { + return false + } + + if !mrs.PID.Equals(other.PID) { + return false + } + + if !mrs.RecentDisconnection.Equals(other.RecentDisconnection) { + return false + } + + if !mrs.RecentViolation.Equals(other.RecentViolation) { + return false + } + + if !mrs.RecentMismatch.Equals(other.RecentMismatch) { + return false + } + + if !mrs.RecentWin.Equals(other.RecentWin) { + return false + } + + if !mrs.RecentLoss.Equals(other.RecentLoss) { + return false + } + + if !mrs.RecentDraw.Equals(other.RecentDraw) { + return false + } + + if !mrs.TotalDisconnect.Equals(other.TotalDisconnect) { + return false + } + + if !mrs.TotalViolation.Equals(other.TotalViolation) { + return false + } + + if !mrs.TotalMismatch.Equals(other.TotalMismatch) { + return false + } + + if !mrs.TotalWin.Equals(other.TotalWin) { + return false + } + + if !mrs.TotalLoss.Equals(other.TotalLoss) { + return false + } + + if !mrs.TotalDraw.Equals(other.TotalDraw) { + return false + } + + return mrs.RatingValue.Equals(other.RatingValue) +} + +// String returns the string representation of the MatchmakeRefereeStats +func (mrs *MatchmakeRefereeStats) String() string { + return mrs.FormatToString(0) +} + +// FormatToString pretty-prints the MatchmakeRefereeStats using the provided indentation level +func (mrs *MatchmakeRefereeStats) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MatchmakeRefereeStats{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, mrs.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUniqueID: %s,\n", indentationValues, mrs.UniqueID)) + b.WriteString(fmt.Sprintf("%sCategory: %s,\n", indentationValues, mrs.Category)) + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, mrs.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sRecentDisconnection: %s,\n", indentationValues, mrs.RecentDisconnection)) + b.WriteString(fmt.Sprintf("%sRecentViolation: %s,\n", indentationValues, mrs.RecentViolation)) + b.WriteString(fmt.Sprintf("%sRecentMismatch: %s,\n", indentationValues, mrs.RecentMismatch)) + b.WriteString(fmt.Sprintf("%sRecentWin: %s,\n", indentationValues, mrs.RecentWin)) + b.WriteString(fmt.Sprintf("%sRecentLoss: %s,\n", indentationValues, mrs.RecentLoss)) + b.WriteString(fmt.Sprintf("%sRecentDraw: %s,\n", indentationValues, mrs.RecentDraw)) + b.WriteString(fmt.Sprintf("%sTotalDisconnect: %s,\n", indentationValues, mrs.TotalDisconnect)) + b.WriteString(fmt.Sprintf("%sTotalViolation: %s,\n", indentationValues, mrs.TotalViolation)) + b.WriteString(fmt.Sprintf("%sTotalMismatch: %s,\n", indentationValues, mrs.TotalMismatch)) + b.WriteString(fmt.Sprintf("%sTotalWin: %s,\n", indentationValues, mrs.TotalWin)) + b.WriteString(fmt.Sprintf("%sTotalLoss: %s,\n", indentationValues, mrs.TotalLoss)) + b.WriteString(fmt.Sprintf("%sTotalDraw: %s,\n", indentationValues, mrs.TotalDraw)) + b.WriteString(fmt.Sprintf("%sRatingValue: %s,\n", indentationValues, mrs.RatingValue)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMatchmakeRefereeStats returns a new MatchmakeRefereeStats +func NewMatchmakeRefereeStats() *MatchmakeRefereeStats { + mrs := &MatchmakeRefereeStats{ + Data: types.NewData(), + UniqueID: types.NewPrimitiveU64(0), + Category: types.NewPrimitiveU32(0), + PID: types.NewPID(0), + RecentDisconnection: types.NewPrimitiveU32(0), + RecentViolation: types.NewPrimitiveU32(0), + RecentMismatch: types.NewPrimitiveU32(0), + RecentWin: types.NewPrimitiveU32(0), + RecentLoss: types.NewPrimitiveU32(0), + RecentDraw: types.NewPrimitiveU32(0), + TotalDisconnect: types.NewPrimitiveU32(0), + TotalViolation: types.NewPrimitiveU32(0), + TotalMismatch: types.NewPrimitiveU32(0), + TotalWin: types.NewPrimitiveU32(0), + TotalLoss: types.NewPrimitiveU32(0), + TotalDraw: types.NewPrimitiveU32(0), + RatingValue: types.NewPrimitiveU32(0), + } + + return mrs +} diff --git a/nex-protocols-go/matchmake-referee/types/matchmake_referee_stats_init_param.go b/nex-protocols-go/matchmake-referee/types/matchmake_referee_stats_init_param.go new file mode 100644 index 0000000..41cb5ea --- /dev/null +++ b/nex-protocols-go/matchmake-referee/types/matchmake_referee_stats_init_param.go @@ -0,0 +1,127 @@ +// Package types implements all the types used by the MatchmakeReferee protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// MatchmakeRefereeStatsInitParam is a type within the MatchmakeReferee protocol +type MatchmakeRefereeStatsInitParam struct { + types.Structure + *types.Data + Category *types.PrimitiveU32 + InitialRatingValue *types.PrimitiveU32 +} + +// WriteTo writes the MatchmakeRefereeStatsInitParam to the given writable +func (mrsip *MatchmakeRefereeStatsInitParam) WriteTo(writable types.Writable) { + mrsip.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + mrsip.Category.WriteTo(contentWritable) + mrsip.InitialRatingValue.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + mrsip.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MatchmakeRefereeStatsInitParam from the given readable +func (mrsip *MatchmakeRefereeStatsInitParam) ExtractFrom(readable types.Readable) error { + var err error + + err = mrsip.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStatsInitParam.Data. %s", err.Error()) + } + + err = mrsip.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStatsInitParam header. %s", err.Error()) + } + + err = mrsip.Category.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStatsInitParam.Category. %s", err.Error()) + } + + err = mrsip.InitialRatingValue.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStatsInitParam.InitialRatingValue. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of MatchmakeRefereeStatsInitParam +func (mrsip *MatchmakeRefereeStatsInitParam) Copy() types.RVType { + copied := NewMatchmakeRefereeStatsInitParam() + + copied.StructureVersion = mrsip.StructureVersion + copied.Data = mrsip.Data.Copy().(*types.Data) + copied.Category = mrsip.Category.Copy().(*types.PrimitiveU32) + copied.InitialRatingValue = mrsip.InitialRatingValue.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given MatchmakeRefereeStatsInitParam contains the same data as the current MatchmakeRefereeStatsInitParam +func (mrsip *MatchmakeRefereeStatsInitParam) Equals(o types.RVType) bool { + if _, ok := o.(*MatchmakeRefereeStatsInitParam); !ok { + return false + } + + other := o.(*MatchmakeRefereeStatsInitParam) + + if mrsip.StructureVersion != other.StructureVersion { + return false + } + + if !mrsip.Data.Equals(other.Data) { + return false + } + + if !mrsip.Category.Equals(other.Category) { + return false + } + + return mrsip.InitialRatingValue.Equals(other.InitialRatingValue) +} + +// String returns the string representation of the MatchmakeRefereeStatsInitParam +func (mrsip *MatchmakeRefereeStatsInitParam) String() string { + return mrsip.FormatToString(0) +} + +// FormatToString pretty-prints the MatchmakeRefereeStatsInitParam using the provided indentation level +func (mrsip *MatchmakeRefereeStatsInitParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MatchmakeRefereeStatsInitParam{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, mrsip.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sCategory: %s,\n", indentationValues, mrsip.Category)) + b.WriteString(fmt.Sprintf("%sInitialRatingValue: %s,\n", indentationValues, mrsip.InitialRatingValue)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMatchmakeRefereeStatsInitParam returns a new MatchmakeRefereeStatsInitParam +func NewMatchmakeRefereeStatsInitParam() *MatchmakeRefereeStatsInitParam { + mrsip := &MatchmakeRefereeStatsInitParam{ + Data: types.NewData(), + Category: types.NewPrimitiveU32(0), + InitialRatingValue: types.NewPrimitiveU32(0), + } + + return mrsip +} diff --git a/nex-protocols-go/matchmake-referee/types/matchmake_referee_stats_target.go b/nex-protocols-go/matchmake-referee/types/matchmake_referee_stats_target.go new file mode 100644 index 0000000..b25bb37 --- /dev/null +++ b/nex-protocols-go/matchmake-referee/types/matchmake_referee_stats_target.go @@ -0,0 +1,127 @@ +// Package types implements all the types used by the MatchmakeReferee protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// MatchmakeRefereeStatsTarget is a type within the MatchmakeReferee protocol +type MatchmakeRefereeStatsTarget struct { + types.Structure + *types.Data + PID *types.PID + Category *types.PrimitiveU32 +} + +// WriteTo writes the MatchmakeRefereeStatsTarget to the given writable +func (mrst *MatchmakeRefereeStatsTarget) WriteTo(writable types.Writable) { + mrst.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + mrst.PID.WriteTo(contentWritable) + mrst.Category.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + mrst.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MatchmakeRefereeStatsTarget from the given readable +func (mrst *MatchmakeRefereeStatsTarget) ExtractFrom(readable types.Readable) error { + var err error + + err = mrst.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStatsTarget.Data. %s", err.Error()) + } + + err = mrst.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStatsTarget header. %s", err.Error()) + } + + err = mrst.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStatsTarget.PID. %s", err.Error()) + } + + err = mrst.Category.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MatchmakeRefereeStatsTarget.Category. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of MatchmakeRefereeStatsTarget +func (mrst *MatchmakeRefereeStatsTarget) Copy() types.RVType { + copied := NewMatchmakeRefereeStatsTarget() + + copied.StructureVersion = mrst.StructureVersion + copied.Data = mrst.Data.Copy().(*types.Data) + copied.PID = mrst.PID.Copy().(*types.PID) + copied.Category = mrst.Category.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given MatchmakeRefereeStatsTarget contains the same data as the current MatchmakeRefereeStatsTarget +func (mrst *MatchmakeRefereeStatsTarget) Equals(o types.RVType) bool { + if _, ok := o.(*MatchmakeRefereeStatsTarget); !ok { + return false + } + + other := o.(*MatchmakeRefereeStatsTarget) + + if mrst.StructureVersion != other.StructureVersion { + return false + } + + if !mrst.Data.Equals(other.Data) { + return false + } + + if !mrst.PID.Equals(other.PID) { + return false + } + + return mrst.Category.Equals(other.Category) +} + +// String returns the string representation of the MatchmakeRefereeStatsTarget +func (mrst *MatchmakeRefereeStatsTarget) String() string { + return mrst.FormatToString(0) +} + +// FormatToString pretty-prints the MatchmakeRefereeStatsTarget using the provided indentation level +func (mrst *MatchmakeRefereeStatsTarget) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MatchmakeRefereeStatsTarget{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, mrst.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, mrst.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sCategory: %s,\n", indentationValues, mrst.Category)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMatchmakeRefereeStatsTarget returns a new MatchmakeRefereeStatsTarget +func NewMatchmakeRefereeStatsTarget() *MatchmakeRefereeStatsTarget { + mrst := &MatchmakeRefereeStatsTarget{ + Data: types.NewData(), + PID: types.NewPID(0), + Category: types.NewPrimitiveU32(0), + } + + return mrst +} diff --git a/nex-protocols-go/message-delivery/deliver_message.go b/nex-protocols-go/message-delivery/deliver_message.go new file mode 100644 index 0000000..b220b23 --- /dev/null +++ b/nex-protocols-go/message-delivery/deliver_message.go @@ -0,0 +1,47 @@ +// Package protocol implements the Message Deliver protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeliverMessage(packet nex.PacketInterface) { + if protocol.DeliverMessage == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "MessageDelivery::DeliverMessage not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + oUserMessage := types.NewAnyDataHolder() + + err := oUserMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeliverMessage(fmt.Errorf("Failed to read oUserMessage from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeliverMessage(nil, packet, callID, oUserMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/message-delivery/protocol.go b/nex-protocols-go/message-delivery/protocol.go new file mode 100644 index 0000000..9f1dcec --- /dev/null +++ b/nex-protocols-go/message-delivery/protocol.go @@ -0,0 +1,79 @@ +// Package protocol implements the Message Deliver protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the Message Delivery protocol + ProtocolID = 0x1B + + // MethodDeliverMessage is the method ID for the method DeliverMessage + MethodDeliverMessage = 0x1 +) + +// Protocol stores all the RMC method handlers for the Message Delivery protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + DeliverMessage func(err error, packet nex.PacketInterface, callID uint32, oUserMessage *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Message Deliver protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerDeliverMessage(handler func(err error, packet nex.PacketInterface, callID uint32, oUserMessage *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerDeliverMessage sets the handler for the DeliverMessage method +func (protocol *Protocol) SetHandlerDeliverMessage(handler func(err error, packet nex.PacketInterface, callID uint32, oUserMessage *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) { + protocol.DeliverMessage = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodDeliverMessage: + protocol.handleDeliverMessage(packet) + default: + errMessage := fmt.Sprintf("Unsupported MessageDelivery method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Message Delivery protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/messaging/delete_all_messages.go b/nex-protocols-go/messaging/delete_all_messages.go new file mode 100644 index 0000000..5f6b2b0 --- /dev/null +++ b/nex-protocols-go/messaging/delete_all_messages.go @@ -0,0 +1,47 @@ +// Package protocol implements the Messaging protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + messaging_types "github.com/PretendoNetwork/nex-protocols-go/v2/messaging/types" +) + +func (protocol *Protocol) handleDeleteAllMessages(packet nex.PacketInterface) { + if protocol.DeleteAllMessages == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Messaging::DeleteAllMessages not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + recipient := messaging_types.NewMessageRecipient() + + err := recipient.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteAllMessages(fmt.Errorf("Failed to read recipient from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteAllMessages(nil, packet, callID, recipient) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/messaging/delete_messages.go b/nex-protocols-go/messaging/delete_messages.go new file mode 100644 index 0000000..6c0ded2 --- /dev/null +++ b/nex-protocols-go/messaging/delete_messages.go @@ -0,0 +1,62 @@ +// Package protocol implements the Messaging protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + messaging_types "github.com/PretendoNetwork/nex-protocols-go/v2/messaging/types" +) + +func (protocol *Protocol) handleDeleteMessages(packet nex.PacketInterface) { + if protocol.DeleteMessages == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Messaging::DeleteMessages not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + recipient := messaging_types.NewMessageRecipient() + lstMessagesToDelete := types.NewList[*types.PrimitiveU32]() + lstMessagesToDelete.Type = types.NewPrimitiveU32(0) + + var err error + + err = recipient.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteMessages(fmt.Errorf("Failed to read recipient from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = lstMessagesToDelete.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteMessages(fmt.Errorf("Failed to read lstMessagesToDelete from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteMessages(nil, packet, callID, recipient, lstMessagesToDelete) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/messaging/deliver_message.go b/nex-protocols-go/messaging/deliver_message.go new file mode 100644 index 0000000..cd70480 --- /dev/null +++ b/nex-protocols-go/messaging/deliver_message.go @@ -0,0 +1,47 @@ +// Package protocol implements the Messaging protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeliverMessage(packet nex.PacketInterface) { + if protocol.DeliverMessage == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Messaging::DeliverMessage not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + oUserMessage := types.NewAnyDataHolder() + + err := oUserMessage.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeliverMessage(fmt.Errorf("Failed to read oUserMessage from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeliverMessage(nil, packet, callID, oUserMessage) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/messaging/deliver_message_multi_target.go b/nex-protocols-go/messaging/deliver_message_multi_target.go new file mode 100644 index 0000000..7b0dc37 --- /dev/null +++ b/nex-protocols-go/messaging/deliver_message_multi_target.go @@ -0,0 +1,31 @@ +// Package protocol implements the Messaging protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeliverMessageMultiTarget(packet nex.PacketInterface) { + if protocol.DeliverMessageMultiTarget == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Messaging::DeliverMessageMultiTarget not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("Messaging::DeliverMessageMultiTarget STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.DeliverMessageMultiTarget(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/messaging/get_messages_headers.go b/nex-protocols-go/messaging/get_messages_headers.go new file mode 100644 index 0000000..a784a51 --- /dev/null +++ b/nex-protocols-go/messaging/get_messages_headers.go @@ -0,0 +1,61 @@ +// Package protocol implements the Messaging protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + messaging_types "github.com/PretendoNetwork/nex-protocols-go/v2/messaging/types" +) + +func (protocol *Protocol) handleGetMessagesHeaders(packet nex.PacketInterface) { + if protocol.GetMessagesHeaders == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Messaging::GetMessagesHeaders not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + recipient := messaging_types.NewMessageRecipient() + resultRange := types.NewResultRange() + + var err error + + err = recipient.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetMessagesHeaders(fmt.Errorf("Failed to read recipient from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetMessagesHeaders(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetMessagesHeaders(nil, packet, callID, recipient, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/messaging/get_number_of_messages.go b/nex-protocols-go/messaging/get_number_of_messages.go new file mode 100644 index 0000000..f05100e --- /dev/null +++ b/nex-protocols-go/messaging/get_number_of_messages.go @@ -0,0 +1,47 @@ +// Package protocol implements the Messaging protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + messaging_types "github.com/PretendoNetwork/nex-protocols-go/v2/messaging/types" +) + +func (protocol *Protocol) handleGetNumberOfMessages(packet nex.PacketInterface) { + if protocol.GetNumberOfMessages == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Messaging::GetNumberOfMessages not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + recipient := messaging_types.NewMessageRecipient() + + err := recipient.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetNumberOfMessages(fmt.Errorf("Failed to read recipient from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetNumberOfMessages(nil, packet, callID, recipient) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/messaging/protocol.go b/nex-protocols-go/messaging/protocol.go new file mode 100644 index 0000000..3089214 --- /dev/null +++ b/nex-protocols-go/messaging/protocol.go @@ -0,0 +1,164 @@ +// Package protocol implements the Messaging protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + messaging_types "github.com/PretendoNetwork/nex-protocols-go/v2/messaging/types" +) + +const ( + // ProtocolID is the protocol ID for the Messaging protocol + ProtocolID = 0x17 + + // MethodDeliverMessage is the method ID for method DeliverMessage + MethodDeliverMessage = 0x1 + + // MethodGetNumberOfMessages is the method ID for method GetNumberOfMessages + MethodGetNumberOfMessages = 0x2 + + // MethodGetMessagesHeaders is the method ID for method GetMessagesHeaders + MethodGetMessagesHeaders = 0x3 + + // MethodRetrieveAllMessagesWithinRange is the method ID for method RetrieveAllMessagesWithinRange + MethodRetrieveAllMessagesWithinRange = 0x4 + + // MethodRetrieveMessages is the method ID for method RetrieveMessages + MethodRetrieveMessages = 0x5 + + // MethodDeleteMessages is the method ID for method DeleteMessages + MethodDeleteMessages = 0x6 + + // MethodDeleteAllMessages is the method ID for method DeleteAllMessages + MethodDeleteAllMessages = 0x7 + + // MethodDeliverMessageMultiTarget is the method ID for method DeliverMessageMultiTarget + MethodDeliverMessageMultiTarget = 0x8 +) + +// Protocol stores all the RMC method handlers for the Messaging protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + DeliverMessage func(err error, packet nex.PacketInterface, callID uint32, oUserMessage *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error) + GetNumberOfMessages func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient) (*nex.RMCMessage, *nex.Error) + GetMessagesHeaders func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + RetrieveAllMessagesWithinRange func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error) + RetrieveMessages func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient, lstMsgIDs *types.List[*types.PrimitiveU32], bLeaveOnServer *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + DeleteMessages func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient, lstMessagesToDelete *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error) + DeleteAllMessages func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient) (*nex.RMCMessage, *nex.Error) + DeliverMessageMultiTarget func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) // TODO - Unknown request/response format + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Messaging protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerDeliverMessage(handler func(err error, packet nex.PacketInterface, callID uint32, oUserMessage *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetNumberOfMessages(handler func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetMessagesHeaders(handler func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerRetrieveAllMessagesWithinRange(handler func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) + SetHandlerRetrieveMessages(handler func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient, lstMsgIDs *types.List[*types.PrimitiveU32], bLeaveOnServer *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeleteMessages(handler func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient, lstMessagesToDelete *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeleteAllMessages(handler func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeliverMessageMultiTarget(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerDeliverMessage sets the handler for the DeliverMessage method +func (protocol *Protocol) SetHandlerDeliverMessage(handler func(err error, packet nex.PacketInterface, callID uint32, oUserMessage *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) { + protocol.DeliverMessage = handler +} + +// SetHandlerGetNumberOfMessages sets the handler for the GetNumberOfMessages method +func (protocol *Protocol) SetHandlerGetNumberOfMessages(handler func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient) (*nex.RMCMessage, *nex.Error)) { + protocol.GetNumberOfMessages = handler +} + +// SetHandlerGetMessagesHeaders sets the handler for the GetMessagesHeaders method +func (protocol *Protocol) SetHandlerGetMessagesHeaders(handler func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.GetMessagesHeaders = handler +} + +// SetHandlerRetrieveAllMessagesWithinRange sets the handler for the RetrieveAllMessagesWithinRange method +func (protocol *Protocol) SetHandlerRetrieveAllMessagesWithinRange(handler func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient, resultRange *types.ResultRange) (*nex.RMCMessage, *nex.Error)) { + protocol.RetrieveAllMessagesWithinRange = handler +} + +// SetHandlerRetrieveMessages sets the handler for the RetrieveMessages method +func (protocol *Protocol) SetHandlerRetrieveMessages(handler func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient, lstMsgIDs *types.List[*types.PrimitiveU32], bLeaveOnServer *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.RetrieveMessages = handler +} + +// SetHandlerDeleteMessages sets the handler for the DeleteMessages method +func (protocol *Protocol) SetHandlerDeleteMessages(handler func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient, lstMessagesToDelete *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) { + protocol.DeleteMessages = handler +} + +// SetHandlerDeleteAllMessages sets the handler for the DeleteAllMessages method +func (protocol *Protocol) SetHandlerDeleteAllMessages(handler func(err error, packet nex.PacketInterface, callID uint32, recipient *messaging_types.MessageRecipient) (*nex.RMCMessage, *nex.Error)) { + protocol.DeleteAllMessages = handler +} + +// SetHandlerDeliverMessageMultiTarget sets the handler for the DeliverMessageMultiTarget method +func (protocol *Protocol) SetHandlerDeliverMessageMultiTarget(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) { + protocol.DeliverMessageMultiTarget = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodDeliverMessage: + protocol.handleDeliverMessage(packet) + case MethodGetNumberOfMessages: + protocol.handleGetNumberOfMessages(packet) + case MethodGetMessagesHeaders: + protocol.handleGetMessagesHeaders(packet) + case MethodRetrieveAllMessagesWithinRange: + protocol.handleRetrieveAllMessagesWithinRange(packet) + case MethodRetrieveMessages: + protocol.handleRetrieveMessages(packet) + case MethodDeleteMessages: + protocol.handleDeleteMessages(packet) + case MethodDeleteAllMessages: + protocol.handleDeleteAllMessages(packet) + case MethodDeliverMessageMultiTarget: + protocol.handleDeliverMessageMultiTarget(packet) + default: + errMessage := fmt.Sprintf("Unsupported Messaging method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Messaging protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/messaging/retrieve_all_messages_within_range.go b/nex-protocols-go/messaging/retrieve_all_messages_within_range.go new file mode 100644 index 0000000..6a1bd0a --- /dev/null +++ b/nex-protocols-go/messaging/retrieve_all_messages_within_range.go @@ -0,0 +1,61 @@ +// Package protocol implements the Messaging protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + messaging_types "github.com/PretendoNetwork/nex-protocols-go/v2/messaging/types" +) + +func (protocol *Protocol) handleRetrieveAllMessagesWithinRange(packet nex.PacketInterface) { + if protocol.RetrieveAllMessagesWithinRange == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Messaging::RetrieveAllMessagesWithinRange not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + recipient := messaging_types.NewMessageRecipient() + resultRange := types.NewResultRange() + + var err error + + err = recipient.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RetrieveAllMessagesWithinRange(fmt.Errorf("Failed to read recipient from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = resultRange.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RetrieveAllMessagesWithinRange(fmt.Errorf("Failed to read resultRange from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RetrieveAllMessagesWithinRange(nil, packet, callID, recipient, resultRange) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/messaging/retrieve_messages.go b/nex-protocols-go/messaging/retrieve_messages.go new file mode 100644 index 0000000..33de79d --- /dev/null +++ b/nex-protocols-go/messaging/retrieve_messages.go @@ -0,0 +1,73 @@ +// Package protocol implements the Messaging protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + messaging_types "github.com/PretendoNetwork/nex-protocols-go/v2/messaging/types" +) + +func (protocol *Protocol) handleRetrieveMessages(packet nex.PacketInterface) { + if protocol.RetrieveMessages == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Messaging::RetrieveMessages not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + recipient := messaging_types.NewMessageRecipient() + lstMsgIDs := types.NewList[*types.PrimitiveU32]() + lstMsgIDs.Type = types.NewPrimitiveU32(0) + bLeaveOnServer := types.NewPrimitiveBool(false) + + var err error + + err = recipient.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RetrieveMessages(fmt.Errorf("Failed to read recipient from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = lstMsgIDs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RetrieveMessages(fmt.Errorf("Failed to read lstMsgIDs from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = bLeaveOnServer.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RetrieveMessages(fmt.Errorf("Failed to read bLeaveOnServer from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RetrieveMessages(nil, packet, callID, recipient, lstMsgIDs, bLeaveOnServer) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/messaging/types/binary_message.go b/nex-protocols-go/messaging/types/binary_message.go new file mode 100644 index 0000000..6a6d8ff --- /dev/null +++ b/nex-protocols-go/messaging/types/binary_message.go @@ -0,0 +1,113 @@ +// Package types implements all the types used by the MessageDelivery protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// BinaryMessage is a type within the MessageDelivery protocol +type BinaryMessage struct { + types.Structure + *UserMessage + BinaryBody *types.QBuffer +} + +// WriteTo writes the BinaryMessage to the given writable +func (bm *BinaryMessage) WriteTo(writable types.Writable) { + bm.UserMessage.WriteTo(writable) + + contentWritable := writable.CopyNew() + + bm.BinaryBody.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + bm.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the BinaryMessage from the given readable +func (bm *BinaryMessage) ExtractFrom(readable types.Readable) error { + var err error + + err = bm.UserMessage.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BinaryMessage.UserMessage. %s", err.Error()) + } + + err = bm.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BinaryMessage header. %s", err.Error()) + } + + err = bm.BinaryBody.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract BinaryMessage.BinaryBody. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of BinaryMessage +func (bm *BinaryMessage) Copy() types.RVType { + copied := NewBinaryMessage() + + copied.StructureVersion = bm.StructureVersion + copied.UserMessage = bm.UserMessage.Copy().(*UserMessage) + copied.BinaryBody = bm.BinaryBody.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given BinaryMessage contains the same data as the current BinaryMessage +func (bm *BinaryMessage) Equals(o types.RVType) bool { + if _, ok := o.(*BinaryMessage); !ok { + return false + } + + other := o.(*BinaryMessage) + + if bm.StructureVersion != other.StructureVersion { + return false + } + + if !bm.UserMessage.Equals(other.UserMessage) { + return false + } + + return bm.BinaryBody.Equals(other.BinaryBody) +} + +// String returns the string representation of the BinaryMessage +func (bm *BinaryMessage) String() string { + return bm.FormatToString(0) +} + +// FormatToString pretty-prints the BinaryMessage using the provided indentation level +func (bm *BinaryMessage) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("BinaryMessage{\n") + b.WriteString(fmt.Sprintf("%sUserMessage (parent): %s,\n", indentationValues, bm.UserMessage.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sBinaryBody: %s,\n", indentationValues, bm.BinaryBody)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewBinaryMessage returns a new BinaryMessage +func NewBinaryMessage() *BinaryMessage { + bm := &BinaryMessage{ + UserMessage: NewUserMessage(), + BinaryBody: types.NewQBuffer(nil), + } + + return bm +} diff --git a/nex-protocols-go/messaging/types/message_recipient.go b/nex-protocols-go/messaging/types/message_recipient.go new file mode 100644 index 0000000..5a34e57 --- /dev/null +++ b/nex-protocols-go/messaging/types/message_recipient.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the MessageDelivery protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// MessageRecipient is a type within the MessageDelivery protocol +type MessageRecipient struct { + types.Structure + UIRecipientType *types.PrimitiveU32 + PrincipalID *types.PID + GatheringID *types.PrimitiveU32 +} + +// WriteTo writes the MessageRecipient to the given writable +func (mr *MessageRecipient) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + mr.UIRecipientType.WriteTo(contentWritable) + mr.PrincipalID.WriteTo(contentWritable) + mr.GatheringID.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + mr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the MessageRecipient from the given readable +func (mr *MessageRecipient) ExtractFrom(readable types.Readable) error { + var err error + + err = mr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MessageRecipient header. %s", err.Error()) + } + + err = mr.UIRecipientType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MessageRecipient.UIRecipientType. %s", err.Error()) + } + + err = mr.PrincipalID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MessageRecipient.PrincipalID. %s", err.Error()) + } + + err = mr.GatheringID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract MessageRecipient.GatheringID. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of MessageRecipient +func (mr *MessageRecipient) Copy() types.RVType { + copied := NewMessageRecipient() + + copied.StructureVersion = mr.StructureVersion + copied.UIRecipientType = mr.UIRecipientType.Copy().(*types.PrimitiveU32) + copied.PrincipalID = mr.PrincipalID.Copy().(*types.PID) + copied.GatheringID = mr.GatheringID.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given MessageRecipient contains the same data as the current MessageRecipient +func (mr *MessageRecipient) Equals(o types.RVType) bool { + if _, ok := o.(*MessageRecipient); !ok { + return false + } + + other := o.(*MessageRecipient) + + if mr.StructureVersion != other.StructureVersion { + return false + } + + if !mr.UIRecipientType.Equals(other.UIRecipientType) { + return false + } + + if !mr.PrincipalID.Equals(other.PrincipalID) { + return false + } + + return mr.GatheringID.Equals(other.GatheringID) +} + +// String returns the string representation of the MessageRecipient +func (mr *MessageRecipient) String() string { + return mr.FormatToString(0) +} + +// FormatToString pretty-prints the MessageRecipient using the provided indentation level +func (mr *MessageRecipient) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("MessageRecipient{\n") + b.WriteString(fmt.Sprintf("%sUIRecipientType: %s,\n", indentationValues, mr.UIRecipientType)) + b.WriteString(fmt.Sprintf("%sPrincipalID: %s,\n", indentationValues, mr.PrincipalID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sGatheringID: %s,\n", indentationValues, mr.GatheringID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewMessageRecipient returns a new MessageRecipient +func NewMessageRecipient() *MessageRecipient { + mr := &MessageRecipient{ + UIRecipientType: types.NewPrimitiveU32(0), + PrincipalID: types.NewPID(0), + GatheringID: types.NewPrimitiveU32(0), + } + + return mr +} diff --git a/nex-protocols-go/messaging/types/text_message.go b/nex-protocols-go/messaging/types/text_message.go new file mode 100644 index 0000000..645e3c9 --- /dev/null +++ b/nex-protocols-go/messaging/types/text_message.go @@ -0,0 +1,113 @@ +// Package types implements all the types used by the MessageDelivery protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// TextMessage is a type within the MessageDelivery protocol +type TextMessage struct { + types.Structure + *UserMessage + StrTextBody *types.String +} + +// WriteTo writes the TextMessage to the given writable +func (tm *TextMessage) WriteTo(writable types.Writable) { + tm.UserMessage.WriteTo(writable) + + contentWritable := writable.CopyNew() + + tm.StrTextBody.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + tm.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the TextMessage from the given readable +func (tm *TextMessage) ExtractFrom(readable types.Readable) error { + var err error + + err = tm.UserMessage.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract TextMessage.UserMessage. %s", err.Error()) + } + + err = tm.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract TextMessage header. %s", err.Error()) + } + + err = tm.StrTextBody.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract TextMessage.StrTextBody. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of TextMessage +func (tm *TextMessage) Copy() types.RVType { + copied := NewTextMessage() + + copied.StructureVersion = tm.StructureVersion + copied.UserMessage = tm.UserMessage.Copy().(*UserMessage) + copied.StrTextBody = tm.StrTextBody.Copy().(*types.String) + + return copied +} + +// Equals checks if the given TextMessage contains the same data as the current TextMessage +func (tm *TextMessage) Equals(o types.RVType) bool { + if _, ok := o.(*TextMessage); !ok { + return false + } + + other := o.(*TextMessage) + + if tm.StructureVersion != other.StructureVersion { + return false + } + + if !tm.UserMessage.Equals(other.UserMessage) { + return false + } + + return tm.StrTextBody.Equals(other.StrTextBody) +} + +// String returns the string representation of the TextMessage +func (tm *TextMessage) String() string { + return tm.FormatToString(0) +} + +// FormatToString pretty-prints the TextMessage using the provided indentation level +func (tm *TextMessage) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("TextMessage{\n") + b.WriteString(fmt.Sprintf("%sUserMessage (parent): %s,\n", indentationValues, tm.UserMessage.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sStrTextBody: %s,\n", indentationValues, tm.StrTextBody)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewTextMessage returns a new TextMessage +func NewTextMessage() *TextMessage { + tm := &TextMessage{ + UserMessage: NewUserMessage(), + StrTextBody: types.NewString(""), + } + + return tm +} diff --git a/nex-protocols-go/messaging/types/user_message.go b/nex-protocols-go/messaging/types/user_message.go new file mode 100644 index 0000000..81efdf6 --- /dev/null +++ b/nex-protocols-go/messaging/types/user_message.go @@ -0,0 +1,245 @@ +// Package types implements all the types used by the MessageDelivery protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// UserMessage is a type within the MessageDelivery protocol +type UserMessage struct { + types.Structure + *types.Data + UIID *types.PrimitiveU32 + UIIDRecipient *types.PrimitiveU32 + UIRecipientType *types.PrimitiveU32 + UIParentID *types.PrimitiveU32 + PIDSender *types.PID + Receptiontime *types.DateTime + UILifeTime *types.PrimitiveU32 + UIFlags *types.PrimitiveU32 + StrSubject *types.String + StrSender *types.String +} + +// WriteTo writes the UserMessage to the given writable +func (um *UserMessage) WriteTo(writable types.Writable) { + um.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + um.UIID.WriteTo(contentWritable) + um.UIIDRecipient.WriteTo(contentWritable) + um.UIRecipientType.WriteTo(contentWritable) + um.UIParentID.WriteTo(contentWritable) + um.PIDSender.WriteTo(contentWritable) + um.Receptiontime.WriteTo(contentWritable) + um.UILifeTime.WriteTo(contentWritable) + um.UIFlags.WriteTo(contentWritable) + um.StrSubject.WriteTo(contentWritable) + um.StrSender.WriteTo(contentWritable) + //um.MessageRecipient.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + um.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the UserMessage from the given readable +func (um *UserMessage) ExtractFrom(readable types.Readable) error { + var err error + + err = um.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UserMessage.Data. %s", err.Error()) + } + + err = um.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UserMessage header. %s", err.Error()) + } + + err = um.UIID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UserMessage.UIID. %s", err.Error()) + } + + err = um.UIIDRecipient.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UserMessage.UIID. %s", err.Error()) + } + + err = um.UIRecipientType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UserMessage.UIID. %s", err.Error()) + } + + err = um.UIParentID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UserMessage.UIParentID. %s", err.Error()) + } + + err = um.PIDSender.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UserMessage.PIDSender. %s", err.Error()) + } + + err = um.Receptiontime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UserMessage.Receptiontime. %s", err.Error()) + } + + err = um.UILifeTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UserMessage.UILifeTime. %s", err.Error()) + } + + err = um.UIFlags.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UserMessage.UIFlags. %s", err.Error()) + } + + err = um.StrSubject.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UserMessage.StrSubject. %s", err.Error()) + } + + err = um.StrSender.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UserMessage.StrSender. %s", err.Error()) + } + + /*err = um.MessageRecipient.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UserMessage.MessageRecipient. %s", err.Error()) + }*/ + + return nil +} + +// Copy returns a new copied instance of UserMessage +func (um *UserMessage) Copy() types.RVType { + copied := NewUserMessage() + + copied.StructureVersion = um.StructureVersion + copied.Data = um.Data.Copy().(*types.Data) + copied.UIID = um.UIID.Copy().(*types.PrimitiveU32) + copied.UIIDRecipient = um.UIID.Copy().(*types.PrimitiveU32) + copied.UIRecipientType = um.UIID.Copy().(*types.PrimitiveU32) + copied.UIParentID = um.UIParentID.Copy().(*types.PrimitiveU32) + copied.PIDSender = um.PIDSender.Copy().(*types.PID) + copied.Receptiontime = um.Receptiontime.Copy().(*types.DateTime) + copied.UILifeTime = um.UILifeTime.Copy().(*types.PrimitiveU32) + copied.UIFlags = um.UIFlags.Copy().(*types.PrimitiveU32) + copied.StrSubject = um.StrSubject.Copy().(*types.String) + copied.StrSender = um.StrSender.Copy().(*types.String) + + return copied +} + +// Equals checks if the given UserMessage contains the same data as the current UserMessage +func (um *UserMessage) Equals(o types.RVType) bool { + if _, ok := o.(*UserMessage); !ok { + return false + } + + other := o.(*UserMessage) + + if um.StructureVersion != other.StructureVersion { + return false + } + + if !um.Data.Equals(other.Data) { + return false + } + + if !um.UIID.Equals(other.UIID) { + return false + } + + if !um.UIIDRecipient.Equals(other.UIIDRecipient) { + return false + } + + if !um.UIRecipientType.Equals(other.UIRecipientType) { + return false + } + + if !um.UIParentID.Equals(other.UIParentID) { + return false + } + + if !um.PIDSender.Equals(other.PIDSender) { + return false + } + + if !um.Receptiontime.Equals(other.Receptiontime) { + return false + } + + if !um.UILifeTime.Equals(other.UILifeTime) { + return false + } + + if !um.UIFlags.Equals(other.UIFlags) { + return false + } + + if !um.StrSubject.Equals(other.StrSubject) { + return false + } + + return um.StrSender.Equals(other.StrSender) +} + +// String returns the string representation of the UserMessage +func (um *UserMessage) String() string { + return um.FormatToString(0) +} + +// FormatToString pretty-prints the UserMessage using the provided indentation level +func (um *UserMessage) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("UserMessage{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, um.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUIID: %s,\n", indentationValues, um.UIID)) + b.WriteString(fmt.Sprintf("%sUIParentID: %s,\n", indentationValues, um.UIParentID)) + b.WriteString(fmt.Sprintf("%sUIIDRecipient: %s,\n", indentationValues, um.UIIDRecipient)) + b.WriteString(fmt.Sprintf("%sUIRecipientType: %s,\n", indentationValues, um.UIRecipientType)) + b.WriteString(fmt.Sprintf("%sPIDSender: %s,\n", indentationValues, um.PIDSender.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sReceptiontime: %s,\n", indentationValues, um.Receptiontime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUILifeTime: %s,\n", indentationValues, um.UILifeTime)) + b.WriteString(fmt.Sprintf("%sUIFlags: %s,\n", indentationValues, um.UIFlags)) + b.WriteString(fmt.Sprintf("%sStrSubject: %s,\n", indentationValues, um.StrSubject)) + b.WriteString(fmt.Sprintf("%sStrSender: %s,\n", indentationValues, um.StrSender)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewUserMessage returns a new UserMessage +func NewUserMessage() *UserMessage { + um := &UserMessage{ + Data: types.NewData(), + UIID: types.NewPrimitiveU32(0), + UIIDRecipient: types.NewPrimitiveU32(0), + UIRecipientType: types.NewPrimitiveU32(0), + UIParentID: types.NewPrimitiveU32(0), + PIDSender: types.NewPID(0), + Receptiontime: types.NewDateTime(0), + UILifeTime: types.NewPrimitiveU32(0), + UIFlags: types.NewPrimitiveU32(0), + StrSubject: types.NewString(""), + StrSender: types.NewString(""), + } + + return um +} diff --git a/nex-protocols-go/monitoring/get_cluster_members.go b/nex-protocols-go/monitoring/get_cluster_members.go new file mode 100644 index 0000000..c41da72 --- /dev/null +++ b/nex-protocols-go/monitoring/get_cluster_members.go @@ -0,0 +1,29 @@ +// Package protocol implements the Monitoring protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetClusterMembers(packet nex.PacketInterface) { + if protocol.GetClusterMembers == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Monitoring::GetClusterMembers not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetClusterMembers(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/monitoring/ping_daemon.go b/nex-protocols-go/monitoring/ping_daemon.go new file mode 100644 index 0000000..9d5570b --- /dev/null +++ b/nex-protocols-go/monitoring/ping_daemon.go @@ -0,0 +1,29 @@ +// Package protocol implements the Monitoring protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePingDaemon(packet nex.PacketInterface) { + if protocol.PingDaemon == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Monitoring::PingDaemon not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.PingDaemon(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/monitoring/protocol.go b/nex-protocols-go/monitoring/protocol.go new file mode 100644 index 0000000..1f9a5fc --- /dev/null +++ b/nex-protocols-go/monitoring/protocol.go @@ -0,0 +1,90 @@ +// Package protocol implements the Monitoring protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the Monitoring protocol + ProtocolID = 0x13 + + // MethodPingDaemon is the method ID for the method PingDaemon + MethodPingDaemon = 0x1 + + // MethodGetClusterMembers is the method ID for the method GetClusterMembers + MethodGetClusterMembers = 0x2 +) + +// Protocol handles the Monitoring protocol +type Protocol struct { + endpoint nex.EndpointInterface + PingDaemon func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + GetClusterMembers func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Monitoring protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerPingDaemon(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetClusterMembers(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerPingDaemon sets the handler for the PingDaemon method +func (protocol *Protocol) SetHandlerPingDaemon(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.PingDaemon = handler +} + +// SetHandlerGetClusterMembers sets the handler for the GetClusterMembers method +func (protocol *Protocol) SetHandlerGetClusterMembers(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetClusterMembers = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodPingDaemon: + protocol.handlePingDaemon(packet) + case MethodGetClusterMembers: + protocol.handleGetClusterMembers(packet) + default: + errMessage := fmt.Sprintf("Unsupported Monitoring method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Monitoring protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/nat-traversal/get_relay_signature_key.go b/nex-protocols-go/nat-traversal/get_relay_signature_key.go new file mode 100644 index 0000000..8789af3 --- /dev/null +++ b/nex-protocols-go/nat-traversal/get_relay_signature_key.go @@ -0,0 +1,29 @@ +// Package protocol implements the NAT Traversal protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetRelaySignatureKey(packet nex.PacketInterface) { + if protocol.GetRelaySignatureKey == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "NATTraversal::GetRelaySignatureKey not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetRelaySignatureKey(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/nat-traversal/initiate_probe.go b/nex-protocols-go/nat-traversal/initiate_probe.go new file mode 100644 index 0000000..3189386 --- /dev/null +++ b/nex-protocols-go/nat-traversal/initiate_probe.go @@ -0,0 +1,47 @@ +// Package protocol implements the NAT Traversal protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleInitiateProbe(packet nex.PacketInterface) { + if protocol.InitiateProbe == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "NATTraversal::InitiateProbe not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + urlStationToProbe := types.NewStationURL("") + + err := urlStationToProbe.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.InitiateProbe(fmt.Errorf("Failed to read urlStationToProbe from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.InitiateProbe(nil, packet, callID, urlStationToProbe) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/nat-traversal/protocol.go b/nex-protocols-go/nat-traversal/protocol.go new file mode 100644 index 0000000..81c6d50 --- /dev/null +++ b/nex-protocols-go/nat-traversal/protocol.go @@ -0,0 +1,151 @@ +// Package protocol implements the NAT Traversal protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the Message Delivery protocol + ProtocolID = 0x3 + + // MethodRequestProbeInitiation is the method ID for the method RequestProbeInitiation + MethodRequestProbeInitiation = 0x1 + + // MethodInitiateProbe is the method ID for the method InitiateProbe + MethodInitiateProbe = 0x2 + + // MethodRequestProbeInitiationExt is the method ID for the method RequestProbeInitiationExt + MethodRequestProbeInitiationExt = 0x3 + + // MethodReportNATTraversalResult is the method ID for the method ReportNATTraversalResult + MethodReportNATTraversalResult = 0x4 + + // MethodReportNATProperties is the method ID for the method ReportNATProperties + MethodReportNATProperties = 0x5 + + // MethodGetRelaySignatureKey is the method ID for the method GetRelaySignatureKey + MethodGetRelaySignatureKey = 0x6 + + // MethodReportNATTraversalResultDetail is the method ID for the method ReportNATTraversalResultDetail + MethodReportNATTraversalResultDetail = 0x7 +) + +// Protocol stores all the RMC method handlers for the NAT Traversal protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + RequestProbeInitiation func(err error, packet nex.PacketInterface, callID uint32, urlTargetList *types.List[*types.StationURL]) (*nex.RMCMessage, *nex.Error) + InitiateProbe func(err error, packet nex.PacketInterface, callID uint32, urlStationToProbe *types.StationURL) (*nex.RMCMessage, *nex.Error) + RequestProbeInitiationExt func(err error, packet nex.PacketInterface, callID uint32, targetList *types.List[*types.String], stationToProbe *types.String) (*nex.RMCMessage, *nex.Error) + ReportNATTraversalResult func(err error, packet nex.PacketInterface, callID uint32, cid *types.PrimitiveU32, result *types.PrimitiveBool, rtt *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + ReportNATProperties func(err error, packet nex.PacketInterface, callID uint32, natmapping *types.PrimitiveU32, natfiltering *types.PrimitiveU32, rtt *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetRelaySignatureKey func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + ReportNATTraversalResultDetail func(err error, packet nex.PacketInterface, callID uint32, cid *types.PrimitiveU32, result *types.PrimitiveBool, detail *types.PrimitiveS32, rtt *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the NAT Traversal protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerRequestProbeInitiation(handler func(err error, packet nex.PacketInterface, callID uint32, urlTargetList *types.List[*types.StationURL]) (*nex.RMCMessage, *nex.Error)) + SetHandlerInitiateProbe(handler func(err error, packet nex.PacketInterface, callID uint32, urlStationToProbe *types.StationURL) (*nex.RMCMessage, *nex.Error)) + SetHandlerRequestProbeInitiationExt(handler func(err error, packet nex.PacketInterface, callID uint32, targetList *types.List[*types.String], stationToProbe *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerReportNATTraversalResult(handler func(err error, packet nex.PacketInterface, callID uint32, cid *types.PrimitiveU32, result *types.PrimitiveBool, rtt *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerReportNATProperties(handler func(err error, packet nex.PacketInterface, callID uint32, natmapping *types.PrimitiveU32, natfiltering *types.PrimitiveU32, rtt *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetRelaySignatureKey(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerReportNATTraversalResultDetail(handler func(err error, packet nex.PacketInterface, callID uint32, cid *types.PrimitiveU32, result *types.PrimitiveBool, detail *types.PrimitiveS32, rtt *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerRequestProbeInitiation sets the handler for the RequestProbeInitiation method +func (protocol *Protocol) SetHandlerRequestProbeInitiation(handler func(err error, packet nex.PacketInterface, callID uint32, urlTargetList *types.List[*types.StationURL]) (*nex.RMCMessage, *nex.Error)) { + protocol.RequestProbeInitiation = handler +} + +// SetHandlerInitiateProbe sets the handler for the InitiateProbe method +func (protocol *Protocol) SetHandlerInitiateProbe(handler func(err error, packet nex.PacketInterface, callID uint32, urlStationToProbe *types.StationURL) (*nex.RMCMessage, *nex.Error)) { + protocol.InitiateProbe = handler +} + +// SetHandlerRequestProbeInitiationExt sets the handler for the RequestProbeInitiationExt method +func (protocol *Protocol) SetHandlerRequestProbeInitiationExt(handler func(err error, packet nex.PacketInterface, callID uint32, targetList *types.List[*types.String], stationToProbe *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.RequestProbeInitiationExt = handler +} + +// SetHandlerReportNATTraversalResult sets the handler for the ReportNATTraversalResult method +func (protocol *Protocol) SetHandlerReportNATTraversalResult(handler func(err error, packet nex.PacketInterface, callID uint32, cid *types.PrimitiveU32, result *types.PrimitiveBool, rtt *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.ReportNATTraversalResult = handler +} + +// SetHandlerReportNATProperties sets the handler for the ReportNATProperties method +func (protocol *Protocol) SetHandlerReportNATProperties(handler func(err error, packet nex.PacketInterface, callID uint32, natmapping *types.PrimitiveU32, natfiltering *types.PrimitiveU32, rtt *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.ReportNATProperties = handler +} + +// SetHandlerGetRelaySignatureKey sets the handler for the GetRelaySignatureKey method +func (protocol *Protocol) SetHandlerGetRelaySignatureKey(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetRelaySignatureKey = handler +} + +// SetHandlerReportNATTraversalResultDetail sets the handler for the ReportNATTraversalResultDetail method +func (protocol *Protocol) SetHandlerReportNATTraversalResultDetail(handler func(err error, packet nex.PacketInterface, callID uint32, cid *types.PrimitiveU32, result *types.PrimitiveBool, detail *types.PrimitiveS32, rtt *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.ReportNATTraversalResultDetail = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodRequestProbeInitiation: + protocol.handleRequestProbeInitiation(packet) + case MethodInitiateProbe: + protocol.handleInitiateProbe(packet) + case MethodRequestProbeInitiationExt: + protocol.handleRequestProbeInitiationExt(packet) + case MethodReportNATTraversalResult: + protocol.handleReportNATTraversalResult(packet) + case MethodReportNATProperties: + protocol.handleReportNATProperties(packet) + case MethodGetRelaySignatureKey: + protocol.handleGetRelaySignatureKey(packet) + case MethodReportNATTraversalResultDetail: + protocol.handleReportNATTraversalResultDetail(packet) + default: + errMessage := fmt.Sprintf("Unsupported NATTraversal method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new NAT Traversal NEX protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/nat-traversal/report_nat_properties.go b/nex-protocols-go/nat-traversal/report_nat_properties.go new file mode 100644 index 0000000..1dbc033 --- /dev/null +++ b/nex-protocols-go/nat-traversal/report_nat_properties.go @@ -0,0 +1,71 @@ +// Package protocol implements the NAT Traversal protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleReportNATProperties(packet nex.PacketInterface) { + if protocol.ReportNATProperties == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "NATTraversal::ReportNATProperties not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + natmapping := types.NewPrimitiveU32(0) + natfiltering := types.NewPrimitiveU32(0) + rtt := types.NewPrimitiveU32(0) + + var err error + + err = natmapping.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReportNATProperties(fmt.Errorf("Failed to read natmapping from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = natfiltering.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReportNATProperties(fmt.Errorf("Failed to read natfiltering from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = rtt.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReportNATProperties(fmt.Errorf("Failed to read rtt from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ReportNATProperties(nil, packet, callID, natmapping, natfiltering, rtt) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/nat-traversal/report_nat_traversal_result.go b/nex-protocols-go/nat-traversal/report_nat_traversal_result.go new file mode 100644 index 0000000..bca1d3b --- /dev/null +++ b/nex-protocols-go/nat-traversal/report_nat_traversal_result.go @@ -0,0 +1,76 @@ +// Package protocol implements the NAT Traversal protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleReportNATTraversalResult(packet nex.PacketInterface) { + if protocol.ReportNATTraversalResult == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "NATTraversal::ReportNATTraversalResult not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + endpoint := packet.Sender().Endpoint() + natTraversalVersion := endpoint.LibraryVersions().NATTraversal + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + cid := types.NewPrimitiveU32(0) + result := types.NewPrimitiveBool(false) + rtt := types.NewPrimitiveU32(0) + + var err error + + err = cid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReportNATTraversalResult(fmt.Errorf("Failed to read cid from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = result.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReportNATTraversalResult(fmt.Errorf("Failed to read result from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + // TODO - Is this the right version? + if natTraversalVersion.GreaterOrEqual("3.0.0") { + err = rtt.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReportNATTraversalResult(fmt.Errorf("Failed to read rtt from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + } + + rmcMessage, rmcError := protocol.ReportNATTraversalResult(nil, packet, callID, cid, result, rtt) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/nat-traversal/report_nat_traversal_result_detail.go b/nex-protocols-go/nat-traversal/report_nat_traversal_result_detail.go new file mode 100644 index 0000000..1746802 --- /dev/null +++ b/nex-protocols-go/nat-traversal/report_nat_traversal_result_detail.go @@ -0,0 +1,87 @@ +// Package protocol implements the NAT Traversal protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleReportNATTraversalResultDetail(packet nex.PacketInterface) { + if protocol.ReportNATTraversalResultDetail == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "NATTraversal::ReportNATTraversalResultDetail not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + endpoint := packet.Sender().Endpoint() + natTraversalVersion := endpoint.LibraryVersions().NATTraversal + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + cid := types.NewPrimitiveU32(0) + result := types.NewPrimitiveBool(false) + detail := types.NewPrimitiveS32(0) + rtt := types.NewPrimitiveU32(0) + + var err error + + err = cid.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReportNATTraversalResultDetail(fmt.Errorf("Failed to read cid from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = result.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReportNATTraversalResultDetail(fmt.Errorf("Failed to read result from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = detail.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReportNATTraversalResultDetail(fmt.Errorf("Failed to read detail from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + // TODO - Is this the right version? + if natTraversalVersion.GreaterOrEqual("3.0.0") { + err = rtt.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReportNATTraversalResult(fmt.Errorf("Failed to read rtt from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + } + + rmcMessage, rmcError := protocol.ReportNATTraversalResultDetail(nil, packet, callID, cid, result, detail, rtt) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/nat-traversal/request_probe_initiation.go b/nex-protocols-go/nat-traversal/request_probe_initiation.go new file mode 100644 index 0000000..3f9dfaa --- /dev/null +++ b/nex-protocols-go/nat-traversal/request_probe_initiation.go @@ -0,0 +1,48 @@ +// Package protocol implements the NAT Traversal protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRequestProbeInitiation(packet nex.PacketInterface) { + if protocol.RequestProbeInitiation == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "NATTraversal::RequestProbeInitiation not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + urlTargetList := types.NewList[*types.StationURL]() + urlTargetList.Type = types.NewStationURL("") + + err := urlTargetList.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RequestProbeInitiation(fmt.Errorf("Failed to read urlTargetList from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RequestProbeInitiation(nil, packet, callID, urlTargetList) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/nat-traversal/request_probe_initiation_ext.go b/nex-protocols-go/nat-traversal/request_probe_initiation_ext.go new file mode 100644 index 0000000..50bd074 --- /dev/null +++ b/nex-protocols-go/nat-traversal/request_probe_initiation_ext.go @@ -0,0 +1,61 @@ +// Package protocol implements the NAT Traversal protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRequestProbeInitiationExt(packet nex.PacketInterface) { + if protocol.RequestProbeInitiationExt == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "NATTraversal::RequestProbeInitiationExt not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + targetList := types.NewList[*types.String]() + targetList.Type = types.NewString("") + stationToProbe := types.NewString("") + + var err error + + err = targetList.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RequestProbeInitiationExt(fmt.Errorf("Failed to read targetList from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = stationToProbe.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RequestProbeInitiationExt(fmt.Errorf("Failed to read stationToProbe from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RequestProbeInitiationExt(nil, packet, callID, targetList, stationToProbe) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/nintendo-notifications/notification_types.go b/nex-protocols-go/nintendo-notifications/notification_types.go new file mode 100644 index 0000000..33f91c0 --- /dev/null +++ b/nex-protocols-go/nintendo-notifications/notification_types.go @@ -0,0 +1,55 @@ +// Package protocol implements the Nintendo Notfications protocol +package protocol + +type notificationTypes struct { + FriendPresenceUpdated3DS uint32 + FriendFavoriteGameUpdated3DS uint32 + FriendCommentUpdated3DS uint32 + FriendMiiChanged3DS uint32 + FriendshipCompleted3DS uint32 + FriendOffline uint32 + FriendMiiChanged uint32 + Unknown1MiiRelated uint32 + FriendPreferencesChanged uint32 + FriendStartedTitle uint32 + Unknown2FriendRequestRelated uint32 + FriendRemoved uint32 // * These 2 are the same event. Split them into 2 for cleaner naming + FriendRequestCanceled uint32 // * These 2 are the same event. Split them into 2 for cleaner naming + FriendRequestReceived uint32 + Unknown3FriendRequestRelated uint32 + Unknown4BlacklistRelated uint32 + FriendRequestAccepted uint32 + Unknown5BlacklistRelated uint32 + Unknown6BlacklistRelated uint32 + FriendStatusMessageChanged uint32 + Unknown7 uint32 + Unknown8FriendshipRelated uint32 + Unknown9PersistentNotificationsRelated uint32 +} + +// NotificationTypes is an enum of all the types a notification can be in the NintendoNotifications protocol +var NotificationTypes = notificationTypes{ + FriendPresenceUpdated3DS: 1, + FriendFavoriteGameUpdated3DS: 2, + FriendCommentUpdated3DS: 3, + FriendMiiChanged3DS: 5, + FriendshipCompleted3DS: 7, + FriendOffline: 10, + FriendMiiChanged: 21, + Unknown1MiiRelated: 22, + FriendPreferencesChanged: 23, + FriendStartedTitle: 24, + Unknown2FriendRequestRelated: 25, + FriendRemoved: 26, // * These 2 are the same event. Split them into 2 for cleaner naming + FriendRequestCanceled: 26, // * These 2 are the same event. Split them into 2 for cleaner naming + FriendRequestReceived: 27, + Unknown3FriendRequestRelated: 28, + Unknown4BlacklistRelated: 29, + FriendRequestAccepted: 30, + Unknown5BlacklistRelated: 31, + Unknown6BlacklistRelated: 32, + FriendStatusMessageChanged: 33, + Unknown7: 34, + Unknown8FriendshipRelated: 35, + Unknown9PersistentNotificationsRelated: 36, +} diff --git a/nex-protocols-go/nintendo-notifications/protocol.go b/nex-protocols-go/nintendo-notifications/protocol.go new file mode 100644 index 0000000..85cde48 --- /dev/null +++ b/nex-protocols-go/nintendo-notifications/protocol.go @@ -0,0 +1,37 @@ +// Package protocol implements the Nintendo Notfications protocol +package protocol + +import nex "github.com/PretendoNetwork/nex-go/v2" + +const ( + // ProtocolID is the protocol ID for the Nintendo Notifications protocol + ProtocolID = 0x64 + + // MethodProcessNintendoNotificationEvent1 is the method ID for the method ProcessNintendoNotificationEvent (1) + MethodProcessNintendoNotificationEvent1 = 0x1 + + // MethodProcessNintendoNotificationEvent2 is the method ID for the method ProcessNintendoNotificationEvent (2) + MethodProcessNintendoNotificationEvent2 = 0x2 +) + +// Protocol handles the NintendoNotifications protocol +type Protocol struct { + endpoint nex.EndpointInterface + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// NewProtocol returns a new Nintendo Notifications protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/nintendo-notifications/types/nintendo_notification_event.go b/nex-protocols-go/nintendo-notifications/types/nintendo_notification_event.go new file mode 100644 index 0000000..db98c4c --- /dev/null +++ b/nex-protocols-go/nintendo-notifications/types/nintendo_notification_event.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the NintendoNotifications protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// NintendoNotificationEvent is a type within the NintendoNotifications protocol +type NintendoNotificationEvent struct { + types.Structure + Type *types.PrimitiveU32 + SenderPID *types.PID + DataHolder *types.AnyDataHolder +} + +// WriteTo writes the NintendoNotificationEvent to the given writable +func (nne *NintendoNotificationEvent) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + nne.Type.WriteTo(contentWritable) + nne.SenderPID.WriteTo(contentWritable) + nne.DataHolder.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + nne.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the NintendoNotificationEvent from the given readable +func (nne *NintendoNotificationEvent) ExtractFrom(readable types.Readable) error { + var err error + + err = nne.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoNotificationEvent header. %s", err.Error()) + } + + err = nne.Type.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoNotificationEvent.Type. %s", err.Error()) + } + + err = nne.SenderPID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoNotificationEvent.SenderPID. %s", err.Error()) + } + + err = nne.DataHolder.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoNotificationEvent.DataHolder. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of NintendoNotificationEvent +func (nne *NintendoNotificationEvent) Copy() types.RVType { + copied := NewNintendoNotificationEvent() + + copied.StructureVersion = nne.StructureVersion + copied.Type = nne.Type.Copy().(*types.PrimitiveU32) + copied.SenderPID = nne.SenderPID.Copy().(*types.PID) + copied.DataHolder = nne.DataHolder.Copy().(*types.AnyDataHolder) + + return copied +} + +// Equals checks if the given NintendoNotificationEvent contains the same data as the current NintendoNotificationEvent +func (nne *NintendoNotificationEvent) Equals(o types.RVType) bool { + if _, ok := o.(*NintendoNotificationEvent); !ok { + return false + } + + other := o.(*NintendoNotificationEvent) + + if nne.StructureVersion != other.StructureVersion { + return false + } + + if !nne.Type.Equals(other.Type) { + return false + } + + if !nne.SenderPID.Equals(other.SenderPID) { + return false + } + + return nne.DataHolder.Equals(other.DataHolder) +} + +// String returns the string representation of the NintendoNotificationEvent +func (nne *NintendoNotificationEvent) String() string { + return nne.FormatToString(0) +} + +// FormatToString pretty-prints the NintendoNotificationEvent using the provided indentation level +func (nne *NintendoNotificationEvent) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("NintendoNotificationEvent{\n") + b.WriteString(fmt.Sprintf("%sType: %s,\n", indentationValues, nne.Type)) + b.WriteString(fmt.Sprintf("%sSenderPID: %s,\n", indentationValues, nne.SenderPID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sDataHolder: %s,\n", indentationValues, nne.DataHolder.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewNintendoNotificationEvent returns a new NintendoNotificationEvent +func NewNintendoNotificationEvent() *NintendoNotificationEvent { + nne := &NintendoNotificationEvent{ + Type: types.NewPrimitiveU32(0), + SenderPID: types.NewPID(0), + DataHolder: types.NewAnyDataHolder(), + } + + return nne +} diff --git a/nex-protocols-go/nintendo-notifications/types/nintendo_notification_event_general.go b/nex-protocols-go/nintendo-notifications/types/nintendo_notification_event_general.go new file mode 100644 index 0000000..b938add --- /dev/null +++ b/nex-protocols-go/nintendo-notifications/types/nintendo_notification_event_general.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the NintendoNotifications protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// NintendoNotificationEventGeneral is a type within the NintendoNotifications protocol +type NintendoNotificationEventGeneral struct { + types.Structure + U32Param *types.PrimitiveU32 + U64Param1 *types.PrimitiveU64 + U64Param2 *types.PrimitiveU64 + StrParam *types.String +} + +// WriteTo writes the NintendoNotificationEventGeneral to the given writable +func (nneg *NintendoNotificationEventGeneral) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + nneg.U32Param.WriteTo(contentWritable) + nneg.U64Param1.WriteTo(contentWritable) + nneg.U64Param2.WriteTo(contentWritable) + nneg.StrParam.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + nneg.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the NintendoNotificationEventGeneral from the given readable +func (nneg *NintendoNotificationEventGeneral) ExtractFrom(readable types.Readable) error { + var err error + + err = nneg.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoNotificationEventGeneral header. %s", err.Error()) + } + + err = nneg.U32Param.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoNotificationEventGeneral.U32Param. %s", err.Error()) + } + + err = nneg.U64Param1.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoNotificationEventGeneral.U64Param1. %s", err.Error()) + } + + err = nneg.U64Param2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoNotificationEventGeneral.U64Param2. %s", err.Error()) + } + + err = nneg.StrParam.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoNotificationEventGeneral.StrParam. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of NintendoNotificationEventGeneral +func (nneg *NintendoNotificationEventGeneral) Copy() types.RVType { + copied := NewNintendoNotificationEventGeneral() + + copied.StructureVersion = nneg.StructureVersion + copied.U32Param = nneg.U32Param.Copy().(*types.PrimitiveU32) + copied.U64Param1 = nneg.U64Param1.Copy().(*types.PrimitiveU64) + copied.U64Param2 = nneg.U64Param2.Copy().(*types.PrimitiveU64) + copied.StrParam = nneg.StrParam.Copy().(*types.String) + + return copied +} + +// Equals checks if the given NintendoNotificationEventGeneral contains the same data as the current NintendoNotificationEventGeneral +func (nneg *NintendoNotificationEventGeneral) Equals(o types.RVType) bool { + if _, ok := o.(*NintendoNotificationEventGeneral); !ok { + return false + } + + other := o.(*NintendoNotificationEventGeneral) + + if nneg.StructureVersion != other.StructureVersion { + return false + } + + if !nneg.U32Param.Equals(other.U32Param) { + return false + } + + if !nneg.U64Param1.Equals(other.U64Param1) { + return false + } + + if !nneg.U64Param2.Equals(other.U64Param2) { + return false + } + + return nneg.StrParam.Equals(other.StrParam) +} + +// String returns the string representation of the NintendoNotificationEventGeneral +func (nneg *NintendoNotificationEventGeneral) String() string { + return nneg.FormatToString(0) +} + +// FormatToString pretty-prints the NintendoNotificationEventGeneral using the provided indentation level +func (nneg *NintendoNotificationEventGeneral) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("NintendoNotificationEventGeneral{\n") + b.WriteString(fmt.Sprintf("%sU32Param: %s,\n", indentationValues, nneg.U32Param)) + b.WriteString(fmt.Sprintf("%sU64Param1: %s,\n", indentationValues, nneg.U64Param1)) + b.WriteString(fmt.Sprintf("%sU64Param2: %s,\n", indentationValues, nneg.U64Param2)) + b.WriteString(fmt.Sprintf("%sStrParam: %s,\n", indentationValues, nneg.StrParam)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewNintendoNotificationEventGeneral returns a new NintendoNotificationEventGeneral +func NewNintendoNotificationEventGeneral() *NintendoNotificationEventGeneral { + nneg := &NintendoNotificationEventGeneral{ + U32Param: types.NewPrimitiveU32(0), + U64Param1: types.NewPrimitiveU64(0), + U64Param2: types.NewPrimitiveU64(0), + StrParam: types.NewString(""), + } + + return nneg +} diff --git a/nex-protocols-go/notifications/build_notification_type.go b/nex-protocols-go/notifications/build_notification_type.go new file mode 100644 index 0000000..63d2d06 --- /dev/null +++ b/nex-protocols-go/notifications/build_notification_type.go @@ -0,0 +1,7 @@ +// Package protocol implements the Notifications protocol +package protocol + +// BuildNotificationType builds a combined type for NotificationEvents using a category and subtype +func BuildNotificationType(category, subtype uint32) uint32 { + return (category * 1000) + subtype +} diff --git a/nex-protocols-go/notifications/notification_categories.go b/nex-protocols-go/notifications/notification_categories.go new file mode 100644 index 0000000..08772a7 --- /dev/null +++ b/nex-protocols-go/notifications/notification_categories.go @@ -0,0 +1,34 @@ +// Package protocol implements the Notifications protocol +package protocol + +type notificationCategories struct { + Participation uint32 + OwnershipChanged uint32 + RequestJoinGathering uint32 // * This is what these mean in WiiU Chat, unclear if this is the real use + EndGathering uint32 // * This is what these mean in WiiU Chat, unclear if this is the real use + GatheringUnregistered uint32 + HostChanged uint32 + ServiceItemRequestCompleted uint32 + MatchmakeRefereeRoundStarted uint32 + SystemPasswordChanged uint32 + SystemPasswordCleared uint32 + SwitchGathering uint32 +} + +// NotificationCategories is a list of all the categories a notification can be in the Notifications protocol +// +// Not all of these are categories, some are stand-alone types +// This is a design choice made by NEX, not us +var NotificationCategories = notificationCategories{ + Participation: 3, + OwnershipChanged: 4, + RequestJoinGathering: 101, // * This is what these mean in WiiU Chat, unclear if this is the real use + EndGathering: 102, // * This is what these mean in WiiU Chat, unclear if this is the real use + GatheringUnregistered: 109, + HostChanged: 110, + ServiceItemRequestCompleted: 115, + MatchmakeRefereeRoundStarted: 116, + SystemPasswordChanged: 120, + SystemPasswordCleared: 121, + SwitchGathering: 122, +} diff --git a/nex-protocols-go/notifications/notification_subtypes.go b/nex-protocols-go/notifications/notification_subtypes.go new file mode 100644 index 0000000..eb0fbe7 --- /dev/null +++ b/nex-protocols-go/notifications/notification_subtypes.go @@ -0,0 +1,107 @@ +// Package protocol implements the Notifications protocol +package protocol + +type notificationSubTypes struct { + Participation notificationParticipationSubTypes + OwnershipChanged notificationsOwnershipChangedSubTypes + RequestJoinGathering notificationsRequestJoinGatheringSubTypes + EndGathering notificationsEndGatheringSubTypes + GatheringUnregistered notificationsGatheringUnregisteredSubTypes + HostChanged notificationsHostChangedSubTypes + ServiceItemRequestCompleted notificationsServiceItemRequestCompletedSubTypes + MatchmakeRefereeRoundStarted notificationsMatchmakeRefereeRoundStartedSubTypes + SystemPasswordChanged notificationsSystemPasswordChangedSubTypes + SystemPasswordCleared notificationsSystemPasswordClearedSubTypes + SwitchGathering notificationsSwitchGatheringSubTypes +} + +type notificationParticipationSubTypes struct { + None uint32 + NewParticipant uint32 + Cancelled uint32 + Disconnected uint32 + Ended uint32 +} + +type notificationsOwnershipChangedSubTypes struct { + None uint32 +} + +type notificationsRequestJoinGatheringSubTypes struct { + None uint32 +} + +type notificationsEndGatheringSubTypes struct { + None uint32 +} + +type notificationsGatheringUnregisteredSubTypes struct { + None uint32 +} + +type notificationsHostChangedSubTypes struct { + None uint32 +} + +type notificationsServiceItemRequestCompletedSubTypes struct { + None uint32 +} + +type notificationsMatchmakeRefereeRoundStartedSubTypes struct { + None uint32 +} + +type notificationsSystemPasswordChangedSubTypes struct { + None uint32 +} + +type notificationsSystemPasswordClearedSubTypes struct { + None uint32 +} + +type notificationsSwitchGatheringSubTypes struct { + None uint32 +} + +// NotificationSubTypes is a list of all the subtypes a notification can be in a given category of the Notifications protocol +// +// Not all categories have subtypes +var NotificationSubTypes = notificationSubTypes{ + Participation: notificationParticipationSubTypes{ + None: 0, + NewParticipant: 1, + Cancelled: 2, + Disconnected: 7, + Ended: 8, + }, + OwnershipChanged: notificationsOwnershipChangedSubTypes{ + None: 0, + }, + RequestJoinGathering: notificationsRequestJoinGatheringSubTypes{ + None: 0, + }, + EndGathering: notificationsEndGatheringSubTypes{ + None: 0, + }, + GatheringUnregistered: notificationsGatheringUnregisteredSubTypes{ + None: 0, + }, + HostChanged: notificationsHostChangedSubTypes{ + None: 0, + }, + ServiceItemRequestCompleted: notificationsServiceItemRequestCompletedSubTypes{ + None: 0, + }, + MatchmakeRefereeRoundStarted: notificationsMatchmakeRefereeRoundStartedSubTypes{ + None: 0, + }, + SystemPasswordChanged: notificationsSystemPasswordChangedSubTypes{ + None: 0, + }, + SystemPasswordCleared: notificationsSystemPasswordClearedSubTypes{ + None: 0, + }, + SwitchGathering: notificationsSwitchGatheringSubTypes{ + None: 0, + }, +} diff --git a/nex-protocols-go/notifications/protocol.go b/nex-protocols-go/notifications/protocol.go new file mode 100644 index 0000000..32672f6 --- /dev/null +++ b/nex-protocols-go/notifications/protocol.go @@ -0,0 +1,36 @@ +// Package protocol implements the Notfications protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" +) + +const ( + // ProtocolID is the protocol ID for the Nintendo Notifications protocol + ProtocolID = 0xE + + // MethodProcessNotificationEvent is the method ID for the method ProcessNotificationEvent + MethodProcessNotificationEvent = 0x1 +) + +// Protocol handles the Notifications protocol +type Protocol struct { + endpoint nex.EndpointInterface + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// NewProtocol returns a new Notifications protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/notifications/types/notification_event.go b/nex-protocols-go/notifications/types/notification_event.go new file mode 100644 index 0000000..a0de044 --- /dev/null +++ b/nex-protocols-go/notifications/types/notification_event.go @@ -0,0 +1,168 @@ +// Package types implements all the types used by the Notifications protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// NotificationEvent is a type within the Notifications protocol +type NotificationEvent struct { + types.Structure + PIDSource *types.PID + Type *types.PrimitiveU32 + Param1 *types.PrimitiveU32 + Param2 *types.PrimitiveU32 + StrParam *types.String + Param3 *types.PrimitiveU32 +} + +// WriteTo writes the NotificationEvent to the given writable +func (ne *NotificationEvent) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + ne.PIDSource.WriteTo(contentWritable) + ne.Type.WriteTo(contentWritable) + ne.Param1.WriteTo(contentWritable) + ne.Param2.WriteTo(contentWritable) + ne.StrParam.WriteTo(contentWritable) + //ne.Param3.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + ne.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the NotificationEvent from the given readable +func (ne *NotificationEvent) ExtractFrom(readable types.Readable) error { + var err error + + err = ne.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NotificationEvent header. %s", err.Error()) + } + + err = ne.PIDSource.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NotificationEvent.PIDSource. %s", err.Error()) + } + + err = ne.Type.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NotificationEvent.Type. %s", err.Error()) + } + + err = ne.Param1.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NotificationEvent.Param1. %s", err.Error()) + } + + err = ne.Param2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NotificationEvent.Param2. %s", err.Error()) + } + + err = ne.StrParam.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NotificationEvent.StrParam. %s", err.Error()) + } + + err = ne.Param3.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NotificationEvent.Param3. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of NotificationEvent +func (ne *NotificationEvent) Copy() types.RVType { + copied := NewNotificationEvent() + + copied.StructureVersion = ne.StructureVersion + copied.PIDSource = ne.PIDSource.Copy().(*types.PID) + copied.Type = ne.Type.Copy().(*types.PrimitiveU32) + copied.Param1 = ne.Param1.Copy().(*types.PrimitiveU32) + copied.Param2 = ne.Param2.Copy().(*types.PrimitiveU32) + copied.StrParam = ne.StrParam.Copy().(*types.String) + copied.Param3 = ne.Param3.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given NotificationEvent contains the same data as the current NotificationEvent +func (ne *NotificationEvent) Equals(o types.RVType) bool { + if _, ok := o.(*NotificationEvent); !ok { + return false + } + + other := o.(*NotificationEvent) + + if ne.StructureVersion != other.StructureVersion { + return false + } + + if !ne.PIDSource.Equals(other.PIDSource) { + return false + } + + if !ne.Type.Equals(other.Type) { + return false + } + + if !ne.Param1.Equals(other.Param1) { + return false + } + + if !ne.Param2.Equals(other.Param2) { + return false + } + + if !ne.StrParam.Equals(other.StrParam) { + return false + } + + return ne.Param3.Equals(other.Param3) +} + +// String returns the string representation of the NotificationEvent +func (ne *NotificationEvent) String() string { + return ne.FormatToString(0) +} + +// FormatToString pretty-prints the NotificationEvent using the provided indentation level +func (ne *NotificationEvent) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("NotificationEvent{\n") + b.WriteString(fmt.Sprintf("%sPIDSource: %s,\n", indentationValues, ne.PIDSource.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sType: %s,\n", indentationValues, ne.Type)) + b.WriteString(fmt.Sprintf("%sParam1: %s,\n", indentationValues, ne.Param1)) + b.WriteString(fmt.Sprintf("%sParam2: %s,\n", indentationValues, ne.Param2)) + b.WriteString(fmt.Sprintf("%sStrParam: %s,\n", indentationValues, ne.StrParam)) + b.WriteString(fmt.Sprintf("%sParam3: %s,\n", indentationValues, ne.Param3)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewNotificationEvent returns a new NotificationEvent +func NewNotificationEvent() *NotificationEvent { + ne := &NotificationEvent{ + PIDSource: types.NewPID(0), + Type: types.NewPrimitiveU32(0), + Param1: types.NewPrimitiveU32(0), + Param2: types.NewPrimitiveU32(0), + StrParam: types.NewString(""), + Param3: types.NewPrimitiveU32(0), + } + + return ne +} diff --git a/nex-protocols-go/persistent-store/find_by_group.go b/nex-protocols-go/persistent-store/find_by_group.go new file mode 100644 index 0000000..8cb136f --- /dev/null +++ b/nex-protocols-go/persistent-store/find_by_group.go @@ -0,0 +1,47 @@ +// Package protocol implements the NAT Traversal protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindByGroup(packet nex.PacketInterface) { + if protocol.FindByGroup == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "PersistentStore::FindByGroup not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiGroup := types.NewPrimitiveU32(0) + + err := uiGroup.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindByGroup(fmt.Errorf("Failed to read uiGroup from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindByGroup(nil, packet, callID, uiGroup) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/persistent-store/find_items_by_sql_query.go b/nex-protocols-go/persistent-store/find_items_by_sql_query.go new file mode 100644 index 0000000..95dfc40 --- /dev/null +++ b/nex-protocols-go/persistent-store/find_items_by_sql_query.go @@ -0,0 +1,71 @@ +// Package protocol implements the NAT Traversal protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFindItemsBySQLQuery(packet nex.PacketInterface) { + if protocol.FindItemsBySQLQuery == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "PersistentStore::FindItemsBySQLQuery not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiGroup := types.NewPrimitiveU32(0) + strTag := types.NewString("") + strQuery := types.NewString("") + + var err error + + err = uiGroup.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindItemsBySQLQuery(fmt.Errorf("Failed to read uiGroup from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strTag.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindItemsBySQLQuery(fmt.Errorf("Failed to read strTag from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strQuery.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.FindItemsBySQLQuery(fmt.Errorf("Failed to read strQuery from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.FindItemsBySQLQuery(nil, packet, callID, uiGroup, strTag, strQuery) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/persistent-store/get_custom_item.go b/nex-protocols-go/persistent-store/get_custom_item.go new file mode 100644 index 0000000..3a9a37d --- /dev/null +++ b/nex-protocols-go/persistent-store/get_custom_item.go @@ -0,0 +1,60 @@ +// Package protocol implements the NAT Traversal protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetCustomItem(packet nex.PacketInterface) { + if protocol.GetCustomItem == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "PersistentStore::GetCustomItem not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiGroup := types.NewPrimitiveU32(0) + strTag := types.NewString("") + + var err error + + err = uiGroup.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetCustomItem(fmt.Errorf("Failed to read uiGroup from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strTag.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetCustomItem(fmt.Errorf("Failed to read strTag from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetCustomItem(nil, packet, callID, uiGroup, strTag) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/persistent-store/get_item.go b/nex-protocols-go/persistent-store/get_item.go new file mode 100644 index 0000000..6839b1b --- /dev/null +++ b/nex-protocols-go/persistent-store/get_item.go @@ -0,0 +1,60 @@ +// Package protocol implements the NAT Traversal protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetItem(packet nex.PacketInterface) { + if protocol.GetItem == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "PersistentStore::GetItem not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiGroup := types.NewPrimitiveU32(0) + strTag := types.NewString("") + + var err error + + err = uiGroup.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetItem(fmt.Errorf("Failed to read uiGroup from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strTag.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetItem(fmt.Errorf("Failed to read strTag from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetItem(nil, packet, callID, uiGroup, strTag) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/persistent-store/insert_custom_item.go b/nex-protocols-go/persistent-store/insert_custom_item.go new file mode 100644 index 0000000..fa2be8f --- /dev/null +++ b/nex-protocols-go/persistent-store/insert_custom_item.go @@ -0,0 +1,82 @@ +// Package protocol implements the NAT Traversal protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleInsertCustomItem(packet nex.PacketInterface) { + if protocol.InsertCustomItem == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "PersistentStore::InsertCustomItem not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiGroup := types.NewPrimitiveU32(0) + strTag := types.NewString("") + hData := types.NewAnyDataHolder() + bReplace := types.NewPrimitiveBool(false) + + var err error + + err = uiGroup.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.InsertCustomItem(fmt.Errorf("Failed to read uiGroup from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strTag.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.InsertCustomItem(fmt.Errorf("Failed to read strTag from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = hData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.InsertCustomItem(fmt.Errorf("Failed to read hData from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = bReplace.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.InsertCustomItem(fmt.Errorf("Failed to read bReplace from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.InsertCustomItem(nil, packet, callID, uiGroup, strTag, hData, bReplace) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/persistent-store/insert_item.go b/nex-protocols-go/persistent-store/insert_item.go new file mode 100644 index 0000000..7a08925 --- /dev/null +++ b/nex-protocols-go/persistent-store/insert_item.go @@ -0,0 +1,82 @@ +// Package protocol implements the NAT Traversal protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleInsertItem(packet nex.PacketInterface) { + if protocol.InsertItem == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "PersistentStore::InsertItem not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiGroup := types.NewPrimitiveU32(0) + strTag := types.NewString("") + bufData := types.NewBuffer(nil) + bReplace := types.NewPrimitiveBool(false) + + var err error + + err = uiGroup.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.InsertItem(fmt.Errorf("Failed to read uiGroup from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strTag.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.InsertItem(fmt.Errorf("Failed to read strTag from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = bufData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.InsertItem(fmt.Errorf("Failed to read bufData from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = bReplace.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.InsertItem(fmt.Errorf("Failed to read bReplace from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.InsertItem(nil, packet, callID, uiGroup, strTag, bufData, bReplace) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/persistent-store/protocol.go b/nex-protocols-go/persistent-store/protocol.go new file mode 100644 index 0000000..4543905 --- /dev/null +++ b/nex-protocols-go/persistent-store/protocol.go @@ -0,0 +1,151 @@ +// Package protocol implements the Persistent Store protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the Persistent Store protocol + ProtocolID = 0x18 + + // MethodFindByGroup is the method ID for method FindByGroup + MethodFindByGroup = 0x1 + + // MethodInsertItem is the method ID for method InsertItem + MethodInsertItem = 0x2 + + // MethodRemoveItem is the method ID for method RemoveItem + MethodRemoveItem = 0x3 + + // MethodGetItem is the method ID for method GetItem + MethodGetItem = 0x4 + + // MethodInsertCustomItem is the method ID for method InsertCustomItem + MethodInsertCustomItem = 0x5 + + // MethodGetCustomItem is the method ID for method GetCustomItem + MethodGetCustomItem = 0x6 + + // MethodFindItemsBySQLQuery is the method ID for method FindItemsBySQLQuery + MethodFindItemsBySQLQuery = 0x7 +) + +// Protocol handles the Persistent Store protocol +type Protocol struct { + endpoint nex.EndpointInterface + FindByGroup func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + InsertItem func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String, bufData *types.Buffer, bReplace *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + RemoveItem func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String) (*nex.RMCMessage, *nex.Error) + GetItem func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String) (*nex.RMCMessage, *nex.Error) + InsertCustomItem func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String, hData *types.AnyDataHolder, bReplace *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + GetCustomItem func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String) (*nex.RMCMessage, *nex.Error) + FindItemsBySQLQuery func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String, strQuery *types.String) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Persistent Store protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerFindByGroup(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerInsertItem(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String, bufData *types.Buffer, bReplace *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerRemoveItem(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetItem(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerInsertCustomItem(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String, hData *types.AnyDataHolder, bReplace *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetCustomItem(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerFindItemsBySQLQuery(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String, strQuery *types.String) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerFindByGroup sets the handler for the FindByGroup method +func (protocol *Protocol) SetHandlerFindByGroup(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.FindByGroup = handler +} + +// SetHandlerInsertItem sets the handler for the InsertItem method +func (protocol *Protocol) SetHandlerInsertItem(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String, bufData *types.Buffer, bReplace *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.InsertItem = handler +} + +// SetHandlerRemoveItem sets the handler for the RemoveItem method +func (protocol *Protocol) SetHandlerRemoveItem(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.RemoveItem = handler +} + +// SetHandlerGetItem sets the handler for the GetItem method +func (protocol *Protocol) SetHandlerGetItem(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.GetItem = handler +} + +// SetHandlerInsertCustomItem sets the handler for the InsertCustomItem method +func (protocol *Protocol) SetHandlerInsertCustomItem(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String, hData *types.AnyDataHolder, bReplace *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error)) { + protocol.InsertCustomItem = handler +} + +// SetHandlerGetCustomItem sets the handler for the GetCustomItem method +func (protocol *Protocol) SetHandlerGetCustomItem(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.GetCustomItem = handler +} + +// SetHandlerFindItemsBySQLQuery sets the handler for the FindItemsBySQLQuery method +func (protocol *Protocol) SetHandlerFindItemsBySQLQuery(handler func(err error, packet nex.PacketInterface, callID uint32, uiGroup *types.PrimitiveU32, strTag *types.String, strQuery *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.FindItemsBySQLQuery = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodFindByGroup: + protocol.handleFindByGroup(packet) + case MethodInsertItem: + protocol.handleInsertItem(packet) + case MethodRemoveItem: + protocol.handleRemoveItem(packet) + case MethodGetItem: + protocol.handleGetItem(packet) + case MethodInsertCustomItem: + protocol.handleInsertCustomItem(packet) + case MethodGetCustomItem: + protocol.handleGetCustomItem(packet) + case MethodFindItemsBySQLQuery: + protocol.handleFindItemsBySQLQuery(packet) + default: + errMessage := fmt.Sprintf("Unsupported Persistent Store method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Persistent Store protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/persistent-store/remove_item.go b/nex-protocols-go/persistent-store/remove_item.go new file mode 100644 index 0000000..0d2befa --- /dev/null +++ b/nex-protocols-go/persistent-store/remove_item.go @@ -0,0 +1,60 @@ +// Package protocol implements the NAT Traversal protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRemoveItem(packet nex.PacketInterface) { + if protocol.RemoveItem == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "PersistentStore::RemoveItem not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uiGroup := types.NewPrimitiveU32(0) + strTag := types.NewString("") + + var err error + + err = uiGroup.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RemoveItem(fmt.Errorf("Failed to read uiGroup from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = strTag.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RemoveItem(fmt.Errorf("Failed to read strTag from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RemoveItem(nil, packet, callID, uiGroup, strTag) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/pokemon-pss/protocol.go b/nex-protocols-go/pokemon-pss/protocol.go new file mode 100644 index 0000000..f118c4e --- /dev/null +++ b/nex-protocols-go/pokemon-pss/protocol.go @@ -0,0 +1,90 @@ +// Package protocol implements the Debug protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the Debug protocol + ProtocolID = 0x76 + + // MethodEnableAPIRecorder is the method ID for the method EnableAPIRecorder + MethodUnk1 = 0x1 + + // MethodEnableAPIRecorder is the method ID for the method EnableAPIRecorder + MethodUnk2 = 0x2 +) + +// Protocol handles the Debug protocol +type Protocol struct { + endpoint nex.EndpointInterface + Unk1 func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + Unk2 func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Debug protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerUnk1(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerUnk2(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerEnableAPIRecorder sets the handler for the EnableAPIRecorder method +func (protocol *Protocol) SetHandlerUnk1(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.Unk1 = handler +} + +// SetHandlerEnableAPIRecorder sets the handler for the EnableAPIRecorder method +func (protocol *Protocol) SetHandlerUnk2(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.Unk1 = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodUnk1: + protocol.handleUnk1(packet) + case MethodUnk2: + protocol.handleUnk2(packet) + default: + errMessage := fmt.Sprintf("Unsupported Debug method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Debug protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/pokemon-pss/unk1.go b/nex-protocols-go/pokemon-pss/unk1.go new file mode 100644 index 0000000..9e66321 --- /dev/null +++ b/nex-protocols-go/pokemon-pss/unk1.go @@ -0,0 +1,29 @@ +// Package protocol implements the AAUser protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUnk1(packet nex.PacketInterface) { + if protocol.Unk1 == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "unk::Unk1 not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.Unk1(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/pokemon-pss/unk2.go b/nex-protocols-go/pokemon-pss/unk2.go new file mode 100644 index 0000000..3b75ff3 --- /dev/null +++ b/nex-protocols-go/pokemon-pss/unk2.go @@ -0,0 +1,29 @@ +// Package protocol implements the AAUser protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUnk2(packet nex.PacketInterface) { + if protocol.Unk2 == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "unk::Unk2 not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.Unk2(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/change_all_attributes.go b/nex-protocols-go/ranking/change_all_attributes.go new file mode 100644 index 0000000..94166cc --- /dev/null +++ b/nex-protocols-go/ranking/change_all_attributes.go @@ -0,0 +1,61 @@ +// Package protocol implements the Ranking protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" +) + +func (protocol *Protocol) handleChangeAllAttributes(packet nex.PacketInterface) { + if protocol.ChangeAllAttributes == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking::ChangeAllAttributes not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + changeParam := ranking_types.NewRankingChangeAttributesParam() + uniqueID := types.NewPrimitiveU64(0) + + var err error + + err = changeParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangeAllAttributes(fmt.Errorf("Failed to read changeParam from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uniqueID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangeAllAttributes(fmt.Errorf("Failed to read uniqueID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ChangeAllAttributes(nil, packet, callID, changeParam, uniqueID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/change_attributes.go b/nex-protocols-go/ranking/change_attributes.go new file mode 100644 index 0000000..723e621 --- /dev/null +++ b/nex-protocols-go/ranking/change_attributes.go @@ -0,0 +1,72 @@ +// Package protocol implements the Ranking protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" +) + +func (protocol *Protocol) handleChangeAttributes(packet nex.PacketInterface) { + if protocol.ChangeAttributes == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking::ChangeAttributes not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + category := types.NewPrimitiveU32(0) + changeParam := ranking_types.NewRankingChangeAttributesParam() + uniqueID := types.NewPrimitiveU64(0) + + var err error + + err = category.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangeAttributes(fmt.Errorf("Failed to read category from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = changeParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangeAttributes(fmt.Errorf("Failed to read changeParam from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uniqueID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ChangeAttributes(fmt.Errorf("Failed to read uniqueID from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ChangeAttributes(nil, packet, callID, category, changeParam, uniqueID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/delete_all_scores.go b/nex-protocols-go/ranking/delete_all_scores.go new file mode 100644 index 0000000..86e27db --- /dev/null +++ b/nex-protocols-go/ranking/delete_all_scores.go @@ -0,0 +1,47 @@ +// Package protocol implements the Ranking protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteAllScores(packet nex.PacketInterface) { + if protocol.DeleteAllScores == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking::DeleteAllScores not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uniqueID := types.NewPrimitiveU64(0) + + err := uniqueID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteAllScores(fmt.Errorf("Failed to read uniqueID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteAllScores(nil, packet, callID, uniqueID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/delete_common_data.go b/nex-protocols-go/ranking/delete_common_data.go new file mode 100644 index 0000000..13b607f --- /dev/null +++ b/nex-protocols-go/ranking/delete_common_data.go @@ -0,0 +1,47 @@ +// Package protocol implements the Ranking protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteCommonData(packet nex.PacketInterface) { + if protocol.DeleteCommonData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking::DeleteCommonData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uniqueID := types.NewPrimitiveU64(0) + + err := uniqueID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteCommonData(fmt.Errorf("Failed to read uniqueID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteCommonData(nil, packet, callID, uniqueID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/delete_score.go b/nex-protocols-go/ranking/delete_score.go new file mode 100644 index 0000000..9e8999e --- /dev/null +++ b/nex-protocols-go/ranking/delete_score.go @@ -0,0 +1,60 @@ +// Package protocol implements the Ranking protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteScore(packet nex.PacketInterface) { + if protocol.DeleteScore == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking::DeleteScore not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + category := types.NewPrimitiveU32(0) + uniqueID := types.NewPrimitiveU64(0) + + var err error + + err = category.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteScore(fmt.Errorf("Failed to read category from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uniqueID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteScore(fmt.Errorf("Failed to read uniqueID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteScore(nil, packet, callID, category, uniqueID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/get_approx_order.go b/nex-protocols-go/ranking/get_approx_order.go new file mode 100644 index 0000000..382da39 --- /dev/null +++ b/nex-protocols-go/ranking/get_approx_order.go @@ -0,0 +1,94 @@ +// Package protocol implements the Ranking protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" +) + +func (protocol *Protocol) handleGetApproxOrder(packet nex.PacketInterface) { + if protocol.GetApproxOrder == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking::GetApproxOrder not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + category := types.NewPrimitiveU32(0) + orderParam := ranking_types.NewRankingOrderParam() + score := types.NewPrimitiveU32(0) + uniqueID := types.NewPrimitiveU64(0) + principalID := types.NewPID(0) + + var err error + + err = category.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetApproxOrder(fmt.Errorf("Failed to read category from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = orderParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetApproxOrder(fmt.Errorf("Failed to read orderParam from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = score.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetApproxOrder(fmt.Errorf("Failed to read score from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uniqueID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetApproxOrder(fmt.Errorf("Failed to read uniqueID from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = principalID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetApproxOrder(fmt.Errorf("Failed to read principalID from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetApproxOrder(nil, packet, callID, category, orderParam, score, uniqueID, principalID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/get_cached_top_x_ranking.go b/nex-protocols-go/ranking/get_cached_top_x_ranking.go new file mode 100644 index 0000000..5e9b7d8 --- /dev/null +++ b/nex-protocols-go/ranking/get_cached_top_x_ranking.go @@ -0,0 +1,61 @@ +// Package protocol implements the Ranking protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" +) + +func (protocol *Protocol) handleGetCachedTopXRanking(packet nex.PacketInterface) { + if protocol.GetCachedTopXRanking == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking::GetCachedTopXRanking not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + category := types.NewPrimitiveU32(0) + orderParam := ranking_types.NewRankingOrderParam() + + var err error + + err = category.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetCachedTopXRanking(fmt.Errorf("Failed to read category from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = orderParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetCachedTopXRanking(fmt.Errorf("Failed to read orderParam from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetCachedTopXRanking(nil, packet, callID, category, orderParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/get_cached_top_x_rankings.go b/nex-protocols-go/ranking/get_cached_top_x_rankings.go new file mode 100644 index 0000000..6f9126a --- /dev/null +++ b/nex-protocols-go/ranking/get_cached_top_x_rankings.go @@ -0,0 +1,63 @@ +// Package protocol implements the Ranking protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" +) + +func (protocol *Protocol) handleGetCachedTopXRankings(packet nex.PacketInterface) { + if protocol.GetCachedTopXRankings == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking::GetCachedTopXRankings not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + categories := types.NewList[*types.PrimitiveU32]() + categories.Type = types.NewPrimitiveU32(0) + orderParams := types.NewList[*ranking_types.RankingOrderParam]() + orderParams.Type = ranking_types.NewRankingOrderParam() + + var err error + + err = categories.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetCachedTopXRankings(fmt.Errorf("Failed to read categories from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = orderParams.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetCachedTopXRankings(fmt.Errorf("Failed to read orderParams from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetCachedTopXRankings(nil, packet, callID, categories, orderParams) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/get_common_data.go b/nex-protocols-go/ranking/get_common_data.go new file mode 100644 index 0000000..fef0f5e --- /dev/null +++ b/nex-protocols-go/ranking/get_common_data.go @@ -0,0 +1,47 @@ +// Package protocol implements the Ranking protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetCommonData(packet nex.PacketInterface) { + if protocol.GetCommonData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking::GetCommonData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uniqueID := types.NewPrimitiveU64(0) + + err := uniqueID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetCommonData(fmt.Errorf("Failed to read uniqueID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetCommonData(nil, packet, callID, uniqueID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/get_ranking.go b/nex-protocols-go/ranking/get_ranking.go new file mode 100644 index 0000000..7d31f23 --- /dev/null +++ b/nex-protocols-go/ranking/get_ranking.go @@ -0,0 +1,94 @@ +// Package protocol implements the Ranking protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" +) + +func (protocol *Protocol) handleGetRanking(packet nex.PacketInterface) { + if protocol.GetRanking == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking::GetRanking not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + rankingMode := types.NewPrimitiveU8(0) + category := types.NewPrimitiveU32(0) + orderParam := ranking_types.NewRankingOrderParam() + uniqueID := types.NewPrimitiveU64(0) + principalID := types.NewPID(0) + + var err error + + err = rankingMode.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRanking(fmt.Errorf("Failed to read rankingMode from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = category.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRanking(fmt.Errorf("Failed to read category from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = orderParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRanking(fmt.Errorf("Failed to read orderParam from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uniqueID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRanking(fmt.Errorf("Failed to read uniqueID from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = principalID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRanking(fmt.Errorf("Failed to read principalID from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetRanking(nil, packet, callID, rankingMode, category, orderParam, uniqueID, principalID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/get_ranking_by_pid_list.go b/nex-protocols-go/ranking/get_ranking_by_pid_list.go new file mode 100644 index 0000000..a0e44d6 --- /dev/null +++ b/nex-protocols-go/ranking/get_ranking_by_pid_list.go @@ -0,0 +1,95 @@ +// Package protocol implements the Ranking protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" +) + +func (protocol *Protocol) handleGetRankingByPIDList(packet nex.PacketInterface) { + if protocol.GetRankingByPIDList == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking::GetRankingByPIDList not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + principalIDList := types.NewList[*types.PID]() + principalIDList.Type = types.NewPID(0) + rankingMode := types.NewPrimitiveU8(0) + category := types.NewPrimitiveU32(0) + orderParam := ranking_types.NewRankingOrderParam() + uniqueID := types.NewPrimitiveU64(0) + + var err error + + err = principalIDList.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRankingByPIDList(fmt.Errorf("Failed to read principalIDList from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = rankingMode.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRankingByPIDList(fmt.Errorf("Failed to read rankingMode from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = category.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRankingByPIDList(fmt.Errorf("Failed to read category from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = orderParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRankingByPIDList(fmt.Errorf("Failed to read orderParam from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uniqueID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRankingByPIDList(fmt.Errorf("Failed to read uniqueID from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetRankingByPIDList(nil, packet, callID, principalIDList, rankingMode, category, orderParam, uniqueID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/get_ranking_by_unique_id_list.go b/nex-protocols-go/ranking/get_ranking_by_unique_id_list.go new file mode 100644 index 0000000..bc8f014 --- /dev/null +++ b/nex-protocols-go/ranking/get_ranking_by_unique_id_list.go @@ -0,0 +1,95 @@ +// Package protocol implements the Ranking protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" +) + +func (protocol *Protocol) handleGetRankingByUniqueIDList(packet nex.PacketInterface) { + if protocol.GetRankingByUniqueIDList == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking::GetRankingByUniqueIDList not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + nexUniqueIDList := types.NewList[*types.PrimitiveU64]() + nexUniqueIDList.Type = types.NewPrimitiveU64(0) + rankingMode := types.NewPrimitiveU8(0) + category := types.NewPrimitiveU32(0) + orderParam := ranking_types.NewRankingOrderParam() + uniqueID := types.NewPrimitiveU64(0) + + var err error + + err = nexUniqueIDList.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRankingByUniqueIDList(fmt.Errorf("Failed to read nexUniqueIDList from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = rankingMode.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRankingByUniqueIDList(fmt.Errorf("Failed to read rankingMode from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = category.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRankingByUniqueIDList(fmt.Errorf("Failed to read category from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = orderParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRankingByUniqueIDList(fmt.Errorf("Failed to read orderParam from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uniqueID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRankingByUniqueIDList(fmt.Errorf("Failed to read uniqueID from parameters. %s", err.Error()), packet, callID, nil, nil, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetRankingByUniqueIDList(nil, packet, callID, nexUniqueIDList, rankingMode, category, orderParam, uniqueID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/get_stats.go b/nex-protocols-go/ranking/get_stats.go new file mode 100644 index 0000000..28d8e1f --- /dev/null +++ b/nex-protocols-go/ranking/get_stats.go @@ -0,0 +1,72 @@ +// Package protocol implements the Ranking protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" +) + +func (protocol *Protocol) handleGetStats(packet nex.PacketInterface) { + if protocol.GetStats == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking::GetStats not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + category := types.NewPrimitiveU32(0) + orderParam := ranking_types.NewRankingOrderParam() + flags := types.NewPrimitiveU32(0) + + var err error + + err = category.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetStats(fmt.Errorf("Failed to read category from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = orderParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetStats(fmt.Errorf("Failed to read orderParam from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = flags.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetStats(fmt.Errorf("Failed to read flags from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetStats(nil, packet, callID, category, orderParam, flags) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/mario-kart-8/get_competition_info.go b/nex-protocols-go/ranking/mario-kart-8/get_competition_info.go new file mode 100644 index 0000000..63f0422 --- /dev/null +++ b/nex-protocols-go/ranking/mario-kart-8/get_competition_info.go @@ -0,0 +1,47 @@ +// Package protocol implements the RankingMarioKart8 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking_mario_kart8_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/mario-kart-8/types" +) + +func (protocol *Protocol) handleGetCompetitionInfo(packet nex.PacketInterface) { + if protocol.GetCompetitionInfo == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "RankingMarioKart8::GetCompetitionInfo not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := ranking_mario_kart8_types.NewCompetitionRankingInfoGetParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetCompetitionInfo(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetCompetitionInfo(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/mario-kart-8/get_competition_ranking_score.go b/nex-protocols-go/ranking/mario-kart-8/get_competition_ranking_score.go new file mode 100644 index 0000000..f77a2c7 --- /dev/null +++ b/nex-protocols-go/ranking/mario-kart-8/get_competition_ranking_score.go @@ -0,0 +1,31 @@ +// Package protocol implements the RankingMarioKart8 protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetCompetitionRankingScore(packet nex.PacketInterface) { + if protocol.GetCompetitionRankingScore == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "RankingMarioKart8::GetCompetitionRankingScore not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("RankingMarioKart8::GetCompetitionRankingScore STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetCompetitionRankingScore(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/mario-kart-8/protocol.go b/nex-protocols-go/ranking/mario-kart-8/protocol.go new file mode 100644 index 0000000..be6f19b --- /dev/null +++ b/nex-protocols-go/ranking/mario-kart-8/protocol.go @@ -0,0 +1,81 @@ +// Package protocol implements the RankingMarioKart8 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking "github.com/PretendoNetwork/nex-protocols-go/v2/ranking" + ranking_mario_kart8_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/mario-kart-8/types" + "golang.org/x/exp/slices" +) + +const ( + // ProtocolID is the Protocol ID for the Ranking (Mario Kart 8) protocol + ProtocolID = 0x70 + + // MethodGetCompetitionRankingScore is the method ID for the GetCompetitionRankingScore method + MethodGetCompetitionRankingScore = 0xE + + // MethodUploadCompetitionRankingScore is the method ID for the UploadCompetitionRankingScore method + MethodUploadCompetitionRankingScore = 0xF + + // MethodGetCompetitionInfo is the method ID for the GetCompetitionInfo method + MethodGetCompetitionInfo = 0x10 +) + +var patchedMethods = []uint32{ + MethodGetCompetitionRankingScore, + MethodUploadCompetitionRankingScore, + MethodGetCompetitionInfo, +} + +type rankingProtocol = ranking.Protocol + +// Protocol stores all the RMC method handlers for the Ranking (Mario Kart 8) protocol and listens for requests +// Embeds the Ranking protocol +type Protocol struct { + endpoint nex.EndpointInterface + rankingProtocol + GetCompetitionRankingScore func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + UploadCompetitionRankingScore func(err error, packet nex.PacketInterface, callID uint32, param *ranking_mario_kart8_types.CompetitionRankingUploadScoreParam) (*nex.RMCMessage, *nex.Error) + GetCompetitionInfo func(err error, packet nex.PacketInterface, callID uint32, param *ranking_mario_kart8_types.CompetitionRankingInfoGetParam) (*nex.RMCMessage, *nex.Error) +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if !slices.Contains(patchedMethods, message.MethodID) { + protocol.rankingProtocol.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodGetCompetitionRankingScore: + protocol.handleGetCompetitionRankingScore(packet) + case MethodUploadCompetitionRankingScore: + protocol.handleUploadCompetitionRankingScore(packet) + case MethodGetCompetitionInfo: + protocol.handleGetCompetitionInfo(packet) + default: + errMessage := fmt.Sprintf("Unsupported Ranking (Mario Kart 8) method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new RankingMarioKart8 protocol +func NewProtocol(endpoint nex.EndpointInterface) *Protocol { + protocol := &Protocol{endpoint: endpoint} + protocol.rankingProtocol.SetEndpoint(endpoint) + + return protocol +} diff --git a/nex-protocols-go/ranking/mario-kart-8/types/competition_ranking_info.go b/nex-protocols-go/ranking/mario-kart-8/types/competition_ranking_info.go new file mode 100644 index 0000000..f59e51c --- /dev/null +++ b/nex-protocols-go/ranking/mario-kart-8/types/competition_ranking_info.go @@ -0,0 +1,128 @@ +// Package types implements all the types used by the Ranking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// CompetitionRankingInfo is a type within the Ranking protocol +type CompetitionRankingInfo struct { + types.Structure + Unknown *types.PrimitiveU32 + Unknown2 *types.PrimitiveU32 + Unknown3 *types.List[*types.PrimitiveU32] +} + +// WriteTo writes the CompetitionRankingInfo to the given writable +func (cri *CompetitionRankingInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + cri.Unknown.WriteTo(contentWritable) + cri.Unknown2.WriteTo(contentWritable) + cri.Unknown3.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + cri.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the CompetitionRankingInfo from the given readable +func (cri *CompetitionRankingInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = cri.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CompetitionRankingInfo header. %s", err.Error()) + } + + err = cri.Unknown.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CompetitionRankingInfo.Unknown. %s", err.Error()) + } + + err = cri.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CompetitionRankingInfo.Unknown2. %s", err.Error()) + } + + err = cri.Unknown3.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CompetitionRankingInfo.Unknown3. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of CompetitionRankingInfo +func (cri *CompetitionRankingInfo) Copy() types.RVType { + copied := NewCompetitionRankingInfo() + + copied.StructureVersion = cri.StructureVersion + copied.Unknown = cri.Unknown.Copy().(*types.PrimitiveU32) + copied.Unknown2 = cri.Unknown2.Copy().(*types.PrimitiveU32) + copied.Unknown3 = cri.Unknown3.Copy().(*types.List[*types.PrimitiveU32]) + + return copied +} + +// Equals checks if the given CompetitionRankingInfo contains the same data as the current CompetitionRankingInfo +func (cri *CompetitionRankingInfo) Equals(o types.RVType) bool { + if _, ok := o.(*CompetitionRankingInfo); !ok { + return false + } + + other := o.(*CompetitionRankingInfo) + + if cri.StructureVersion != other.StructureVersion { + return false + } + + if !cri.Unknown.Equals(other.Unknown) { + return false + } + + if !cri.Unknown2.Equals(other.Unknown2) { + return false + } + + return cri.Unknown3.Equals(other.Unknown3) +} + +// String returns the string representation of the CompetitionRankingInfo +func (cri *CompetitionRankingInfo) String() string { + return cri.FormatToString(0) +} + +// FormatToString pretty-prints the CompetitionRankingInfo using the provided indentation level +func (cri *CompetitionRankingInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("CompetitionRankingInfo{\n") + b.WriteString(fmt.Sprintf("%sUnknown: %s,\n", indentationValues, cri.Unknown)) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, cri.Unknown2)) + b.WriteString(fmt.Sprintf("%sUnknown3: %s,\n", indentationValues, cri.Unknown3)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewCompetitionRankingInfo returns a new CompetitionRankingInfo +func NewCompetitionRankingInfo() *CompetitionRankingInfo { + cri := &CompetitionRankingInfo{ + Unknown: types.NewPrimitiveU32(0), + Unknown2: types.NewPrimitiveU32(0), + Unknown3: types.NewList[*types.PrimitiveU32](), + } + + cri.Unknown3.Type = types.NewPrimitiveU32(0) + + return cri +} diff --git a/nex-protocols-go/ranking/mario-kart-8/types/competition_ranking_info_get_param.go b/nex-protocols-go/ranking/mario-kart-8/types/competition_ranking_info_get_param.go new file mode 100644 index 0000000..45f5dfe --- /dev/null +++ b/nex-protocols-go/ranking/mario-kart-8/types/competition_ranking_info_get_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the Ranking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// CompetitionRankingInfoGetParam is a type within the Ranking protocol +type CompetitionRankingInfoGetParam struct { + types.Structure + Unknown *types.PrimitiveU8 + Result *types.ResultRange +} + +// WriteTo writes the CompetitionRankingInfoGetParam to the given writable +func (crigp *CompetitionRankingInfoGetParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + crigp.Unknown.WriteTo(contentWritable) + crigp.Result.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + crigp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the CompetitionRankingInfoGetParam from the given readable +func (crigp *CompetitionRankingInfoGetParam) ExtractFrom(readable types.Readable) error { + var err error + + err = crigp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CompetitionRankingInfoGetParam header. %s", err.Error()) + } + + err = crigp.Unknown.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CompetitionRankingInfoGetParam.Unknown. %s", err.Error()) + } + + err = crigp.Result.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CompetitionRankingInfoGetParam.Result. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of CompetitionRankingInfoGetParam +func (crigp *CompetitionRankingInfoGetParam) Copy() types.RVType { + copied := NewCompetitionRankingInfoGetParam() + + copied.StructureVersion = crigp.StructureVersion + copied.Unknown = crigp.Unknown.Copy().(*types.PrimitiveU8) + copied.Result = crigp.Result.Copy().(*types.ResultRange) + + return copied +} + +// Equals checks if the given CompetitionRankingInfoGetParam contains the same data as the current CompetitionRankingInfoGetParam +func (crigp *CompetitionRankingInfoGetParam) Equals(o types.RVType) bool { + if _, ok := o.(*CompetitionRankingInfoGetParam); !ok { + return false + } + + other := o.(*CompetitionRankingInfoGetParam) + + if crigp.StructureVersion != other.StructureVersion { + return false + } + + if !crigp.Unknown.Equals(other.Unknown) { + return false + } + + return crigp.Result.Equals(other.Result) +} + +// String returns the string representation of the CompetitionRankingInfoGetParam +func (crigp *CompetitionRankingInfoGetParam) String() string { + return crigp.FormatToString(0) +} + +// FormatToString pretty-prints the CompetitionRankingInfoGetParam using the provided indentation level +func (crigp *CompetitionRankingInfoGetParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("CompetitionRankingInfoGetParam{\n") + b.WriteString(fmt.Sprintf("%sUnknown: %s,\n", indentationValues, crigp.Unknown)) + b.WriteString(fmt.Sprintf("%sResult: %s,\n", indentationValues, crigp.Result.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewCompetitionRankingInfoGetParam returns a new CompetitionRankingInfoGetParam +func NewCompetitionRankingInfoGetParam() *CompetitionRankingInfoGetParam { + crigp := &CompetitionRankingInfoGetParam{ + Unknown: types.NewPrimitiveU8(0), + Result: types.NewResultRange(), + } + + return crigp +} diff --git a/nex-protocols-go/ranking/mario-kart-8/types/competition_ranking_upload_score_param.go b/nex-protocols-go/ranking/mario-kart-8/types/competition_ranking_upload_score_param.go new file mode 100644 index 0000000..89c147b --- /dev/null +++ b/nex-protocols-go/ranking/mario-kart-8/types/competition_ranking_upload_score_param.go @@ -0,0 +1,196 @@ +// Package types implements all the types used by the Ranking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// CompetitionRankingUploadScoreParam is a type within the Ranking protocol +type CompetitionRankingUploadScoreParam struct { + types.Structure + Unknown *types.PrimitiveU32 + Unknown2 *types.PrimitiveU32 + Unknown3 *types.PrimitiveU32 + Unknown4 *types.PrimitiveU32 + Unknown5 *types.PrimitiveU8 + Unknown6 *types.PrimitiveU32 + Unknown7 *types.PrimitiveBool + Metadata *types.QBuffer +} + +// WriteTo writes the CompetitionRankingUploadScoreParam to the given writable +func (crusp *CompetitionRankingUploadScoreParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + crusp.Unknown.WriteTo(contentWritable) + crusp.Unknown2.WriteTo(contentWritable) + crusp.Unknown3.WriteTo(contentWritable) + crusp.Unknown4.WriteTo(contentWritable) + crusp.Unknown5.WriteTo(contentWritable) + crusp.Unknown6.WriteTo(contentWritable) + crusp.Unknown7.WriteTo(contentWritable) + crusp.Metadata.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + crusp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the CompetitionRankingUploadScoreParam from the given readable +func (crusp *CompetitionRankingUploadScoreParam) ExtractFrom(readable types.Readable) error { + var err error + + err = crusp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CompetitionRankingUploadScoreParam header. %s", err.Error()) + } + + err = crusp.Unknown.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CompetitionRankingUploadScoreParam.Unknown. %s", err.Error()) + } + + err = crusp.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CompetitionRankingUploadScoreParam.Unknown2. %s", err.Error()) + } + + err = crusp.Unknown3.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CompetitionRankingUploadScoreParam.Unknown3. %s", err.Error()) + } + + err = crusp.Unknown4.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CompetitionRankingUploadScoreParam.Unknown4. %s", err.Error()) + } + + err = crusp.Unknown5.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CompetitionRankingUploadScoreParam.Unknown5. %s", err.Error()) + } + + err = crusp.Unknown6.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CompetitionRankingUploadScoreParam.Unknown6. %s", err.Error()) + } + + err = crusp.Unknown7.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CompetitionRankingUploadScoreParam.Unknown7. %s", err.Error()) + } + + err = crusp.Metadata.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract CompetitionRankingUploadScoreParam.Metadata. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of CompetitionRankingUploadScoreParam +func (crusp *CompetitionRankingUploadScoreParam) Copy() types.RVType { + copied := NewCompetitionRankingUploadScoreParam() + + copied.StructureVersion = crusp.StructureVersion + copied.Unknown = crusp.Unknown.Copy().(*types.PrimitiveU32) + copied.Unknown2 = crusp.Unknown2.Copy().(*types.PrimitiveU32) + copied.Unknown3 = crusp.Unknown3.Copy().(*types.PrimitiveU32) + copied.Unknown4 = crusp.Unknown4.Copy().(*types.PrimitiveU32) + copied.Unknown5 = crusp.Unknown5.Copy().(*types.PrimitiveU8) + copied.Unknown6 = crusp.Unknown6.Copy().(*types.PrimitiveU32) + copied.Unknown7 = crusp.Unknown7.Copy().(*types.PrimitiveBool) + copied.Metadata = crusp.Metadata.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given CompetitionRankingUploadScoreParam contains the same data as the current CompetitionRankingUploadScoreParam +func (crusp *CompetitionRankingUploadScoreParam) Equals(o types.RVType) bool { + if _, ok := o.(*CompetitionRankingUploadScoreParam); !ok { + return false + } + + other := o.(*CompetitionRankingUploadScoreParam) + + if crusp.StructureVersion != other.StructureVersion { + return false + } + + if !crusp.Unknown.Equals(other.Unknown) { + return false + } + + if !crusp.Unknown2.Equals(other.Unknown2) { + return false + } + + if !crusp.Unknown3.Equals(other.Unknown3) { + return false + } + + if !crusp.Unknown4.Equals(other.Unknown4) { + return false + } + + if !crusp.Unknown5.Equals(other.Unknown5) { + return false + } + + if !crusp.Unknown6.Equals(other.Unknown6) { + return false + } + + if !crusp.Unknown7.Equals(other.Unknown7) { + return false + } + + return crusp.Metadata.Equals(other.Metadata) +} + +// String returns the string representation of the CompetitionRankingUploadScoreParam +func (crusp *CompetitionRankingUploadScoreParam) String() string { + return crusp.FormatToString(0) +} + +// FormatToString pretty-prints the CompetitionRankingUploadScoreParam using the provided indentation level +func (crusp *CompetitionRankingUploadScoreParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("CompetitionRankingUploadScoreParam{\n") + b.WriteString(fmt.Sprintf("%sUnknown: %s,\n", indentationValues, crusp.Unknown)) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, crusp.Unknown2)) + b.WriteString(fmt.Sprintf("%sUnknown3: %s,\n", indentationValues, crusp.Unknown3)) + b.WriteString(fmt.Sprintf("%sUnknown4: %s,\n", indentationValues, crusp.Unknown4)) + b.WriteString(fmt.Sprintf("%sUnknown5: %s,\n", indentationValues, crusp.Unknown5)) + b.WriteString(fmt.Sprintf("%sUnknown6: %s,\n", indentationValues, crusp.Unknown6)) + b.WriteString(fmt.Sprintf("%sUnknown7: %s,\n", indentationValues, crusp.Unknown7)) + b.WriteString(fmt.Sprintf("%sMetadata: %s,\n", indentationValues, crusp.Metadata)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewCompetitionRankingUploadScoreParam returns a new CompetitionRankingUploadScoreParam +func NewCompetitionRankingUploadScoreParam() *CompetitionRankingUploadScoreParam { + crusp := &CompetitionRankingUploadScoreParam{ + Unknown: types.NewPrimitiveU32(0), + Unknown2: types.NewPrimitiveU32(0), + Unknown3: types.NewPrimitiveU32(0), + Unknown4: types.NewPrimitiveU32(0), + Unknown5: types.NewPrimitiveU8(0), + Unknown6: types.NewPrimitiveU32(0), + Unknown7: types.NewPrimitiveBool(false), + Metadata: types.NewQBuffer(nil), + } + + return crusp +} diff --git a/nex-protocols-go/ranking/mario-kart-8/upload_competition_ranking_score.go b/nex-protocols-go/ranking/mario-kart-8/upload_competition_ranking_score.go new file mode 100644 index 0000000..bd1d7aa --- /dev/null +++ b/nex-protocols-go/ranking/mario-kart-8/upload_competition_ranking_score.go @@ -0,0 +1,47 @@ +// Package protocol implements the RankingMarioKart8 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking_mario_kart8_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/mario-kart-8/types" +) + +func (protocol *Protocol) handleUploadCompetitionRankingScore(packet nex.PacketInterface) { + if protocol.UploadCompetitionRankingScore == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "RankingMarioKart8::UploadCompetitionRankingScore not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := ranking_mario_kart8_types.NewCompetitionRankingUploadScoreParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UploadCompetitionRankingScore(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UploadCompetitionRankingScore(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/protocol.go b/nex-protocols-go/ranking/protocol.go new file mode 100644 index 0000000..1956a47 --- /dev/null +++ b/nex-protocols-go/ranking/protocol.go @@ -0,0 +1,248 @@ +// Package protocol implements the Ranking protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" +) + +const ( + // ProtocolID is the protocol ID for the Ranking protocol + ProtocolID = 0x70 + + // MethodUploadScore is the method ID for method UploadScore + MethodUploadScore = 0x1 + + // MethodDeleteScore is the method ID for method DeleteScore + MethodDeleteScore = 0x2 + + // MethodDeleteAllScores is the method ID for method DeleteAllScores + MethodDeleteAllScores = 0x3 + + // MethodUploadCommonData is the method ID for method UploadCommonData + MethodUploadCommonData = 0x4 + + // MethodDeleteCommonData is the method ID for method DeleteCommonData + MethodDeleteCommonData = 0x5 + + // MethodGetCommonData is the method ID for method GetCommonData + MethodGetCommonData = 0x6 + + // MethodChangeAttributes is the method ID for method ChangeAttributes + MethodChangeAttributes = 0x7 + + // MethodChangeAllAttributes is the method ID for method ChangeAllAttributes + MethodChangeAllAttributes = 0x8 + + // MethodGetRanking is the method ID for method GetRanking + MethodGetRanking = 0x9 + + // MethodGetApproxOrder is the method ID for method GetApproxOrder + MethodGetApproxOrder = 0xA + + // MethodGetStats is the method ID for method GetStats + MethodGetStats = 0xB + + // MethodGetRankingByPIDList is the method ID for method GetRankingByPIDList + MethodGetRankingByPIDList = 0xC + + // MethodGetRankingByUniqueIDList is the method ID for method GetRankingByUniqueIDList + MethodGetRankingByUniqueIDList = 0xD + + // MethodGetCachedTopXRanking is the method ID for method GetCachedTopXRanking + MethodGetCachedTopXRanking = 0xE + + // MethodGetCachedTopXRankings is the method ID for method GetCachedTopXRankings + MethodGetCachedTopXRankings = 0xF +) + +// Protocol stores all the RMC method handlers for the Ranking protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + UploadScore func(err error, packet nex.PacketInterface, callID uint32, scoreData *ranking_types.RankingScoreData, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + DeleteScore func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + DeleteAllScores func(err error, packet nex.PacketInterface, callID uint32, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + UploadCommonData func(err error, packet nex.PacketInterface, callID uint32, commonData *types.Buffer, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + DeleteCommonData func(err error, packet nex.PacketInterface, callID uint32, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + GetCommonData func(err error, packet nex.PacketInterface, callID uint32, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + ChangeAttributes func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32, changeParam *ranking_types.RankingChangeAttributesParam, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + ChangeAllAttributes func(err error, packet nex.PacketInterface, callID uint32, changeParam *ranking_types.RankingChangeAttributesParam, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + GetRanking func(err error, packet nex.PacketInterface, callID uint32, rankingMode *types.PrimitiveU8, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, uniqueID *types.PrimitiveU64, principalID *types.PID) (*nex.RMCMessage, *nex.Error) + GetApproxOrder func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, score *types.PrimitiveU32, uniqueID *types.PrimitiveU64, principalID *types.PID) (*nex.RMCMessage, *nex.Error) + GetStats func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, flags *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetRankingByPIDList func(err error, packet nex.PacketInterface, callID uint32, principalIDList *types.List[*types.PID], rankingMode *types.PrimitiveU8, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + GetRankingByUniqueIDList func(err error, packet nex.PacketInterface, callID uint32, nexUniqueIDList *types.List[*types.PrimitiveU64], rankingMode *types.PrimitiveU8, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + GetCachedTopXRanking func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam) (*nex.RMCMessage, *nex.Error) + GetCachedTopXRankings func(err error, packet nex.PacketInterface, callID uint32, categories *types.List[*types.PrimitiveU32], orderParams *types.List[*ranking_types.RankingOrderParam]) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Ranking protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerUploadScore(handler func(err error, packet nex.PacketInterface, callID uint32, scoreData *ranking_types.RankingScoreData, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeleteScore(handler func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeleteAllScores(handler func(err error, packet nex.PacketInterface, callID uint32, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerUploadCommonData(handler func(err error, packet nex.PacketInterface, callID uint32, commonData *types.Buffer, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeleteCommonData(handler func(err error, packet nex.PacketInterface, callID uint32, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetCommonData(handler func(err error, packet nex.PacketInterface, callID uint32, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerChangeAttributes(handler func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32, changeParam *ranking_types.RankingChangeAttributesParam, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerChangeAllAttributes(handler func(err error, packet nex.PacketInterface, callID uint32, changeParam *ranking_types.RankingChangeAttributesParam, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetRanking(handler func(err error, packet nex.PacketInterface, callID uint32, rankingMode *types.PrimitiveU8, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, uniqueID *types.PrimitiveU64, principalID *types.PID) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetApproxOrder(handler func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, score *types.PrimitiveU32, uniqueID *types.PrimitiveU64, principalID *types.PID) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetStats(handler func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, flags *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetRankingByPIDList(handler func(err error, packet nex.PacketInterface, callID uint32, principalIDList *types.List[*types.PID], rankingMode *types.PrimitiveU8, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetRankingByUniqueIDList(handler func(err error, packet nex.PacketInterface, callID uint32, nexUniqueIDList *types.List[*types.PrimitiveU64], rankingMode *types.PrimitiveU8, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetCachedTopXRanking(handler func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetCachedTopXRankings(handler func(err error, packet nex.PacketInterface, callID uint32, categories *types.List[*types.PrimitiveU32], orderParams *types.List[*ranking_types.RankingOrderParam]) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerUploadScore sets the handler for the UploadScore method +func (protocol *Protocol) SetHandlerUploadScore(handler func(err error, packet nex.PacketInterface, callID uint32, scoreData *ranking_types.RankingScoreData, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.UploadScore = handler +} + +// SetHandlerDeleteScore sets the handler for the DeleteScore method +func (protocol *Protocol) SetHandlerDeleteScore(handler func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.DeleteScore = handler +} + +// SetHandlerDeleteAllScores sets the handler for the DeleteAllScores method +func (protocol *Protocol) SetHandlerDeleteAllScores(handler func(err error, packet nex.PacketInterface, callID uint32, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.DeleteAllScores = handler +} + +// SetHandlerUploadCommonData sets the handler for the UploadCommonData method +func (protocol *Protocol) SetHandlerUploadCommonData(handler func(err error, packet nex.PacketInterface, callID uint32, commonData *types.Buffer, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.UploadCommonData = handler +} + +// SetHandlerDeleteCommonData sets the handler for the DeleteCommonData method +func (protocol *Protocol) SetHandlerDeleteCommonData(handler func(err error, packet nex.PacketInterface, callID uint32, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.DeleteCommonData = handler +} + +// SetHandlerGetCommonData sets the handler for the GetCommonData method +func (protocol *Protocol) SetHandlerGetCommonData(handler func(err error, packet nex.PacketInterface, callID uint32, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.GetCommonData = handler +} + +// SetHandlerChangeAttributes sets the handler for the ChangeAttributes method +func (protocol *Protocol) SetHandlerChangeAttributes(handler func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32, changeParam *ranking_types.RankingChangeAttributesParam, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.ChangeAttributes = handler +} + +// SetHandlerChangeAllAttributes sets the handler for the ChangeAllAttributes method +func (protocol *Protocol) SetHandlerChangeAllAttributes(handler func(err error, packet nex.PacketInterface, callID uint32, changeParam *ranking_types.RankingChangeAttributesParam, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.ChangeAllAttributes = handler +} + +// SetHandlerGetRanking sets the handler for the GetRanking method +func (protocol *Protocol) SetHandlerGetRanking(handler func(err error, packet nex.PacketInterface, callID uint32, rankingMode *types.PrimitiveU8, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, uniqueID *types.PrimitiveU64, principalID *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.GetRanking = handler +} + +// SetHandlerGetApproxOrder sets the handler for the GetApproxOrder method +func (protocol *Protocol) SetHandlerGetApproxOrder(handler func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, score *types.PrimitiveU32, uniqueID *types.PrimitiveU64, principalID *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.GetApproxOrder = handler +} + +// SetHandlerGetStats sets the handler for the GetStats method +func (protocol *Protocol) SetHandlerGetStats(handler func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, flags *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetStats = handler +} + +// SetHandlerGetRankingByPIDList sets the handler for the GetRankingByPIDList method +func (protocol *Protocol) SetHandlerGetRankingByPIDList(handler func(err error, packet nex.PacketInterface, callID uint32, principalIDList *types.List[*types.PID], rankingMode *types.PrimitiveU8, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.GetRankingByPIDList = handler +} + +// SetHandlerGetRankingByUniqueIDList sets the handler for the GetRankingByUniqueIDList method +func (protocol *Protocol) SetHandlerGetRankingByUniqueIDList(handler func(err error, packet nex.PacketInterface, callID uint32, nexUniqueIDList *types.List[*types.PrimitiveU64], rankingMode *types.PrimitiveU8, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, uniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.GetRankingByUniqueIDList = handler +} + +// SetHandlerGetCachedTopXRanking sets the handler for the GetCachedTopXRanking method +func (protocol *Protocol) SetHandlerGetCachedTopXRanking(handler func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam) (*nex.RMCMessage, *nex.Error)) { + protocol.GetCachedTopXRanking = handler +} + +// SetHandlerGetCachedTopXRankings sets the handler for the GetCachedTopXRankings method +func (protocol *Protocol) SetHandlerGetCachedTopXRankings(handler func(err error, packet nex.PacketInterface, callID uint32, categories *types.List[*types.PrimitiveU32], orderParams *types.List[*ranking_types.RankingOrderParam]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetCachedTopXRankings = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodUploadScore: + protocol.handleUploadScore(packet) + case MethodDeleteScore: + protocol.handleDeleteScore(packet) + case MethodDeleteAllScores: + protocol.handleDeleteAllScores(packet) + case MethodUploadCommonData: + protocol.handleUploadCommonData(packet) + case MethodDeleteCommonData: + protocol.handleDeleteCommonData(packet) + case MethodGetCommonData: + protocol.handleGetCommonData(packet) + case MethodChangeAttributes: + protocol.handleChangeAttributes(packet) + case MethodChangeAllAttributes: + protocol.handleChangeAllAttributes(packet) + case MethodGetRanking: + protocol.handleGetRanking(packet) + case MethodGetApproxOrder: + protocol.handleGetApproxOrder(packet) + case MethodGetStats: + protocol.handleGetStats(packet) + case MethodGetRankingByPIDList: + protocol.handleGetRankingByPIDList(packet) + case MethodGetRankingByUniqueIDList: + protocol.handleGetRankingByUniqueIDList(packet) + case MethodGetCachedTopXRanking: + protocol.handleGetCachedTopXRanking(packet) + case MethodGetCachedTopXRankings: + protocol.handleGetCachedTopXRankings(packet) + default: + errMessage := fmt.Sprintf("Unsupported Ranking method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Ranking protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/ranking/splatoon/delete_competition_ranking_score.go b/nex-protocols-go/ranking/splatoon/delete_competition_ranking_score.go new file mode 100644 index 0000000..67a00a9 --- /dev/null +++ b/nex-protocols-go/ranking/splatoon/delete_competition_ranking_score.go @@ -0,0 +1,31 @@ +// Package protocol implements the RankingSplatoon protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteCompetitionRankingScore(packet nex.PacketInterface) { + if protocol.DeleteCompetitionRankingScore == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "RankingSplatoon::DeleteCompetitionRankingScore not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("RankingSplatoon::DeleteCompetitionRankingScore STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.DeleteCompetitionRankingScore(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/splatoon/get_competition_ranking_score.go b/nex-protocols-go/ranking/splatoon/get_competition_ranking_score.go new file mode 100644 index 0000000..4e0006b --- /dev/null +++ b/nex-protocols-go/ranking/splatoon/get_competition_ranking_score.go @@ -0,0 +1,31 @@ +// Package protocol implements the RankingSplatoon protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetCompetitionRankingScore(packet nex.PacketInterface) { + if protocol.GetCompetitionRankingScore == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "RankingSplatoon::GetCompetitionRankingScore not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("RankingSplatoon::GetCompetitionRankingScore STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetCompetitionRankingScore(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/splatoon/getcompetition_ranking_score_by_period_list.go b/nex-protocols-go/ranking/splatoon/getcompetition_ranking_score_by_period_list.go new file mode 100644 index 0000000..ed8ae0f --- /dev/null +++ b/nex-protocols-go/ranking/splatoon/getcompetition_ranking_score_by_period_list.go @@ -0,0 +1,31 @@ +// Package protocol implements the RankingSplatoon protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetcompetitionRankingScoreByPeriodList(packet nex.PacketInterface) { + if protocol.GetcompetitionRankingScoreByPeriodList == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "RankingSplatoon::GetcompetitionRankingScoreByPeriodList not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("RankingSplatoon::GetcompetitionRankingScoreByPeriodList STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetcompetitionRankingScoreByPeriodList(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/splatoon/protocol.go b/nex-protocols-go/ranking/splatoon/protocol.go new file mode 100644 index 0000000..9411814 --- /dev/null +++ b/nex-protocols-go/ranking/splatoon/protocol.go @@ -0,0 +1,87 @@ +// Package protocol implements the RankingSplatoon protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking "github.com/PretendoNetwork/nex-protocols-go/v2/ranking" + "golang.org/x/exp/slices" +) + +const ( + // ProtocolID is the Protocol ID for the Ranking (Splatoon) protocol + ProtocolID = 0x70 + + // MethodGetCompetitionRankingScore is the method ID for the GetCompetitionRankingScore method + MethodGetCompetitionRankingScore = 0x10 + + // MethodGetcompetitionRankingScoreByPeriodList is the method ID for the GetcompetitionRankingScoreByPeriodList method + MethodGetcompetitionRankingScoreByPeriodList = 0x11 + + // MethodUploadCompetitionRankingScore is the method ID for the UploadCompetitionRankingScore method + MethodUploadCompetitionRankingScore = 0x12 + + // MethodDeleteCompetitionRankingScore is the method ID for the DeleteCompetitionRankingScore method + MethodDeleteCompetitionRankingScore = 0x13 +) + +var patchedMethods = []uint32{ + MethodGetCompetitionRankingScore, + MethodGetcompetitionRankingScoreByPeriodList, + MethodUploadCompetitionRankingScore, + MethodDeleteCompetitionRankingScore, +} + +type rankingProtocol = ranking.Protocol + +// Protocol stores all the RMC method handlers for the Ranking (Splatoon) protocol and listens for requests +// Embeds the Ranking protocol +type Protocol struct { + endpoint nex.EndpointInterface + rankingProtocol + GetCompetitionRankingScore func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + GetcompetitionRankingScoreByPeriodList func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + UploadCompetitionRankingScore func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + DeleteCompetitionRankingScore func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if !slices.Contains(patchedMethods, message.MethodID) { + protocol.rankingProtocol.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodGetCompetitionRankingScore: + protocol.handleGetCompetitionRankingScore(packet) + case MethodGetcompetitionRankingScoreByPeriodList: + protocol.handleGetcompetitionRankingScoreByPeriodList(packet) + case MethodUploadCompetitionRankingScore: + protocol.handleUploadCompetitionRankingScore(packet) + case MethodDeleteCompetitionRankingScore: + protocol.handleDeleteCompetitionRankingScore(packet) + default: + errMessage := fmt.Sprintf("Unsupported Ranking (Splatoon) method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new RankingSplatoon protocol +func NewProtocol(endpoint nex.EndpointInterface) *Protocol { + protocol := &Protocol{endpoint: endpoint} + protocol.rankingProtocol.SetEndpoint(endpoint) + + return protocol +} diff --git a/nex-protocols-go/ranking/splatoon/upload_competition_ranking_score.go b/nex-protocols-go/ranking/splatoon/upload_competition_ranking_score.go new file mode 100644 index 0000000..c220d41 --- /dev/null +++ b/nex-protocols-go/ranking/splatoon/upload_competition_ranking_score.go @@ -0,0 +1,31 @@ +// Package protocol implements the RankingSplatoon protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUploadCompetitionRankingScore(packet nex.PacketInterface) { + if protocol.UploadCompetitionRankingScore == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "RankingSplatoon::UploadCompetitionRankingScore not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("RankingSplatoon::UploadCompetitionRankingScore STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.UploadCompetitionRankingScore(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/types/ranking_cached_result.go b/nex-protocols-go/ranking/types/ranking_cached_result.go new file mode 100644 index 0000000..9f277a7 --- /dev/null +++ b/nex-protocols-go/ranking/types/ranking_cached_result.go @@ -0,0 +1,141 @@ +// Package types implements all the types used by the Ranking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// RankingCachedResult is a type within the Ranking protocol +type RankingCachedResult struct { + types.Structure + *RankingResult + CreatedTime *types.DateTime + ExpiredTime *types.DateTime + MaxLength *types.PrimitiveU8 +} + +// WriteTo writes the RankingCachedResult to the given writable +func (rcr *RankingCachedResult) WriteTo(writable types.Writable) { + rcr.RankingResult.WriteTo(writable) + + contentWritable := writable.CopyNew() + + rcr.CreatedTime.WriteTo(contentWritable) + rcr.ExpiredTime.WriteTo(contentWritable) + rcr.MaxLength.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + rcr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the RankingCachedResult from the given readable +func (rcr *RankingCachedResult) ExtractFrom(readable types.Readable) error { + var err error + + err = rcr.RankingResult.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingCachedResult.RankingResult. %s", err.Error()) + } + + err = rcr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingCachedResult header. %s", err.Error()) + } + + err = rcr.CreatedTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingCachedResult.CreatedTime. %s", err.Error()) + } + + err = rcr.ExpiredTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingCachedResult.ExpiredTime. %s", err.Error()) + } + + err = rcr.MaxLength.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingCachedResult.MaxLength. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of RankingCachedResult +func (rcr *RankingCachedResult) Copy() types.RVType { + copied := NewRankingCachedResult() + + copied.StructureVersion = rcr.StructureVersion + copied.RankingResult = rcr.RankingResult.Copy().(*RankingResult) + copied.CreatedTime = rcr.CreatedTime.Copy().(*types.DateTime) + copied.ExpiredTime = rcr.ExpiredTime.Copy().(*types.DateTime) + copied.MaxLength = rcr.MaxLength.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given RankingCachedResult contains the same data as the current RankingCachedResult +func (rcr *RankingCachedResult) Equals(o types.RVType) bool { + if _, ok := o.(*RankingCachedResult); !ok { + return false + } + + other := o.(*RankingCachedResult) + + if rcr.StructureVersion != other.StructureVersion { + return false + } + + if !rcr.RankingResult.Equals(other.RankingResult) { + return false + } + + if !rcr.CreatedTime.Equals(other.CreatedTime) { + return false + } + + if !rcr.ExpiredTime.Equals(other.ExpiredTime) { + return false + } + + return rcr.MaxLength.Equals(other.MaxLength) +} + +// String returns the string representation of the RankingCachedResult +func (rcr *RankingCachedResult) String() string { + return rcr.FormatToString(0) +} + +// FormatToString pretty-prints the RankingCachedResult using the provided indentation level +func (rcr *RankingCachedResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("RankingCachedResult{\n") + b.WriteString(fmt.Sprintf("%sRankingResult (parent): %s,\n", indentationValues, rcr.RankingResult.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sCreatedTime: %s,\n", indentationValues, rcr.CreatedTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sExpiredTime: %s,\n", indentationValues, rcr.ExpiredTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sMaxLength: %s,\n", indentationValues, rcr.MaxLength)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRankingCachedResult returns a new RankingCachedResult +func NewRankingCachedResult() *RankingCachedResult { + rcr := &RankingCachedResult{ + RankingResult: NewRankingResult(), + CreatedTime: types.NewDateTime(0), + ExpiredTime: types.NewDateTime(0), + MaxLength: types.NewPrimitiveU8(0), + } + + return rcr +} diff --git a/nex-protocols-go/ranking/types/ranking_change_attributes_param.go b/nex-protocols-go/ranking/types/ranking_change_attributes_param.go new file mode 100644 index 0000000..0c60d3b --- /dev/null +++ b/nex-protocols-go/ranking/types/ranking_change_attributes_param.go @@ -0,0 +1,128 @@ +// Package types implements all the types used by the Ranking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// RankingChangeAttributesParam is a type within the Ranking protocol +type RankingChangeAttributesParam struct { + types.Structure + ModificationFlag *types.PrimitiveU8 + Groups *types.List[*types.PrimitiveU8] + Param *types.PrimitiveU64 +} + +// WriteTo writes the RankingChangeAttributesParam to the given writable +func (rcap *RankingChangeAttributesParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + rcap.ModificationFlag.WriteTo(contentWritable) + rcap.Groups.WriteTo(contentWritable) + rcap.Param.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + rcap.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the RankingChangeAttributesParam from the given readable +func (rcap *RankingChangeAttributesParam) ExtractFrom(readable types.Readable) error { + var err error + + err = rcap.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingChangeAttributesParam header. %s", err.Error()) + } + + err = rcap.ModificationFlag.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingChangeAttributesParam.ModificationFlag. %s", err.Error()) + } + + err = rcap.Groups.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingChangeAttributesParam.Groups. %s", err.Error()) + } + + err = rcap.Param.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingChangeAttributesParam.Param. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of RankingChangeAttributesParam +func (rcap *RankingChangeAttributesParam) Copy() types.RVType { + copied := NewRankingChangeAttributesParam() + + copied.StructureVersion = rcap.StructureVersion + copied.ModificationFlag = rcap.ModificationFlag.Copy().(*types.PrimitiveU8) + copied.Groups = rcap.Groups.Copy().(*types.List[*types.PrimitiveU8]) + copied.Param = rcap.Param.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given RankingChangeAttributesParam contains the same data as the current RankingChangeAttributesParam +func (rcap *RankingChangeAttributesParam) Equals(o types.RVType) bool { + if _, ok := o.(*RankingChangeAttributesParam); !ok { + return false + } + + other := o.(*RankingChangeAttributesParam) + + if rcap.StructureVersion != other.StructureVersion { + return false + } + + if !rcap.ModificationFlag.Equals(other.ModificationFlag) { + return false + } + + if !rcap.Groups.Equals(other.Groups) { + return false + } + + return rcap.Param.Equals(other.Param) +} + +// String returns the string representation of the RankingChangeAttributesParam +func (rcap *RankingChangeAttributesParam) String() string { + return rcap.FormatToString(0) +} + +// FormatToString pretty-prints the RankingChangeAttributesParam using the provided indentation level +func (rcap *RankingChangeAttributesParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("RankingChangeAttributesParam{\n") + b.WriteString(fmt.Sprintf("%sModificationFlag: %s,\n", indentationValues, rcap.ModificationFlag)) + b.WriteString(fmt.Sprintf("%sGroups: %s,\n", indentationValues, rcap.Groups)) + b.WriteString(fmt.Sprintf("%sParam: %s,\n", indentationValues, rcap.Param)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRankingChangeAttributesParam returns a new RankingChangeAttributesParam +func NewRankingChangeAttributesParam() *RankingChangeAttributesParam { + rcap := &RankingChangeAttributesParam{ + ModificationFlag: types.NewPrimitiveU8(0), + Groups: types.NewList[*types.PrimitiveU8](), + Param: types.NewPrimitiveU64(0), + } + + rcap.Groups.Type = types.NewPrimitiveU8(0) + + return rcap +} diff --git a/nex-protocols-go/ranking/types/ranking_order_param.go b/nex-protocols-go/ranking/types/ranking_order_param.go new file mode 100644 index 0000000..eda4809 --- /dev/null +++ b/nex-protocols-go/ranking/types/ranking_order_param.go @@ -0,0 +1,168 @@ +// Package types implements all the types used by the Ranking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// RankingOrderParam is a type within the Ranking protocol +type RankingOrderParam struct { + types.Structure + OrderCalculation *types.PrimitiveU8 + GroupIndex *types.PrimitiveU8 + GroupNum *types.PrimitiveU8 + TimeScope *types.PrimitiveU8 + Offset *types.PrimitiveU32 + Length *types.PrimitiveU8 +} + +// WriteTo writes the RankingOrderParam to the given writable +func (rop *RankingOrderParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + rop.OrderCalculation.WriteTo(contentWritable) + rop.GroupIndex.WriteTo(contentWritable) + rop.GroupNum.WriteTo(contentWritable) + rop.TimeScope.WriteTo(contentWritable) + rop.Offset.WriteTo(contentWritable) + rop.Length.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + rop.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the RankingOrderParam from the given readable +func (rop *RankingOrderParam) ExtractFrom(readable types.Readable) error { + var err error + + err = rop.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingOrderParam header. %s", err.Error()) + } + + err = rop.OrderCalculation.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingOrderParam.OrderCalculation. %s", err.Error()) + } + + err = rop.GroupIndex.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingOrderParam.GroupIndex. %s", err.Error()) + } + + err = rop.GroupNum.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingOrderParam.GroupNum. %s", err.Error()) + } + + err = rop.TimeScope.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingOrderParam.TimeScope. %s", err.Error()) + } + + err = rop.Offset.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingOrderParam.Offset. %s", err.Error()) + } + + err = rop.Length.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingOrderParam.Length. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of RankingOrderParam +func (rop *RankingOrderParam) Copy() types.RVType { + copied := NewRankingOrderParam() + + copied.StructureVersion = rop.StructureVersion + copied.OrderCalculation = rop.OrderCalculation.Copy().(*types.PrimitiveU8) + copied.GroupIndex = rop.GroupIndex.Copy().(*types.PrimitiveU8) + copied.GroupNum = rop.GroupNum.Copy().(*types.PrimitiveU8) + copied.TimeScope = rop.TimeScope.Copy().(*types.PrimitiveU8) + copied.Offset = rop.Offset.Copy().(*types.PrimitiveU32) + copied.Length = rop.Length.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given RankingOrderParam contains the same data as the current RankingOrderParam +func (rop *RankingOrderParam) Equals(o types.RVType) bool { + if _, ok := o.(*RankingOrderParam); !ok { + return false + } + + other := o.(*RankingOrderParam) + + if rop.StructureVersion != other.StructureVersion { + return false + } + + if !rop.OrderCalculation.Equals(other.OrderCalculation) { + return false + } + + if !rop.GroupIndex.Equals(other.GroupIndex) { + return false + } + + if !rop.GroupNum.Equals(other.GroupNum) { + return false + } + + if !rop.TimeScope.Equals(other.TimeScope) { + return false + } + + if !rop.Offset.Equals(other.Offset) { + return false + } + + return rop.Length.Equals(other.Length) +} + +// String returns the string representation of the RankingOrderParam +func (rop *RankingOrderParam) String() string { + return rop.FormatToString(0) +} + +// FormatToString pretty-prints the RankingOrderParam using the provided indentation level +func (rop *RankingOrderParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("RankingOrderParam{\n") + b.WriteString(fmt.Sprintf("%sOrderCalculation: %s,\n", indentationValues, rop.OrderCalculation)) + b.WriteString(fmt.Sprintf("%sGroupIndex: %s,\n", indentationValues, rop.GroupIndex)) + b.WriteString(fmt.Sprintf("%sGroupNum: %s,\n", indentationValues, rop.GroupNum)) + b.WriteString(fmt.Sprintf("%sTimeScope: %s,\n", indentationValues, rop.TimeScope)) + b.WriteString(fmt.Sprintf("%sOffset: %s,\n", indentationValues, rop.Offset)) + b.WriteString(fmt.Sprintf("%sLength: %s,\n", indentationValues, rop.Length)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRankingOrderParam returns a new RankingOrderParam +func NewRankingOrderParam() *RankingOrderParam { + rop := &RankingOrderParam{ + OrderCalculation: types.NewPrimitiveU8(0), + GroupIndex: types.NewPrimitiveU8(0), + GroupNum: types.NewPrimitiveU8(0), + TimeScope: types.NewPrimitiveU8(0), + Offset: types.NewPrimitiveU32(0), + Length: types.NewPrimitiveU8(0), + } + + return rop +} diff --git a/nex-protocols-go/ranking/types/ranking_rank_data.go b/nex-protocols-go/ranking/types/ranking_rank_data.go new file mode 100644 index 0000000..e78e9c6 --- /dev/null +++ b/nex-protocols-go/ranking/types/ranking_rank_data.go @@ -0,0 +1,222 @@ +// Package types implements all the types used by the Ranking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// RankingRankData is a type within the Ranking protocol +type RankingRankData struct { + types.Structure + PrincipalID *types.PID + UniqueID *types.PrimitiveU64 + Order *types.PrimitiveU32 + Category *types.PrimitiveU32 + Score *types.PrimitiveU32 + Groups *types.Buffer + Param *types.PrimitiveU64 + CommonData *types.Buffer + UpdateTime *types.DateTime // * NEX v3.6.0 +} + +// WriteTo writes the RankingRankData to the given writable +func (rrd *RankingRankData) WriteTo(writable types.Writable) { + stream := writable.(*nex.ByteStreamOut) + libraryVersion := stream.LibraryVersions.Ranking + + contentWritable := writable.CopyNew() + + rrd.PrincipalID.WriteTo(contentWritable) + rrd.UniqueID.WriteTo(contentWritable) + rrd.Order.WriteTo(contentWritable) + rrd.Category.WriteTo(contentWritable) + rrd.Score.WriteTo(contentWritable) + rrd.Groups.WriteTo(contentWritable) + rrd.Param.WriteTo(contentWritable) + rrd.CommonData.WriteTo(contentWritable) + + if libraryVersion.GreaterOrEqual("3.6.0") { + rrd.UpdateTime.WriteTo(contentWritable) + } + + content := contentWritable.Bytes() + + rrd.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the RankingRankData from the given readable +func (rrd *RankingRankData) ExtractFrom(readable types.Readable) error { + stream := readable.(*nex.ByteStreamIn) + libraryVersion := stream.LibraryVersions.Ranking + + var err error + + err = rrd.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingRankData header. %s", err.Error()) + } + + err = rrd.PrincipalID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingRankData.PrincipalID. %s", err.Error()) + } + + err = rrd.UniqueID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingRankData.UniqueID. %s", err.Error()) + } + + err = rrd.Order.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingRankData.Order. %s", err.Error()) + } + + err = rrd.Category.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingRankData.Category. %s", err.Error()) + } + + err = rrd.Score.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingRankData.Score. %s", err.Error()) + } + + err = rrd.Groups.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingRankData.Groups. %s", err.Error()) + } + + err = rrd.Param.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingRankData.Param. %s", err.Error()) + } + + err = rrd.CommonData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingRankData.CommonData. %s", err.Error()) + } + + if libraryVersion.GreaterOrEqual("3.6.0") { + err = rrd.UpdateTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingRankData.UpdateTime. %s", err.Error()) + } + } + + return nil +} + +// Copy returns a new copied instance of RankingRankData +func (rrd *RankingRankData) Copy() types.RVType { + copied := NewRankingRankData() + + copied.StructureVersion = rrd.StructureVersion + copied.PrincipalID = rrd.PrincipalID.Copy().(*types.PID) + copied.UniqueID = rrd.UniqueID.Copy().(*types.PrimitiveU64) + copied.Order = rrd.Order.Copy().(*types.PrimitiveU32) + copied.Category = rrd.Category.Copy().(*types.PrimitiveU32) + copied.Score = rrd.Score.Copy().(*types.PrimitiveU32) + copied.Groups = rrd.Groups.Copy().(*types.Buffer) + copied.Param = rrd.Param.Copy().(*types.PrimitiveU64) + copied.CommonData = rrd.CommonData.Copy().(*types.Buffer) + copied.UpdateTime = rrd.UpdateTime.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given RankingRankData contains the same data as the current RankingRankData +func (rrd *RankingRankData) Equals(o types.RVType) bool { + if _, ok := o.(*RankingRankData); !ok { + return false + } + + other := o.(*RankingRankData) + + if rrd.StructureVersion != other.StructureVersion { + return false + } + + if !rrd.PrincipalID.Equals(other.PrincipalID) { + return false + } + + if !rrd.UniqueID.Equals(other.UniqueID) { + return false + } + + if !rrd.Order.Equals(other.Order) { + return false + } + + if !rrd.Category.Equals(other.Category) { + return false + } + + if !rrd.Score.Equals(other.Score) { + return false + } + + if !rrd.Groups.Equals(other.Groups) { + return false + } + + if !rrd.Param.Equals(other.Param) { + return false + } + + if !rrd.CommonData.Equals(other.CommonData) { + return false + } + + return rrd.UpdateTime.Equals(other.UpdateTime) +} + +// String returns the string representation of the RankingRankData +func (rrd *RankingRankData) String() string { + return rrd.FormatToString(0) +} + +// FormatToString pretty-prints the RankingRankData using the provided indentation level +func (rrd *RankingRankData) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("RankingRankData{\n") + b.WriteString(fmt.Sprintf("%sPrincipalID: %s,\n", indentationValues, rrd.PrincipalID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUniqueID: %s,\n", indentationValues, rrd.UniqueID)) + b.WriteString(fmt.Sprintf("%sOrder: %s,\n", indentationValues, rrd.Order)) + b.WriteString(fmt.Sprintf("%sCategory: %s,\n", indentationValues, rrd.Category)) + b.WriteString(fmt.Sprintf("%sScore: %s,\n", indentationValues, rrd.Score)) + b.WriteString(fmt.Sprintf("%sGroups: %s,\n", indentationValues, rrd.Groups)) + b.WriteString(fmt.Sprintf("%sParam: %s,\n", indentationValues, rrd.Param)) + b.WriteString(fmt.Sprintf("%sCommonData: %s,\n", indentationValues, rrd.CommonData)) + b.WriteString(fmt.Sprintf("%sUpdateTime: %s,\n", indentationValues, rrd.UpdateTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRankingRankData returns a new RankingRankData +func NewRankingRankData() *RankingRankData { + rrd := &RankingRankData{ + PrincipalID: types.NewPID(0), + UniqueID: types.NewPrimitiveU64(0), + Order: types.NewPrimitiveU32(0), + Category: types.NewPrimitiveU32(0), + Score: types.NewPrimitiveU32(0), + Groups: types.NewBuffer(nil), + Param: types.NewPrimitiveU64(0), + CommonData: types.NewBuffer(nil), + UpdateTime: types.NewDateTime(0), + } + + return rrd +} diff --git a/nex-protocols-go/ranking/types/ranking_result.go b/nex-protocols-go/ranking/types/ranking_result.go new file mode 100644 index 0000000..1ef6961 --- /dev/null +++ b/nex-protocols-go/ranking/types/ranking_result.go @@ -0,0 +1,128 @@ +// Package types implements all the types used by the Ranking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// RankingResult is a type within the Ranking protocol +type RankingResult struct { + types.Structure + RankDataList *types.List[*RankingRankData] + TotalCount *types.PrimitiveU32 + SinceTime *types.DateTime +} + +// WriteTo writes the RankingResult to the given writable +func (rr *RankingResult) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + rr.RankDataList.WriteTo(contentWritable) + rr.TotalCount.WriteTo(contentWritable) + rr.SinceTime.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + rr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the RankingResult from the given readable +func (rr *RankingResult) ExtractFrom(readable types.Readable) error { + var err error + + err = rr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingResult header. %s", err.Error()) + } + + err = rr.RankDataList.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingResult.RankDataList. %s", err.Error()) + } + + err = rr.TotalCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingResult.TotalCount. %s", err.Error()) + } + + err = rr.SinceTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingResult.SinceTime. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of RankingResult +func (rr *RankingResult) Copy() types.RVType { + copied := NewRankingResult() + + copied.StructureVersion = rr.StructureVersion + copied.RankDataList = rr.RankDataList.Copy().(*types.List[*RankingRankData]) + copied.TotalCount = rr.TotalCount.Copy().(*types.PrimitiveU32) + copied.SinceTime = rr.SinceTime.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given RankingResult contains the same data as the current RankingResult +func (rr *RankingResult) Equals(o types.RVType) bool { + if _, ok := o.(*RankingResult); !ok { + return false + } + + other := o.(*RankingResult) + + if rr.StructureVersion != other.StructureVersion { + return false + } + + if !rr.RankDataList.Equals(other.RankDataList) { + return false + } + + if !rr.TotalCount.Equals(other.TotalCount) { + return false + } + + return rr.SinceTime.Equals(other.SinceTime) +} + +// String returns the string representation of the RankingResult +func (rr *RankingResult) String() string { + return rr.FormatToString(0) +} + +// FormatToString pretty-prints the RankingResult using the provided indentation level +func (rr *RankingResult) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("RankingResult{\n") + b.WriteString(fmt.Sprintf("%sRankDataList: %s,\n", indentationValues, rr.RankDataList)) + b.WriteString(fmt.Sprintf("%sTotalCount: %s,\n", indentationValues, rr.TotalCount)) + b.WriteString(fmt.Sprintf("%sSinceTime: %s,\n", indentationValues, rr.SinceTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRankingResult returns a new RankingResult +func NewRankingResult() *RankingResult { + rr := &RankingResult{ + RankDataList: types.NewList[*RankingRankData](), + TotalCount: types.NewPrimitiveU32(0), + SinceTime: types.NewDateTime(0), + } + + rr.RankDataList.Type = NewRankingRankData() + + return rr +} diff --git a/nex-protocols-go/ranking/types/ranking_score_data.go b/nex-protocols-go/ranking/types/ranking_score_data.go new file mode 100644 index 0000000..9a9b096 --- /dev/null +++ b/nex-protocols-go/ranking/types/ranking_score_data.go @@ -0,0 +1,168 @@ +// Package types implements all the types used by the Ranking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// RankingScoreData is a type within the Ranking protocol +type RankingScoreData struct { + types.Structure + Category *types.PrimitiveU32 + Score *types.PrimitiveU32 + OrderBy *types.PrimitiveU8 + UpdateMode *types.PrimitiveU8 + Groups *types.Buffer + Param *types.PrimitiveU64 +} + +// WriteTo writes the RankingScoreData to the given writable +func (rsd *RankingScoreData) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + rsd.Category.WriteTo(contentWritable) + rsd.Score.WriteTo(contentWritable) + rsd.OrderBy.WriteTo(contentWritable) + rsd.UpdateMode.WriteTo(contentWritable) + rsd.Groups.WriteTo(contentWritable) + rsd.Param.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + rsd.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the RankingScoreData from the given readable +func (rsd *RankingScoreData) ExtractFrom(readable types.Readable) error { + var err error + + err = rsd.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingScoreData header. %s", err.Error()) + } + + err = rsd.Category.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingScoreData.Category. %s", err.Error()) + } + + err = rsd.Score.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingScoreData.Score. %s", err.Error()) + } + + err = rsd.OrderBy.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingScoreData.OrderBy. %s", err.Error()) + } + + err = rsd.UpdateMode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingScoreData.UpdateMode. %s", err.Error()) + } + + err = rsd.Groups.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingScoreData.Groups. %s", err.Error()) + } + + err = rsd.Param.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingScoreData.Param. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of RankingScoreData +func (rsd *RankingScoreData) Copy() types.RVType { + copied := NewRankingScoreData() + + copied.StructureVersion = rsd.StructureVersion + copied.Category = rsd.Category.Copy().(*types.PrimitiveU32) + copied.Score = rsd.Score.Copy().(*types.PrimitiveU32) + copied.OrderBy = rsd.OrderBy.Copy().(*types.PrimitiveU8) + copied.UpdateMode = rsd.UpdateMode.Copy().(*types.PrimitiveU8) + copied.Groups = rsd.Groups.Copy().(*types.Buffer) + copied.Param = rsd.Param.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given RankingScoreData contains the same data as the current RankingScoreData +func (rsd *RankingScoreData) Equals(o types.RVType) bool { + if _, ok := o.(*RankingScoreData); !ok { + return false + } + + other := o.(*RankingScoreData) + + if rsd.StructureVersion != other.StructureVersion { + return false + } + + if !rsd.Category.Equals(other.Category) { + return false + } + + if !rsd.Score.Equals(other.Score) { + return false + } + + if !rsd.OrderBy.Equals(other.OrderBy) { + return false + } + + if !rsd.UpdateMode.Equals(other.UpdateMode) { + return false + } + + if !rsd.Groups.Equals(other.Groups) { + return false + } + + return rsd.Param.Equals(other.Param) +} + +// String returns the string representation of the RankingScoreData +func (rsd *RankingScoreData) String() string { + return rsd.FormatToString(0) +} + +// FormatToString pretty-prints the RankingScoreData using the provided indentation level +func (rsd *RankingScoreData) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("RankingScoreData{\n") + b.WriteString(fmt.Sprintf("%sCategory: %s,\n", indentationValues, rsd.Category)) + b.WriteString(fmt.Sprintf("%sScore: %s,\n", indentationValues, rsd.Score)) + b.WriteString(fmt.Sprintf("%sOrderBy: %s,\n", indentationValues, rsd.OrderBy)) + b.WriteString(fmt.Sprintf("%sUpdateMode: %s,\n", indentationValues, rsd.UpdateMode)) + b.WriteString(fmt.Sprintf("%sGroups: %s,\n", indentationValues, rsd.Groups)) + b.WriteString(fmt.Sprintf("%sParam: %s,\n", indentationValues, rsd.Param)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRankingScoreData returns a new RankingScoreData +func NewRankingScoreData() *RankingScoreData { + rsd := &RankingScoreData{ + Category: types.NewPrimitiveU32(0), + Score: types.NewPrimitiveU32(0), + OrderBy: types.NewPrimitiveU8(0), + UpdateMode: types.NewPrimitiveU8(0), + Groups: types.NewBuffer(nil), + Param: types.NewPrimitiveU64(0), + } + + return rsd +} diff --git a/nex-protocols-go/ranking/types/ranking_stats.go b/nex-protocols-go/ranking/types/ranking_stats.go new file mode 100644 index 0000000..a3ad592 --- /dev/null +++ b/nex-protocols-go/ranking/types/ranking_stats.go @@ -0,0 +1,100 @@ +// Package types implements all the types used by the Ranking protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// RankingStats is a type within the Ranking protocol +type RankingStats struct { + types.Structure + StatsList *types.List[*types.PrimitiveF64] +} + +// WriteTo writes the RankingStats to the given writable +func (rs *RankingStats) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + rs.StatsList.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + rs.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the RankingStats from the given readable +func (rs *RankingStats) ExtractFrom(readable types.Readable) error { + var err error + + err = rs.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingStats header. %s", err.Error()) + } + + err = rs.StatsList.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract RankingStats.StatsList. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of RankingStats +func (rs *RankingStats) Copy() types.RVType { + copied := NewRankingStats() + + copied.StructureVersion = rs.StructureVersion + copied.StatsList = rs.StatsList.Copy().(*types.List[*types.PrimitiveF64]) + + return copied +} + +// Equals checks if the given RankingStats contains the same data as the current RankingStats +func (rs *RankingStats) Equals(o types.RVType) bool { + if _, ok := o.(*RankingStats); !ok { + return false + } + + other := o.(*RankingStats) + + if rs.StructureVersion != other.StructureVersion { + return false + } + + return rs.StatsList.Equals(other.StatsList) +} + +// String returns the string representation of the RankingStats +func (rs *RankingStats) String() string { + return rs.FormatToString(0) +} + +// FormatToString pretty-prints the RankingStats using the provided indentation level +func (rs *RankingStats) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("RankingStats{\n") + b.WriteString(fmt.Sprintf("%sStatsList: %s,\n", indentationValues, rs.StatsList)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRankingStats returns a new RankingStats +func NewRankingStats() *RankingStats { + rs := &RankingStats{ + StatsList: types.NewList[*types.PrimitiveF64](), + } + + rs.StatsList.Type = types.NewPrimitiveF64(0) + + return rs +} diff --git a/nex-protocols-go/ranking/upload_common_data.go b/nex-protocols-go/ranking/upload_common_data.go new file mode 100644 index 0000000..d79d833 --- /dev/null +++ b/nex-protocols-go/ranking/upload_common_data.go @@ -0,0 +1,60 @@ +// Package protocol implements the Ranking protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUploadCommonData(packet nex.PacketInterface) { + if protocol.UploadCommonData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking::UploadCommonData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + commonData := types.NewBuffer(nil) + uniqueID := types.NewPrimitiveU64(0) + + var err error + + err = commonData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UploadCommonData(fmt.Errorf("Failed to read commonData from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uniqueID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UploadCommonData(fmt.Errorf("Failed to read uniqueID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UploadCommonData(nil, packet, callID, commonData, uniqueID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking/upload_score.go b/nex-protocols-go/ranking/upload_score.go new file mode 100644 index 0000000..916d19e --- /dev/null +++ b/nex-protocols-go/ranking/upload_score.go @@ -0,0 +1,61 @@ +// Package protocol implements the Ranking protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking/types" +) + +func (protocol *Protocol) handleUploadScore(packet nex.PacketInterface) { + if protocol.UploadScore == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking::UploadScore not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + scoreData := ranking_types.NewRankingScoreData() + uniqueID := types.NewPrimitiveU64(0) + + var err error + + err = scoreData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UploadScore(fmt.Errorf("Failed to read scoreData from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = uniqueID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UploadScore(fmt.Errorf("Failed to read uniqueID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UploadScore(nil, packet, callID, scoreData, uniqueID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking2/delete_common_data.go b/nex-protocols-go/ranking2/delete_common_data.go new file mode 100644 index 0000000..f0b8741 --- /dev/null +++ b/nex-protocols-go/ranking2/delete_common_data.go @@ -0,0 +1,47 @@ +// Package protocol implements the Ranking2 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteCommonData(packet nex.PacketInterface) { + if protocol.DeleteCommonData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking2::DeleteCommonData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + nexUniqueID := types.NewPrimitiveU64(0) + + err := nexUniqueID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteCommonData(fmt.Errorf("Failed to read nexUniqueID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteCommonData(nil, packet, callID, nexUniqueID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking2/get_category_setting.go b/nex-protocols-go/ranking2/get_category_setting.go new file mode 100644 index 0000000..376aa58 --- /dev/null +++ b/nex-protocols-go/ranking2/get_category_setting.go @@ -0,0 +1,47 @@ +// Package protocol implements the Ranking2 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetCategorySetting(packet nex.PacketInterface) { + if protocol.GetCategorySetting == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking2::GetCategorySetting not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + category := types.NewPrimitiveU32(0) + + err := category.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetCategorySetting(fmt.Errorf("Failed to read category from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetCategorySetting(nil, packet, callID, category) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking2/get_common_data.go b/nex-protocols-go/ranking2/get_common_data.go new file mode 100644 index 0000000..86330e4 --- /dev/null +++ b/nex-protocols-go/ranking2/get_common_data.go @@ -0,0 +1,71 @@ +// Package protocol implements the Ranking2 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetCommonData(packet nex.PacketInterface) { + if protocol.GetCommonData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking2::GetCommonData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + optionFlags := types.NewPrimitiveU32(0) + principalID := types.NewPID(0) + nexUniqueID := types.NewPrimitiveU64(0) + + var err error + + err = optionFlags.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetCommonData(fmt.Errorf("Failed to read optionFlags from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = principalID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetCommonData(fmt.Errorf("Failed to read principalID from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = nexUniqueID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetCommonData(fmt.Errorf("Failed to read nexUniqueID from parameters. %s", err.Error()), packet, callID, nil, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetCommonData(nil, packet, callID, optionFlags, principalID, nexUniqueID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking2/get_estimate_score_rank.go b/nex-protocols-go/ranking2/get_estimate_score_rank.go new file mode 100644 index 0000000..ec28e42 --- /dev/null +++ b/nex-protocols-go/ranking2/get_estimate_score_rank.go @@ -0,0 +1,47 @@ +// Package protocol implements the Ranking2 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking2_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking2/types" +) + +func (protocol *Protocol) handleGetEstimateScoreRank(packet nex.PacketInterface) { + if protocol.GetEstimateScoreRank == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking2::GetEstimateScoreRank not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + input := ranking2_types.NewRanking2EstimateScoreRankInput() + + err := input.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetEstimateScoreRank(fmt.Errorf("Failed to read input from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetEstimateScoreRank(nil, packet, callID, input) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking2/get_ranking.go b/nex-protocols-go/ranking2/get_ranking.go new file mode 100644 index 0000000..0e1d461 --- /dev/null +++ b/nex-protocols-go/ranking2/get_ranking.go @@ -0,0 +1,47 @@ +// Package protocol implements the Ranking2 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking2_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking2/types" +) + +func (protocol *Protocol) handleGetRanking(packet nex.PacketInterface) { + if protocol.GetRanking == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking2::GetRanking not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + getParam := ranking2_types.NewRanking2GetParam() + + err := getParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRanking(fmt.Errorf("Failed to read getParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetRanking(nil, packet, callID, getParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking2/get_ranking_by_principal_id.go b/nex-protocols-go/ranking2/get_ranking_by_principal_id.go new file mode 100644 index 0000000..dcba52f --- /dev/null +++ b/nex-protocols-go/ranking2/get_ranking_by_principal_id.go @@ -0,0 +1,62 @@ +// Package protocol implements the Ranking2 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking2_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking2/types" +) + +func (protocol *Protocol) handleGetRankingByPrincipalID(packet nex.PacketInterface) { + if protocol.GetRankingByPrincipalID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking2::GetRankingByPrincipalID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + getParam := ranking2_types.NewRanking2GetParam() + principalIDList := types.NewList[*types.PID]() + principalIDList.Type = types.NewPID(0) + + var err error + + err = getParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRankingByPrincipalID(fmt.Errorf("Failed to read getParam from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = principalIDList.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRankingByPrincipalID(fmt.Errorf("Failed to read principalIDList from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetRankingByPrincipalID(nil, packet, callID, getParam, principalIDList) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking2/get_ranking_chart.go b/nex-protocols-go/ranking2/get_ranking_chart.go new file mode 100644 index 0000000..5633bd8 --- /dev/null +++ b/nex-protocols-go/ranking2/get_ranking_chart.go @@ -0,0 +1,47 @@ +// Package protocol implements the Ranking2 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking2_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking2/types" +) + +func (protocol *Protocol) handleGetRankingChart(packet nex.PacketInterface) { + if protocol.GetRankingChart == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking2::GetRankingChart not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + info := ranking2_types.NewRanking2ChartInfoInput() + + err := info.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRankingChart(fmt.Errorf("Failed to read info from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetRankingChart(nil, packet, callID, info) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking2/get_ranking_charts.go b/nex-protocols-go/ranking2/get_ranking_charts.go new file mode 100644 index 0000000..c2e9c67 --- /dev/null +++ b/nex-protocols-go/ranking2/get_ranking_charts.go @@ -0,0 +1,49 @@ +// Package protocol implements the Ranking2 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking2_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking2/types" +) + +func (protocol *Protocol) handleGetRankingCharts(packet nex.PacketInterface) { + if protocol.GetRankingCharts == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking2::GetRankingCharts not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + infoArray := types.NewList[*ranking2_types.Ranking2ChartInfoInput]() + infoArray.Type = ranking2_types.NewRanking2ChartInfoInput() + + err := infoArray.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRankingCharts(fmt.Errorf("Failed to read infoArray from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetRankingCharts(nil, packet, callID, infoArray) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking2/protocol.go b/nex-protocols-go/ranking2/protocol.go new file mode 100644 index 0000000..1b16156 --- /dev/null +++ b/nex-protocols-go/ranking2/protocol.go @@ -0,0 +1,188 @@ +// Package protocol implements the Ranking2 protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking2_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking2/types" +) + +const ( + // ProtocolID is the protocol ID for the Ranking2 protocol + ProtocolID = 0x7A + + // MethodPutScore is the method ID for the method PutScore + MethodPutScore = 0x1 + + // MethodGetCommonData is the method ID for the method GetCommonData + MethodGetCommonData = 0x2 + + // MethodPutCommonData is the method ID for the method PutCommonData + MethodPutCommonData = 0x3 + + // MethodDeleteCommonData is the method ID for the method DeleteCommonData + MethodDeleteCommonData = 0x4 + + // MethodGetRanking is the method ID for the method GetRanking + MethodGetRanking = 0x5 + + // MethodGetRankingByPrincipalID is the method ID for the method GetRankingByPrincipalID + MethodGetRankingByPrincipalID = 0x6 + + // MethodGetCategorySetting is the method ID for the method GetCategorySetting + MethodGetCategorySetting = 0x7 + + // MethodGetRankingChart is the method ID for the method GetRankingChart + MethodGetRankingChart = 0x8 + + // MethodGetRankingCharts is the method ID for the method GetRankingCharts + MethodGetRankingCharts = 0x9 + + // MethodGetEstimateScoreRank is the method ID for the method GetEstimateScoreRank + MethodGetEstimateScoreRank = 0xA +) + +// Protocol stores all the RMC method handlers for the Ranking2 protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + PutScore func(err error, packet nex.PacketInterface, callID uint32, scoreDataList *types.List[*ranking2_types.Ranking2ScoreData], nexUniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + GetCommonData func(err error, packet nex.PacketInterface, callID uint32, optionFlags *types.PrimitiveU32, principalID *types.PID, nexUniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + PutCommonData func(err error, packet nex.PacketInterface, callID uint32, commonData *ranking2_types.Ranking2CommonData, nexUniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + DeleteCommonData func(err error, packet nex.PacketInterface, callID uint32, nexUniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + GetRanking func(err error, packet nex.PacketInterface, callID uint32, getParam *ranking2_types.Ranking2GetParam) (*nex.RMCMessage, *nex.Error) + GetRankingByPrincipalID func(err error, packet nex.PacketInterface, callID uint32, getParam *ranking2_types.Ranking2GetParam, principalIDList *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error) + GetCategorySetting func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetRankingChart func(err error, packet nex.PacketInterface, callID uint32, info *ranking2_types.Ranking2ChartInfoInput) (*nex.RMCMessage, *nex.Error) + GetRankingCharts func(err error, packet nex.PacketInterface, callID uint32, infoArray *types.List[*ranking2_types.Ranking2ChartInfoInput]) (*nex.RMCMessage, *nex.Error) + GetEstimateScoreRank func(err error, packet nex.PacketInterface, callID uint32, input *ranking2_types.Ranking2EstimateScoreRankInput) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Ranking2 protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerPutScore(handler func(err error, packet nex.PacketInterface, callID uint32, scoreDataList *types.List[*ranking2_types.Ranking2ScoreData], nexUniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetCommonData(handler func(err error, packet nex.PacketInterface, callID uint32, optionFlags *types.PrimitiveU32, principalID *types.PID, nexUniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerPutCommonData(handler func(err error, packet nex.PacketInterface, callID uint32, commonData *ranking2_types.Ranking2CommonData, nexUniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeleteCommonData(handler func(err error, packet nex.PacketInterface, callID uint32, nexUniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetRanking(handler func(err error, packet nex.PacketInterface, callID uint32, getParam *ranking2_types.Ranking2GetParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetRankingByPrincipalID(handler func(err error, packet nex.PacketInterface, callID uint32, getParam *ranking2_types.Ranking2GetParam, principalIDList *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetCategorySetting(handler func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetRankingChart(handler func(err error, packet nex.PacketInterface, callID uint32, info *ranking2_types.Ranking2ChartInfoInput) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetRankingCharts(handler func(err error, packet nex.PacketInterface, callID uint32, infoArray *types.List[*ranking2_types.Ranking2ChartInfoInput]) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetEstimateScoreRank(handler func(err error, packet nex.PacketInterface, callID uint32, input *ranking2_types.Ranking2EstimateScoreRankInput) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerPutScore sets the handler for the PutScore method +func (protocol *Protocol) SetHandlerPutScore(handler func(err error, packet nex.PacketInterface, callID uint32, scoreDataList *types.List[*ranking2_types.Ranking2ScoreData], nexUniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.PutScore = handler +} + +// SetHandlerGetCommonData sets the handler for the GetCommonData method +func (protocol *Protocol) SetHandlerGetCommonData(handler func(err error, packet nex.PacketInterface, callID uint32, optionFlags *types.PrimitiveU32, principalID *types.PID, nexUniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.GetCommonData = handler +} + +// SetHandlerPutCommonData sets the handler for the PutCommonData method +func (protocol *Protocol) SetHandlerPutCommonData(handler func(err error, packet nex.PacketInterface, callID uint32, commonData *ranking2_types.Ranking2CommonData, nexUniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.PutCommonData = handler +} + +// SetHandlerDeleteCommonData sets the handler for the DeleteCommonData method +func (protocol *Protocol) SetHandlerDeleteCommonData(handler func(err error, packet nex.PacketInterface, callID uint32, nexUniqueID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.DeleteCommonData = handler +} + +// SetHandlerGetRanking sets the handler for the GetRanking method +func (protocol *Protocol) SetHandlerGetRanking(handler func(err error, packet nex.PacketInterface, callID uint32, getParam *ranking2_types.Ranking2GetParam) (*nex.RMCMessage, *nex.Error)) { + protocol.GetRanking = handler +} + +// SetHandlerGetRankingByPrincipalID sets the handler for the GetRankingByPrincipalID method +func (protocol *Protocol) SetHandlerGetRankingByPrincipalID(handler func(err error, packet nex.PacketInterface, callID uint32, getParam *ranking2_types.Ranking2GetParam, principalIDList *types.List[*types.PID]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetRankingByPrincipalID = handler +} + +// SetHandlerGetCategorySetting sets the handler for the GetCategorySetting method +func (protocol *Protocol) SetHandlerGetCategorySetting(handler func(err error, packet nex.PacketInterface, callID uint32, category *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetCategorySetting = handler +} + +// SetHandlerGetRankingChart sets the handler for the GetRankingChart method +func (protocol *Protocol) SetHandlerGetRankingChart(handler func(err error, packet nex.PacketInterface, callID uint32, info *ranking2_types.Ranking2ChartInfoInput) (*nex.RMCMessage, *nex.Error)) { + protocol.GetRankingChart = handler +} + +// SetHandlerGetRankingCharts sets the handler for the GetRankingCharts method +func (protocol *Protocol) SetHandlerGetRankingCharts(handler func(err error, packet nex.PacketInterface, callID uint32, infoArray *types.List[*ranking2_types.Ranking2ChartInfoInput]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetRankingCharts = handler +} + +// SetHandlerGetEstimateScoreRank sets the handler for the GetEstimateScoreRank method +func (protocol *Protocol) SetHandlerGetEstimateScoreRank(handler func(err error, packet nex.PacketInterface, callID uint32, input *ranking2_types.Ranking2EstimateScoreRankInput) (*nex.RMCMessage, *nex.Error)) { + protocol.GetEstimateScoreRank = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodPutScore: + protocol.handlePutScore(packet) + case MethodGetCommonData: + protocol.handleGetCommonData(packet) + case MethodPutCommonData: + protocol.handlePutCommonData(packet) + case MethodDeleteCommonData: + protocol.handleDeleteCommonData(packet) + case MethodGetRanking: + protocol.handleGetRanking(packet) + case MethodGetRankingByPrincipalID: + protocol.handleGetRankingByPrincipalID(packet) + case MethodGetCategorySetting: + protocol.handleGetCategorySetting(packet) + case MethodGetRankingChart: + protocol.handleGetRankingChart(packet) + case MethodGetRankingCharts: + protocol.handleGetRankingCharts(packet) + case MethodGetEstimateScoreRank: + protocol.handleGetEstimateScoreRank(packet) + default: + errMessage := fmt.Sprintf("Unsupported Ranking2 method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Ranking2 protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/ranking2/put_common_data.go b/nex-protocols-go/ranking2/put_common_data.go new file mode 100644 index 0000000..45e479d --- /dev/null +++ b/nex-protocols-go/ranking2/put_common_data.go @@ -0,0 +1,61 @@ +// Package protocol implements the Ranking2 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking2_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking2/types" +) + +func (protocol *Protocol) handlePutCommonData(packet nex.PacketInterface) { + if protocol.PutCommonData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking2::PutCommonData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + commonData := ranking2_types.NewRanking2CommonData() + nexUniqueID := types.NewPrimitiveU64(0) + + var err error + + err = commonData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PutCommonData(fmt.Errorf("Failed to read commonData from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = nexUniqueID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PutCommonData(fmt.Errorf("Failed to read nexUniqueID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PutCommonData(nil, packet, callID, commonData, nexUniqueID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking2/put_score.go b/nex-protocols-go/ranking2/put_score.go new file mode 100644 index 0000000..c362572 --- /dev/null +++ b/nex-protocols-go/ranking2/put_score.go @@ -0,0 +1,62 @@ +// Package protocol implements the Ranking2 protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + ranking2_types "github.com/PretendoNetwork/nex-protocols-go/v2/ranking2/types" +) + +func (protocol *Protocol) handlePutScore(packet nex.PacketInterface) { + if protocol.PutScore == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Ranking2::PutScore not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + scoreDataList := types.NewList[*ranking2_types.Ranking2ScoreData]() + scoreDataList.Type = ranking2_types.NewRanking2ScoreData() + nexUniqueID := types.NewPrimitiveU64(0) + + var err error + + err = scoreDataList.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PutScore(fmt.Errorf("Failed to read scoreDataList from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = nexUniqueID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PutScore(fmt.Errorf("Failed to read nexUniqueID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PutScore(nil, packet, callID, scoreDataList, nexUniqueID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ranking2/types/ranking2_category_setting.go b/nex-protocols-go/ranking2/types/ranking2_category_setting.go new file mode 100644 index 0000000..0042104 --- /dev/null +++ b/nex-protocols-go/ranking2/types/ranking2_category_setting.go @@ -0,0 +1,210 @@ +// Package types implements all the types used by the Ranking2 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// Ranking2CategorySetting is a type within the Ranking2 protocol +type Ranking2CategorySetting struct { + types.Structure + MinScore *types.PrimitiveU32 + MaxScore *types.PrimitiveU32 + LowestRank *types.PrimitiveU32 + ResetMonth *types.PrimitiveU16 + ResetDay *types.PrimitiveU8 + ResetHour *types.PrimitiveU8 + ResetMode *types.PrimitiveU8 + MaxSeasonsToGoBack *types.PrimitiveU8 + ScoreOrder *types.PrimitiveBool +} + +// WriteTo writes the Ranking2CategorySetting to the given writable +func (rcs *Ranking2CategorySetting) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + rcs.MinScore.WriteTo(contentWritable) + rcs.MaxScore.WriteTo(contentWritable) + rcs.LowestRank.WriteTo(contentWritable) + rcs.ResetMonth.WriteTo(contentWritable) + rcs.ResetDay.WriteTo(contentWritable) + rcs.ResetHour.WriteTo(contentWritable) + rcs.ResetMode.WriteTo(contentWritable) + rcs.MaxSeasonsToGoBack.WriteTo(contentWritable) + rcs.ScoreOrder.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + rcs.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the Ranking2CategorySetting from the given readable +func (rcs *Ranking2CategorySetting) ExtractFrom(readable types.Readable) error { + var err error + + err = rcs.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2CategorySetting header. %s", err.Error()) + } + + err = rcs.MinScore.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2CategorySetting.MinScore. %s", err.Error()) + } + + err = rcs.MaxScore.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2CategorySetting.MaxScore. %s", err.Error()) + } + + err = rcs.LowestRank.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2CategorySetting.LowestRank. %s", err.Error()) + } + + err = rcs.ResetMonth.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2CategorySetting.ResetMonth. %s", err.Error()) + } + + err = rcs.ResetDay.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2CategorySetting.ResetDay. %s", err.Error()) + } + + err = rcs.ResetHour.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2CategorySetting.ResetHour. %s", err.Error()) + } + + err = rcs.ResetMode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2CategorySetting.ResetMode. %s", err.Error()) + } + + err = rcs.MaxSeasonsToGoBack.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2CategorySetting.MaxSeasonsToGoBack. %s", err.Error()) + } + + err = rcs.ScoreOrder.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2CategorySetting.ScoreOrder. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of Ranking2CategorySetting +func (rcs *Ranking2CategorySetting) Copy() types.RVType { + copied := NewRanking2CategorySetting() + + copied.StructureVersion = rcs.StructureVersion + copied.MinScore = rcs.MinScore.Copy().(*types.PrimitiveU32) + copied.MaxScore = rcs.MaxScore.Copy().(*types.PrimitiveU32) + copied.LowestRank = rcs.LowestRank.Copy().(*types.PrimitiveU32) + copied.ResetMonth = rcs.ResetMonth.Copy().(*types.PrimitiveU16) + copied.ResetDay = rcs.ResetDay.Copy().(*types.PrimitiveU8) + copied.ResetHour = rcs.ResetHour.Copy().(*types.PrimitiveU8) + copied.ResetMode = rcs.ResetMode.Copy().(*types.PrimitiveU8) + copied.MaxSeasonsToGoBack = rcs.MaxSeasonsToGoBack.Copy().(*types.PrimitiveU8) + copied.ScoreOrder = rcs.ScoreOrder.Copy().(*types.PrimitiveBool) + + return copied +} + +// Equals checks if the given Ranking2CategorySetting contains the same data as the current Ranking2CategorySetting +func (rcs *Ranking2CategorySetting) Equals(o types.RVType) bool { + if _, ok := o.(*Ranking2CategorySetting); !ok { + return false + } + + other := o.(*Ranking2CategorySetting) + + if rcs.StructureVersion != other.StructureVersion { + return false + } + + if !rcs.MinScore.Equals(other.MinScore) { + return false + } + + if !rcs.MaxScore.Equals(other.MaxScore) { + return false + } + + if !rcs.LowestRank.Equals(other.LowestRank) { + return false + } + + if !rcs.ResetMonth.Equals(other.ResetMonth) { + return false + } + + if !rcs.ResetDay.Equals(other.ResetDay) { + return false + } + + if !rcs.ResetHour.Equals(other.ResetHour) { + return false + } + + if !rcs.ResetMode.Equals(other.ResetMode) { + return false + } + + if !rcs.MaxSeasonsToGoBack.Equals(other.MaxSeasonsToGoBack) { + return false + } + + return rcs.ScoreOrder.Equals(other.ScoreOrder) +} + +// String returns the string representation of the Ranking2CategorySetting +func (rcs *Ranking2CategorySetting) String() string { + return rcs.FormatToString(0) +} + +// FormatToString pretty-prints the Ranking2CategorySetting using the provided indentation level +func (rcs *Ranking2CategorySetting) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("Ranking2CategorySetting{\n") + b.WriteString(fmt.Sprintf("%sMinScore: %s,\n", indentationValues, rcs.MinScore)) + b.WriteString(fmt.Sprintf("%sMaxScore: %s,\n", indentationValues, rcs.MaxScore)) + b.WriteString(fmt.Sprintf("%sLowestRank: %s,\n", indentationValues, rcs.LowestRank)) + b.WriteString(fmt.Sprintf("%sResetMonth: %s,\n", indentationValues, rcs.ResetMonth)) + b.WriteString(fmt.Sprintf("%sResetDay: %s,\n", indentationValues, rcs.ResetDay)) + b.WriteString(fmt.Sprintf("%sResetHour: %s,\n", indentationValues, rcs.ResetHour)) + b.WriteString(fmt.Sprintf("%sResetMode: %s,\n", indentationValues, rcs.ResetMode)) + b.WriteString(fmt.Sprintf("%sMaxSeasonsToGoBack: %s,\n", indentationValues, rcs.MaxSeasonsToGoBack)) + b.WriteString(fmt.Sprintf("%sScoreOrder: %s,\n", indentationValues, rcs.ScoreOrder)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRanking2CategorySetting returns a new Ranking2CategorySetting +func NewRanking2CategorySetting() *Ranking2CategorySetting { + rcs := &Ranking2CategorySetting{ + MinScore: types.NewPrimitiveU32(0), + MaxScore: types.NewPrimitiveU32(0), + LowestRank: types.NewPrimitiveU32(0), + ResetMonth: types.NewPrimitiveU16(0), + ResetDay: types.NewPrimitiveU8(0), + ResetHour: types.NewPrimitiveU8(0), + ResetMode: types.NewPrimitiveU8(0), + MaxSeasonsToGoBack: types.NewPrimitiveU8(0), + ScoreOrder: types.NewPrimitiveBool(false), + } + + return rcs +} diff --git a/nex-protocols-go/ranking2/types/ranking2_chart_info.go b/nex-protocols-go/ranking2/types/ranking2_chart_info.go new file mode 100644 index 0000000..fd091d6 --- /dev/null +++ b/nex-protocols-go/ranking2/types/ranking2_chart_info.go @@ -0,0 +1,338 @@ +// Package types implements all the types used by the Ranking2 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// Ranking2ChartInfo is a type within the Ranking2 protocol +type Ranking2ChartInfo struct { + types.Structure + CreateTime *types.DateTime + Index *types.PrimitiveU32 + Category *types.PrimitiveU32 + Season *types.PrimitiveS32 + BinsSize *types.PrimitiveU8 + SamplingRate *types.PrimitiveU8 + ScoreOrder *types.PrimitiveBool + EstimateLength *types.PrimitiveU32 + EstimateHighestScore *types.PrimitiveU32 + EstimateLowestScore *types.PrimitiveU32 + EstimateMedianScore *types.PrimitiveU32 + EstimateAverageScore *types.PrimitiveF64 + HighestBinsScore *types.PrimitiveU32 + LowestBinsScore *types.PrimitiveU32 + BinsWidth *types.PrimitiveU32 + Attribute1 *types.PrimitiveU32 + Attribute2 *types.PrimitiveU32 + Quantities *types.List[*types.PrimitiveU32] +} + +// WriteTo writes the Ranking2ChartInfo to the given writable +func (rci *Ranking2ChartInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + rci.CreateTime.WriteTo(contentWritable) + rci.Index.WriteTo(contentWritable) + rci.Category.WriteTo(contentWritable) + rci.Season.WriteTo(contentWritable) + rci.BinsSize.WriteTo(contentWritable) + rci.SamplingRate.WriteTo(contentWritable) + rci.ScoreOrder.WriteTo(contentWritable) + rci.EstimateLength.WriteTo(contentWritable) + rci.EstimateHighestScore.WriteTo(contentWritable) + rci.EstimateLowestScore.WriteTo(contentWritable) + rci.EstimateMedianScore.WriteTo(contentWritable) + rci.EstimateAverageScore.WriteTo(contentWritable) + rci.HighestBinsScore.WriteTo(contentWritable) + rci.LowestBinsScore.WriteTo(contentWritable) + rci.BinsWidth.WriteTo(contentWritable) + rci.Attribute1.WriteTo(contentWritable) + rci.Attribute2.WriteTo(contentWritable) + rci.Quantities.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + rci.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the Ranking2ChartInfo from the given readable +func (rci *Ranking2ChartInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = rci.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo header. %s", err.Error()) + } + + err = rci.CreateTime.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.CreateTime. %s", err.Error()) + } + + err = rci.Index.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.Index. %s", err.Error()) + } + + err = rci.Category.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.Category. %s", err.Error()) + } + + err = rci.Season.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.Season. %s", err.Error()) + } + + err = rci.BinsSize.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.BinsSize. %s", err.Error()) + } + + err = rci.SamplingRate.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.SamplingRate. %s", err.Error()) + } + + err = rci.ScoreOrder.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.ScoreOrder. %s", err.Error()) + } + + err = rci.EstimateLength.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.EstimateLength. %s", err.Error()) + } + + err = rci.EstimateHighestScore.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.EstimateHighestScore. %s", err.Error()) + } + + err = rci.EstimateLowestScore.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.EstimateLowestScore. %s", err.Error()) + } + + err = rci.EstimateMedianScore.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.EstimateMedianScore. %s", err.Error()) + } + + err = rci.EstimateAverageScore.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.EstimateAverageScore. %s", err.Error()) + } + + err = rci.HighestBinsScore.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.HighestBinsScore. %s", err.Error()) + } + + err = rci.LowestBinsScore.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.LowestBinsScore. %s", err.Error()) + } + + err = rci.BinsWidth.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.BinsWidth. %s", err.Error()) + } + + err = rci.Attribute1.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.Attribute1. %s", err.Error()) + } + + err = rci.Attribute2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.Attribute2. %s", err.Error()) + } + + err = rci.Quantities.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfo.Quantities. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of Ranking2ChartInfo +func (rci *Ranking2ChartInfo) Copy() types.RVType { + copied := NewRanking2ChartInfo() + + copied.StructureVersion = rci.StructureVersion + copied.CreateTime = rci.CreateTime.Copy().(*types.DateTime) + copied.Index = rci.Index.Copy().(*types.PrimitiveU32) + copied.Category = rci.Category.Copy().(*types.PrimitiveU32) + copied.Season = rci.Season.Copy().(*types.PrimitiveS32) + copied.BinsSize = rci.BinsSize.Copy().(*types.PrimitiveU8) + copied.SamplingRate = rci.SamplingRate.Copy().(*types.PrimitiveU8) + copied.ScoreOrder = rci.ScoreOrder.Copy().(*types.PrimitiveBool) + copied.EstimateLength = rci.EstimateLength.Copy().(*types.PrimitiveU32) + copied.EstimateHighestScore = rci.EstimateHighestScore.Copy().(*types.PrimitiveU32) + copied.EstimateLowestScore = rci.EstimateLowestScore.Copy().(*types.PrimitiveU32) + copied.EstimateMedianScore = rci.EstimateMedianScore.Copy().(*types.PrimitiveU32) + copied.EstimateAverageScore = rci.EstimateAverageScore.Copy().(*types.PrimitiveF64) + copied.HighestBinsScore = rci.HighestBinsScore.Copy().(*types.PrimitiveU32) + copied.LowestBinsScore = rci.LowestBinsScore.Copy().(*types.PrimitiveU32) + copied.BinsWidth = rci.BinsWidth.Copy().(*types.PrimitiveU32) + copied.Attribute1 = rci.Attribute1.Copy().(*types.PrimitiveU32) + copied.Attribute2 = rci.Attribute2.Copy().(*types.PrimitiveU32) + copied.Quantities = rci.Quantities.Copy().(*types.List[*types.PrimitiveU32]) + + return copied +} + +// Equals checks if the given Ranking2ChartInfo contains the same data as the current Ranking2ChartInfo +func (rci *Ranking2ChartInfo) Equals(o types.RVType) bool { + if _, ok := o.(*Ranking2ChartInfo); !ok { + return false + } + + other := o.(*Ranking2ChartInfo) + + if rci.StructureVersion != other.StructureVersion { + return false + } + + if !rci.CreateTime.Equals(other.CreateTime) { + return false + } + + if !rci.Index.Equals(other.Index) { + return false + } + + if !rci.Category.Equals(other.Category) { + return false + } + + if !rci.Season.Equals(other.Season) { + return false + } + + if !rci.BinsSize.Equals(other.BinsSize) { + return false + } + + if !rci.SamplingRate.Equals(other.SamplingRate) { + return false + } + + if !rci.ScoreOrder.Equals(other.ScoreOrder) { + return false + } + + if !rci.EstimateLength.Equals(other.EstimateLength) { + return false + } + + if !rci.EstimateHighestScore.Equals(other.EstimateHighestScore) { + return false + } + + if !rci.EstimateLowestScore.Equals(other.EstimateLowestScore) { + return false + } + + if !rci.EstimateMedianScore.Equals(other.EstimateMedianScore) { + return false + } + + if !rci.EstimateAverageScore.Equals(other.EstimateAverageScore) { + return false + } + + if !rci.HighestBinsScore.Equals(other.HighestBinsScore) { + return false + } + + if !rci.LowestBinsScore.Equals(other.LowestBinsScore) { + return false + } + + if !rci.BinsWidth.Equals(other.BinsWidth) { + return false + } + + if !rci.Attribute1.Equals(other.Attribute1) { + return false + } + + if !rci.Attribute2.Equals(other.Attribute2) { + return false + } + + return rci.Quantities.Equals(other.Quantities) +} + +// String returns the string representation of the Ranking2ChartInfo +func (rci *Ranking2ChartInfo) String() string { + return rci.FormatToString(0) +} + +// FormatToString pretty-prints the Ranking2ChartInfo using the provided indentation level +func (rci *Ranking2ChartInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("Ranking2ChartInfo{\n") + b.WriteString(fmt.Sprintf("%sCreateTime: %s,\n", indentationValues, rci.CreateTime.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sIndex: %s,\n", indentationValues, rci.Index)) + b.WriteString(fmt.Sprintf("%sCategory: %s,\n", indentationValues, rci.Category)) + b.WriteString(fmt.Sprintf("%sSeason: %s,\n", indentationValues, rci.Season)) + b.WriteString(fmt.Sprintf("%sBinsSize: %s,\n", indentationValues, rci.BinsSize)) + b.WriteString(fmt.Sprintf("%sSamplingRate: %s,\n", indentationValues, rci.SamplingRate)) + b.WriteString(fmt.Sprintf("%sScoreOrder: %s,\n", indentationValues, rci.ScoreOrder)) + b.WriteString(fmt.Sprintf("%sEstimateLength: %s,\n", indentationValues, rci.EstimateLength)) + b.WriteString(fmt.Sprintf("%sEstimateHighestScore: %s,\n", indentationValues, rci.EstimateHighestScore)) + b.WriteString(fmt.Sprintf("%sEstimateLowestScore: %s,\n", indentationValues, rci.EstimateLowestScore)) + b.WriteString(fmt.Sprintf("%sEstimateMedianScore: %s,\n", indentationValues, rci.EstimateMedianScore)) + b.WriteString(fmt.Sprintf("%sEstimateAverageScore: %s,\n", indentationValues, rci.EstimateAverageScore)) + b.WriteString(fmt.Sprintf("%sHighestBinsScore: %s,\n", indentationValues, rci.HighestBinsScore)) + b.WriteString(fmt.Sprintf("%sLowestBinsScore: %s,\n", indentationValues, rci.LowestBinsScore)) + b.WriteString(fmt.Sprintf("%sBinsWidth: %s,\n", indentationValues, rci.BinsWidth)) + b.WriteString(fmt.Sprintf("%sAttribute1: %s,\n", indentationValues, rci.Attribute1)) + b.WriteString(fmt.Sprintf("%sAttribute2: %s,\n", indentationValues, rci.Attribute2)) + b.WriteString(fmt.Sprintf("%sQuantities: %s,\n", indentationValues, rci.Quantities)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRanking2ChartInfo returns a new Ranking2ChartInfo +func NewRanking2ChartInfo() *Ranking2ChartInfo { + rci := &Ranking2ChartInfo{ + CreateTime: types.NewDateTime(0), + Index: types.NewPrimitiveU32(0), + Category: types.NewPrimitiveU32(0), + Season: types.NewPrimitiveS32(0), + BinsSize: types.NewPrimitiveU8(0), + SamplingRate: types.NewPrimitiveU8(0), + ScoreOrder: types.NewPrimitiveBool(false), + EstimateLength: types.NewPrimitiveU32(0), + EstimateHighestScore: types.NewPrimitiveU32(0), + EstimateLowestScore: types.NewPrimitiveU32(0), + EstimateMedianScore: types.NewPrimitiveU32(0), + EstimateAverageScore: types.NewPrimitiveF64(0), + HighestBinsScore: types.NewPrimitiveU32(0), + LowestBinsScore: types.NewPrimitiveU32(0), + BinsWidth: types.NewPrimitiveU32(0), + Attribute1: types.NewPrimitiveU32(0), + Attribute2: types.NewPrimitiveU32(0), + Quantities: types.NewList[*types.PrimitiveU32](), + } + + rci.Quantities.Type = types.NewPrimitiveU32(0) + + return rci +} diff --git a/nex-protocols-go/ranking2/types/ranking2_chart_info_input.go b/nex-protocols-go/ranking2/types/ranking2_chart_info_input.go new file mode 100644 index 0000000..7abc180 --- /dev/null +++ b/nex-protocols-go/ranking2/types/ranking2_chart_info_input.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the Ranking2 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// Ranking2ChartInfoInput is a type within the Ranking2 protocol +type Ranking2ChartInfoInput struct { + types.Structure + ChartIndex *types.PrimitiveU32 + NumSeasonsToGoBack *types.PrimitiveU8 +} + +// WriteTo writes the Ranking2ChartInfoInput to the given writable +func (rcii *Ranking2ChartInfoInput) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + rcii.ChartIndex.WriteTo(contentWritable) + rcii.NumSeasonsToGoBack.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + rcii.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the Ranking2ChartInfoInput from the given readable +func (rcii *Ranking2ChartInfoInput) ExtractFrom(readable types.Readable) error { + var err error + + err = rcii.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfoInput header. %s", err.Error()) + } + + err = rcii.ChartIndex.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfoInput.ChartIndex. %s", err.Error()) + } + + err = rcii.NumSeasonsToGoBack.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ChartInfoInput.NumSeasonsToGoBack. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of Ranking2ChartInfoInput +func (rcii *Ranking2ChartInfoInput) Copy() types.RVType { + copied := NewRanking2ChartInfoInput() + + copied.StructureVersion = rcii.StructureVersion + copied.ChartIndex = rcii.ChartIndex.Copy().(*types.PrimitiveU32) + copied.NumSeasonsToGoBack = rcii.NumSeasonsToGoBack.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given Ranking2ChartInfoInput contains the same data as the current Ranking2ChartInfoInput +func (rcii *Ranking2ChartInfoInput) Equals(o types.RVType) bool { + if _, ok := o.(*Ranking2ChartInfoInput); !ok { + return false + } + + other := o.(*Ranking2ChartInfoInput) + + if rcii.StructureVersion != other.StructureVersion { + return false + } + + if !rcii.ChartIndex.Equals(other.ChartIndex) { + return false + } + + return rcii.NumSeasonsToGoBack.Equals(other.NumSeasonsToGoBack) +} + +// String returns the string representation of the Ranking2ChartInfoInput +func (rcii *Ranking2ChartInfoInput) String() string { + return rcii.FormatToString(0) +} + +// FormatToString pretty-prints the Ranking2ChartInfoInput using the provided indentation level +func (rcii *Ranking2ChartInfoInput) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("Ranking2ChartInfoInput{\n") + b.WriteString(fmt.Sprintf("%sChartIndex: %s,\n", indentationValues, rcii.ChartIndex)) + b.WriteString(fmt.Sprintf("%sNumSeasonsToGoBack: %s,\n", indentationValues, rcii.NumSeasonsToGoBack)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRanking2ChartInfoInput returns a new Ranking2ChartInfoInput +func NewRanking2ChartInfoInput() *Ranking2ChartInfoInput { + rcii := &Ranking2ChartInfoInput{ + ChartIndex: types.NewPrimitiveU32(0), + NumSeasonsToGoBack: types.NewPrimitiveU8(0), + } + + return rcii +} diff --git a/nex-protocols-go/ranking2/types/ranking2_common_data.go b/nex-protocols-go/ranking2/types/ranking2_common_data.go new file mode 100644 index 0000000..3ff03a5 --- /dev/null +++ b/nex-protocols-go/ranking2/types/ranking2_common_data.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the Ranking2 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// Ranking2CommonData is a type within the Ranking2 protocol +type Ranking2CommonData struct { + types.Structure + UserName *types.String + Mii *types.QBuffer + BinaryData *types.QBuffer +} + +// WriteTo writes the Ranking2CommonData to the given writable +func (rcd *Ranking2CommonData) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + rcd.UserName.WriteTo(contentWritable) + rcd.Mii.WriteTo(contentWritable) + rcd.BinaryData.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + rcd.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the Ranking2CommonData from the given readable +func (rcd *Ranking2CommonData) ExtractFrom(readable types.Readable) error { + var err error + + err = rcd.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2CommonData header. %s", err.Error()) + } + + err = rcd.UserName.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2CommonData.UserName. %s", err.Error()) + } + + err = rcd.Mii.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2CommonData.Mii. %s", err.Error()) + } + + err = rcd.BinaryData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2CommonData.BinaryData. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of Ranking2CommonData +func (rcd *Ranking2CommonData) Copy() types.RVType { + copied := NewRanking2CommonData() + + copied.StructureVersion = rcd.StructureVersion + copied.UserName = rcd.UserName.Copy().(*types.String) + copied.Mii = rcd.Mii.Copy().(*types.QBuffer) + copied.BinaryData = rcd.BinaryData.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given Ranking2CommonData contains the same data as the current Ranking2CommonData +func (rcd *Ranking2CommonData) Equals(o types.RVType) bool { + if _, ok := o.(*Ranking2CommonData); !ok { + return false + } + + other := o.(*Ranking2CommonData) + + if rcd.StructureVersion != other.StructureVersion { + return false + } + + if !rcd.UserName.Equals(other.UserName) { + return false + } + + if !rcd.Mii.Equals(other.Mii) { + return false + } + + return rcd.BinaryData.Equals(other.BinaryData) +} + +// String returns the string representation of the Ranking2CommonData +func (rcd *Ranking2CommonData) String() string { + return rcd.FormatToString(0) +} + +// FormatToString pretty-prints the Ranking2CommonData using the provided indentation level +func (rcd *Ranking2CommonData) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("Ranking2CommonData{\n") + b.WriteString(fmt.Sprintf("%sUserName: %s,\n", indentationValues, rcd.UserName)) + b.WriteString(fmt.Sprintf("%sMii: %s,\n", indentationValues, rcd.Mii)) + b.WriteString(fmt.Sprintf("%sBinaryData: %s,\n", indentationValues, rcd.BinaryData)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRanking2CommonData returns a new Ranking2CommonData +func NewRanking2CommonData() *Ranking2CommonData { + rcd := &Ranking2CommonData{ + UserName: types.NewString(""), + Mii: types.NewQBuffer(nil), + BinaryData: types.NewQBuffer(nil), + } + + return rcd +} diff --git a/nex-protocols-go/ranking2/types/ranking2_estimate_score_rank_input.go b/nex-protocols-go/ranking2/types/ranking2_estimate_score_rank_input.go new file mode 100644 index 0000000..273f55b --- /dev/null +++ b/nex-protocols-go/ranking2/types/ranking2_estimate_score_rank_input.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the Ranking2 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// Ranking2EstimateScoreRankInput is a type within the Ranking2 protocol +type Ranking2EstimateScoreRankInput struct { + types.Structure + Category *types.PrimitiveU32 + NumSeasonsToGoBack *types.PrimitiveU8 + Score *types.PrimitiveU32 +} + +// WriteTo writes the Ranking2EstimateScoreRankInput to the given writable +func (resri *Ranking2EstimateScoreRankInput) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + resri.Category.WriteTo(contentWritable) + resri.NumSeasonsToGoBack.WriteTo(contentWritable) + resri.Score.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + resri.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the Ranking2EstimateScoreRankInput from the given readable +func (resri *Ranking2EstimateScoreRankInput) ExtractFrom(readable types.Readable) error { + var err error + + err = resri.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2EstimateScoreRankInput header. %s", err.Error()) + } + + err = resri.Category.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2EstimateScoreRankInput.Category. %s", err.Error()) + } + + err = resri.NumSeasonsToGoBack.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2EstimateScoreRankInput.NumSeasonsToGoBack. %s", err.Error()) + } + + err = resri.Score.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2EstimateScoreRankInput.Score. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of Ranking2EstimateScoreRankInput +func (resri *Ranking2EstimateScoreRankInput) Copy() types.RVType { + copied := NewRanking2EstimateScoreRankInput() + + copied.StructureVersion = resri.StructureVersion + copied.Category = resri.Category.Copy().(*types.PrimitiveU32) + copied.NumSeasonsToGoBack = resri.NumSeasonsToGoBack.Copy().(*types.PrimitiveU8) + copied.Score = resri.Score.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given Ranking2EstimateScoreRankInput contains the same data as the current Ranking2EstimateScoreRankInput +func (resri *Ranking2EstimateScoreRankInput) Equals(o types.RVType) bool { + if _, ok := o.(*Ranking2EstimateScoreRankInput); !ok { + return false + } + + other := o.(*Ranking2EstimateScoreRankInput) + + if resri.StructureVersion != other.StructureVersion { + return false + } + + if !resri.Category.Equals(other.Category) { + return false + } + + if !resri.NumSeasonsToGoBack.Equals(other.NumSeasonsToGoBack) { + return false + } + + return resri.Score.Equals(other.Score) +} + +// String returns the string representation of the Ranking2EstimateScoreRankInput +func (resri *Ranking2EstimateScoreRankInput) String() string { + return resri.FormatToString(0) +} + +// FormatToString pretty-prints the Ranking2EstimateScoreRankInput using the provided indentation level +func (resri *Ranking2EstimateScoreRankInput) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("Ranking2EstimateScoreRankInput{\n") + b.WriteString(fmt.Sprintf("%sCategory: %s,\n", indentationValues, resri.Category)) + b.WriteString(fmt.Sprintf("%sNumSeasonsToGoBack: %s,\n", indentationValues, resri.NumSeasonsToGoBack)) + b.WriteString(fmt.Sprintf("%sScore: %s,\n", indentationValues, resri.Score)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRanking2EstimateScoreRankInput returns a new Ranking2EstimateScoreRankInput +func NewRanking2EstimateScoreRankInput() *Ranking2EstimateScoreRankInput { + resri := &Ranking2EstimateScoreRankInput{ + Category: types.NewPrimitiveU32(0), + NumSeasonsToGoBack: types.NewPrimitiveU8(0), + Score: types.NewPrimitiveU32(0), + } + + return resri +} diff --git a/nex-protocols-go/ranking2/types/ranking2_estimate_score_rank_output.go b/nex-protocols-go/ranking2/types/ranking2_estimate_score_rank_output.go new file mode 100644 index 0000000..dd16a44 --- /dev/null +++ b/nex-protocols-go/ranking2/types/ranking2_estimate_score_rank_output.go @@ -0,0 +1,168 @@ +// Package types implements all the types used by the Ranking2 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// Ranking2EstimateScoreRankOutput is a type within the Ranking2 protocol +type Ranking2EstimateScoreRankOutput struct { + types.Structure + Rank *types.PrimitiveU32 + Length *types.PrimitiveU32 + Score *types.PrimitiveU32 + Category *types.PrimitiveU32 + Season *types.PrimitiveS32 + SamplingRate *types.PrimitiveU8 +} + +// WriteTo writes the Ranking2EstimateScoreRankOutput to the given writable +func (resro *Ranking2EstimateScoreRankOutput) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + resro.Rank.WriteTo(contentWritable) + resro.Length.WriteTo(contentWritable) + resro.Score.WriteTo(contentWritable) + resro.Category.WriteTo(contentWritable) + resro.Season.WriteTo(contentWritable) + resro.SamplingRate.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + resro.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the Ranking2EstimateScoreRankOutput from the given readable +func (resro *Ranking2EstimateScoreRankOutput) ExtractFrom(readable types.Readable) error { + var err error + + err = resro.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2EstimateScoreRankOutput header. %s", err.Error()) + } + + err = resro.Rank.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2EstimateScoreRankOutput.Rank. %s", err.Error()) + } + + err = resro.Length.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2EstimateScoreRankOutput.Length. %s", err.Error()) + } + + err = resro.Score.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2EstimateScoreRankOutput.Score. %s", err.Error()) + } + + err = resro.Category.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2EstimateScoreRankOutput.Category. %s", err.Error()) + } + + err = resro.Season.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2EstimateScoreRankOutput.Season. %s", err.Error()) + } + + err = resro.SamplingRate.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2EstimateScoreRankOutput.SamplingRate. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of Ranking2EstimateScoreRankOutput +func (resro *Ranking2EstimateScoreRankOutput) Copy() types.RVType { + copied := NewRanking2EstimateScoreRankOutput() + + copied.StructureVersion = resro.StructureVersion + copied.Rank = resro.Rank.Copy().(*types.PrimitiveU32) + copied.Length = resro.Length.Copy().(*types.PrimitiveU32) + copied.Score = resro.Score.Copy().(*types.PrimitiveU32) + copied.Category = resro.Category.Copy().(*types.PrimitiveU32) + copied.Season = resro.Season.Copy().(*types.PrimitiveS32) + copied.SamplingRate = resro.SamplingRate.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given Ranking2EstimateScoreRankOutput contains the same data as the current Ranking2EstimateScoreRankOutput +func (resro *Ranking2EstimateScoreRankOutput) Equals(o types.RVType) bool { + if _, ok := o.(*Ranking2EstimateScoreRankOutput); !ok { + return false + } + + other := o.(*Ranking2EstimateScoreRankOutput) + + if resro.StructureVersion != other.StructureVersion { + return false + } + + if !resro.Rank.Equals(other.Rank) { + return false + } + + if !resro.Length.Equals(other.Length) { + return false + } + + if !resro.Score.Equals(other.Score) { + return false + } + + if !resro.Category.Equals(other.Category) { + return false + } + + if !resro.Season.Equals(other.Season) { + return false + } + + return resro.SamplingRate.Equals(other.SamplingRate) +} + +// String returns the string representation of the Ranking2EstimateScoreRankOutput +func (resro *Ranking2EstimateScoreRankOutput) String() string { + return resro.FormatToString(0) +} + +// FormatToString pretty-prints the Ranking2EstimateScoreRankOutput using the provided indentation level +func (resro *Ranking2EstimateScoreRankOutput) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("Ranking2EstimateScoreRankOutput{\n") + b.WriteString(fmt.Sprintf("%sRank: %s,\n", indentationValues, resro.Rank)) + b.WriteString(fmt.Sprintf("%sLength: %s,\n", indentationValues, resro.Length)) + b.WriteString(fmt.Sprintf("%sScore: %s,\n", indentationValues, resro.Score)) + b.WriteString(fmt.Sprintf("%sCategory: %s,\n", indentationValues, resro.Category)) + b.WriteString(fmt.Sprintf("%sSeason: %s,\n", indentationValues, resro.Season)) + b.WriteString(fmt.Sprintf("%sSamplingRate: %s,\n", indentationValues, resro.SamplingRate)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRanking2EstimateScoreRankOutput returns a new Ranking2EstimateScoreRankOutput +func NewRanking2EstimateScoreRankOutput() *Ranking2EstimateScoreRankOutput { + resro := &Ranking2EstimateScoreRankOutput{ + Rank: types.NewPrimitiveU32(0), + Length: types.NewPrimitiveU32(0), + Score: types.NewPrimitiveU32(0), + Category: types.NewPrimitiveU32(0), + Season: types.NewPrimitiveS32(0), + SamplingRate: types.NewPrimitiveU8(0), + } + + return resro +} diff --git a/nex-protocols-go/ranking2/types/ranking2_get_by_list_param.go b/nex-protocols-go/ranking2/types/ranking2_get_by_list_param.go new file mode 100644 index 0000000..5d7507d --- /dev/null +++ b/nex-protocols-go/ranking2/types/ranking2_get_by_list_param.go @@ -0,0 +1,168 @@ +// Package types implements all the types used by the Ranking2 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// Ranking2GetByListParam is a type within the Ranking2 protocol +type Ranking2GetByListParam struct { + types.Structure + Category *types.PrimitiveU32 + Offset *types.PrimitiveU32 + Length *types.PrimitiveU32 + SortFlags *types.PrimitiveU32 + OptionFlags *types.PrimitiveU32 + NumSeasonsToGoBack *types.PrimitiveU8 +} + +// WriteTo writes the Ranking2GetByListParam to the given writable +func (rgblp *Ranking2GetByListParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + rgblp.Category.WriteTo(contentWritable) + rgblp.Offset.WriteTo(contentWritable) + rgblp.Length.WriteTo(contentWritable) + rgblp.SortFlags.WriteTo(contentWritable) + rgblp.OptionFlags.WriteTo(contentWritable) + rgblp.NumSeasonsToGoBack.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + rgblp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the Ranking2GetByListParam from the given readable +func (rgblp *Ranking2GetByListParam) ExtractFrom(readable types.Readable) error { + var err error + + err = rgblp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2GetByListParam header. %s", err.Error()) + } + + err = rgblp.Category.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2GetByListParam.Category. %s", err.Error()) + } + + err = rgblp.Offset.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2GetByListParam.Offset. %s", err.Error()) + } + + err = rgblp.Length.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2GetByListParam.Length. %s", err.Error()) + } + + err = rgblp.SortFlags.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2GetByListParam.SortFlags. %s", err.Error()) + } + + err = rgblp.OptionFlags.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2GetByListParam.OptionFlags. %s", err.Error()) + } + + err = rgblp.NumSeasonsToGoBack.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2GetByListParam.NumSeasonsToGoBack. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of Ranking2GetByListParam +func (rgblp *Ranking2GetByListParam) Copy() types.RVType { + copied := NewRanking2GetByListParam() + + copied.StructureVersion = rgblp.StructureVersion + copied.Category = rgblp.Category.Copy().(*types.PrimitiveU32) + copied.Offset = rgblp.Offset.Copy().(*types.PrimitiveU32) + copied.Length = rgblp.Length.Copy().(*types.PrimitiveU32) + copied.SortFlags = rgblp.SortFlags.Copy().(*types.PrimitiveU32) + copied.OptionFlags = rgblp.OptionFlags.Copy().(*types.PrimitiveU32) + copied.NumSeasonsToGoBack = rgblp.NumSeasonsToGoBack.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given Ranking2GetByListParam contains the same data as the current Ranking2GetByListParam +func (rgblp *Ranking2GetByListParam) Equals(o types.RVType) bool { + if _, ok := o.(*Ranking2GetByListParam); !ok { + return false + } + + other := o.(*Ranking2GetByListParam) + + if rgblp.StructureVersion != other.StructureVersion { + return false + } + + if !rgblp.Category.Equals(other.Category) { + return false + } + + if !rgblp.Offset.Equals(other.Offset) { + return false + } + + if !rgblp.Length.Equals(other.Length) { + return false + } + + if !rgblp.SortFlags.Equals(other.SortFlags) { + return false + } + + if !rgblp.OptionFlags.Equals(other.OptionFlags) { + return false + } + + return rgblp.NumSeasonsToGoBack.Equals(other.NumSeasonsToGoBack) +} + +// String returns the string representation of the Ranking2GetByListParam +func (rgblp *Ranking2GetByListParam) String() string { + return rgblp.FormatToString(0) +} + +// FormatToString pretty-prints the Ranking2GetByListParam using the provided indentation level +func (rgblp *Ranking2GetByListParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("Ranking2GetByListParam{\n") + b.WriteString(fmt.Sprintf("%sCategory: %s,\n", indentationValues, rgblp.Category)) + b.WriteString(fmt.Sprintf("%sOffset: %s,\n", indentationValues, rgblp.Offset)) + b.WriteString(fmt.Sprintf("%sLength: %s,\n", indentationValues, rgblp.Length)) + b.WriteString(fmt.Sprintf("%sSortFlags: %s,\n", indentationValues, rgblp.SortFlags)) + b.WriteString(fmt.Sprintf("%sOptionFlags: %s,\n", indentationValues, rgblp.OptionFlags)) + b.WriteString(fmt.Sprintf("%sNumSeasonsToGoBack: %s,\n", indentationValues, rgblp.NumSeasonsToGoBack)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRanking2GetByListParam returns a new Ranking2GetByListParam +func NewRanking2GetByListParam() *Ranking2GetByListParam { + rgblp := &Ranking2GetByListParam{ + Category: types.NewPrimitiveU32(0), + Offset: types.NewPrimitiveU32(0), + Length: types.NewPrimitiveU32(0), + SortFlags: types.NewPrimitiveU32(0), + OptionFlags: types.NewPrimitiveU32(0), + NumSeasonsToGoBack: types.NewPrimitiveU8(0), + } + + return rgblp +} diff --git a/nex-protocols-go/ranking2/types/ranking2_get_param.go b/nex-protocols-go/ranking2/types/ranking2_get_param.go new file mode 100644 index 0000000..6a3664a --- /dev/null +++ b/nex-protocols-go/ranking2/types/ranking2_get_param.go @@ -0,0 +1,210 @@ +// Package types implements all the types used by the Ranking2 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// Ranking2GetParam is a type within the Ranking2 protocol +type Ranking2GetParam struct { + types.Structure + NexUniqueID *types.PrimitiveU64 + PrincipalID *types.PID + Category *types.PrimitiveU32 + Offset *types.PrimitiveU32 + Length *types.PrimitiveU32 + SortFlags *types.PrimitiveU32 + OptionFlags *types.PrimitiveU32 + Mode *types.PrimitiveU8 + NumSeasonsToGoBack *types.PrimitiveU8 +} + +// WriteTo writes the Ranking2GetParam to the given writable +func (rgp *Ranking2GetParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + rgp.NexUniqueID.WriteTo(contentWritable) + rgp.PrincipalID.WriteTo(contentWritable) + rgp.Category.WriteTo(contentWritable) + rgp.Offset.WriteTo(contentWritable) + rgp.Length.WriteTo(contentWritable) + rgp.SortFlags.WriteTo(contentWritable) + rgp.OptionFlags.WriteTo(contentWritable) + rgp.Mode.WriteTo(contentWritable) + rgp.NumSeasonsToGoBack.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + rgp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the Ranking2GetParam from the given readable +func (rgp *Ranking2GetParam) ExtractFrom(readable types.Readable) error { + var err error + + err = rgp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2GetParam header. %s", err.Error()) + } + + err = rgp.NexUniqueID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2GetParam.NexUniqueID. %s", err.Error()) + } + + err = rgp.PrincipalID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2GetParam.PrincipalID. %s", err.Error()) + } + + err = rgp.Category.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2GetParam.Category. %s", err.Error()) + } + + err = rgp.Offset.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2GetParam.Offset. %s", err.Error()) + } + + err = rgp.Length.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2GetParam.Length. %s", err.Error()) + } + + err = rgp.SortFlags.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2GetParam.SortFlags. %s", err.Error()) + } + + err = rgp.OptionFlags.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2GetParam.OptionFlags. %s", err.Error()) + } + + err = rgp.Mode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2GetParam.Mode. %s", err.Error()) + } + + err = rgp.NumSeasonsToGoBack.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2GetParam.NumSeasonsToGoBack. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of Ranking2GetParam +func (rgp *Ranking2GetParam) Copy() types.RVType { + copied := NewRanking2GetParam() + + copied.StructureVersion = rgp.StructureVersion + copied.NexUniqueID = rgp.NexUniqueID.Copy().(*types.PrimitiveU64) + copied.PrincipalID = rgp.PrincipalID.Copy().(*types.PID) + copied.Category = rgp.Category.Copy().(*types.PrimitiveU32) + copied.Offset = rgp.Offset.Copy().(*types.PrimitiveU32) + copied.Length = rgp.Length.Copy().(*types.PrimitiveU32) + copied.SortFlags = rgp.SortFlags.Copy().(*types.PrimitiveU32) + copied.OptionFlags = rgp.OptionFlags.Copy().(*types.PrimitiveU32) + copied.Mode = rgp.Mode.Copy().(*types.PrimitiveU8) + copied.NumSeasonsToGoBack = rgp.NumSeasonsToGoBack.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given Ranking2GetParam contains the same data as the current Ranking2GetParam +func (rgp *Ranking2GetParam) Equals(o types.RVType) bool { + if _, ok := o.(*Ranking2GetParam); !ok { + return false + } + + other := o.(*Ranking2GetParam) + + if rgp.StructureVersion != other.StructureVersion { + return false + } + + if !rgp.NexUniqueID.Equals(other.NexUniqueID) { + return false + } + + if !rgp.PrincipalID.Equals(other.PrincipalID) { + return false + } + + if !rgp.Category.Equals(other.Category) { + return false + } + + if !rgp.Offset.Equals(other.Offset) { + return false + } + + if !rgp.Length.Equals(other.Length) { + return false + } + + if !rgp.SortFlags.Equals(other.SortFlags) { + return false + } + + if !rgp.OptionFlags.Equals(other.OptionFlags) { + return false + } + + if !rgp.Mode.Equals(other.Mode) { + return false + } + + return rgp.NumSeasonsToGoBack.Equals(other.NumSeasonsToGoBack) +} + +// String returns the string representation of the Ranking2GetParam +func (rgp *Ranking2GetParam) String() string { + return rgp.FormatToString(0) +} + +// FormatToString pretty-prints the Ranking2GetParam using the provided indentation level +func (rgp *Ranking2GetParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("Ranking2GetParam{\n") + b.WriteString(fmt.Sprintf("%sNexUniqueID: %s,\n", indentationValues, rgp.NexUniqueID)) + b.WriteString(fmt.Sprintf("%sPrincipalID: %s,\n", indentationValues, rgp.PrincipalID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sCategory: %s,\n", indentationValues, rgp.Category)) + b.WriteString(fmt.Sprintf("%sOffset: %s,\n", indentationValues, rgp.Offset)) + b.WriteString(fmt.Sprintf("%sLength: %s,\n", indentationValues, rgp.Length)) + b.WriteString(fmt.Sprintf("%sSortFlags: %s,\n", indentationValues, rgp.SortFlags)) + b.WriteString(fmt.Sprintf("%sOptionFlags: %s,\n", indentationValues, rgp.OptionFlags)) + b.WriteString(fmt.Sprintf("%sMode: %s,\n", indentationValues, rgp.Mode)) + b.WriteString(fmt.Sprintf("%sNumSeasonsToGoBack: %s,\n", indentationValues, rgp.NumSeasonsToGoBack)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRanking2GetParam returns a new Ranking2GetParam +func NewRanking2GetParam() *Ranking2GetParam { + rgp := &Ranking2GetParam{ + NexUniqueID: types.NewPrimitiveU64(0), + PrincipalID: types.NewPID(0), + Category: types.NewPrimitiveU32(0), + Offset: types.NewPrimitiveU32(0), + Length: types.NewPrimitiveU32(0), + SortFlags: types.NewPrimitiveU32(0), + OptionFlags: types.NewPrimitiveU32(0), + Mode: types.NewPrimitiveU8(0), + NumSeasonsToGoBack: types.NewPrimitiveU8(0), + } + + return rgp +} diff --git a/nex-protocols-go/ranking2/types/ranking2_info.go b/nex-protocols-go/ranking2/types/ranking2_info.go new file mode 100644 index 0000000..4b0b889 --- /dev/null +++ b/nex-protocols-go/ranking2/types/ranking2_info.go @@ -0,0 +1,142 @@ +// Package types implements all the types used by the Ranking2 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// Ranking2Info is a type within the Ranking2 protocol +type Ranking2Info struct { + types.Structure + RankDataList *types.List[*Ranking2RankData] + LowestRank *types.PrimitiveU32 + NumRankedIn *types.PrimitiveU32 + Season *types.PrimitiveS32 +} + +// WriteTo writes the Ranking2Info to the given writable +func (ri *Ranking2Info) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + ri.RankDataList.WriteTo(contentWritable) + ri.LowestRank.WriteTo(contentWritable) + ri.NumRankedIn.WriteTo(contentWritable) + ri.Season.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + ri.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the Ranking2Info from the given readable +func (ri *Ranking2Info) ExtractFrom(readable types.Readable) error { + var err error + + err = ri.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2Info header. %s", err.Error()) + } + + err = ri.RankDataList.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2Info.RankDataList. %s", err.Error()) + } + + err = ri.LowestRank.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2Info.LowestRank. %s", err.Error()) + } + + err = ri.NumRankedIn.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2Info.NumRankedIn. %s", err.Error()) + } + + err = ri.Season.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2Info.Season. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of Ranking2Info +func (ri *Ranking2Info) Copy() types.RVType { + copied := NewRanking2Info() + + copied.StructureVersion = ri.StructureVersion + copied.RankDataList = ri.RankDataList.Copy().(*types.List[*Ranking2RankData]) + copied.LowestRank = ri.LowestRank.Copy().(*types.PrimitiveU32) + copied.NumRankedIn = ri.NumRankedIn.Copy().(*types.PrimitiveU32) + copied.Season = ri.Season.Copy().(*types.PrimitiveS32) + + return copied +} + +// Equals checks if the given Ranking2Info contains the same data as the current Ranking2Info +func (ri *Ranking2Info) Equals(o types.RVType) bool { + if _, ok := o.(*Ranking2Info); !ok { + return false + } + + other := o.(*Ranking2Info) + + if ri.StructureVersion != other.StructureVersion { + return false + } + + if !ri.RankDataList.Equals(other.RankDataList) { + return false + } + + if !ri.LowestRank.Equals(other.LowestRank) { + return false + } + + if !ri.NumRankedIn.Equals(other.NumRankedIn) { + return false + } + + return ri.Season.Equals(other.Season) +} + +// String returns the string representation of the Ranking2Info +func (ri *Ranking2Info) String() string { + return ri.FormatToString(0) +} + +// FormatToString pretty-prints the Ranking2Info using the provided indentation level +func (ri *Ranking2Info) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("Ranking2Info{\n") + b.WriteString(fmt.Sprintf("%sRankDataList: %s,\n", indentationValues, ri.RankDataList)) + b.WriteString(fmt.Sprintf("%sLowestRank: %s,\n", indentationValues, ri.LowestRank)) + b.WriteString(fmt.Sprintf("%sNumRankedIn: %s,\n", indentationValues, ri.NumRankedIn)) + b.WriteString(fmt.Sprintf("%sSeason: %s,\n", indentationValues, ri.Season)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRanking2Info returns a new Ranking2Info +func NewRanking2Info() *Ranking2Info { + ri := &Ranking2Info{ + RankDataList: types.NewList[*Ranking2RankData](), + LowestRank: types.NewPrimitiveU32(0), + NumRankedIn: types.NewPrimitiveU32(0), + Season: types.NewPrimitiveS32(0), + } + + ri.RankDataList.Type = NewRanking2RankData() + + return ri +} diff --git a/nex-protocols-go/ranking2/types/ranking2_rank_data.go b/nex-protocols-go/ranking2/types/ranking2_rank_data.go new file mode 100644 index 0000000..46f3521 --- /dev/null +++ b/nex-protocols-go/ranking2/types/ranking2_rank_data.go @@ -0,0 +1,168 @@ +// Package types implements all the types used by the Ranking2 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// Ranking2RankData is a type within the Ranking2 protocol +type Ranking2RankData struct { + types.Structure + Misc *types.PrimitiveU64 + NexUniqueID *types.PrimitiveU64 + PrincipalID *types.PID + Rank *types.PrimitiveU32 + Score *types.PrimitiveU32 + CommonData *Ranking2CommonData +} + +// WriteTo writes the Ranking2RankData to the given writable +func (rrd *Ranking2RankData) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + rrd.Misc.WriteTo(contentWritable) + rrd.NexUniqueID.WriteTo(contentWritable) + rrd.PrincipalID.WriteTo(contentWritable) + rrd.Rank.WriteTo(contentWritable) + rrd.Score.WriteTo(contentWritable) + rrd.CommonData.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + rrd.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the Ranking2RankData from the given readable +func (rrd *Ranking2RankData) ExtractFrom(readable types.Readable) error { + var err error + + err = rrd.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2RankData header. %s", err.Error()) + } + + err = rrd.Misc.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2RankData.Misc. %s", err.Error()) + } + + err = rrd.NexUniqueID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2RankData.NexUniqueID. %s", err.Error()) + } + + err = rrd.PrincipalID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2RankData.PrincipalID. %s", err.Error()) + } + + err = rrd.Rank.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2RankData.Rank. %s", err.Error()) + } + + err = rrd.Score.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2RankData.Score. %s", err.Error()) + } + + err = rrd.CommonData.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2RankData.CommonData. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of Ranking2RankData +func (rrd *Ranking2RankData) Copy() types.RVType { + copied := NewRanking2RankData() + + copied.StructureVersion = rrd.StructureVersion + copied.Misc = rrd.Misc.Copy().(*types.PrimitiveU64) + copied.NexUniqueID = rrd.NexUniqueID.Copy().(*types.PrimitiveU64) + copied.PrincipalID = rrd.PrincipalID.Copy().(*types.PID) + copied.Rank = rrd.Rank.Copy().(*types.PrimitiveU32) + copied.Score = rrd.Score.Copy().(*types.PrimitiveU32) + copied.CommonData = rrd.CommonData.Copy().(*Ranking2CommonData) + + return copied +} + +// Equals checks if the given Ranking2RankData contains the same data as the current Ranking2RankData +func (rrd *Ranking2RankData) Equals(o types.RVType) bool { + if _, ok := o.(*Ranking2RankData); !ok { + return false + } + + other := o.(*Ranking2RankData) + + if rrd.StructureVersion != other.StructureVersion { + return false + } + + if !rrd.Misc.Equals(other.Misc) { + return false + } + + if !rrd.NexUniqueID.Equals(other.NexUniqueID) { + return false + } + + if !rrd.PrincipalID.Equals(other.PrincipalID) { + return false + } + + if !rrd.Rank.Equals(other.Rank) { + return false + } + + if !rrd.Score.Equals(other.Score) { + return false + } + + return rrd.CommonData.Equals(other.CommonData) +} + +// String returns the string representation of the Ranking2RankData +func (rrd *Ranking2RankData) String() string { + return rrd.FormatToString(0) +} + +// FormatToString pretty-prints the Ranking2RankData using the provided indentation level +func (rrd *Ranking2RankData) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("Ranking2RankData{\n") + b.WriteString(fmt.Sprintf("%sMisc: %s,\n", indentationValues, rrd.Misc)) + b.WriteString(fmt.Sprintf("%sNexUniqueID: %s,\n", indentationValues, rrd.NexUniqueID)) + b.WriteString(fmt.Sprintf("%sPrincipalID: %s,\n", indentationValues, rrd.PrincipalID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sRank: %s,\n", indentationValues, rrd.Rank)) + b.WriteString(fmt.Sprintf("%sScore: %s,\n", indentationValues, rrd.Score)) + b.WriteString(fmt.Sprintf("%sCommonData: %s,\n", indentationValues, rrd.CommonData.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRanking2RankData returns a new Ranking2RankData +func NewRanking2RankData() *Ranking2RankData { + rrd := &Ranking2RankData{ + Misc: types.NewPrimitiveU64(0), + NexUniqueID: types.NewPrimitiveU64(0), + PrincipalID: types.NewPID(0), + Rank: types.NewPrimitiveU32(0), + Score: types.NewPrimitiveU32(0), + CommonData: NewRanking2CommonData(), + } + + return rrd +} diff --git a/nex-protocols-go/ranking2/types/ranking2_score_data.go b/nex-protocols-go/ranking2/types/ranking2_score_data.go new file mode 100644 index 0000000..f114509 --- /dev/null +++ b/nex-protocols-go/ranking2/types/ranking2_score_data.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the Ranking2 protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// Ranking2ScoreData is a type within the Ranking2 protocol +type Ranking2ScoreData struct { + types.Structure + Misc *types.PrimitiveU64 + Category *types.PrimitiveU32 + Score *types.PrimitiveU32 +} + +// WriteTo writes the Ranking2ScoreData to the given writable +func (rsd *Ranking2ScoreData) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + rsd.Misc.WriteTo(contentWritable) + rsd.Category.WriteTo(contentWritable) + rsd.Score.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + rsd.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the Ranking2ScoreData from the given readable +func (rsd *Ranking2ScoreData) ExtractFrom(readable types.Readable) error { + var err error + + err = rsd.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ScoreData header. %s", err.Error()) + } + + err = rsd.Misc.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ScoreData.Misc. %s", err.Error()) + } + + err = rsd.Category.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ScoreData.Category. %s", err.Error()) + } + + err = rsd.Score.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Ranking2ScoreData.Score. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of Ranking2ScoreData +func (rsd *Ranking2ScoreData) Copy() types.RVType { + copied := NewRanking2ScoreData() + + copied.StructureVersion = rsd.StructureVersion + copied.Misc = rsd.Misc.Copy().(*types.PrimitiveU64) + copied.Category = rsd.Category.Copy().(*types.PrimitiveU32) + copied.Score = rsd.Score.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given Ranking2ScoreData contains the same data as the current Ranking2ScoreData +func (rsd *Ranking2ScoreData) Equals(o types.RVType) bool { + if _, ok := o.(*Ranking2ScoreData); !ok { + return false + } + + other := o.(*Ranking2ScoreData) + + if rsd.StructureVersion != other.StructureVersion { + return false + } + + if !rsd.Misc.Equals(other.Misc) { + return false + } + + if !rsd.Category.Equals(other.Category) { + return false + } + + return rsd.Score.Equals(other.Score) +} + +// String returns the string representation of the Ranking2ScoreData +func (rsd *Ranking2ScoreData) String() string { + return rsd.FormatToString(0) +} + +// FormatToString pretty-prints the Ranking2ScoreData using the provided indentation level +func (rsd *Ranking2ScoreData) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("Ranking2ScoreData{\n") + b.WriteString(fmt.Sprintf("%sMisc: %s,\n", indentationValues, rsd.Misc)) + b.WriteString(fmt.Sprintf("%sCategory: %s,\n", indentationValues, rsd.Category)) + b.WriteString(fmt.Sprintf("%sScore: %s,\n", indentationValues, rsd.Score)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewRanking2ScoreData returns a new Ranking2ScoreData +func NewRanking2ScoreData() *Ranking2ScoreData { + rsd := &Ranking2ScoreData{ + Misc: types.NewPrimitiveU64(0), + Category: types.NewPrimitiveU32(0), + Score: types.NewPrimitiveU32(0), + } + + return rsd +} diff --git a/nex-protocols-go/remote-log-device/log.go b/nex-protocols-go/remote-log-device/log.go new file mode 100644 index 0000000..d11248a --- /dev/null +++ b/nex-protocols-go/remote-log-device/log.go @@ -0,0 +1,47 @@ +// Package protocol implements the Remote Log Device protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleLog(packet nex.PacketInterface) { + if protocol.Log == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "RemoteLogDevice::Log not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strLine := types.NewString("") + + err := strLine.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.Log(fmt.Errorf("Failed to read strLine from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.Log(nil, packet, callID, strLine) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/remote-log-device/protocol.go b/nex-protocols-go/remote-log-device/protocol.go new file mode 100644 index 0000000..f010b49 --- /dev/null +++ b/nex-protocols-go/remote-log-device/protocol.go @@ -0,0 +1,79 @@ +// Package protocol implements the Remote Log Device protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the RemoteLogDevice protocol + ProtocolID = 0x1 + + // MethodLog is the method ID for the method Log + MethodLog = 0x1 +) + +// Protocol handles the RemoteLogDevice protocol +type Protocol struct { + endpoint nex.EndpointInterface + Log func(err error, packet nex.PacketInterface, callID uint32, strLine *types.String) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Remote Log Device protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerLog(handler func(err error, packet nex.PacketInterface, callID uint32, strLine *types.String) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerLog sets the handler for the Log method +func (protocol *Protocol) SetHandlerLog(handler func(err error, packet nex.PacketInterface, callID uint32, strLine *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.Log = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodLog: + protocol.handleLog(packet) + default: + errMessage := fmt.Sprintf("Unsupported RemoteLogDevice method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Remote Log Device protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/screening/protocol.go b/nex-protocols-go/screening/protocol.go new file mode 100644 index 0000000..2dca4d5 --- /dev/null +++ b/nex-protocols-go/screening/protocol.go @@ -0,0 +1,90 @@ +// Package protocol implements the Screening protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the Screening protocol + ProtocolID = 0x7C + + // MethodReportDataStoreContent is the method ID for the method ReportDataStoreContent + MethodReportDataStoreContent = 0x1 + + // MethodReportUser is the method ID for the method ReportUser + MethodReportUser = 0x2 +) + +// Protocol handles the Screening protocol +type Protocol struct { + endpoint nex.EndpointInterface + ReportDataStoreContent func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) // TODO - Unknown request/response format + ReportUser func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) // TODO - Unknown request/response format + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Screening protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerReportDataStoreContent(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) + SetHandlerReportUser(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerReportDataStoreContent sets the handler for the ReportDataStoreContent method +func (protocol *Protocol) SetHandlerReportDataStoreContent(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) { + protocol.ReportDataStoreContent = handler +} + +// SetHandlerReportUser sets the handler for the ReportUser method +func (protocol *Protocol) SetHandlerReportUser(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) { + protocol.ReportUser = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodReportDataStoreContent: + protocol.handleReportDataStoreContent(packet) + case MethodReportUser: + protocol.handleReportUser(packet) + default: + errMessage := fmt.Sprintf("Unsupported Screening method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Screening protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/screening/report_datastore_content.go b/nex-protocols-go/screening/report_datastore_content.go new file mode 100644 index 0000000..d75a321 --- /dev/null +++ b/nex-protocols-go/screening/report_datastore_content.go @@ -0,0 +1,31 @@ +// Package protocol implements the Screening protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleReportDataStoreContent(packet nex.PacketInterface) { + if protocol.ReportDataStoreContent == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Screening::ReportDataStoreContent not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("Screening::ReportDataStoreContent STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.ReportDataStoreContent(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/screening/report_user.go b/nex-protocols-go/screening/report_user.go new file mode 100644 index 0000000..2f7f191 --- /dev/null +++ b/nex-protocols-go/screening/report_user.go @@ -0,0 +1,31 @@ +// Package protocol implements the Screening protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleReportUser(packet nex.PacketInterface) { + if protocol.ReportUser == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Screening::ReportUser not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("Screening::ReportUser STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.ReportUser(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/secure-connection/nintendo-badge-arcade/get_maintenance_status.go b/nex-protocols-go/secure-connection/nintendo-badge-arcade/get_maintenance_status.go new file mode 100644 index 0000000..a31ff52 --- /dev/null +++ b/nex-protocols-go/secure-connection/nintendo-badge-arcade/get_maintenance_status.go @@ -0,0 +1,29 @@ +// Package protocol implements the Nintendo Badge Arcade Secure Connection protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetMaintenanceStatus(packet nex.PacketInterface) { + if protocol.GetMaintenanceStatus == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "SecureConnectionNintendoBadgeArcade::GetMaintenanceStatus not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetMaintenanceStatus(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/secure-connection/nintendo-badge-arcade/protocol.go b/nex-protocols-go/secure-connection/nintendo-badge-arcade/protocol.go new file mode 100644 index 0000000..35b629d --- /dev/null +++ b/nex-protocols-go/secure-connection/nintendo-badge-arcade/protocol.go @@ -0,0 +1,66 @@ +// Package protocol implements the Nintendo Badge Arcade Secure Connection protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + secure_connection "github.com/PretendoNetwork/nex-protocols-go/v2/secure-connection" + "golang.org/x/exp/slices" +) + +const ( + // ProtocolID is the protocol ID for the Secure Connection (Nintendo Badge Arcade) protocol. ID is the same as the Secure Connection Protocol + ProtocolID = 0xB + + // MethodGetMaintenanceStatus is the method ID for GetMaintenanceStatus + MethodGetMaintenanceStatus = 0x9 +) + +var patchedMethods = []uint32{ + MethodGetMaintenanceStatus, +} + +type secureConnectionProtocol = secure_connection.Protocol + +// Protocol stores all the RMC method handlers for the Secure Connection (Nintendo Badge Arcade) protocol and listens for requests +// Embeds the SecureConnection Protocol +type Protocol struct { + endpoint nex.EndpointInterface + secureConnectionProtocol + GetMaintenanceStatus func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if !slices.Contains(patchedMethods, message.MethodID) { + protocol.secureConnectionProtocol.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodGetMaintenanceStatus: + protocol.handleGetMaintenanceStatus(packet) + default: + errMessage := fmt.Sprintf("Unsupported SecureConnectionNintendoBadgeArcade method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Secure Connection (Nintendo Badge Arcade) protocol +func NewProtocol(endpoint nex.EndpointInterface) *Protocol { + protocol := &Protocol{endpoint: endpoint} + protocol.secureConnectionProtocol.SetEndpoint(endpoint) + + return protocol +} diff --git a/nex-protocols-go/secure-connection/protocol.go b/nex-protocols-go/secure-connection/protocol.go new file mode 100644 index 0000000..5de7e79 --- /dev/null +++ b/nex-protocols-go/secure-connection/protocol.go @@ -0,0 +1,163 @@ +// Package protocol implements the Secure Connection protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the Secure Connection protocol + ProtocolID = 0xB + + // MethodRegister is the method ID for the method Register + MethodRegister = 0x1 + + // MethodRequestConnectionData is the method ID for the method RequestConnectionData + MethodRequestConnectionData = 0x2 + + // MethodRequestURLs is the method ID for the method RequestURLs + MethodRequestURLs = 0x3 + + // MethodRegisterEx is the method ID for the method RegisterEx + MethodRegisterEx = 0x4 + + // MethodTestConnectivity is the method ID for the method TestConnectivity + MethodTestConnectivity = 0x5 + + // MethodUpdateURLs is the method ID for the method UpdateURLs + MethodUpdateURLs = 0x6 + + // MethodReplaceURL is the method ID for the method ReplaceURL + MethodReplaceURL = 0x7 + + // MethodSendReport is the method ID for the method SendReport + MethodSendReport = 0x8 +) + +// Protocol stores all the RMC method handlers for the Secure Connection protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + Register func(err error, packet nex.PacketInterface, callID uint32, vecMyURLs *types.List[*types.StationURL]) (*nex.RMCMessage, *nex.Error) + RequestConnectionData func(err error, packet nex.PacketInterface, callID uint32, cidTarget *types.PrimitiveU32, pidTarget *types.PID) (*nex.RMCMessage, *nex.Error) + RequestURLs func(err error, packet nex.PacketInterface, callID uint32, cidTarget *types.PrimitiveU32, pidTarget *types.PID) (*nex.RMCMessage, *nex.Error) + RegisterEx func(err error, packet nex.PacketInterface, callID uint32, vecMyURLs *types.List[*types.StationURL], hCustomData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error) + TestConnectivity func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + UpdateURLs func(err error, packet nex.PacketInterface, callID uint32, vecMyURLs *types.List[*types.StationURL]) (*nex.RMCMessage, *nex.Error) + ReplaceURL func(err error, packet nex.PacketInterface, callID uint32, target *types.StationURL, url *types.StationURL) (*nex.RMCMessage, *nex.Error) + SendReport func(err error, packet nex.PacketInterface, callID uint32, reportID *types.PrimitiveU32, reportData *types.QBuffer) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Secure Connection protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerRegister(handler func(err error, packet nex.PacketInterface, callID uint32, vecMyURLs *types.List[*types.StationURL]) (*nex.RMCMessage, *nex.Error)) + SetHandlerRequestConnectionData(handler func(err error, packet nex.PacketInterface, callID uint32, cidTarget *types.PrimitiveU32, pidTarget *types.PID) (*nex.RMCMessage, *nex.Error)) + SetHandlerRequestURLs(handler func(err error, packet nex.PacketInterface, callID uint32, cidTarget *types.PrimitiveU32, pidTarget *types.PID) (*nex.RMCMessage, *nex.Error)) + SetHandlerRegisterEx(handler func(err error, packet nex.PacketInterface, callID uint32, vecMyURLs *types.List[*types.StationURL], hCustomData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) + SetHandlerTestConnectivity(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateURLs(handler func(err error, packet nex.PacketInterface, callID uint32, vecMyURLs *types.List[*types.StationURL]) (*nex.RMCMessage, *nex.Error)) + SetHandlerReplaceURL(handler func(err error, packet nex.PacketInterface, callID uint32, target *types.StationURL, url *types.StationURL) (*nex.RMCMessage, *nex.Error)) + SetHandlerSendReport(handler func(err error, packet nex.PacketInterface, callID uint32, reportID *types.PrimitiveU32, reportData *types.QBuffer) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerRegister sets the handler for the Register method +func (protocol *Protocol) SetHandlerRegister(handler func(err error, packet nex.PacketInterface, callID uint32, vecMyURLs *types.List[*types.StationURL]) (*nex.RMCMessage, *nex.Error)) { + protocol.Register = handler +} + +// SetHandlerRequestConnectionData sets the handler for the RequestConnectionData method +func (protocol *Protocol) SetHandlerRequestConnectionData(handler func(err error, packet nex.PacketInterface, callID uint32, cidTarget *types.PrimitiveU32, pidTarget *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.RequestConnectionData = handler +} + +// SetHandlerRequestURLs sets the handler for the RequestURLs method +func (protocol *Protocol) SetHandlerRequestURLs(handler func(err error, packet nex.PacketInterface, callID uint32, cidTarget *types.PrimitiveU32, pidTarget *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.RequestURLs = handler +} + +// SetHandlerRegisterEx sets the handler for the RegisterEx method +func (protocol *Protocol) SetHandlerRegisterEx(handler func(err error, packet nex.PacketInterface, callID uint32, vecMyURLs *types.List[*types.StationURL], hCustomData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) { + protocol.RegisterEx = handler +} + +// SetHandlerTestConnectivity sets the handler for the TestConnectivity method +func (protocol *Protocol) SetHandlerTestConnectivity(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.TestConnectivity = handler +} + +// SetHandlerUpdateURLs sets the handler for the UpdateURLs method +func (protocol *Protocol) SetHandlerUpdateURLs(handler func(err error, packet nex.PacketInterface, callID uint32, vecMyURLs *types.List[*types.StationURL]) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateURLs = handler +} + +// SetHandlerReplaceURL sets the handler for the ReplaceURL method +func (protocol *Protocol) SetHandlerReplaceURL(handler func(err error, packet nex.PacketInterface, callID uint32, target *types.StationURL, url *types.StationURL) (*nex.RMCMessage, *nex.Error)) { + protocol.ReplaceURL = handler +} + +// SetHandlerSendReport sets the handler for the SendReport method +func (protocol *Protocol) SetHandlerSendReport(handler func(err error, packet nex.PacketInterface, callID uint32, reportID *types.PrimitiveU32, reportData *types.QBuffer) (*nex.RMCMessage, *nex.Error)) { + protocol.SendReport = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodRegister: + protocol.handleRegister(packet) + case MethodRequestConnectionData: + protocol.handleRequestConnectionData(packet) + case MethodRequestURLs: + protocol.handleRequestURLs(packet) + case MethodRegisterEx: + protocol.handleRegisterEx(packet) + case MethodTestConnectivity: + protocol.handleTestConnectivity(packet) + case MethodUpdateURLs: + protocol.handleUpdateURLs(packet) + case MethodReplaceURL: + protocol.handleReplaceURL(packet) + case MethodSendReport: + protocol.handleSendReport(packet) + default: + errMessage := fmt.Sprintf("Unsupported SecureConnection method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Secure Connection protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/secure-connection/register.go b/nex-protocols-go/secure-connection/register.go new file mode 100644 index 0000000..fbc8069 --- /dev/null +++ b/nex-protocols-go/secure-connection/register.go @@ -0,0 +1,48 @@ +// Package protocol implements the Secure Connection protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRegister(packet nex.PacketInterface) { + if protocol.Register == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "SecureConnection::Register not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + vecMyURLs := types.NewList[*types.StationURL]() + vecMyURLs.Type = types.NewStationURL("") + + err := vecMyURLs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.Register(fmt.Errorf("Failed to read vecMyURLs from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.Register(nil, packet, callID, vecMyURLs) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/secure-connection/register_ex.go b/nex-protocols-go/secure-connection/register_ex.go new file mode 100644 index 0000000..c7cb73d --- /dev/null +++ b/nex-protocols-go/secure-connection/register_ex.go @@ -0,0 +1,61 @@ +// Package protocol implements the Secure Connection protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRegisterEx(packet nex.PacketInterface) { + if protocol.RegisterEx == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "SecureConnection::RegisterEx not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + vecMyURLs := types.NewList[*types.StationURL]() + vecMyURLs.Type = types.NewStationURL("") + hCustomData := types.NewAnyDataHolder() + + var err error + + err = vecMyURLs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RegisterEx(fmt.Errorf("Failed to read vecMyURLs from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = hCustomData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RegisterEx(fmt.Errorf("Failed to read hCustomData from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RegisterEx(nil, packet, callID, vecMyURLs, hCustomData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/secure-connection/replace_url.go b/nex-protocols-go/secure-connection/replace_url.go new file mode 100644 index 0000000..1cddb89 --- /dev/null +++ b/nex-protocols-go/secure-connection/replace_url.go @@ -0,0 +1,60 @@ +// Package protocol implements the Secure Connection protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleReplaceURL(packet nex.PacketInterface) { + if protocol.ReplaceURL == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "SecureConnection::ReplaceURL not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + target := types.NewStationURL("") + url := types.NewStationURL("") + + var err error + + err = target.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReplaceURL(fmt.Errorf("Failed to read target from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = url.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ReplaceURL(fmt.Errorf("Failed to read url from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ReplaceURL(nil, packet, callID, target, url) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/secure-connection/request_connection_data.go b/nex-protocols-go/secure-connection/request_connection_data.go new file mode 100644 index 0000000..485023a --- /dev/null +++ b/nex-protocols-go/secure-connection/request_connection_data.go @@ -0,0 +1,60 @@ +// Package protocol implements the Secure Connection protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRequestConnectionData(packet nex.PacketInterface) { + if protocol.RequestConnectionData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "SecureConnection::RequestConnectionData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + cidTarget := types.NewPrimitiveU32(0) + pidTarget := types.NewPID(0) + + var err error + + err = cidTarget.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RequestConnectionData(fmt.Errorf("Failed to read cidTarget from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = pidTarget.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RequestConnectionData(fmt.Errorf("Failed to read pidTarget from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RequestConnectionData(nil, packet, callID, cidTarget, pidTarget) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/secure-connection/request_urls.go b/nex-protocols-go/secure-connection/request_urls.go new file mode 100644 index 0000000..0a1e4aa --- /dev/null +++ b/nex-protocols-go/secure-connection/request_urls.go @@ -0,0 +1,60 @@ +// Package protocol implements the Secure Connection protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRequestURLs(packet nex.PacketInterface) { + if protocol.RequestURLs == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "SecureConnection::RequestURLs not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + cidTarget := types.NewPrimitiveU32(0) + pidTarget := types.NewPID(0) + + var err error + + err = cidTarget.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RequestURLs(fmt.Errorf("Failed to read cidTarget from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = pidTarget.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RequestURLs(fmt.Errorf("Failed to read pidTarget from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RequestURLs(nil, packet, callID, cidTarget, pidTarget) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/secure-connection/send_report.go b/nex-protocols-go/secure-connection/send_report.go new file mode 100644 index 0000000..7839e95 --- /dev/null +++ b/nex-protocols-go/secure-connection/send_report.go @@ -0,0 +1,60 @@ +// Package protocol implements the Secure Connection protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleSendReport(packet nex.PacketInterface) { + if protocol.SendReport == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "SecureConnection::SendReport not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + reportID := types.NewPrimitiveU32(0) + reportData := types.NewQBuffer(nil) + + var err error + + err = reportID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SendReport(fmt.Errorf("Failed to read reportID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = reportData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SendReport(fmt.Errorf("Failed to read reportData from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SendReport(nil, packet, callID, reportID, reportData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/secure-connection/test_connectivity.go b/nex-protocols-go/secure-connection/test_connectivity.go new file mode 100644 index 0000000..c17019e --- /dev/null +++ b/nex-protocols-go/secure-connection/test_connectivity.go @@ -0,0 +1,29 @@ +// Package protocol implements the Secure Connection protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleTestConnectivity(packet nex.PacketInterface) { + if protocol.TestConnectivity == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "SecureConnection::TestConnectivity not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.TestConnectivity(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/secure-connection/update_urls.go b/nex-protocols-go/secure-connection/update_urls.go new file mode 100644 index 0000000..5f0c943 --- /dev/null +++ b/nex-protocols-go/secure-connection/update_urls.go @@ -0,0 +1,48 @@ +// Package protocol implements the Secure Connection protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateURLs(packet nex.PacketInterface) { + if protocol.UpdateURLs == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "SecureConnection::UpdateURLs not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + vecMyURLs := types.NewList[*types.StationURL]() + vecMyURLs.Type = types.NewStationURL("") + + err := vecMyURLs.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateURLs(fmt.Errorf("Failed to read vecMyURLs from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateURLs(nil, packet, callID, vecMyURLs) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/protocol.go b/nex-protocols-go/service-item/protocol.go new file mode 100644 index 0000000..385efe8 --- /dev/null +++ b/nex-protocols-go/service-item/protocol.go @@ -0,0 +1,57 @@ +// Package protocol implements the Service Item protocol +package protocol + +// TODO - Figure out more about this protocol, unsure if anything here is right + +import ( + "fmt" + "slices" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the Protocol ID for the Service Item protocol + ProtocolID = 0x77 +) + +// Protocol stores all the RMC method handlers for the Service Item protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + default: + errMessage := fmt.Sprintf("Unsupported ServiceItem method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/acquire_service_item_by_account.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/acquire_service_item_by_account.go new file mode 100644 index 0000000..789197a --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/acquire_service_item_by_account.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_team_kirby_clash_deluxe_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/team-kirby-clash-deluxe/types" +) + +func (protocol *Protocol) handleAcquireServiceItemByAccount(packet nex.PacketInterface) { + if protocol.AcquireServiceItemByAccount == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::AcquireServiceItemByAccount not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + acquireServiceItemByAccountParam := service_item_team_kirby_clash_deluxe_types.NewServiceItemAcquireServiceItemByAccountParam() + + err := acquireServiceItemByAccountParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AcquireServiceItemByAccount(fmt.Errorf("Failed to read acquireServiceItemByAccountParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AcquireServiceItemByAccount(nil, packet, callID, acquireServiceItemByAccountParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_balance_request.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_balance_request.go new file mode 100644 index 0000000..528fb25 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_balance_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_team_kirby_clash_deluxe_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/team-kirby-clash-deluxe/types" +) + +func (protocol *Protocol) handleGetBalanceRequest(packet nex.PacketInterface) { + if protocol.GetBalanceRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::GetBalanceRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + getBalanceParam := service_item_team_kirby_clash_deluxe_types.NewServiceItemGetBalanceParam() + + err := getBalanceParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetBalanceRequest(fmt.Errorf("Failed to read getBalanceParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetBalanceRequest(nil, packet, callID, getBalanceParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_balance_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_balance_response.go new file mode 100644 index 0000000..f5e427d --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_balance_response.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetBalanceResponse(packet nex.PacketInterface) { + if protocol.GetBalanceResponse == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::GetBalanceResponse not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestID := types.NewPrimitiveU32(0) + + err := requestID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetBalanceResponse(fmt.Errorf("Failed to read requestID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetBalanceResponse(nil, packet, callID, requestID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_environment.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_environment.go new file mode 100644 index 0000000..cc72474 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_environment.go @@ -0,0 +1,60 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetEnvironment(packet nex.PacketInterface) { + if protocol.GetEnvironment == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::GetEnvironment not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uniqueID := types.NewString("") + platform := types.NewPrimitiveU8(0) + + var err error + + err = uniqueID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetEnvironment(fmt.Errorf("Failed to read uniqueID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = platform.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetEnvironment(fmt.Errorf("Failed to read platform from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetEnvironment(nil, packet, callID, uniqueID, platform) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_law_message_request.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_law_message_request.go new file mode 100644 index 0000000..4f87dee --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_law_message_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_team_kirby_clash_deluxe_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/team-kirby-clash-deluxe/types" +) + +func (protocol *Protocol) handleGetLawMessageRequest(packet nex.PacketInterface) { + if protocol.GetLawMessageRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::GetLawMessageRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + getLawMessageParam := service_item_team_kirby_clash_deluxe_types.NewServiceItemGetLawMessageParam() + + err := getLawMessageParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetLawMessageRequest(fmt.Errorf("Failed to read getLawMessageParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetLawMessageRequest(nil, packet, callID, getLawMessageParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_law_message_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_law_message_response.go new file mode 100644 index 0000000..806c1c4 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_law_message_response.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetLawMessageResponse(packet nex.PacketInterface) { + if protocol.GetLawMessageResponse == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::GetLawMessageResponse not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestID := types.NewPrimitiveU32(0) + + err := requestID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetLawMessageResponse(fmt.Errorf("Failed to read requestID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetLawMessageResponse(nil, packet, callID, requestID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_prepurchase_info_request.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_prepurchase_info_request.go new file mode 100644 index 0000000..ad82ad1 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_prepurchase_info_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_team_kirby_clash_deluxe_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/team-kirby-clash-deluxe/types" +) + +func (protocol *Protocol) handleGetPrepurchaseInfoRequest(packet nex.PacketInterface) { + if protocol.GetPrepurchaseInfoRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::GetPrepurchaseInfoRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + getPrepurchaseInfoParam := service_item_team_kirby_clash_deluxe_types.NewServiceItemGetPrepurchaseInfoParam() + + err := getPrepurchaseInfoParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPrepurchaseInfoRequest(fmt.Errorf("Failed to read getPrepurchaseInfoParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetPrepurchaseInfoRequest(nil, packet, callID, getPrepurchaseInfoParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_prepurchase_info_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_prepurchase_info_response.go new file mode 100644 index 0000000..890a11f --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_prepurchase_info_response.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetPrepurchaseInfoResponse(packet nex.PacketInterface) { + if protocol.GetPrepurchaseInfoResponse == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::GetPrepurchaseInfoResponse not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestID := types.NewPrimitiveU32(0) + + err := requestID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPrepurchaseInfoResponse(fmt.Errorf("Failed to read requestID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetPrepurchaseInfoResponse(nil, packet, callID, requestID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_purchase_history_request.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_purchase_history_request.go new file mode 100644 index 0000000..463a5b9 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_purchase_history_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_team_kirby_clash_deluxe_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/team-kirby-clash-deluxe/types" +) + +func (protocol *Protocol) handleGetPurchaseHistoryRequest(packet nex.PacketInterface) { + if protocol.GetPurchaseHistoryRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::GetPurchaseHistoryRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + getPurchaseHistoryParam := service_item_team_kirby_clash_deluxe_types.NewServiceItemGetPurchaseHistoryParam() + + err := getPurchaseHistoryParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPurchaseHistoryRequest(fmt.Errorf("Failed to read getPurchaseHistoryParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetPurchaseHistoryRequest(nil, packet, callID, getPurchaseHistoryParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_purchase_history_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_purchase_history_response.go new file mode 100644 index 0000000..188422c --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_purchase_history_response.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetPurchaseHistoryResponse(packet nex.PacketInterface) { + if protocol.GetPurchaseHistoryResponse == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::GetPurchaseHistoryResponse not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestID := types.NewPrimitiveU32(0) + + err := requestID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPurchaseHistoryResponse(fmt.Errorf("Failed to read requestID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetPurchaseHistoryResponse(nil, packet, callID, requestID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_service_item_right_request.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_service_item_right_request.go new file mode 100644 index 0000000..00e5439 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_service_item_right_request.go @@ -0,0 +1,61 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_team_kirby_clash_deluxe_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/team-kirby-clash-deluxe/types" +) + +func (protocol *Protocol) handleGetServiceItemRightRequest(packet nex.PacketInterface) { + if protocol.GetServiceItemRightRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::GetServiceItemRightRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + getServiceItemRightParam := service_item_team_kirby_clash_deluxe_types.NewServiceItemGetServiceItemRightParam() + withoutRightBinary := types.NewPrimitiveBool(false) + + var err error + + err = getServiceItemRightParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetServiceItemRightRequest(fmt.Errorf("Failed to read getServiceItemRightParam from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = withoutRightBinary.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetServiceItemRightRequest(fmt.Errorf("Failed to read withoutRightBinary from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetServiceItemRightRequest(nil, packet, callID, getServiceItemRightParam, withoutRightBinary) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_service_item_right_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_service_item_right_response.go new file mode 100644 index 0000000..4e7c558 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_service_item_right_response.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetServiceItemRightResponse(packet nex.PacketInterface) { + if protocol.GetServiceItemRightResponse == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::GetServiceItemRightResponse not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestID := types.NewPrimitiveU32(0) + + err := requestID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetServiceItemRightResponse(fmt.Errorf("Failed to read requestID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetServiceItemRightResponse(nil, packet, callID, requestID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_support_id.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_support_id.go new file mode 100644 index 0000000..6f8c099 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/get_support_id.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_team_kirby_clash_deluxe_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/team-kirby-clash-deluxe/types" +) + +func (protocol *Protocol) handleGetSupportID(packet nex.PacketInterface) { + if protocol.GetSupportID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::GetSupportID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + getSuppordIDParam := service_item_team_kirby_clash_deluxe_types.NewServiceItemGetSupportIDParam() + + err := getSuppordIDParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetSupportID(fmt.Errorf("Failed to read getSuppordIDParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetSupportID(nil, packet, callID, getSuppordIDParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/http_get_request.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/http_get_request.go new file mode 100644 index 0000000..a6d44df --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/http_get_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_team_kirby_clash_deluxe_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/team-kirby-clash-deluxe/types" +) + +func (protocol *Protocol) handleHTTPGetRequest(packet nex.PacketInterface) { + if protocol.HTTPGetRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::HTTPGetRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + url := service_item_team_kirby_clash_deluxe_types.NewServiceItemHTTPGetParam() + + err := url.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.HTTPGetRequest(fmt.Errorf("Failed to read url from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.HTTPGetRequest(nil, packet, callID, url) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/http_get_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/http_get_response.go new file mode 100644 index 0000000..3e79a46 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/http_get_response.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleHTTPGetResponse(packet nex.PacketInterface) { + if protocol.HTTPGetResponse == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::HTTPGetResponse not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestID := types.NewPrimitiveU32(0) + + err := requestID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.HTTPGetResponse(fmt.Errorf("Failed to read requestID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.HTTPGetResponse(nil, packet, callID, requestID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/list_service_item_request.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/list_service_item_request.go new file mode 100644 index 0000000..a207d3b --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/list_service_item_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_team_kirby_clash_deluxe_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/team-kirby-clash-deluxe/types" +) + +func (protocol *Protocol) handleListServiceItemRequest(packet nex.PacketInterface) { + if protocol.ListServiceItemRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::ListServiceItemRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + listServiceItemParam := service_item_team_kirby_clash_deluxe_types.NewServiceItemListServiceItemParam() + + err := listServiceItemParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ListServiceItemRequest(fmt.Errorf("Failed to read listServiceItemParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ListServiceItemRequest(nil, packet, callID, listServiceItemParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/list_service_item_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/list_service_item_response.go new file mode 100644 index 0000000..4d0e84c --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/list_service_item_response.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleListServiceItemResponse(packet nex.PacketInterface) { + if protocol.ListServiceItemResponse == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::ListServiceItemResponse not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestID := types.NewPrimitiveU32(0) + + err := requestID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ListServiceItemResponse(fmt.Errorf("Failed to read requestID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ListServiceItemResponse(nil, packet, callID, requestID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/post_right_binary_by_account.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/post_right_binary_by_account.go new file mode 100644 index 0000000..9636223 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/post_right_binary_by_account.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_team_kirby_clash_deluxe_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/team-kirby-clash-deluxe/types" +) + +func (protocol *Protocol) handlePostRightBinaryByAccount(packet nex.PacketInterface) { + if protocol.PostRightBinaryByAccount == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::PostRightBinaryByAccount not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + postRightBinaryByAccountParam := service_item_team_kirby_clash_deluxe_types.NewServiceItemPostRightBinaryByAccountParam() + + err := postRightBinaryByAccountParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PostRightBinaryByAccount(fmt.Errorf("Failed to read postRightBinaryByAccountParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PostRightBinaryByAccount(nil, packet, callID, postRightBinaryByAccountParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/protocol.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/protocol.go new file mode 100644 index 0000000..007d713 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/protocol.go @@ -0,0 +1,215 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item "github.com/PretendoNetwork/nex-protocols-go/v2/service-item" + service_item_team_kirby_clash_deluxe_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/team-kirby-clash-deluxe/types" + "golang.org/x/exp/slices" +) + +const ( + // ProtocolID is the Protocol ID for the Service Item (Team Kirby Clash Deluxe) protocol + ProtocolID = 0x77 + + // MethodGetEnvironment is the method ID for the GetEnvironment method + MethodGetEnvironment = 0x1 + + // MethodHTTPGetRequest is the method ID for the HTTPGetRequest method + MethodHTTPGetRequest = 0x2 + + // MethodHTTPGetResponse is the method ID for the HTTPGetResponse method + MethodHTTPGetResponse = 0x3 + + // MethodPurchaseServiceItemRequest is the method ID for the PurchaseServiceItemRequest method + MethodPurchaseServiceItemRequest = 0x4 + + // MethodPurchaseServiceItemResponse is the method ID for the PurchaseServiceItemResponse method + MethodPurchaseServiceItemResponse = 0x5 + + // MethodListServiceItemRequest is the method ID for the ListServiceItemRequest method + MethodListServiceItemRequest = 0x6 + + // MethodListServiceItemResponse is the method ID for the ListServiceItemResponse method + MethodListServiceItemResponse = 0x7 + + // MethodGetBalanceRequest is the method ID for the GetBalanceRequest method + MethodGetBalanceRequest = 0x8 + + // MethodGetBalanceResponse is the method ID for the GetBalanceResponse method + MethodGetBalanceResponse = 0x9 + + // MethodGetPrepurchaseInfoRequest is the method ID for the GetPrepurchaseInfoRequest method + MethodGetPrepurchaseInfoRequest = 0xA + + // MethodGetPrepurchaseInfoResponse is the method ID for the GetPrepurchaseInfoResponse method + MethodGetPrepurchaseInfoResponse = 0xB + + // MethodGetServiceItemRightRequest is the method ID for the GetServiceItemRightRequest method + MethodGetServiceItemRightRequest = 0xC + + // MethodGetServiceItemRightResponse is the method ID for the GetServiceItemRightResponse method + MethodGetServiceItemRightResponse = 0xD + + // MethodGetPurchaseHistoryRequest is the method ID for the GetPurchaseHistoryRequest method + MethodGetPurchaseHistoryRequest = 0xE + + // MethodGetPurchaseHistoryResponse is the method ID for the GetPurchaseHistoryResponse method + MethodGetPurchaseHistoryResponse = 0xF + + // MethodPostRightBinaryByAccount is the method ID for the PostRightBinaryByAccount method + MethodPostRightBinaryByAccount = 0x10 + + // MethodUseServiceItemByAccountRequest is the method ID for the UseServiceItemByAccountRequest method + MethodUseServiceItemByAccountRequest = 0x11 + + // MethodUseServiceItemByAccountResponse is the method ID for the UseServiceItemByAccountResponse method + MethodUseServiceItemByAccountResponse = 0x12 + + // MethodAcquireServiceItemByAccount is the method ID for the AcquireServiceItemByAccount method + MethodAcquireServiceItemByAccount = 0x13 + + // MethodGetSupportID is the method ID for the GetSupportID method + MethodGetSupportID = 0x14 + + // MethodGetLawMessageRequest is the method ID for the GetLawMessageRequest method + MethodGetLawMessageRequest = 0x15 + + // MethodGetLawMessageResponse is the method ID for the GetLawMessageResponse method + MethodGetLawMessageResponse = 0x16 +) + +var patchedMethods = []uint32{ + MethodGetEnvironment, + MethodHTTPGetRequest, + MethodHTTPGetResponse, + MethodPurchaseServiceItemRequest, + MethodPurchaseServiceItemResponse, + MethodListServiceItemRequest, + MethodListServiceItemResponse, + MethodGetBalanceRequest, + MethodGetBalanceResponse, + MethodGetPrepurchaseInfoRequest, + MethodGetPrepurchaseInfoResponse, + MethodGetServiceItemRightRequest, + MethodGetServiceItemRightResponse, + MethodGetPurchaseHistoryRequest, + MethodGetPurchaseHistoryResponse, + MethodPostRightBinaryByAccount, + MethodUseServiceItemByAccountRequest, + MethodUseServiceItemByAccountResponse, + MethodAcquireServiceItemByAccount, + MethodGetSupportID, + MethodGetLawMessageRequest, + MethodGetLawMessageResponse, +} + +type serviceItemProtocol = service_item.Protocol + +// Protocol stores all the RMC method handlers for the Service Item (Team Kirby Clash Deluxe) protocol and listens for requests +// Embeds the Service Item protocol +type Protocol struct { + endpoint nex.EndpointInterface + serviceItemProtocol + GetEnvironment func(err error, packet nex.PacketInterface, callID uint32, uniqueID *types.String, platform *types.PrimitiveU8) (*nex.RMCMessage, *nex.Error) + HTTPGetRequest func(err error, packet nex.PacketInterface, callID uint32, url *service_item_team_kirby_clash_deluxe_types.ServiceItemHTTPGetParam) (*nex.RMCMessage, *nex.Error) + HTTPGetResponse func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + PurchaseServiceItemRequest func(err error, packet nex.PacketInterface, callID uint32, purchaseServiceItemParam *service_item_team_kirby_clash_deluxe_types.ServiceItemPurchaseServiceItemParam) (*nex.RMCMessage, *nex.Error) + PurchaseServiceItemResponse func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + ListServiceItemRequest func(err error, packet nex.PacketInterface, callID uint32, listServiceItemParam *service_item_team_kirby_clash_deluxe_types.ServiceItemListServiceItemParam) (*nex.RMCMessage, *nex.Error) + ListServiceItemResponse func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetBalanceRequest func(err error, packet nex.PacketInterface, callID uint32, getBalanceParam *service_item_team_kirby_clash_deluxe_types.ServiceItemGetBalanceParam) (*nex.RMCMessage, *nex.Error) + GetBalanceResponse func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetPrepurchaseInfoRequest func(err error, packet nex.PacketInterface, callID uint32, getPrepurchaseInfoParam *service_item_team_kirby_clash_deluxe_types.ServiceItemGetPrepurchaseInfoParam) (*nex.RMCMessage, *nex.Error) + GetPrepurchaseInfoResponse func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetServiceItemRightRequest func(err error, packet nex.PacketInterface, callID uint32, getServiceItemRightParam *service_item_team_kirby_clash_deluxe_types.ServiceItemGetServiceItemRightParam, withoutRightBinary *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + GetServiceItemRightResponse func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetPurchaseHistoryRequest func(err error, packet nex.PacketInterface, callID uint32, getPurchaseHistoryParam *service_item_team_kirby_clash_deluxe_types.ServiceItemGetPurchaseHistoryParam) (*nex.RMCMessage, *nex.Error) + GetPurchaseHistoryResponse func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + PostRightBinaryByAccount func(err error, packet nex.PacketInterface, callID uint32, postRightBinaryByAccountParam *service_item_team_kirby_clash_deluxe_types.ServiceItemPostRightBinaryByAccountParam) (*nex.RMCMessage, *nex.Error) + UseServiceItemByAccountRequest func(err error, packet nex.PacketInterface, callID uint32, useServiceItemByAccountParam *service_item_team_kirby_clash_deluxe_types.ServiceItemUseServiceItemByAccountParam) (*nex.RMCMessage, *nex.Error) + UseServiceItemByAccountResponse func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + AcquireServiceItemByAccount func(err error, packet nex.PacketInterface, callID uint32, acquireServiceItemByAccountParam *service_item_team_kirby_clash_deluxe_types.ServiceItemAcquireServiceItemByAccountParam) (*nex.RMCMessage, *nex.Error) + GetSupportID func(err error, packet nex.PacketInterface, callID uint32, getSuppordIDParam *service_item_team_kirby_clash_deluxe_types.ServiceItemGetSupportIDParam) (*nex.RMCMessage, *nex.Error) + GetLawMessageRequest func(err error, packet nex.PacketInterface, callID uint32, getLawMessageParam *service_item_team_kirby_clash_deluxe_types.ServiceItemGetLawMessageParam) (*nex.RMCMessage, *nex.Error) + GetLawMessageResponse func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if !slices.Contains(patchedMethods, message.MethodID) { + protocol.serviceItemProtocol.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodGetEnvironment: + protocol.handleGetEnvironment(packet) + case MethodHTTPGetRequest: + protocol.handleHTTPGetRequest(packet) + case MethodHTTPGetResponse: + protocol.handleHTTPGetResponse(packet) + case MethodPurchaseServiceItemRequest: + protocol.handlePurchaseServiceItemRequest(packet) + case MethodPurchaseServiceItemResponse: + protocol.handlePurchaseServiceItemResponse(packet) + case MethodListServiceItemRequest: + protocol.handleListServiceItemRequest(packet) + case MethodListServiceItemResponse: + protocol.handleListServiceItemResponse(packet) + case MethodGetBalanceRequest: + protocol.handleGetBalanceRequest(packet) + case MethodGetBalanceResponse: + protocol.handleGetBalanceResponse(packet) + case MethodGetPrepurchaseInfoRequest: + protocol.handleGetPrepurchaseInfoRequest(packet) + case MethodGetPrepurchaseInfoResponse: + protocol.handleGetPrepurchaseInfoResponse(packet) + case MethodGetServiceItemRightRequest: + protocol.handleGetServiceItemRightRequest(packet) + case MethodGetServiceItemRightResponse: + protocol.handleGetServiceItemRightResponse(packet) + case MethodGetPurchaseHistoryRequest: + protocol.handleGetPurchaseHistoryRequest(packet) + case MethodGetPurchaseHistoryResponse: + protocol.handleGetPurchaseHistoryResponse(packet) + case MethodPostRightBinaryByAccount: + protocol.handlePostRightBinaryByAccount(packet) + case MethodUseServiceItemByAccountRequest: + protocol.handleUseServiceItemByAccountRequest(packet) + case MethodUseServiceItemByAccountResponse: + protocol.handleUseServiceItemByAccountResponse(packet) + case MethodAcquireServiceItemByAccount: + protocol.handleAcquireServiceItemByAccount(packet) + case MethodGetSupportID: + protocol.handleGetSupportID(packet) + case MethodGetLawMessageRequest: + protocol.handleGetLawMessageRequest(packet) + case MethodGetLawMessageResponse: + protocol.handleGetLawMessageResponse(packet) + default: + errMessage := fmt.Sprintf("Unsupported Service Item (Team Kirby Clash Deluxe) method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new ServiceItemTeamKirbyClashDeluxe protocol +func NewProtocol(endpoint nex.EndpointInterface) *Protocol { + protocol := &Protocol{endpoint: endpoint} + protocol.serviceItemProtocol.SetEndpoint(endpoint) + + return protocol +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/purchase_service_item_request.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/purchase_service_item_request.go new file mode 100644 index 0000000..b4a67f5 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/purchase_service_item_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_team_kirby_clash_deluxe_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/team-kirby-clash-deluxe/types" +) + +func (protocol *Protocol) handlePurchaseServiceItemRequest(packet nex.PacketInterface) { + if protocol.PurchaseServiceItemRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::PurchaseServiceItemRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + purchaseServiceItemParam := service_item_team_kirby_clash_deluxe_types.NewServiceItemPurchaseServiceItemParam() + + err := purchaseServiceItemParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PurchaseServiceItemRequest(fmt.Errorf("Failed to read purchaseServiceItemParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PurchaseServiceItemRequest(nil, packet, callID, purchaseServiceItemParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/purchase_service_item_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/purchase_service_item_response.go new file mode 100644 index 0000000..3f4d8fb --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/purchase_service_item_response.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePurchaseServiceItemResponse(packet nex.PacketInterface) { + if protocol.PurchaseServiceItemResponse == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::PurchaseServiceItemResponse not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestID := types.NewPrimitiveU32(0) + + err := requestID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PurchaseServiceItemResponse(fmt.Errorf("Failed to read requestID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PurchaseServiceItemResponse(nil, packet, callID, requestID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_account_right.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_account_right.go new file mode 100644 index 0000000..fb1503e --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_account_right.go @@ -0,0 +1,128 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemAccountRight is a type within the ServiceItem protocol +type ServiceItemAccountRight struct { + types.Structure + PID *types.PID + Limitation *ServiceItemLimitation + RightBinaries *types.List[*ServiceItemRightBinary] +} + +// WriteTo writes the ServiceItemAccountRight to the given writable +func (siar *ServiceItemAccountRight) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siar.PID.WriteTo(contentWritable) + siar.Limitation.WriteTo(contentWritable) + siar.RightBinaries.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siar.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemAccountRight from the given readable +func (siar *ServiceItemAccountRight) ExtractFrom(readable types.Readable) error { + var err error + + err = siar.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAccountRight header. %s", err.Error()) + } + + err = siar.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAccountRight.PID. %s", err.Error()) + } + + err = siar.Limitation.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAccountRight.Limitation. %s", err.Error()) + } + + err = siar.RightBinaries.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAccountRight.RightBinaries. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemAccountRight +func (siar *ServiceItemAccountRight) Copy() types.RVType { + copied := NewServiceItemAccountRight() + + copied.StructureVersion = siar.StructureVersion + copied.PID = siar.PID.Copy().(*types.PID) + copied.Limitation = siar.Limitation.Copy().(*ServiceItemLimitation) + copied.RightBinaries = siar.RightBinaries.Copy().(*types.List[*ServiceItemRightBinary]) + + return copied +} + +// Equals checks if the given ServiceItemAccountRight contains the same data as the current ServiceItemAccountRight +func (siar *ServiceItemAccountRight) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemAccountRight); !ok { + return false + } + + other := o.(*ServiceItemAccountRight) + + if siar.StructureVersion != other.StructureVersion { + return false + } + + if !siar.PID.Equals(other.PID) { + return false + } + + if !siar.Limitation.Equals(other.Limitation) { + return false + } + + return siar.RightBinaries.Equals(other.RightBinaries) +} + +// String returns the string representation of the ServiceItemAccountRight +func (siar *ServiceItemAccountRight) String() string { + return siar.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemAccountRight using the provided indentation level +func (siar *ServiceItemAccountRight) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemAccountRight{\n") + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, siar.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sLimitation: %s,\n", indentationValues, siar.Limitation.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sRightBinaries: %s,\n", indentationValues, siar.RightBinaries)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemAccountRight returns a new ServiceItemAccountRight +func NewServiceItemAccountRight() *ServiceItemAccountRight { + siar := &ServiceItemAccountRight{ + PID: types.NewPID(0), + Limitation: NewServiceItemLimitation(), + RightBinaries: types.NewList[*ServiceItemRightBinary](), + } + + siar.RightBinaries.Type = NewServiceItemRightBinary() + + return siar +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_account_right_consumption.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_account_right_consumption.go new file mode 100644 index 0000000..dc945d5 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_account_right_consumption.go @@ -0,0 +1,143 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemAccountRightConsumption is a type within the ServiceItem protocol +type ServiceItemAccountRightConsumption struct { + types.Structure + *ServiceItemAccountRight + UsedCount *types.PrimitiveU32 + ExpiredCount *types.PrimitiveU32 + ExpiryCounts *types.List[*types.PrimitiveU32] +} + +// WriteTo writes the ServiceItemAccountRightConsumption to the given writable +func (siarc *ServiceItemAccountRightConsumption) WriteTo(writable types.Writable) { + siarc.ServiceItemAccountRight.WriteTo(writable) + + contentWritable := writable.CopyNew() + + siarc.UsedCount.WriteTo(contentWritable) + siarc.ExpiredCount.WriteTo(contentWritable) + siarc.ExpiryCounts.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siarc.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemAccountRightConsumption from the given readable +func (siarc *ServiceItemAccountRightConsumption) ExtractFrom(readable types.Readable) error { + var err error + + err = siarc.ServiceItemAccountRight.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAccountRightConsumption.ServiceItemAccountRight. %s", err.Error()) + } + + err = siarc.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAccountRightConsumption header. %s", err.Error()) + } + + err = siarc.UsedCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAccountRightConsumption.UsedCount. %s", err.Error()) + } + + err = siarc.ExpiredCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAccountRightConsumption.ExpiredCount. %s", err.Error()) + } + + err = siarc.ExpiryCounts.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAccountRightConsumption.ExpiryCounts. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemAccountRightConsumption +func (siarc *ServiceItemAccountRightConsumption) Copy() types.RVType { + copied := NewServiceItemAccountRightConsumption() + + copied.StructureVersion = siarc.StructureVersion + copied.ServiceItemAccountRight = siarc.ServiceItemAccountRight.Copy().(*ServiceItemAccountRight) + copied.UsedCount = siarc.UsedCount.Copy().(*types.PrimitiveU32) + copied.ExpiredCount = siarc.ExpiredCount.Copy().(*types.PrimitiveU32) + copied.ExpiryCounts = siarc.ExpiryCounts.Copy().(*types.List[*types.PrimitiveU32]) + + return copied +} + +// Equals checks if the given ServiceItemAccountRightConsumption contains the same data as the current ServiceItemAccountRightConsumption +func (siarc *ServiceItemAccountRightConsumption) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemAccountRightConsumption); !ok { + return false + } + + other := o.(*ServiceItemAccountRightConsumption) + + if siarc.StructureVersion != other.StructureVersion { + return false + } + + if !siarc.ServiceItemAccountRight.Equals(other.ServiceItemAccountRight) { + return false + } + + if !siarc.UsedCount.Equals(other.UsedCount) { + return false + } + + if !siarc.ExpiredCount.Equals(other.ExpiredCount) { + return false + } + + return siarc.ExpiryCounts.Equals(other.ExpiryCounts) +} + +// String returns the string representation of the ServiceItemAccountRightConsumption +func (siarc *ServiceItemAccountRightConsumption) String() string { + return siarc.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemAccountRightConsumption using the provided indentation level +func (siarc *ServiceItemAccountRightConsumption) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemAccountRightConsumption{\n") + b.WriteString(fmt.Sprintf("%sServiceItemAccountRight (parent): %s,\n", indentationValues, siarc.ServiceItemAccountRight.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUsedCount: %s,\n", indentationValues, siarc.UsedCount)) + b.WriteString(fmt.Sprintf("%sExpiredCount: %s,\n", indentationValues, siarc.ExpiredCount)) + b.WriteString(fmt.Sprintf("%sExpiryCounts: %s,\n", indentationValues, siarc.ExpiryCounts)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemAccountRightConsumption returns a new ServiceItemAccountRightConsumption +func NewServiceItemAccountRightConsumption() *ServiceItemAccountRightConsumption { + siarc := &ServiceItemAccountRightConsumption{ + ServiceItemAccountRight: NewServiceItemAccountRight(), + UsedCount: types.NewPrimitiveU32(0), + ExpiredCount: types.NewPrimitiveU32(0), + ExpiryCounts: types.NewList[*types.PrimitiveU32](), + } + + siarc.ExpiryCounts.Type = types.NewPrimitiveU32(0) + + return siarc +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_account_right_time.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_account_right_time.go new file mode 100644 index 0000000..31f09b5 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_account_right_time.go @@ -0,0 +1,102 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemAccountRightTime is a type within the ServiceItem protocol +type ServiceItemAccountRightTime struct { + types.Structure + *ServiceItemAccountRight +} + +// WriteTo writes the ServiceItemAccountRightTime to the given writable +func (siart *ServiceItemAccountRightTime) WriteTo(writable types.Writable) { + siart.ServiceItemAccountRight.WriteTo(writable) + + contentWritable := writable.CopyNew() + + content := contentWritable.Bytes() + + siart.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemAccountRightTime from the given readable +func (siart *ServiceItemAccountRightTime) ExtractFrom(readable types.Readable) error { + var err error + + err = siart.ServiceItemAccountRight.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAccountRightTime.ServiceItemAccountRight. %s", err.Error()) + } + + err = siart.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAccountRightTime header. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemAccountRightTime +func (siart *ServiceItemAccountRightTime) Copy() types.RVType { + copied := NewServiceItemAccountRightTime() + + copied.StructureVersion = siart.StructureVersion + copied.ServiceItemAccountRight = siart.ServiceItemAccountRight.Copy().(*ServiceItemAccountRight) + + return copied +} + +// Equals checks if the given ServiceItemAccountRightTime contains the same data as the current ServiceItemAccountRightTime +func (siart *ServiceItemAccountRightTime) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemAccountRightTime); !ok { + return false + } + + other := o.(*ServiceItemAccountRightTime) + + if siart.StructureVersion != other.StructureVersion { + return false + } + + if !siart.ServiceItemAccountRight.Equals(other.ServiceItemAccountRight) { + return false + } + + return true +} + +// String returns the string representation of the ServiceItemAccountRightTime +func (siart *ServiceItemAccountRightTime) String() string { + return siart.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemAccountRightTime using the provided indentation level +func (siart *ServiceItemAccountRightTime) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemAccountRightTime{\n") + b.WriteString(fmt.Sprintf("%sServiceItemAccountRight (parent): %s,\n", indentationValues, siart.ServiceItemAccountRight.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemAccountRightTime returns a new ServiceItemAccountRightTime +func NewServiceItemAccountRightTime() *ServiceItemAccountRightTime { + siart := &ServiceItemAccountRightTime{ + ServiceItemAccountRight: NewServiceItemAccountRight(), + } + + return siart +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_acquire_service_item_by_account_param.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_acquire_service_item_by_account_param.go new file mode 100644 index 0000000..001d1d8 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_acquire_service_item_by_account_param.go @@ -0,0 +1,210 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemAcquireServiceItemByAccountParam is a type within the ServiceItem protocol +type ServiceItemAcquireServiceItemByAccountParam struct { + types.Structure + ReferenceIDForAcquisition *types.String + ReferenceIDForRightBinary *types.String + UseType *types.PrimitiveU8 + LimitationType *types.PrimitiveU32 + LimitationValue *types.PrimitiveU32 + RightBinary *types.QBuffer + LogMessage *types.String + UniqueID *types.PrimitiveU32 + Platform *types.PrimitiveU8 +} + +// WriteTo writes the ServiceItemAcquireServiceItemByAccountParam to the given writable +func (siasibap *ServiceItemAcquireServiceItemByAccountParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siasibap.ReferenceIDForAcquisition.WriteTo(contentWritable) + siasibap.ReferenceIDForRightBinary.WriteTo(contentWritable) + siasibap.UseType.WriteTo(contentWritable) + siasibap.LimitationType.WriteTo(contentWritable) + siasibap.LimitationValue.WriteTo(contentWritable) + siasibap.RightBinary.WriteTo(contentWritable) + siasibap.LogMessage.WriteTo(contentWritable) + siasibap.UniqueID.WriteTo(contentWritable) + siasibap.Platform.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siasibap.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemAcquireServiceItemByAccountParam from the given readable +func (siasibap *ServiceItemAcquireServiceItemByAccountParam) ExtractFrom(readable types.Readable) error { + var err error + + err = siasibap.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAcquireServiceItemByAccountParam header. %s", err.Error()) + } + + err = siasibap.ReferenceIDForAcquisition.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAcquireServiceItemByAccountParam.ReferenceIDForAcquisition. %s", err.Error()) + } + + err = siasibap.ReferenceIDForRightBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAcquireServiceItemByAccountParam.ReferenceIDForRightBinary. %s", err.Error()) + } + + err = siasibap.UseType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAcquireServiceItemByAccountParam.UseType. %s", err.Error()) + } + + err = siasibap.LimitationType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAcquireServiceItemByAccountParam.LimitationType. %s", err.Error()) + } + + err = siasibap.LimitationValue.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAcquireServiceItemByAccountParam.LimitationValue. %s", err.Error()) + } + + err = siasibap.RightBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAcquireServiceItemByAccountParam.RightBinary. %s", err.Error()) + } + + err = siasibap.LogMessage.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAcquireServiceItemByAccountParam.LogMessage. %s", err.Error()) + } + + err = siasibap.UniqueID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAcquireServiceItemByAccountParam.UniqueID. %s", err.Error()) + } + + err = siasibap.Platform.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAcquireServiceItemByAccountParam.Platform. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemAcquireServiceItemByAccountParam +func (siasibap *ServiceItemAcquireServiceItemByAccountParam) Copy() types.RVType { + copied := NewServiceItemAcquireServiceItemByAccountParam() + + copied.StructureVersion = siasibap.StructureVersion + copied.ReferenceIDForAcquisition = siasibap.ReferenceIDForAcquisition.Copy().(*types.String) + copied.ReferenceIDForRightBinary = siasibap.ReferenceIDForRightBinary.Copy().(*types.String) + copied.UseType = siasibap.UseType.Copy().(*types.PrimitiveU8) + copied.LimitationType = siasibap.LimitationType.Copy().(*types.PrimitiveU32) + copied.LimitationValue = siasibap.LimitationValue.Copy().(*types.PrimitiveU32) + copied.RightBinary = siasibap.RightBinary.Copy().(*types.QBuffer) + copied.LogMessage = siasibap.LogMessage.Copy().(*types.String) + copied.UniqueID = siasibap.UniqueID.Copy().(*types.PrimitiveU32) + copied.Platform = siasibap.Platform.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given ServiceItemAcquireServiceItemByAccountParam contains the same data as the current ServiceItemAcquireServiceItemByAccountParam +func (siasibap *ServiceItemAcquireServiceItemByAccountParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemAcquireServiceItemByAccountParam); !ok { + return false + } + + other := o.(*ServiceItemAcquireServiceItemByAccountParam) + + if siasibap.StructureVersion != other.StructureVersion { + return false + } + + if !siasibap.ReferenceIDForAcquisition.Equals(other.ReferenceIDForAcquisition) { + return false + } + + if !siasibap.ReferenceIDForRightBinary.Equals(other.ReferenceIDForRightBinary) { + return false + } + + if !siasibap.UseType.Equals(other.UseType) { + return false + } + + if !siasibap.LimitationType.Equals(other.LimitationType) { + return false + } + + if !siasibap.LimitationValue.Equals(other.LimitationValue) { + return false + } + + if !siasibap.RightBinary.Equals(other.RightBinary) { + return false + } + + if !siasibap.LogMessage.Equals(other.LogMessage) { + return false + } + + if !siasibap.UniqueID.Equals(other.UniqueID) { + return false + } + + return siasibap.Platform.Equals(other.Platform) +} + +// String returns the string representation of the ServiceItemAcquireServiceItemByAccountParam +func (siasibap *ServiceItemAcquireServiceItemByAccountParam) String() string { + return siasibap.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemAcquireServiceItemByAccountParam using the provided indentation level +func (siasibap *ServiceItemAcquireServiceItemByAccountParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemAcquireServiceItemByAccountParam{\n") + b.WriteString(fmt.Sprintf("%sReferenceIDForAcquisition: %s,\n", indentationValues, siasibap.ReferenceIDForAcquisition)) + b.WriteString(fmt.Sprintf("%sReferenceIDForRightBinary: %s,\n", indentationValues, siasibap.ReferenceIDForRightBinary)) + b.WriteString(fmt.Sprintf("%sUseType: %s,\n", indentationValues, siasibap.UseType)) + b.WriteString(fmt.Sprintf("%sLimitationType: %s,\n", indentationValues, siasibap.LimitationType)) + b.WriteString(fmt.Sprintf("%sLimitationValue: %s,\n", indentationValues, siasibap.LimitationValue)) + b.WriteString(fmt.Sprintf("%sRightBinary: %s,\n", indentationValues, siasibap.RightBinary)) + b.WriteString(fmt.Sprintf("%sLogMessage: %s,\n", indentationValues, siasibap.LogMessage)) + b.WriteString(fmt.Sprintf("%sUniqueID: %s,\n", indentationValues, siasibap.UniqueID)) + b.WriteString(fmt.Sprintf("%sPlatform: %s,\n", indentationValues, siasibap.Platform)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemAcquireServiceItemByAccountParam returns a new ServiceItemAcquireServiceItemByAccountParam +func NewServiceItemAcquireServiceItemByAccountParam() *ServiceItemAcquireServiceItemByAccountParam { + siasibap := &ServiceItemAcquireServiceItemByAccountParam{ + ReferenceIDForAcquisition: types.NewString(""), + ReferenceIDForRightBinary: types.NewString(""), + UseType: types.NewPrimitiveU8(0), + LimitationType: types.NewPrimitiveU32(0), + LimitationValue: types.NewPrimitiveU32(0), + RightBinary: types.NewQBuffer(nil), + LogMessage: types.NewString(""), + UniqueID: types.NewPrimitiveU32(0), + Platform: types.NewPrimitiveU8(0), + } + + return siasibap +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_acquire_service_item_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_acquire_service_item_response.go new file mode 100644 index 0000000..2ade5b3 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_acquire_service_item_response.go @@ -0,0 +1,170 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemAcquireServiceItemResponse is a type within the ServiceItem protocol +type ServiceItemAcquireServiceItemResponse struct { + types.Structure + LimitationType *types.PrimitiveU32 + AcquiredCount *types.PrimitiveU32 + UsedCount *types.PrimitiveU32 + ExpiryDate *types.PrimitiveU32 + ExpiredCount *types.PrimitiveU32 + ExpiryCounts *types.List[*types.PrimitiveU32] +} + +// WriteTo writes the ServiceItemAcquireServiceItemResponse to the given writable +func (siasir *ServiceItemAcquireServiceItemResponse) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siasir.LimitationType.WriteTo(contentWritable) + siasir.AcquiredCount.WriteTo(contentWritable) + siasir.UsedCount.WriteTo(contentWritable) + siasir.ExpiryDate.WriteTo(contentWritable) + siasir.ExpiredCount.WriteTo(contentWritable) + siasir.ExpiryCounts.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siasir.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemAcquireServiceItemResponse from the given readable +func (siasir *ServiceItemAcquireServiceItemResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = siasir.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAcquireServiceItemResponse header. %s", err.Error()) + } + + err = siasir.LimitationType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAcquireServiceItemResponse.LimitationType. %s", err.Error()) + } + + err = siasir.AcquiredCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAcquireServiceItemResponse.AcquiredCount. %s", err.Error()) + } + + err = siasir.UsedCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAcquireServiceItemResponse.UsedCount. %s", err.Error()) + } + + err = siasir.ExpiryDate.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAcquireServiceItemResponse.ExpiryDate. %s", err.Error()) + } + + err = siasir.ExpiredCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAcquireServiceItemResponse.ExpiredCount. %s", err.Error()) + } + + err = siasir.ExpiryCounts.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAcquireServiceItemResponse.ExpiryCounts. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemAcquireServiceItemResponse +func (siasir *ServiceItemAcquireServiceItemResponse) Copy() types.RVType { + copied := NewServiceItemAcquireServiceItemResponse() + + copied.StructureVersion = siasir.StructureVersion + copied.LimitationType = siasir.LimitationType.Copy().(*types.PrimitiveU32) + copied.AcquiredCount = siasir.AcquiredCount.Copy().(*types.PrimitiveU32) + copied.UsedCount = siasir.UsedCount.Copy().(*types.PrimitiveU32) + copied.ExpiryDate = siasir.ExpiryDate.Copy().(*types.PrimitiveU32) + copied.ExpiredCount = siasir.ExpiredCount.Copy().(*types.PrimitiveU32) + copied.ExpiryCounts = siasir.ExpiryCounts.Copy().(*types.List[*types.PrimitiveU32]) + + return copied +} + +// Equals checks if the given ServiceItemAcquireServiceItemResponse contains the same data as the current ServiceItemAcquireServiceItemResponse +func (siasir *ServiceItemAcquireServiceItemResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemAcquireServiceItemResponse); !ok { + return false + } + + other := o.(*ServiceItemAcquireServiceItemResponse) + + if siasir.StructureVersion != other.StructureVersion { + return false + } + + if !siasir.LimitationType.Equals(other.LimitationType) { + return false + } + + if !siasir.AcquiredCount.Equals(other.AcquiredCount) { + return false + } + + if !siasir.UsedCount.Equals(other.UsedCount) { + return false + } + + if !siasir.ExpiryDate.Equals(other.ExpiryDate) { + return false + } + + if !siasir.ExpiredCount.Equals(other.ExpiredCount) { + return false + } + + return siasir.ExpiryCounts.Equals(other.ExpiryCounts) +} + +// String returns the string representation of the ServiceItemAcquireServiceItemResponse +func (siasir *ServiceItemAcquireServiceItemResponse) String() string { + return siasir.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemAcquireServiceItemResponse using the provided indentation level +func (siasir *ServiceItemAcquireServiceItemResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemAcquireServiceItemResponse{\n") + b.WriteString(fmt.Sprintf("%sLimitationType: %s,\n", indentationValues, siasir.LimitationType)) + b.WriteString(fmt.Sprintf("%sAcquiredCount: %s,\n", indentationValues, siasir.AcquiredCount)) + b.WriteString(fmt.Sprintf("%sUsedCount: %s,\n", indentationValues, siasir.UsedCount)) + b.WriteString(fmt.Sprintf("%sExpiryDate: %s,\n", indentationValues, siasir.ExpiryDate)) + b.WriteString(fmt.Sprintf("%sExpiredCount: %s,\n", indentationValues, siasir.ExpiredCount)) + b.WriteString(fmt.Sprintf("%sExpiryCounts: %s,\n", indentationValues, siasir.ExpiryCounts)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemAcquireServiceItemResponse returns a new ServiceItemAcquireServiceItemResponse +func NewServiceItemAcquireServiceItemResponse() *ServiceItemAcquireServiceItemResponse { + siasir := &ServiceItemAcquireServiceItemResponse{ + LimitationType: types.NewPrimitiveU32(0), + AcquiredCount: types.NewPrimitiveU32(0), + UsedCount: types.NewPrimitiveU32(0), + ExpiryDate: types.NewPrimitiveU32(0), + ExpiredCount: types.NewPrimitiveU32(0), + ExpiryCounts: types.NewList[*types.PrimitiveU32](), + } + + siasir.ExpiryCounts.Type = types.NewPrimitiveU32(0) + + return siasir +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_amount.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_amount.go new file mode 100644 index 0000000..630b5bb --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_amount.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemAmount is a type within the ServiceItem protocol +type ServiceItemAmount struct { + types.Structure + FormattedAmount *types.String + Currency *types.String + RawValue *types.String +} + +// WriteTo writes the ServiceItemAmount to the given writable +func (sia *ServiceItemAmount) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sia.FormattedAmount.WriteTo(contentWritable) + sia.Currency.WriteTo(contentWritable) + sia.RawValue.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sia.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemAmount from the given readable +func (sia *ServiceItemAmount) ExtractFrom(readable types.Readable) error { + var err error + + err = sia.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAmount header. %s", err.Error()) + } + + err = sia.FormattedAmount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAmount.FormattedAmount. %s", err.Error()) + } + + err = sia.Currency.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAmount.Currency. %s", err.Error()) + } + + err = sia.RawValue.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAmount.RawValue. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemAmount +func (sia *ServiceItemAmount) Copy() types.RVType { + copied := NewServiceItemAmount() + + copied.StructureVersion = sia.StructureVersion + copied.FormattedAmount = sia.FormattedAmount.Copy().(*types.String) + copied.Currency = sia.Currency.Copy().(*types.String) + copied.RawValue = sia.RawValue.Copy().(*types.String) + + return copied +} + +// Equals checks if the given ServiceItemAmount contains the same data as the current ServiceItemAmount +func (sia *ServiceItemAmount) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemAmount); !ok { + return false + } + + other := o.(*ServiceItemAmount) + + if sia.StructureVersion != other.StructureVersion { + return false + } + + if !sia.FormattedAmount.Equals(other.FormattedAmount) { + return false + } + + if !sia.Currency.Equals(other.Currency) { + return false + } + + return sia.RawValue.Equals(other.RawValue) +} + +// String returns the string representation of the ServiceItemAmount +func (sia *ServiceItemAmount) String() string { + return sia.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemAmount using the provided indentation level +func (sia *ServiceItemAmount) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemAmount{\n") + b.WriteString(fmt.Sprintf("%sFormattedAmount: %s,\n", indentationValues, sia.FormattedAmount)) + b.WriteString(fmt.Sprintf("%sCurrency: %s,\n", indentationValues, sia.Currency)) + b.WriteString(fmt.Sprintf("%sRawValue: %s,\n", indentationValues, sia.RawValue)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemAmount returns a new ServiceItemAmount +func NewServiceItemAmount() *ServiceItemAmount { + sia := &ServiceItemAmount{ + FormattedAmount: types.NewString(""), + Currency: types.NewString(""), + RawValue: types.NewString(""), + } + + return sia +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_attribute.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_attribute.go new file mode 100644 index 0000000..6511084 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_attribute.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemAttribute is a type within the ServiceItem protocol +type ServiceItemAttribute struct { + types.Structure + Name *types.String + Value *types.String +} + +// WriteTo writes the ServiceItemAttribute to the given writable +func (sia *ServiceItemAttribute) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sia.Name.WriteTo(contentWritable) + sia.Value.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sia.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemAttribute from the given readable +func (sia *ServiceItemAttribute) ExtractFrom(readable types.Readable) error { + var err error + + err = sia.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAttribute header. %s", err.Error()) + } + + err = sia.Name.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAttribute.Name. %s", err.Error()) + } + + err = sia.Value.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAttribute.Value. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemAttribute +func (sia *ServiceItemAttribute) Copy() types.RVType { + copied := NewServiceItemAttribute() + + copied.StructureVersion = sia.StructureVersion + copied.Name = sia.Name.Copy().(*types.String) + copied.Value = sia.Value.Copy().(*types.String) + + return copied +} + +// Equals checks if the given ServiceItemAttribute contains the same data as the current ServiceItemAttribute +func (sia *ServiceItemAttribute) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemAttribute); !ok { + return false + } + + other := o.(*ServiceItemAttribute) + + if sia.StructureVersion != other.StructureVersion { + return false + } + + if !sia.Name.Equals(other.Name) { + return false + } + + return sia.Value.Equals(other.Value) +} + +// String returns the string representation of the ServiceItemAttribute +func (sia *ServiceItemAttribute) String() string { + return sia.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemAttribute using the provided indentation level +func (sia *ServiceItemAttribute) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemAttribute{\n") + b.WriteString(fmt.Sprintf("%sName: %s,\n", indentationValues, sia.Name)) + b.WriteString(fmt.Sprintf("%sValue: %s,\n", indentationValues, sia.Value)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemAttribute returns a new ServiceItemAttribute +func NewServiceItemAttribute() *ServiceItemAttribute { + sia := &ServiceItemAttribute{ + Name: types.NewString(""), + Value: types.NewString(""), + } + + return sia +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_catalog.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_catalog.go new file mode 100644 index 0000000..e5897c5 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_catalog.go @@ -0,0 +1,156 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemCatalog is a type within the ServiceItem protocol +type ServiceItemCatalog struct { + types.Structure + TotalSize *types.PrimitiveU32 + Offset *types.PrimitiveU32 + ListItems *types.List[*ServiceItemListItem] + IsBalanceAvailable *types.PrimitiveBool + Balance *ServiceItemAmount +} + +// WriteTo writes the ServiceItemCatalog to the given writable +func (sic *ServiceItemCatalog) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sic.TotalSize.WriteTo(contentWritable) + sic.Offset.WriteTo(contentWritable) + sic.ListItems.WriteTo(contentWritable) + sic.IsBalanceAvailable.WriteTo(contentWritable) + sic.Balance.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sic.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemCatalog from the given readable +func (sic *ServiceItemCatalog) ExtractFrom(readable types.Readable) error { + var err error + + err = sic.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemCatalog header. %s", err.Error()) + } + + err = sic.TotalSize.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemCatalog.TotalSize. %s", err.Error()) + } + + err = sic.Offset.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemCatalog.Offset. %s", err.Error()) + } + + err = sic.ListItems.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemCatalog.ListItems. %s", err.Error()) + } + + err = sic.IsBalanceAvailable.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemCatalog.IsBalanceAvailable. %s", err.Error()) + } + + err = sic.Balance.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemCatalog.Balance. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemCatalog +func (sic *ServiceItemCatalog) Copy() types.RVType { + copied := NewServiceItemCatalog() + + copied.StructureVersion = sic.StructureVersion + copied.TotalSize = sic.TotalSize.Copy().(*types.PrimitiveU32) + copied.Offset = sic.Offset.Copy().(*types.PrimitiveU32) + copied.ListItems = sic.ListItems.Copy().(*types.List[*ServiceItemListItem]) + copied.IsBalanceAvailable = sic.IsBalanceAvailable.Copy().(*types.PrimitiveBool) + copied.Balance = sic.Balance.Copy().(*ServiceItemAmount) + + return copied +} + +// Equals checks if the given ServiceItemCatalog contains the same data as the current ServiceItemCatalog +func (sic *ServiceItemCatalog) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemCatalog); !ok { + return false + } + + other := o.(*ServiceItemCatalog) + + if sic.StructureVersion != other.StructureVersion { + return false + } + + if !sic.TotalSize.Equals(other.TotalSize) { + return false + } + + if !sic.Offset.Equals(other.Offset) { + return false + } + + if !sic.ListItems.Equals(other.ListItems) { + return false + } + + if !sic.IsBalanceAvailable.Equals(other.IsBalanceAvailable) { + return false + } + + return sic.Balance.Equals(other.Balance) +} + +// String returns the string representation of the ServiceItemCatalog +func (sic *ServiceItemCatalog) String() string { + return sic.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemCatalog using the provided indentation level +func (sic *ServiceItemCatalog) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemCatalog{\n") + b.WriteString(fmt.Sprintf("%sTotalSize: %s,\n", indentationValues, sic.TotalSize)) + b.WriteString(fmt.Sprintf("%sOffset: %s,\n", indentationValues, sic.Offset)) + b.WriteString(fmt.Sprintf("%sListItems: %s,\n", indentationValues, sic.ListItems)) + b.WriteString(fmt.Sprintf("%sIsBalanceAvailable: %s,\n", indentationValues, sic.IsBalanceAvailable)) + b.WriteString(fmt.Sprintf("%sBalance: %s,\n", indentationValues, sic.Balance.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemCatalog returns a new ServiceItemCatalog +func NewServiceItemCatalog() *ServiceItemCatalog { + sic := &ServiceItemCatalog{ + TotalSize: types.NewPrimitiveU32(0), + Offset: types.NewPrimitiveU32(0), + ListItems: types.NewList[*ServiceItemListItem](), + IsBalanceAvailable: types.NewPrimitiveBool(false), + Balance: NewServiceItemAmount(), + } + + sic.ListItems.Type = NewServiceItemListItem() + + return sic +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_eshop_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_eshop_response.go new file mode 100644 index 0000000..2bcca34 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_eshop_response.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemEShopResponse is a type within the ServiceItem protocol +type ServiceItemEShopResponse struct { + types.Structure + HTTPStatus *types.PrimitiveU32 + ErrorCode *types.PrimitiveU32 + CorrelationID *types.String +} + +// WriteTo writes the ServiceItemEShopResponse to the given writable +func (siesr *ServiceItemEShopResponse) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siesr.HTTPStatus.WriteTo(contentWritable) + siesr.ErrorCode.WriteTo(contentWritable) + siesr.CorrelationID.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siesr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemEShopResponse from the given readable +func (siesr *ServiceItemEShopResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = siesr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEShopResponse header. %s", err.Error()) + } + + err = siesr.HTTPStatus.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEShopResponse.HTTPStatus. %s", err.Error()) + } + + err = siesr.ErrorCode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEShopResponse.ErrorCode. %s", err.Error()) + } + + err = siesr.CorrelationID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEShopResponse.CorrelationID. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemEShopResponse +func (siesr *ServiceItemEShopResponse) Copy() types.RVType { + copied := NewServiceItemEShopResponse() + + copied.StructureVersion = siesr.StructureVersion + copied.HTTPStatus = siesr.HTTPStatus.Copy().(*types.PrimitiveU32) + copied.ErrorCode = siesr.ErrorCode.Copy().(*types.PrimitiveU32) + copied.CorrelationID = siesr.CorrelationID.Copy().(*types.String) + + return copied +} + +// Equals checks if the given ServiceItemEShopResponse contains the same data as the current ServiceItemEShopResponse +func (siesr *ServiceItemEShopResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemEShopResponse); !ok { + return false + } + + other := o.(*ServiceItemEShopResponse) + + if siesr.StructureVersion != other.StructureVersion { + return false + } + + if !siesr.HTTPStatus.Equals(other.HTTPStatus) { + return false + } + + if !siesr.ErrorCode.Equals(other.ErrorCode) { + return false + } + + return siesr.CorrelationID.Equals(other.CorrelationID) +} + +// String returns the string representation of the ServiceItemEShopResponse +func (siesr *ServiceItemEShopResponse) String() string { + return siesr.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemEShopResponse using the provided indentation level +func (siesr *ServiceItemEShopResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemEShopResponse{\n") + b.WriteString(fmt.Sprintf("%sHTTPStatus: %s,\n", indentationValues, siesr.HTTPStatus)) + b.WriteString(fmt.Sprintf("%sErrorCode: %s,\n", indentationValues, siesr.ErrorCode)) + b.WriteString(fmt.Sprintf("%sCorrelationID: %s,\n", indentationValues, siesr.CorrelationID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemEShopResponse returns a new ServiceItemEShopResponse +func NewServiceItemEShopResponse() *ServiceItemEShopResponse { + siesr := &ServiceItemEShopResponse{ + HTTPStatus: types.NewPrimitiveU32(0), + ErrorCode: types.NewPrimitiveU32(0), + CorrelationID: types.NewString(""), + } + + return siesr +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_balance_param.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_balance_param.go new file mode 100644 index 0000000..e9f268b --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_balance_param.go @@ -0,0 +1,131 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetBalanceParam is a type within the ServiceItem protocol +type ServiceItemGetBalanceParam struct { + types.Structure + Language *types.String + UniqueID *types.PrimitiveU32 + Platform *types.PrimitiveU8 // * Revision 1 +} + +// WriteTo writes the ServiceItemGetBalanceParam to the given writable +func (sigbp *ServiceItemGetBalanceParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sigbp.Language.WriteTo(contentWritable) + sigbp.UniqueID.WriteTo(contentWritable) + + if sigbp.StructureVersion >= 1 { + sigbp.Platform.WriteTo(contentWritable) + } + + content := contentWritable.Bytes() + + sigbp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetBalanceParam from the given readable +func (sigbp *ServiceItemGetBalanceParam) ExtractFrom(readable types.Readable) error { + var err error + + err = sigbp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetBalanceParam header. %s", err.Error()) + } + + err = sigbp.Language.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetBalanceParam.Language. %s", err.Error()) + } + + err = sigbp.UniqueID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetBalanceParam.UniqueID. %s", err.Error()) + } + + if sigbp.StructureVersion >= 1 { + err = sigbp.Platform.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetBalanceParam.Platform. %s", err.Error()) + } + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetBalanceParam +func (sigbp *ServiceItemGetBalanceParam) Copy() types.RVType { + copied := NewServiceItemGetBalanceParam() + + copied.StructureVersion = sigbp.StructureVersion + copied.Language = sigbp.Language.Copy().(*types.String) + copied.UniqueID = sigbp.UniqueID.Copy().(*types.PrimitiveU32) + copied.Platform = sigbp.Platform.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given ServiceItemGetBalanceParam contains the same data as the current ServiceItemGetBalanceParam +func (sigbp *ServiceItemGetBalanceParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetBalanceParam); !ok { + return false + } + + other := o.(*ServiceItemGetBalanceParam) + + if sigbp.StructureVersion != other.StructureVersion { + return false + } + + if !sigbp.Language.Equals(other.Language) { + return false + } + + if !sigbp.UniqueID.Equals(other.UniqueID) { + return false + } + + return sigbp.Platform.Equals(other.Platform) +} + +// String returns the string representation of the ServiceItemGetBalanceParam +func (sigbp *ServiceItemGetBalanceParam) String() string { + return sigbp.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetBalanceParam using the provided indentation level +func (sigbp *ServiceItemGetBalanceParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetBalanceParam{\n") + b.WriteString(fmt.Sprintf("%sLanguage: %s,\n", indentationValues, sigbp.Language)) + b.WriteString(fmt.Sprintf("%sUniqueID: %s,\n", indentationValues, sigbp.UniqueID)) + b.WriteString(fmt.Sprintf("%sPlatform: %s,\n", indentationValues, sigbp.Platform)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetBalanceParam returns a new ServiceItemGetBalanceParam +func NewServiceItemGetBalanceParam() *ServiceItemGetBalanceParam { + sigbp := &ServiceItemGetBalanceParam{ + Language: types.NewString(""), + UniqueID: types.NewPrimitiveU32(0), + Platform: types.NewPrimitiveU8(0), + } + + return sigbp +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_balance_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_balance_response.go new file mode 100644 index 0000000..f274469 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_balance_response.go @@ -0,0 +1,115 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetBalanceResponse is a type within the ServiceItem protocol +type ServiceItemGetBalanceResponse struct { + types.Structure + *ServiceItemEShopResponse + NullableBalance *types.List[*ServiceItemAmount] +} + +// WriteTo writes the ServiceItemGetBalanceResponse to the given writable +func (sigbr *ServiceItemGetBalanceResponse) WriteTo(writable types.Writable) { + sigbr.ServiceItemEShopResponse.WriteTo(writable) + + contentWritable := writable.CopyNew() + + sigbr.NullableBalance.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sigbr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetBalanceResponse from the given readable +func (sigbr *ServiceItemGetBalanceResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = sigbr.ServiceItemEShopResponse.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetBalanceResponse.ServiceItemEShopResponse. %s", err.Error()) + } + + err = sigbr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetBalanceResponse header. %s", err.Error()) + } + + err = sigbr.NullableBalance.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetBalanceResponse.NullableBalance. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetBalanceResponse +func (sigbr *ServiceItemGetBalanceResponse) Copy() types.RVType { + copied := NewServiceItemGetBalanceResponse() + + copied.StructureVersion = sigbr.StructureVersion + copied.ServiceItemEShopResponse = sigbr.ServiceItemEShopResponse.Copy().(*ServiceItemEShopResponse) + copied.NullableBalance = sigbr.NullableBalance.Copy().(*types.List[*ServiceItemAmount]) + + return copied +} + +// Equals checks if the given ServiceItemGetBalanceResponse contains the same data as the current ServiceItemGetBalanceResponse +func (sigbr *ServiceItemGetBalanceResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetBalanceResponse); !ok { + return false + } + + other := o.(*ServiceItemGetBalanceResponse) + + if sigbr.StructureVersion != other.StructureVersion { + return false + } + + if !sigbr.ServiceItemEShopResponse.Equals(other.ServiceItemEShopResponse) { + return false + } + + return sigbr.NullableBalance.Equals(other.NullableBalance) +} + +// String returns the string representation of the ServiceItemGetBalanceResponse +func (sigbr *ServiceItemGetBalanceResponse) String() string { + return sigbr.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetBalanceResponse using the provided indentation level +func (sigbr *ServiceItemGetBalanceResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetBalanceResponse{\n") + b.WriteString(fmt.Sprintf("%sServiceItemEShopResponse (parent): %s,\n", indentationValues, sigbr.ServiceItemEShopResponse.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sNullableBalance: %s,\n", indentationValues, sigbr.NullableBalance)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetBalanceResponse returns a new ServiceItemGetBalanceResponse +func NewServiceItemGetBalanceResponse() *ServiceItemGetBalanceResponse { + sigbr := &ServiceItemGetBalanceResponse{ + ServiceItemEShopResponse: NewServiceItemEShopResponse(), + NullableBalance: types.NewList[*ServiceItemAmount](), + } + + sigbr.NullableBalance.Type = NewServiceItemAmount() + + return sigbr +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_law_message_param.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_law_message_param.go new file mode 100644 index 0000000..266231a --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_law_message_param.go @@ -0,0 +1,131 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetLawMessageParam is a type within the ServiceItem protocol +type ServiceItemGetLawMessageParam struct { + types.Structure + Language *types.String + UniqueID *types.PrimitiveU32 + Platform *types.PrimitiveU8 // * Revision 1 +} + +// WriteTo writes the ServiceItemGetLawMessageParam to the given writable +func (siglmp *ServiceItemGetLawMessageParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siglmp.Language.WriteTo(contentWritable) + siglmp.UniqueID.WriteTo(contentWritable) + + if siglmp.StructureVersion >= 1 { + siglmp.Platform.WriteTo(contentWritable) + } + + content := contentWritable.Bytes() + + siglmp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetLawMessageParam from the given readable +func (siglmp *ServiceItemGetLawMessageParam) ExtractFrom(readable types.Readable) error { + var err error + + err = siglmp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetLawMessageParam header. %s", err.Error()) + } + + err = siglmp.Language.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetLawMessageParam.Language. %s", err.Error()) + } + + err = siglmp.UniqueID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetLawMessageParam.UniqueID. %s", err.Error()) + } + + if siglmp.StructureVersion >= 1 { + err = siglmp.Platform.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetLawMessageParam.Platform. %s", err.Error()) + } + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetLawMessageParam +func (siglmp *ServiceItemGetLawMessageParam) Copy() types.RVType { + copied := NewServiceItemGetLawMessageParam() + + copied.StructureVersion = siglmp.StructureVersion + copied.Language = siglmp.Language.Copy().(*types.String) + copied.UniqueID = siglmp.UniqueID.Copy().(*types.PrimitiveU32) + copied.Platform = siglmp.Platform.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given ServiceItemGetLawMessageParam contains the same data as the current ServiceItemGetLawMessageParam +func (siglmp *ServiceItemGetLawMessageParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetLawMessageParam); !ok { + return false + } + + other := o.(*ServiceItemGetLawMessageParam) + + if siglmp.StructureVersion != other.StructureVersion { + return false + } + + if !siglmp.Language.Equals(other.Language) { + return false + } + + if !siglmp.UniqueID.Equals(other.UniqueID) { + return false + } + + return siglmp.Platform.Equals(other.Platform) +} + +// String returns the string representation of the ServiceItemGetLawMessageParam +func (siglmp *ServiceItemGetLawMessageParam) String() string { + return siglmp.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetLawMessageParam using the provided indentation level +func (siglmp *ServiceItemGetLawMessageParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetLawMessageParam{\n") + b.WriteString(fmt.Sprintf("%sLanguage: %s,\n", indentationValues, siglmp.Language)) + b.WriteString(fmt.Sprintf("%sUniqueID: %s,\n", indentationValues, siglmp.UniqueID)) + b.WriteString(fmt.Sprintf("%sPlatform: %s,\n", indentationValues, siglmp.Platform)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetLawMessageParam returns a new ServiceItemGetLawMessageParam +func NewServiceItemGetLawMessageParam() *ServiceItemGetLawMessageParam { + siglmp := &ServiceItemGetLawMessageParam{ + Language: types.NewString(""), + UniqueID: types.NewPrimitiveU32(0), + Platform: types.NewPrimitiveU8(0), + } + + return siglmp +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_law_message_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_law_message_response.go new file mode 100644 index 0000000..c40736d --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_law_message_response.go @@ -0,0 +1,115 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetLawMessageResponse is a type within the ServiceItem protocol +type ServiceItemGetLawMessageResponse struct { + types.Structure + *ServiceItemEShopResponse + NullableLawMessage *types.List[*ServiceItemLawMessage] +} + +// WriteTo writes the ServiceItemGetLawMessageResponse to the given writable +func (siglmr *ServiceItemGetLawMessageResponse) WriteTo(writable types.Writable) { + siglmr.ServiceItemEShopResponse.WriteTo(writable) + + contentWritable := writable.CopyNew() + + siglmr.NullableLawMessage.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siglmr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetLawMessageResponse from the given readable +func (siglmr *ServiceItemGetLawMessageResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = siglmr.ServiceItemEShopResponse.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetLawMessageResponse.ServiceItemEShopResponse. %s", err.Error()) + } + + err = siglmr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetLawMessageResponse header. %s", err.Error()) + } + + err = siglmr.NullableLawMessage.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetLawMessageResponse.NullableLawMessage. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetLawMessageResponse +func (siglmr *ServiceItemGetLawMessageResponse) Copy() types.RVType { + copied := NewServiceItemGetLawMessageResponse() + + copied.StructureVersion = siglmr.StructureVersion + copied.ServiceItemEShopResponse = siglmr.ServiceItemEShopResponse.Copy().(*ServiceItemEShopResponse) + copied.NullableLawMessage = siglmr.NullableLawMessage.Copy().(*types.List[*ServiceItemLawMessage]) + + return copied +} + +// Equals checks if the given ServiceItemGetLawMessageResponse contains the same data as the current ServiceItemGetLawMessageResponse +func (siglmr *ServiceItemGetLawMessageResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetLawMessageResponse); !ok { + return false + } + + other := o.(*ServiceItemGetLawMessageResponse) + + if siglmr.StructureVersion != other.StructureVersion { + return false + } + + if !siglmr.ServiceItemEShopResponse.Equals(other.ServiceItemEShopResponse) { + return false + } + + return siglmr.NullableLawMessage.Equals(other.NullableLawMessage) +} + +// String returns the string representation of the ServiceItemGetLawMessageResponse +func (siglmr *ServiceItemGetLawMessageResponse) String() string { + return siglmr.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetLawMessageResponse using the provided indentation level +func (siglmr *ServiceItemGetLawMessageResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetLawMessageResponse{\n") + b.WriteString(fmt.Sprintf("%sServiceItemEShopResponse (parent): %s,\n", indentationValues, siglmr.ServiceItemEShopResponse.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sNullableLawMessage: %s,\n", indentationValues, siglmr.NullableLawMessage)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetLawMessageResponse returns a new ServiceItemGetLawMessageResponse +func NewServiceItemGetLawMessageResponse() *ServiceItemGetLawMessageResponse { + siglmr := &ServiceItemGetLawMessageResponse{ + ServiceItemEShopResponse: NewServiceItemEShopResponse(), + NullableLawMessage: types.NewList[*ServiceItemLawMessage](), + } + + siglmr.NullableLawMessage.Type = NewServiceItemLawMessage() + + return siglmr +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_notice_param.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_notice_param.go new file mode 100644 index 0000000..6612856 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_notice_param.go @@ -0,0 +1,98 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetNoticeParam is a type within the ServiceItem protocol +type ServiceItemGetNoticeParam struct { + types.Structure + ScheduleType *types.PrimitiveU32 +} + +// WriteTo writes the ServiceItemGetNoticeParam to the given writable +func (signp *ServiceItemGetNoticeParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + signp.ScheduleType.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + signp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetNoticeParam from the given readable +func (signp *ServiceItemGetNoticeParam) ExtractFrom(readable types.Readable) error { + var err error + + err = signp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetNoticeParam header. %s", err.Error()) + } + + err = signp.ScheduleType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetNoticeParam.ScheduleType. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetNoticeParam +func (signp *ServiceItemGetNoticeParam) Copy() types.RVType { + copied := NewServiceItemGetNoticeParam() + + copied.StructureVersion = signp.StructureVersion + copied.ScheduleType = signp.ScheduleType.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given ServiceItemGetNoticeParam contains the same data as the current ServiceItemGetNoticeParam +func (signp *ServiceItemGetNoticeParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetNoticeParam); !ok { + return false + } + + other := o.(*ServiceItemGetNoticeParam) + + if signp.StructureVersion != other.StructureVersion { + return false + } + + return signp.ScheduleType.Equals(other.ScheduleType) +} + +// String returns the string representation of the ServiceItemGetNoticeParam +func (signp *ServiceItemGetNoticeParam) String() string { + return signp.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetNoticeParam using the provided indentation level +func (signp *ServiceItemGetNoticeParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetNoticeParam{\n") + b.WriteString(fmt.Sprintf("%sScheduleType: %s,\n", indentationValues, signp.ScheduleType)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetNoticeParam returns a new ServiceItemGetNoticeParam +func NewServiceItemGetNoticeParam() *ServiceItemGetNoticeParam { + signp := &ServiceItemGetNoticeParam{ + ScheduleType: types.NewPrimitiveU32(0), + } + + return signp +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_prepurchase_info_param.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_prepurchase_info_param.go new file mode 100644 index 0000000..f399347 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_prepurchase_info_param.go @@ -0,0 +1,154 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetPrepurchaseInfoParam is a type within the ServiceItem protocol +type ServiceItemGetPrepurchaseInfoParam struct { + types.Structure + ItemCode *types.String + ReferenceID *types.String + Limitation *ServiceItemLimitation + Language *types.String + UniqueID *types.PrimitiveU32 +} + +// WriteTo writes the ServiceItemGetPrepurchaseInfoParam to the given writable +func (sigpip *ServiceItemGetPrepurchaseInfoParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sigpip.ItemCode.WriteTo(contentWritable) + sigpip.ReferenceID.WriteTo(contentWritable) + sigpip.Limitation.WriteTo(contentWritable) + sigpip.Language.WriteTo(contentWritable) + sigpip.UniqueID.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sigpip.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetPrepurchaseInfoParam from the given readable +func (sigpip *ServiceItemGetPrepurchaseInfoParam) ExtractFrom(readable types.Readable) error { + var err error + + err = sigpip.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPrepurchaseInfoParam header. %s", err.Error()) + } + + err = sigpip.ItemCode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPrepurchaseInfoParam.ItemCode. %s", err.Error()) + } + + err = sigpip.ReferenceID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPrepurchaseInfoParam.ReferenceID. %s", err.Error()) + } + + err = sigpip.Limitation.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPrepurchaseInfoParam.Limitation. %s", err.Error()) + } + + err = sigpip.Language.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPrepurchaseInfoParam.Language. %s", err.Error()) + } + + err = sigpip.UniqueID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPrepurchaseInfoParam.UniqueID. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetPrepurchaseInfoParam +func (sigpip *ServiceItemGetPrepurchaseInfoParam) Copy() types.RVType { + copied := NewServiceItemGetPrepurchaseInfoParam() + + copied.StructureVersion = sigpip.StructureVersion + copied.ItemCode = sigpip.ItemCode.Copy().(*types.String) + copied.ReferenceID = sigpip.ReferenceID.Copy().(*types.String) + copied.Limitation = sigpip.Limitation.Copy().(*ServiceItemLimitation) + copied.Language = sigpip.Language.Copy().(*types.String) + copied.UniqueID = sigpip.UniqueID.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given ServiceItemGetPrepurchaseInfoParam contains the same data as the current ServiceItemGetPrepurchaseInfoParam +func (sigpip *ServiceItemGetPrepurchaseInfoParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetPrepurchaseInfoParam); !ok { + return false + } + + other := o.(*ServiceItemGetPrepurchaseInfoParam) + + if sigpip.StructureVersion != other.StructureVersion { + return false + } + + if !sigpip.ItemCode.Equals(other.ItemCode) { + return false + } + + if !sigpip.ReferenceID.Equals(other.ReferenceID) { + return false + } + + if !sigpip.Limitation.Equals(other.Limitation) { + return false + } + + if !sigpip.Language.Equals(other.Language) { + return false + } + + return sigpip.UniqueID.Equals(other.UniqueID) +} + +// String returns the string representation of the ServiceItemGetPrepurchaseInfoParam +func (sigpip *ServiceItemGetPrepurchaseInfoParam) String() string { + return sigpip.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetPrepurchaseInfoParam using the provided indentation level +func (sigpip *ServiceItemGetPrepurchaseInfoParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetPrepurchaseInfoParam{\n") + b.WriteString(fmt.Sprintf("%sItemCode: %s,\n", indentationValues, sigpip.ItemCode)) + b.WriteString(fmt.Sprintf("%sReferenceID: %s,\n", indentationValues, sigpip.ReferenceID)) + b.WriteString(fmt.Sprintf("%sLimitation: %s,\n", indentationValues, sigpip.Limitation.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sLanguage: %s,\n", indentationValues, sigpip.Language)) + b.WriteString(fmt.Sprintf("%sUniqueID: %s,\n", indentationValues, sigpip.UniqueID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetPrepurchaseInfoParam returns a new ServiceItemGetPrepurchaseInfoParam +func NewServiceItemGetPrepurchaseInfoParam() *ServiceItemGetPrepurchaseInfoParam { + sigpip := &ServiceItemGetPrepurchaseInfoParam{ + ItemCode: types.NewString(""), + ReferenceID: types.NewString(""), + Limitation: NewServiceItemLimitation(), + Language: types.NewString(""), + UniqueID: types.NewPrimitiveU32(0), + } + + return sigpip +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_prepurchase_info_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_prepurchase_info_response.go new file mode 100644 index 0000000..222f513 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_prepurchase_info_response.go @@ -0,0 +1,115 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetPrepurchaseInfoResponse is a type within the ServiceItem protocol +type ServiceItemGetPrepurchaseInfoResponse struct { + types.Structure + *ServiceItemEShopResponse + NullablePrepurchaseInfo *types.List[*ServiceItemPrepurchaseInfo] +} + +// WriteTo writes the ServiceItemGetPrepurchaseInfoResponse to the given writable +func (sigpir *ServiceItemGetPrepurchaseInfoResponse) WriteTo(writable types.Writable) { + sigpir.ServiceItemEShopResponse.WriteTo(writable) + + contentWritable := writable.CopyNew() + + sigpir.NullablePrepurchaseInfo.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sigpir.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetPrepurchaseInfoResponse from the given readable +func (sigpir *ServiceItemGetPrepurchaseInfoResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = sigpir.ServiceItemEShopResponse.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPrepurchaseInfoResponse.ServiceItemEShopResponse. %s", err.Error()) + } + + err = sigpir.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPrepurchaseInfoResponse header. %s", err.Error()) + } + + err = sigpir.NullablePrepurchaseInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPrepurchaseInfoResponse.NullablePrepurchaseInfo. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetPrepurchaseInfoResponse +func (sigpir *ServiceItemGetPrepurchaseInfoResponse) Copy() types.RVType { + copied := NewServiceItemGetPrepurchaseInfoResponse() + + copied.StructureVersion = sigpir.StructureVersion + copied.ServiceItemEShopResponse = sigpir.ServiceItemEShopResponse.Copy().(*ServiceItemEShopResponse) + copied.NullablePrepurchaseInfo = sigpir.NullablePrepurchaseInfo.Copy().(*types.List[*ServiceItemPrepurchaseInfo]) + + return copied +} + +// Equals checks if the given ServiceItemGetPrepurchaseInfoResponse contains the same data as the current ServiceItemGetPrepurchaseInfoResponse +func (sigpir *ServiceItemGetPrepurchaseInfoResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetPrepurchaseInfoResponse); !ok { + return false + } + + other := o.(*ServiceItemGetPrepurchaseInfoResponse) + + if sigpir.StructureVersion != other.StructureVersion { + return false + } + + if !sigpir.ServiceItemEShopResponse.Equals(other.ServiceItemEShopResponse) { + return false + } + + return sigpir.NullablePrepurchaseInfo.Equals(other.NullablePrepurchaseInfo) +} + +// String returns the string representation of the ServiceItemGetPrepurchaseInfoResponse +func (sigpir *ServiceItemGetPrepurchaseInfoResponse) String() string { + return sigpir.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetPrepurchaseInfoResponse using the provided indentation level +func (sigpir *ServiceItemGetPrepurchaseInfoResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetPrepurchaseInfoResponse{\n") + b.WriteString(fmt.Sprintf("%sServiceItemEShopResponse (parent): %s,\n", indentationValues, sigpir.ServiceItemEShopResponse.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sNullablePrepurchaseInfo: %s,\n", indentationValues, sigpir.NullablePrepurchaseInfo)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetPrepurchaseInfoResponse returns a new ServiceItemGetPrepurchaseInfoResponse +func NewServiceItemGetPrepurchaseInfoResponse() *ServiceItemGetPrepurchaseInfoResponse { + sigpir := &ServiceItemGetPrepurchaseInfoResponse{ + ServiceItemEShopResponse: NewServiceItemEShopResponse(), + NullablePrepurchaseInfo: types.NewList[*ServiceItemPrepurchaseInfo](), + } + + sigpir.NullablePrepurchaseInfo.Type = NewServiceItemPrepurchaseInfo() + + return sigpir +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_purchase_history_param.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_purchase_history_param.go new file mode 100644 index 0000000..bc7aa5a --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_purchase_history_param.go @@ -0,0 +1,154 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetPurchaseHistoryParam is a type within the ServiceItem protocol +type ServiceItemGetPurchaseHistoryParam struct { + types.Structure + Language *types.String + Offset *types.PrimitiveU32 + Size *types.PrimitiveU32 + UniqueID *types.PrimitiveU32 + Platform *types.PrimitiveU8 +} + +// WriteTo writes the ServiceItemGetPurchaseHistoryParam to the given writable +func (sigphp *ServiceItemGetPurchaseHistoryParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sigphp.Language.WriteTo(contentWritable) + sigphp.Offset.WriteTo(contentWritable) + sigphp.Size.WriteTo(contentWritable) + sigphp.UniqueID.WriteTo(contentWritable) + sigphp.Platform.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sigphp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetPurchaseHistoryParam from the given readable +func (sigphp *ServiceItemGetPurchaseHistoryParam) ExtractFrom(readable types.Readable) error { + var err error + + err = sigphp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPurchaseHistoryParam header. %s", err.Error()) + } + + err = sigphp.Language.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPurchaseHistoryParam.Language. %s", err.Error()) + } + + err = sigphp.Offset.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPurchaseHistoryParam.Offset. %s", err.Error()) + } + + err = sigphp.Size.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPurchaseHistoryParam.Size. %s", err.Error()) + } + + err = sigphp.UniqueID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPurchaseHistoryParam.UniqueID. %s", err.Error()) + } + + err = sigphp.Platform.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPurchaseHistoryParam.Platform. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetPurchaseHistoryParam +func (sigphp *ServiceItemGetPurchaseHistoryParam) Copy() types.RVType { + copied := NewServiceItemGetPurchaseHistoryParam() + + copied.StructureVersion = sigphp.StructureVersion + copied.Language = sigphp.Language.Copy().(*types.String) + copied.Offset = sigphp.Offset.Copy().(*types.PrimitiveU32) + copied.Size = sigphp.Size.Copy().(*types.PrimitiveU32) + copied.UniqueID = sigphp.UniqueID.Copy().(*types.PrimitiveU32) + copied.Platform = sigphp.Platform.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given ServiceItemGetPurchaseHistoryParam contains the same data as the current ServiceItemGetPurchaseHistoryParam +func (sigphp *ServiceItemGetPurchaseHistoryParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetPurchaseHistoryParam); !ok { + return false + } + + other := o.(*ServiceItemGetPurchaseHistoryParam) + + if sigphp.StructureVersion != other.StructureVersion { + return false + } + + if !sigphp.Language.Equals(other.Language) { + return false + } + + if !sigphp.Offset.Equals(other.Offset) { + return false + } + + if !sigphp.Size.Equals(other.Size) { + return false + } + + if !sigphp.UniqueID.Equals(other.UniqueID) { + return false + } + + return sigphp.Platform.Equals(other.Platform) +} + +// String returns the string representation of the ServiceItemGetPurchaseHistoryParam +func (sigphp *ServiceItemGetPurchaseHistoryParam) String() string { + return sigphp.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetPurchaseHistoryParam using the provided indentation level +func (sigphp *ServiceItemGetPurchaseHistoryParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetPurchaseHistoryParam{\n") + b.WriteString(fmt.Sprintf("%sLanguage: %s,\n", indentationValues, sigphp.Language)) + b.WriteString(fmt.Sprintf("%sOffset: %s,\n", indentationValues, sigphp.Offset)) + b.WriteString(fmt.Sprintf("%sSize: %s,\n", indentationValues, sigphp.Size)) + b.WriteString(fmt.Sprintf("%sUniqueID: %s,\n", indentationValues, sigphp.UniqueID)) + b.WriteString(fmt.Sprintf("%sPlatform: %s,\n", indentationValues, sigphp.Platform)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetPurchaseHistoryParam returns a new ServiceItemGetPurchaseHistoryParam +func NewServiceItemGetPurchaseHistoryParam() *ServiceItemGetPurchaseHistoryParam { + sigphp := &ServiceItemGetPurchaseHistoryParam{ + Language: types.NewString(""), + Offset: types.NewPrimitiveU32(0), + Size: types.NewPrimitiveU32(0), + UniqueID: types.NewPrimitiveU32(0), + Platform: types.NewPrimitiveU8(0), + } + + return sigphp +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_purchase_history_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_purchase_history_response.go new file mode 100644 index 0000000..4cf460e --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_purchase_history_response.go @@ -0,0 +1,115 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetPurchaseHistoryResponse is a type within the ServiceItem protocol +type ServiceItemGetPurchaseHistoryResponse struct { + types.Structure + *ServiceItemEShopResponse + NullablePurchaseHistory *types.List[*ServiceItemPurchaseHistory] +} + +// WriteTo writes the ServiceItemGetPurchaseHistoryResponse to the given writable +func (sigphr *ServiceItemGetPurchaseHistoryResponse) WriteTo(writable types.Writable) { + sigphr.ServiceItemEShopResponse.WriteTo(writable) + + contentWritable := writable.CopyNew() + + sigphr.NullablePurchaseHistory.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sigphr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetPurchaseHistoryResponse from the given readable +func (sigphr *ServiceItemGetPurchaseHistoryResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = sigphr.ServiceItemEShopResponse.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPurchaseHistoryResponse.ServiceItemEShopResponse. %s", err.Error()) + } + + err = sigphr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPurchaseHistoryResponse header. %s", err.Error()) + } + + err = sigphr.NullablePurchaseHistory.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPurchaseHistoryResponse.NullablePurchaseHistory. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetPurchaseHistoryResponse +func (sigphr *ServiceItemGetPurchaseHistoryResponse) Copy() types.RVType { + copied := NewServiceItemGetPurchaseHistoryResponse() + + copied.StructureVersion = sigphr.StructureVersion + copied.ServiceItemEShopResponse = sigphr.ServiceItemEShopResponse.Copy().(*ServiceItemEShopResponse) + copied.NullablePurchaseHistory = sigphr.NullablePurchaseHistory.Copy().(*types.List[*ServiceItemPurchaseHistory]) + + return copied +} + +// Equals checks if the given ServiceItemGetPurchaseHistoryResponse contains the same data as the current ServiceItemGetPurchaseHistoryResponse +func (sigphr *ServiceItemGetPurchaseHistoryResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetPurchaseHistoryResponse); !ok { + return false + } + + other := o.(*ServiceItemGetPurchaseHistoryResponse) + + if sigphr.StructureVersion != other.StructureVersion { + return false + } + + if !sigphr.ServiceItemEShopResponse.Equals(other.ServiceItemEShopResponse) { + return false + } + + return sigphr.NullablePurchaseHistory.Equals(other.NullablePurchaseHistory) +} + +// String returns the string representation of the ServiceItemGetPurchaseHistoryResponse +func (sigphr *ServiceItemGetPurchaseHistoryResponse) String() string { + return sigphr.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetPurchaseHistoryResponse using the provided indentation level +func (sigphr *ServiceItemGetPurchaseHistoryResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetPurchaseHistoryResponse{\n") + b.WriteString(fmt.Sprintf("%sServiceItemEShopResponse (parent): %s,\n", indentationValues, sigphr.ServiceItemEShopResponse.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sNullablePurchaseHistory: %s,\n", indentationValues, sigphr.NullablePurchaseHistory)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetPurchaseHistoryResponse returns a new ServiceItemGetPurchaseHistoryResponse +func NewServiceItemGetPurchaseHistoryResponse() *ServiceItemGetPurchaseHistoryResponse { + sigphr := &ServiceItemGetPurchaseHistoryResponse{ + ServiceItemEShopResponse: NewServiceItemEShopResponse(), + NullablePurchaseHistory: types.NewList[*ServiceItemPurchaseHistory](), + } + + sigphr.NullablePurchaseHistory.Type = NewServiceItemPurchaseHistory() + + return sigphr +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_service_item_right_param.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_service_item_right_param.go new file mode 100644 index 0000000..614d888 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_service_item_right_param.go @@ -0,0 +1,159 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetServiceItemRightParam is a type within the ServiceItem protocol +type ServiceItemGetServiceItemRightParam struct { + types.Structure + ReferenceID *types.String + DeviceID *types.String + UniqueID *types.PrimitiveU32 + ItemGroup *types.PrimitiveU8 + Platform *types.PrimitiveU8 // * Revision 1 +} + +// WriteTo writes the ServiceItemGetServiceItemRightParam to the given writable +func (sigsirp *ServiceItemGetServiceItemRightParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sigsirp.ReferenceID.WriteTo(contentWritable) + sigsirp.DeviceID.WriteTo(contentWritable) + sigsirp.UniqueID.WriteTo(contentWritable) + sigsirp.ItemGroup.WriteTo(contentWritable) + + if sigsirp.StructureVersion >= 1 { + sigsirp.Platform.WriteTo(contentWritable) + } + + content := contentWritable.Bytes() + + sigsirp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetServiceItemRightParam from the given readable +func (sigsirp *ServiceItemGetServiceItemRightParam) ExtractFrom(readable types.Readable) error { + var err error + + err = sigsirp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetServiceItemRightParam header. %s", err.Error()) + } + + err = sigsirp.ReferenceID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetServiceItemRightParam.ReferenceID. %s", err.Error()) + } + + err = sigsirp.DeviceID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetServiceItemRightParam.DeviceID. %s", err.Error()) + } + + err = sigsirp.UniqueID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetServiceItemRightParam.UniqueID. %s", err.Error()) + } + + err = sigsirp.ItemGroup.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetServiceItemRightParam.ItemGroup. %s", err.Error()) + } + + if sigsirp.StructureVersion >= 1 { + err = sigsirp.Platform.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetServiceItemRightParam.Platform. %s", err.Error()) + } + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetServiceItemRightParam +func (sigsirp *ServiceItemGetServiceItemRightParam) Copy() types.RVType { + copied := NewServiceItemGetServiceItemRightParam() + + copied.StructureVersion = sigsirp.StructureVersion + copied.ReferenceID = sigsirp.ReferenceID.Copy().(*types.String) + copied.DeviceID = sigsirp.DeviceID.Copy().(*types.String) + copied.UniqueID = sigsirp.UniqueID.Copy().(*types.PrimitiveU32) + copied.ItemGroup = sigsirp.ItemGroup.Copy().(*types.PrimitiveU8) + copied.Platform = sigsirp.Platform.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given ServiceItemGetServiceItemRightParam contains the same data as the current ServiceItemGetServiceItemRightParam +func (sigsirp *ServiceItemGetServiceItemRightParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetServiceItemRightParam); !ok { + return false + } + + other := o.(*ServiceItemGetServiceItemRightParam) + + if sigsirp.StructureVersion != other.StructureVersion { + return false + } + + if !sigsirp.ReferenceID.Equals(other.ReferenceID) { + return false + } + + if !sigsirp.DeviceID.Equals(other.DeviceID) { + return false + } + + if !sigsirp.UniqueID.Equals(other.UniqueID) { + return false + } + + if !sigsirp.ItemGroup.Equals(other.ItemGroup) { + return false + } + + return sigsirp.Platform.Equals(other.Platform) +} + +// String returns the string representation of the ServiceItemGetServiceItemRightParam +func (sigsirp *ServiceItemGetServiceItemRightParam) String() string { + return sigsirp.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetServiceItemRightParam using the provided indentation level +func (sigsirp *ServiceItemGetServiceItemRightParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetServiceItemRightParam{\n") + b.WriteString(fmt.Sprintf("%sReferenceID: %s,\n", indentationValues, sigsirp.ReferenceID)) + b.WriteString(fmt.Sprintf("%sDeviceID: %s,\n", indentationValues, sigsirp.DeviceID)) + b.WriteString(fmt.Sprintf("%sUniqueID: %s,\n", indentationValues, sigsirp.UniqueID)) + b.WriteString(fmt.Sprintf("%sItemGroup: %s,\n", indentationValues, sigsirp.ItemGroup)) + b.WriteString(fmt.Sprintf("%sPlatform: %s,\n", indentationValues, sigsirp.Platform)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetServiceItemRightParam returns a new ServiceItemGetServiceItemRightParam +func NewServiceItemGetServiceItemRightParam() *ServiceItemGetServiceItemRightParam { + sigsirp := &ServiceItemGetServiceItemRightParam{ + ReferenceID: types.NewString(""), + DeviceID: types.NewString(""), + UniqueID: types.NewPrimitiveU32(0), + ItemGroup: types.NewPrimitiveU8(0), + Platform: types.NewPrimitiveU8(0), + } + + return sigsirp +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_service_item_right_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_service_item_right_response.go new file mode 100644 index 0000000..804af19 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_service_item_right_response.go @@ -0,0 +1,115 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetServiceItemRightResponse is a type within the ServiceItem protocol +type ServiceItemGetServiceItemRightResponse struct { + types.Structure + *ServiceItemEShopResponse + NullableRightInfos *types.List[*ServiceItemRightInfos] +} + +// WriteTo writes the ServiceItemGetServiceItemRightResponse to the given writable +func (sigsirr *ServiceItemGetServiceItemRightResponse) WriteTo(writable types.Writable) { + sigsirr.ServiceItemEShopResponse.WriteTo(writable) + + contentWritable := writable.CopyNew() + + sigsirr.NullableRightInfos.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sigsirr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetServiceItemRightResponse from the given readable +func (sigsirr *ServiceItemGetServiceItemRightResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = sigsirr.ServiceItemEShopResponse.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetServiceItemRightResponse.ServiceItemEShopResponse. %s", err.Error()) + } + + err = sigsirr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetServiceItemRightResponse header. %s", err.Error()) + } + + err = sigsirr.NullableRightInfos.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetServiceItemRightResponse.NullableRightInfos. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetServiceItemRightResponse +func (sigsirr *ServiceItemGetServiceItemRightResponse) Copy() types.RVType { + copied := NewServiceItemGetServiceItemRightResponse() + + copied.StructureVersion = sigsirr.StructureVersion + copied.ServiceItemEShopResponse = sigsirr.ServiceItemEShopResponse.Copy().(*ServiceItemEShopResponse) + copied.NullableRightInfos = sigsirr.NullableRightInfos.Copy().(*types.List[*ServiceItemRightInfos]) + + return copied +} + +// Equals checks if the given ServiceItemGetServiceItemRightResponse contains the same data as the current ServiceItemGetServiceItemRightResponse +func (sigsirr *ServiceItemGetServiceItemRightResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetServiceItemRightResponse); !ok { + return false + } + + other := o.(*ServiceItemGetServiceItemRightResponse) + + if sigsirr.StructureVersion != other.StructureVersion { + return false + } + + if !sigsirr.ServiceItemEShopResponse.Equals(other.ServiceItemEShopResponse) { + return false + } + + return sigsirr.NullableRightInfos.Equals(other.NullableRightInfos) +} + +// String returns the string representation of the ServiceItemGetServiceItemRightResponse +func (sigsirr *ServiceItemGetServiceItemRightResponse) String() string { + return sigsirr.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetServiceItemRightResponse using the provided indentation level +func (sigsirr *ServiceItemGetServiceItemRightResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetServiceItemRightResponse{\n") + b.WriteString(fmt.Sprintf("%sServiceItemEShopResponse (parent): %s,\n", indentationValues, sigsirr.ServiceItemEShopResponse.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sNullableRightInfos: %s,\n", indentationValues, sigsirr.NullableRightInfos)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetServiceItemRightResponse returns a new ServiceItemGetServiceItemRightResponse +func NewServiceItemGetServiceItemRightResponse() *ServiceItemGetServiceItemRightResponse { + sigsirr := &ServiceItemGetServiceItemRightResponse{ + ServiceItemEShopResponse: NewServiceItemEShopResponse(), + NullableRightInfos: types.NewList[*ServiceItemRightInfos](), + } + + sigsirr.NullableRightInfos.Type = NewServiceItemRightInfos() + + return sigsirr +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_support_id_param.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_support_id_param.go new file mode 100644 index 0000000..fec6beb --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_get_support_id_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetSupportIDParam is a type within the ServiceItem protocol +type ServiceItemGetSupportIDParam struct { + types.Structure + UniqueID *types.PrimitiveU32 + Platform *types.PrimitiveU8 +} + +// WriteTo writes the ServiceItemGetSupportIDParam to the given writable +func (sigsidp *ServiceItemGetSupportIDParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sigsidp.UniqueID.WriteTo(contentWritable) + sigsidp.Platform.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sigsidp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetSupportIDParam from the given readable +func (sigsidp *ServiceItemGetSupportIDParam) ExtractFrom(readable types.Readable) error { + var err error + + err = sigsidp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetSupportIDParam header. %s", err.Error()) + } + + err = sigsidp.UniqueID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetSupportIDParam.UniqueID. %s", err.Error()) + } + + err = sigsidp.Platform.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetSupportIDParam.Platform. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetSupportIDParam +func (sigsidp *ServiceItemGetSupportIDParam) Copy() types.RVType { + copied := NewServiceItemGetSupportIDParam() + + copied.StructureVersion = sigsidp.StructureVersion + copied.UniqueID = sigsidp.UniqueID.Copy().(*types.PrimitiveU32) + copied.Platform = sigsidp.Platform.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given ServiceItemGetSupportIDParam contains the same data as the current ServiceItemGetSupportIDParam +func (sigsidp *ServiceItemGetSupportIDParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetSupportIDParam); !ok { + return false + } + + other := o.(*ServiceItemGetSupportIDParam) + + if sigsidp.StructureVersion != other.StructureVersion { + return false + } + + if !sigsidp.UniqueID.Equals(other.UniqueID) { + return false + } + + return sigsidp.Platform.Equals(other.Platform) +} + +// String returns the string representation of the ServiceItemGetSupportIDParam +func (sigsidp *ServiceItemGetSupportIDParam) String() string { + return sigsidp.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetSupportIDParam using the provided indentation level +func (sigsidp *ServiceItemGetSupportIDParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetSupportIDParam{\n") + b.WriteString(fmt.Sprintf("%sUniqueID: %s,\n", indentationValues, sigsidp.UniqueID)) + b.WriteString(fmt.Sprintf("%sPlatform: %s,\n", indentationValues, sigsidp.Platform)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetSupportIDParam returns a new ServiceItemGetSupportIDParam +func NewServiceItemGetSupportIDParam() *ServiceItemGetSupportIDParam { + sigsidp := &ServiceItemGetSupportIDParam{ + UniqueID: types.NewPrimitiveU32(0), + Platform: types.NewPrimitiveU8(0), + } + + return sigsidp +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_http_get_param.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_http_get_param.go new file mode 100644 index 0000000..e436cd5 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_http_get_param.go @@ -0,0 +1,98 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemHTTPGetParam is a type within the ServiceItem protocol +type ServiceItemHTTPGetParam struct { + types.Structure + URL *types.String +} + +// WriteTo writes the ServiceItemHTTPGetParam to the given writable +func (sihttpgp *ServiceItemHTTPGetParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sihttpgp.URL.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sihttpgp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemHTTPGetParam from the given readable +func (sihttpgp *ServiceItemHTTPGetParam) ExtractFrom(readable types.Readable) error { + var err error + + err = sihttpgp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemHTTPGetParam header. %s", err.Error()) + } + + err = sihttpgp.URL.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemHTTPGetParam.URL. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemHTTPGetParam +func (sihttpgp *ServiceItemHTTPGetParam) Copy() types.RVType { + copied := NewServiceItemHTTPGetParam() + + copied.StructureVersion = sihttpgp.StructureVersion + copied.URL = sihttpgp.URL.Copy().(*types.String) + + return copied +} + +// Equals checks if the given ServiceItemHTTPGetParam contains the same data as the current ServiceItemHTTPGetParam +func (sihttpgp *ServiceItemHTTPGetParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemHTTPGetParam); !ok { + return false + } + + other := o.(*ServiceItemHTTPGetParam) + + if sihttpgp.StructureVersion != other.StructureVersion { + return false + } + + return sihttpgp.URL.Equals(other.URL) +} + +// String returns the string representation of the ServiceItemHTTPGetParam +func (sihttpgp *ServiceItemHTTPGetParam) String() string { + return sihttpgp.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemHTTPGetParam using the provided indentation level +func (sihttpgp *ServiceItemHTTPGetParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemHTTPGetParam{\n") + b.WriteString(fmt.Sprintf("%sURL: %s,\n", indentationValues, sihttpgp.URL)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemHTTPGetParam returns a new ServiceItemHTTPGetParam +func NewServiceItemHTTPGetParam() *ServiceItemHTTPGetParam { + sihttpgp := &ServiceItemHTTPGetParam{ + URL: types.NewString(""), + } + + return sihttpgp +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_http_get_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_http_get_response.go new file mode 100644 index 0000000..cb46db5 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_http_get_response.go @@ -0,0 +1,98 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemHTTPGetResponse is a type within the ServiceItem protocol +type ServiceItemHTTPGetResponse struct { + types.Structure + Response *types.QBuffer +} + +// WriteTo writes the ServiceItemHTTPGetResponse to the given writable +func (sihttpgr *ServiceItemHTTPGetResponse) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sihttpgr.Response.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sihttpgr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemHTTPGetResponse from the given readable +func (sihttpgr *ServiceItemHTTPGetResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = sihttpgr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemHTTPGetResponse header. %s", err.Error()) + } + + err = sihttpgr.Response.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemHTTPGetResponse.Response. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemHTTPGetResponse +func (sihttpgr *ServiceItemHTTPGetResponse) Copy() types.RVType { + copied := NewServiceItemHTTPGetResponse() + + copied.StructureVersion = sihttpgr.StructureVersion + copied.Response = sihttpgr.Response.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given ServiceItemHTTPGetResponse contains the same data as the current ServiceItemHTTPGetResponse +func (sihttpgr *ServiceItemHTTPGetResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemHTTPGetResponse); !ok { + return false + } + + other := o.(*ServiceItemHTTPGetResponse) + + if sihttpgr.StructureVersion != other.StructureVersion { + return false + } + + return sihttpgr.Response.Equals(other.Response) +} + +// String returns the string representation of the ServiceItemHTTPGetResponse +func (sihttpgr *ServiceItemHTTPGetResponse) String() string { + return sihttpgr.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemHTTPGetResponse using the provided indentation level +func (sihttpgr *ServiceItemHTTPGetResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemHTTPGetResponse{\n") + b.WriteString(fmt.Sprintf("%sResponse: %s,\n", indentationValues, sihttpgr.Response)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemHTTPGetResponse returns a new ServiceItemHTTPGetResponse +func NewServiceItemHTTPGetResponse() *ServiceItemHTTPGetResponse { + sihttpgr := &ServiceItemHTTPGetResponse{ + Response: types.NewQBuffer(nil), + } + + return sihttpgr +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_law_message.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_law_message.go new file mode 100644 index 0000000..95112c6 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_law_message.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemLawMessage is a type within the ServiceItem protocol +type ServiceItemLawMessage struct { + types.Structure + IsMessageRequired *types.PrimitiveBool + LawMessage *types.String +} + +// WriteTo writes the ServiceItemLawMessage to the given writable +func (silm *ServiceItemLawMessage) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + silm.IsMessageRequired.WriteTo(contentWritable) + silm.LawMessage.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + silm.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemLawMessage from the given readable +func (silm *ServiceItemLawMessage) ExtractFrom(readable types.Readable) error { + var err error + + err = silm.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemLawMessage header. %s", err.Error()) + } + + err = silm.IsMessageRequired.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemLawMessage.IsMessageRequired. %s", err.Error()) + } + + err = silm.LawMessage.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemLawMessage.LawMessage. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemLawMessage +func (silm *ServiceItemLawMessage) Copy() types.RVType { + copied := NewServiceItemLawMessage() + + copied.StructureVersion = silm.StructureVersion + copied.IsMessageRequired = silm.IsMessageRequired.Copy().(*types.PrimitiveBool) + copied.LawMessage = silm.LawMessage.Copy().(*types.String) + + return copied +} + +// Equals checks if the given ServiceItemLawMessage contains the same data as the current ServiceItemLawMessage +func (silm *ServiceItemLawMessage) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemLawMessage); !ok { + return false + } + + other := o.(*ServiceItemLawMessage) + + if silm.StructureVersion != other.StructureVersion { + return false + } + + if !silm.IsMessageRequired.Equals(other.IsMessageRequired) { + return false + } + + return silm.LawMessage.Equals(other.LawMessage) +} + +// String returns the string representation of the ServiceItemLawMessage +func (silm *ServiceItemLawMessage) String() string { + return silm.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemLawMessage using the provided indentation level +func (silm *ServiceItemLawMessage) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemLawMessage{\n") + b.WriteString(fmt.Sprintf("%sIsMessageRequired: %s,\n", indentationValues, silm.IsMessageRequired)) + b.WriteString(fmt.Sprintf("%sLawMessage: %s,\n", indentationValues, silm.LawMessage)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemLawMessage returns a new ServiceItemLawMessage +func NewServiceItemLawMessage() *ServiceItemLawMessage { + silm := &ServiceItemLawMessage{ + IsMessageRequired: types.NewPrimitiveBool(false), + LawMessage: types.NewString(""), + } + + return silm +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_limitation.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_limitation.go new file mode 100644 index 0000000..1d8a03e --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_limitation.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemLimitation is a type within the ServiceItem protocol +type ServiceItemLimitation struct { + types.Structure + LimitationType *types.PrimitiveU32 + LimitationValue *types.PrimitiveU32 +} + +// WriteTo writes the ServiceItemLimitation to the given writable +func (sil *ServiceItemLimitation) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sil.LimitationType.WriteTo(contentWritable) + sil.LimitationValue.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sil.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemLimitation from the given readable +func (sil *ServiceItemLimitation) ExtractFrom(readable types.Readable) error { + var err error + + err = sil.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemLimitation header. %s", err.Error()) + } + + err = sil.LimitationType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemLimitation.LimitationType. %s", err.Error()) + } + + err = sil.LimitationValue.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemLimitation.LimitationValue. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemLimitation +func (sil *ServiceItemLimitation) Copy() types.RVType { + copied := NewServiceItemLimitation() + + copied.StructureVersion = sil.StructureVersion + copied.LimitationType = sil.LimitationType.Copy().(*types.PrimitiveU32) + copied.LimitationValue = sil.LimitationValue.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given ServiceItemLimitation contains the same data as the current ServiceItemLimitation +func (sil *ServiceItemLimitation) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemLimitation); !ok { + return false + } + + other := o.(*ServiceItemLimitation) + + if sil.StructureVersion != other.StructureVersion { + return false + } + + if !sil.LimitationType.Equals(other.LimitationType) { + return false + } + + return sil.LimitationValue.Equals(other.LimitationValue) +} + +// String returns the string representation of the ServiceItemLimitation +func (sil *ServiceItemLimitation) String() string { + return sil.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemLimitation using the provided indentation level +func (sil *ServiceItemLimitation) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemLimitation{\n") + b.WriteString(fmt.Sprintf("%sLimitationType: %s,\n", indentationValues, sil.LimitationType)) + b.WriteString(fmt.Sprintf("%sLimitationValue: %s,\n", indentationValues, sil.LimitationValue)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemLimitation returns a new ServiceItemLimitation +func NewServiceItemLimitation() *ServiceItemLimitation { + sil := &ServiceItemLimitation{ + LimitationType: types.NewPrimitiveU32(0), + LimitationValue: types.NewPrimitiveU32(0), + } + + return sil +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_list_item.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_list_item.go new file mode 100644 index 0000000..18c3e9c --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_list_item.go @@ -0,0 +1,170 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemListItem is a type within the ServiceItem protocol +type ServiceItemListItem struct { + types.Structure + ItemCode *types.String + RegularPrice *ServiceItemAmount + TaxExcluded *types.PrimitiveBool + InitialPurchaseOnly *types.PrimitiveBool + Limitation *ServiceItemLimitation + Attributes *types.List[*ServiceItemAttribute] +} + +// WriteTo writes the ServiceItemListItem to the given writable +func (sili *ServiceItemListItem) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sili.ItemCode.WriteTo(contentWritable) + sili.RegularPrice.WriteTo(contentWritable) + sili.TaxExcluded.WriteTo(contentWritable) + sili.InitialPurchaseOnly.WriteTo(contentWritable) + sili.Limitation.WriteTo(contentWritable) + sili.Attributes.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sili.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemListItem from the given readable +func (sili *ServiceItemListItem) ExtractFrom(readable types.Readable) error { + var err error + + err = sili.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListItem header. %s", err.Error()) + } + + err = sili.ItemCode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListItem.ItemCode. %s", err.Error()) + } + + err = sili.RegularPrice.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListItem.RegularPrice. %s", err.Error()) + } + + err = sili.TaxExcluded.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListItem.TaxExcluded. %s", err.Error()) + } + + err = sili.InitialPurchaseOnly.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListItem.InitialPurchaseOnly. %s", err.Error()) + } + + err = sili.Limitation.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListItem.Limitation. %s", err.Error()) + } + + err = sili.Attributes.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListItem.Attributes. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemListItem +func (sili *ServiceItemListItem) Copy() types.RVType { + copied := NewServiceItemListItem() + + copied.StructureVersion = sili.StructureVersion + copied.ItemCode = sili.ItemCode.Copy().(*types.String) + copied.RegularPrice = sili.RegularPrice.Copy().(*ServiceItemAmount) + copied.TaxExcluded = sili.TaxExcluded.Copy().(*types.PrimitiveBool) + copied.InitialPurchaseOnly = sili.InitialPurchaseOnly.Copy().(*types.PrimitiveBool) + copied.Limitation = sili.Limitation.Copy().(*ServiceItemLimitation) + copied.Attributes = sili.Attributes.Copy().(*types.List[*ServiceItemAttribute]) + + return copied +} + +// Equals checks if the given ServiceItemListItem contains the same data as the current ServiceItemListItem +func (sili *ServiceItemListItem) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemListItem); !ok { + return false + } + + other := o.(*ServiceItemListItem) + + if sili.StructureVersion != other.StructureVersion { + return false + } + + if !sili.ItemCode.Equals(other.ItemCode) { + return false + } + + if !sili.RegularPrice.Equals(other.RegularPrice) { + return false + } + + if !sili.TaxExcluded.Equals(other.TaxExcluded) { + return false + } + + if !sili.InitialPurchaseOnly.Equals(other.InitialPurchaseOnly) { + return false + } + + if !sili.Limitation.Equals(other.Limitation) { + return false + } + + return sili.Attributes.Equals(other.Attributes) +} + +// String returns the string representation of the ServiceItemListItem +func (sili *ServiceItemListItem) String() string { + return sili.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemListItem using the provided indentation level +func (sili *ServiceItemListItem) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemListItem{\n") + b.WriteString(fmt.Sprintf("%sItemCode: %s,\n", indentationValues, sili.ItemCode)) + b.WriteString(fmt.Sprintf("%sRegularPrice: %s,\n", indentationValues, sili.RegularPrice.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sTaxExcluded: %s,\n", indentationValues, sili.TaxExcluded)) + b.WriteString(fmt.Sprintf("%sInitialPurchaseOnly: %s,\n", indentationValues, sili.InitialPurchaseOnly)) + b.WriteString(fmt.Sprintf("%sLimitation: %s,\n", indentationValues, sili.Limitation.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sAttributes: %s,\n", indentationValues, sili.Attributes)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemListItem returns a new ServiceItemListItem +func NewServiceItemListItem() *ServiceItemListItem { + sili := &ServiceItemListItem{ + ItemCode: types.NewString(""), + RegularPrice: NewServiceItemAmount(), + TaxExcluded: types.NewPrimitiveBool(false), + InitialPurchaseOnly: types.NewPrimitiveBool(false), + Limitation: NewServiceItemLimitation(), + Attributes: types.NewList[*ServiceItemAttribute](), + } + + sili.Attributes.Type = NewServiceItemAttribute() + + return sili +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_list_service_item_param.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_list_service_item_param.go new file mode 100644 index 0000000..33bf248 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_list_service_item_param.go @@ -0,0 +1,173 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemListServiceItemParam is a type within the ServiceItem protocol +type ServiceItemListServiceItemParam struct { + types.Structure + Language *types.String + Offset *types.PrimitiveU32 + Size *types.PrimitiveU32 + IsBalanceAvailable *types.PrimitiveBool + UniqueID *types.PrimitiveU32 + Platform *types.PrimitiveU8 // * Revision 1 +} + +// WriteTo writes the ServiceItemListServiceItemParam to the given writable +func (silsip *ServiceItemListServiceItemParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + silsip.Language.WriteTo(contentWritable) + silsip.Offset.WriteTo(contentWritable) + silsip.Size.WriteTo(contentWritable) + silsip.IsBalanceAvailable.WriteTo(contentWritable) + silsip.UniqueID.WriteTo(contentWritable) + + if silsip.StructureVersion >= 1 { + silsip.Platform.WriteTo(contentWritable) + } + + content := contentWritable.Bytes() + + silsip.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemListServiceItemParam from the given readable +func (silsip *ServiceItemListServiceItemParam) ExtractFrom(readable types.Readable) error { + var err error + + err = silsip.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemParam header. %s", err.Error()) + } + + err = silsip.Language.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemParam.Language. %s", err.Error()) + } + + err = silsip.Offset.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemParam.Offset. %s", err.Error()) + } + + err = silsip.Size.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemParam.Size. %s", err.Error()) + } + + err = silsip.IsBalanceAvailable.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemParam.IsBalanceAvailable. %s", err.Error()) + } + + err = silsip.UniqueID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemParam.UniqueID. %s", err.Error()) + } + + if silsip.StructureVersion >= 1 { + err = silsip.Platform.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemParam.Platform. %s", err.Error()) + } + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemListServiceItemParam +func (silsip *ServiceItemListServiceItemParam) Copy() types.RVType { + copied := NewServiceItemListServiceItemParam() + + copied.StructureVersion = silsip.StructureVersion + copied.Language = silsip.Language.Copy().(*types.String) + copied.Offset = silsip.Offset.Copy().(*types.PrimitiveU32) + copied.Size = silsip.Size.Copy().(*types.PrimitiveU32) + copied.IsBalanceAvailable = silsip.IsBalanceAvailable.Copy().(*types.PrimitiveBool) + copied.UniqueID = silsip.UniqueID.Copy().(*types.PrimitiveU32) + copied.Platform = silsip.Platform.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given ServiceItemListServiceItemParam contains the same data as the current ServiceItemListServiceItemParam +func (silsip *ServiceItemListServiceItemParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemListServiceItemParam); !ok { + return false + } + + other := o.(*ServiceItemListServiceItemParam) + + if silsip.StructureVersion != other.StructureVersion { + return false + } + + if !silsip.Language.Equals(other.Language) { + return false + } + + if !silsip.Offset.Equals(other.Offset) { + return false + } + + if !silsip.Size.Equals(other.Size) { + return false + } + + if !silsip.IsBalanceAvailable.Equals(other.IsBalanceAvailable) { + return false + } + + if !silsip.UniqueID.Equals(other.UniqueID) { + return false + } + + return silsip.Platform.Equals(other.Platform) +} + +// String returns the string representation of the ServiceItemListServiceItemParam +func (silsip *ServiceItemListServiceItemParam) String() string { + return silsip.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemListServiceItemParam using the provided indentation level +func (silsip *ServiceItemListServiceItemParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemListServiceItemParam{\n") + b.WriteString(fmt.Sprintf("%sLanguage: %s,\n", indentationValues, silsip.Language)) + b.WriteString(fmt.Sprintf("%sOffset: %s,\n", indentationValues, silsip.Offset)) + b.WriteString(fmt.Sprintf("%sSize: %s,\n", indentationValues, silsip.Size)) + b.WriteString(fmt.Sprintf("%sIsBalanceAvailable: %s,\n", indentationValues, silsip.IsBalanceAvailable)) + b.WriteString(fmt.Sprintf("%sUniqueID: %s,\n", indentationValues, silsip.UniqueID)) + b.WriteString(fmt.Sprintf("%sPlatform: %s,\n", indentationValues, silsip.Platform)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemListServiceItemParam returns a new ServiceItemListServiceItemParam +func NewServiceItemListServiceItemParam() *ServiceItemListServiceItemParam { + silsip := &ServiceItemListServiceItemParam{ + Language: types.NewString(""), + Offset: types.NewPrimitiveU32(0), + Size: types.NewPrimitiveU32(0), + IsBalanceAvailable: types.NewPrimitiveBool(false), + UniqueID: types.NewPrimitiveU32(0), + Platform: types.NewPrimitiveU8(0), + } + + return silsip +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_list_service_item_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_list_service_item_response.go new file mode 100644 index 0000000..a47e9fa --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_list_service_item_response.go @@ -0,0 +1,115 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemListServiceItemResponse is a type within the ServiceItem protocol +type ServiceItemListServiceItemResponse struct { + types.Structure + *ServiceItemEShopResponse + NullableCatalog *types.List[*ServiceItemCatalog] +} + +// WriteTo writes the ServiceItemListServiceItemResponse to the given writable +func (silsir *ServiceItemListServiceItemResponse) WriteTo(writable types.Writable) { + silsir.ServiceItemEShopResponse.WriteTo(writable) + + contentWritable := writable.CopyNew() + + silsir.NullableCatalog.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + silsir.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemListServiceItemResponse from the given readable +func (silsir *ServiceItemListServiceItemResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = silsir.ServiceItemEShopResponse.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemResponse.ServiceItemEShopResponse. %s", err.Error()) + } + + err = silsir.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemResponse header. %s", err.Error()) + } + + err = silsir.NullableCatalog.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemResponse.NullableCatalog. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemListServiceItemResponse +func (silsir *ServiceItemListServiceItemResponse) Copy() types.RVType { + copied := NewServiceItemListServiceItemResponse() + + copied.StructureVersion = silsir.StructureVersion + copied.ServiceItemEShopResponse = silsir.ServiceItemEShopResponse.Copy().(*ServiceItemEShopResponse) + copied.NullableCatalog = silsir.NullableCatalog.Copy().(*types.List[*ServiceItemCatalog]) + + return copied +} + +// Equals checks if the given ServiceItemListServiceItemResponse contains the same data as the current ServiceItemListServiceItemResponse +func (silsir *ServiceItemListServiceItemResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemListServiceItemResponse); !ok { + return false + } + + other := o.(*ServiceItemListServiceItemResponse) + + if silsir.StructureVersion != other.StructureVersion { + return false + } + + if !silsir.ServiceItemEShopResponse.Equals(other.ServiceItemEShopResponse) { + return false + } + + return silsir.NullableCatalog.Equals(other.NullableCatalog) +} + +// String returns the string representation of the ServiceItemListServiceItemResponse +func (silsir *ServiceItemListServiceItemResponse) String() string { + return silsir.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemListServiceItemResponse using the provided indentation level +func (silsir *ServiceItemListServiceItemResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemListServiceItemResponse{\n") + b.WriteString(fmt.Sprintf("%sServiceItemEShopResponse (parent): %s,\n", indentationValues, silsir.ServiceItemEShopResponse.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sNullableCatalog: %s,\n", indentationValues, silsir.NullableCatalog)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemListServiceItemResponse returns a new ServiceItemListServiceItemResponse +func NewServiceItemListServiceItemResponse() *ServiceItemListServiceItemResponse { + silsir := &ServiceItemListServiceItemResponse{ + ServiceItemEShopResponse: NewServiceItemEShopResponse(), + NullableCatalog: types.NewList[*ServiceItemCatalog](), + } + + silsir.NullableCatalog.Type = NewServiceItemCatalog() + + return silsir +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_notice.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_notice.go new file mode 100644 index 0000000..d169741 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_notice.go @@ -0,0 +1,182 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemNotice is a type within the ServiceItem protocol +type ServiceItemNotice struct { + types.Structure + ScheduleID *types.PrimitiveU64 + ScheduleType *types.PrimitiveU32 + ParamInt *types.PrimitiveS32 + ParamString *types.String + ParamBinary *types.QBuffer + TimeBegin *types.DateTime + TimeEnd *types.DateTime +} + +// WriteTo writes the ServiceItemNotice to the given writable +func (sin *ServiceItemNotice) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sin.ScheduleID.WriteTo(contentWritable) + sin.ScheduleType.WriteTo(contentWritable) + sin.ParamInt.WriteTo(contentWritable) + sin.ParamString.WriteTo(contentWritable) + sin.ParamBinary.WriteTo(contentWritable) + sin.TimeBegin.WriteTo(contentWritable) + sin.TimeEnd.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sin.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemNotice from the given readable +func (sin *ServiceItemNotice) ExtractFrom(readable types.Readable) error { + var err error + + err = sin.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemNotice header. %s", err.Error()) + } + + err = sin.ScheduleID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemNotice.ScheduleID. %s", err.Error()) + } + + err = sin.ScheduleType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemNotice.ScheduleType. %s", err.Error()) + } + + err = sin.ParamInt.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemNotice.ParamInt. %s", err.Error()) + } + + err = sin.ParamString.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemNotice.ParamString. %s", err.Error()) + } + + err = sin.ParamBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemNotice.ParamBinary. %s", err.Error()) + } + + err = sin.TimeBegin.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemNotice.TimeBegin. %s", err.Error()) + } + + err = sin.TimeEnd.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemNotice.TimeEnd. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemNotice +func (sin *ServiceItemNotice) Copy() types.RVType { + copied := NewServiceItemNotice() + + copied.StructureVersion = sin.StructureVersion + copied.ScheduleID = sin.ScheduleID.Copy().(*types.PrimitiveU64) + copied.ScheduleType = sin.ScheduleType.Copy().(*types.PrimitiveU32) + copied.ParamInt = sin.ParamInt.Copy().(*types.PrimitiveS32) + copied.ParamString = sin.ParamString.Copy().(*types.String) + copied.ParamBinary = sin.ParamBinary.Copy().(*types.QBuffer) + copied.TimeBegin = sin.TimeBegin.Copy().(*types.DateTime) + copied.TimeEnd = sin.TimeEnd.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given ServiceItemNotice contains the same data as the current ServiceItemNotice +func (sin *ServiceItemNotice) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemNotice); !ok { + return false + } + + other := o.(*ServiceItemNotice) + + if sin.StructureVersion != other.StructureVersion { + return false + } + + if !sin.ScheduleID.Equals(other.ScheduleID) { + return false + } + + if !sin.ScheduleType.Equals(other.ScheduleType) { + return false + } + + if !sin.ParamInt.Equals(other.ParamInt) { + return false + } + + if !sin.ParamString.Equals(other.ParamString) { + return false + } + + if !sin.ParamBinary.Equals(other.ParamBinary) { + return false + } + + if !sin.TimeBegin.Equals(other.TimeBegin) { + return false + } + + return sin.TimeEnd.Equals(other.TimeEnd) +} + +// String returns the string representation of the ServiceItemNotice +func (sin *ServiceItemNotice) String() string { + return sin.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemNotice using the provided indentation level +func (sin *ServiceItemNotice) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemNotice{\n") + b.WriteString(fmt.Sprintf("%sScheduleID: %s,\n", indentationValues, sin.ScheduleID)) + b.WriteString(fmt.Sprintf("%sScheduleType: %s,\n", indentationValues, sin.ScheduleType)) + b.WriteString(fmt.Sprintf("%sParamInt: %s,\n", indentationValues, sin.ParamInt)) + b.WriteString(fmt.Sprintf("%sParamString: %s,\n", indentationValues, sin.ParamString)) + b.WriteString(fmt.Sprintf("%sParamBinary: %s,\n", indentationValues, sin.ParamBinary)) + b.WriteString(fmt.Sprintf("%sTimeBegin: %s,\n", indentationValues, sin.TimeBegin.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sTimeEnd: %s,\n", indentationValues, sin.TimeEnd.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemNotice returns a new ServiceItemNotice +func NewServiceItemNotice() *ServiceItemNotice { + sin := &ServiceItemNotice{ + ScheduleID: types.NewPrimitiveU64(0), + ScheduleType: types.NewPrimitiveU32(0), + ParamInt: types.NewPrimitiveS32(0), + ParamString: types.NewString(""), + ParamBinary: types.NewQBuffer(nil), + TimeBegin: types.NewDateTime(0), + TimeEnd: types.NewDateTime(0), + } + + return sin +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_post_right_binary_by_account_param.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_post_right_binary_by_account_param.go new file mode 100644 index 0000000..af0f04c --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_post_right_binary_by_account_param.go @@ -0,0 +1,168 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemPostRightBinaryByAccountParam is a type within the ServiceItem protocol +type ServiceItemPostRightBinaryByAccountParam struct { + types.Structure + ReferenceID *types.String + UseType *types.PrimitiveU8 + RightBinary *types.QBuffer + LogMessage *types.String + UniqueID *types.PrimitiveU32 + Platform *types.PrimitiveU8 +} + +// WriteTo writes the ServiceItemPostRightBinaryByAccountParam to the given writable +func (siprbbap *ServiceItemPostRightBinaryByAccountParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siprbbap.ReferenceID.WriteTo(contentWritable) + siprbbap.UseType.WriteTo(contentWritable) + siprbbap.RightBinary.WriteTo(contentWritable) + siprbbap.LogMessage.WriteTo(contentWritable) + siprbbap.UniqueID.WriteTo(contentWritable) + siprbbap.Platform.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siprbbap.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemPostRightBinaryByAccountParam from the given readable +func (siprbbap *ServiceItemPostRightBinaryByAccountParam) ExtractFrom(readable types.Readable) error { + var err error + + err = siprbbap.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPostRightBinaryByAccountParam header. %s", err.Error()) + } + + err = siprbbap.ReferenceID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPostRightBinaryByAccountParam.ReferenceID. %s", err.Error()) + } + + err = siprbbap.UseType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPostRightBinaryByAccountParam.UseType. %s", err.Error()) + } + + err = siprbbap.RightBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPostRightBinaryByAccountParam.RightBinary. %s", err.Error()) + } + + err = siprbbap.LogMessage.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPostRightBinaryByAccountParam.LogMessage. %s", err.Error()) + } + + err = siprbbap.UniqueID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPostRightBinaryByAccountParam.UniqueID. %s", err.Error()) + } + + err = siprbbap.Platform.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPostRightBinaryByAccountParam.Platform. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemPostRightBinaryByAccountParam +func (siprbbap *ServiceItemPostRightBinaryByAccountParam) Copy() types.RVType { + copied := NewServiceItemPostRightBinaryByAccountParam() + + copied.StructureVersion = siprbbap.StructureVersion + copied.ReferenceID = siprbbap.ReferenceID.Copy().(*types.String) + copied.UseType = siprbbap.UseType.Copy().(*types.PrimitiveU8) + copied.RightBinary = siprbbap.RightBinary.Copy().(*types.QBuffer) + copied.LogMessage = siprbbap.LogMessage.Copy().(*types.String) + copied.UniqueID = siprbbap.UniqueID.Copy().(*types.PrimitiveU32) + copied.Platform = siprbbap.Platform.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given ServiceItemPostRightBinaryByAccountParam contains the same data as the current ServiceItemPostRightBinaryByAccountParam +func (siprbbap *ServiceItemPostRightBinaryByAccountParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemPostRightBinaryByAccountParam); !ok { + return false + } + + other := o.(*ServiceItemPostRightBinaryByAccountParam) + + if siprbbap.StructureVersion != other.StructureVersion { + return false + } + + if !siprbbap.ReferenceID.Equals(other.ReferenceID) { + return false + } + + if !siprbbap.UseType.Equals(other.UseType) { + return false + } + + if !siprbbap.RightBinary.Equals(other.RightBinary) { + return false + } + + if !siprbbap.LogMessage.Equals(other.LogMessage) { + return false + } + + if !siprbbap.UniqueID.Equals(other.UniqueID) { + return false + } + + return siprbbap.Platform.Equals(other.Platform) +} + +// String returns the string representation of the ServiceItemPostRightBinaryByAccountParam +func (siprbbap *ServiceItemPostRightBinaryByAccountParam) String() string { + return siprbbap.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemPostRightBinaryByAccountParam using the provided indentation level +func (siprbbap *ServiceItemPostRightBinaryByAccountParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemPostRightBinaryByAccountParam{\n") + b.WriteString(fmt.Sprintf("%sReferenceID: %s,\n", indentationValues, siprbbap.ReferenceID)) + b.WriteString(fmt.Sprintf("%sUseType: %s,\n", indentationValues, siprbbap.UseType)) + b.WriteString(fmt.Sprintf("%sRightBinary: %s,\n", indentationValues, siprbbap.RightBinary)) + b.WriteString(fmt.Sprintf("%sLogMessage: %s,\n", indentationValues, siprbbap.LogMessage)) + b.WriteString(fmt.Sprintf("%sUniqueID: %s,\n", indentationValues, siprbbap.UniqueID)) + b.WriteString(fmt.Sprintf("%sPlatform: %s,\n", indentationValues, siprbbap.Platform)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemPostRightBinaryByAccountParam returns a new ServiceItemPostRightBinaryByAccountParam +func NewServiceItemPostRightBinaryByAccountParam() *ServiceItemPostRightBinaryByAccountParam { + siprbbap := &ServiceItemPostRightBinaryByAccountParam{ + ReferenceID: types.NewString(""), + UseType: types.NewPrimitiveU8(0), + RightBinary: types.NewQBuffer(nil), + LogMessage: types.NewString(""), + UniqueID: types.NewPrimitiveU32(0), + Platform: types.NewPrimitiveU8(0), + } + + return siprbbap +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_prepurchase_info.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_prepurchase_info.go new file mode 100644 index 0000000..fd6a734 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_prepurchase_info.go @@ -0,0 +1,224 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemPrepurchaseInfo is a type within the ServiceItem protocol +type ServiceItemPrepurchaseInfo struct { + types.Structure + ItemCode *types.String + PriceID *types.String + RegularPrice *ServiceItemAmount + IsTaxAvailable *types.PrimitiveBool + TaxAmount *ServiceItemAmount + TotalAmount *ServiceItemAmount + CurrentBalance *ServiceItemAmount + PostBalance *ServiceItemAmount + CurrentRightInfo *ServiceItemPrepurchaseRightInfo + PostRightInfo *ServiceItemPrepurchaseRightInfo +} + +// WriteTo writes the ServiceItemPrepurchaseInfo to the given writable +func (sipi *ServiceItemPrepurchaseInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sipi.ItemCode.WriteTo(contentWritable) + sipi.PriceID.WriteTo(contentWritable) + sipi.RegularPrice.WriteTo(contentWritable) + sipi.IsTaxAvailable.WriteTo(contentWritable) + sipi.TaxAmount.WriteTo(contentWritable) + sipi.TotalAmount.WriteTo(contentWritable) + sipi.CurrentBalance.WriteTo(contentWritable) + sipi.PostBalance.WriteTo(contentWritable) + sipi.CurrentRightInfo.WriteTo(contentWritable) + sipi.PostRightInfo.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sipi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemPrepurchaseInfo from the given readable +func (sipi *ServiceItemPrepurchaseInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = sipi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo header. %s", err.Error()) + } + + err = sipi.ItemCode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.ItemCode. %s", err.Error()) + } + + err = sipi.PriceID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.PriceID. %s", err.Error()) + } + + err = sipi.RegularPrice.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.RegularPrice. %s", err.Error()) + } + + err = sipi.IsTaxAvailable.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.IsTaxAvailable. %s", err.Error()) + } + + err = sipi.TaxAmount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.TaxAmount. %s", err.Error()) + } + + err = sipi.TotalAmount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.TotalAmount. %s", err.Error()) + } + + err = sipi.CurrentBalance.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.CurrentBalance. %s", err.Error()) + } + + err = sipi.PostBalance.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.PostBalance. %s", err.Error()) + } + + err = sipi.CurrentRightInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.CurrentRightInfo. %s", err.Error()) + } + + err = sipi.PostRightInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.PostRightInfo. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemPrepurchaseInfo +func (sipi *ServiceItemPrepurchaseInfo) Copy() types.RVType { + copied := NewServiceItemPrepurchaseInfo() + + copied.StructureVersion = sipi.StructureVersion + copied.ItemCode = sipi.ItemCode.Copy().(*types.String) + copied.PriceID = sipi.PriceID.Copy().(*types.String) + copied.RegularPrice = sipi.RegularPrice.Copy().(*ServiceItemAmount) + copied.IsTaxAvailable = sipi.IsTaxAvailable.Copy().(*types.PrimitiveBool) + copied.TaxAmount = sipi.TaxAmount.Copy().(*ServiceItemAmount) + copied.TotalAmount = sipi.TotalAmount.Copy().(*ServiceItemAmount) + copied.CurrentBalance = sipi.CurrentBalance.Copy().(*ServiceItemAmount) + copied.PostBalance = sipi.PostBalance.Copy().(*ServiceItemAmount) + copied.CurrentRightInfo = sipi.CurrentRightInfo.Copy().(*ServiceItemPrepurchaseRightInfo) + copied.PostRightInfo = sipi.PostRightInfo.Copy().(*ServiceItemPrepurchaseRightInfo) + + return copied +} + +// Equals checks if the given ServiceItemPrepurchaseInfo contains the same data as the current ServiceItemPrepurchaseInfo +func (sipi *ServiceItemPrepurchaseInfo) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemPrepurchaseInfo); !ok { + return false + } + + other := o.(*ServiceItemPrepurchaseInfo) + + if sipi.StructureVersion != other.StructureVersion { + return false + } + + if !sipi.ItemCode.Equals(other.ItemCode) { + return false + } + + if !sipi.PriceID.Equals(other.PriceID) { + return false + } + + if !sipi.RegularPrice.Equals(other.RegularPrice) { + return false + } + + if !sipi.IsTaxAvailable.Equals(other.IsTaxAvailable) { + return false + } + + if !sipi.TaxAmount.Equals(other.TaxAmount) { + return false + } + + if !sipi.TotalAmount.Equals(other.TotalAmount) { + return false + } + + if !sipi.CurrentBalance.Equals(other.CurrentBalance) { + return false + } + + if !sipi.PostBalance.Equals(other.PostBalance) { + return false + } + + if !sipi.CurrentRightInfo.Equals(other.CurrentRightInfo) { + return false + } + + return sipi.PostRightInfo.Equals(other.PostRightInfo) +} + +// String returns the string representation of the ServiceItemPrepurchaseInfo +func (sipi *ServiceItemPrepurchaseInfo) String() string { + return sipi.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemPrepurchaseInfo using the provided indentation level +func (sipi *ServiceItemPrepurchaseInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemPrepurchaseInfo{\n") + b.WriteString(fmt.Sprintf("%sItemCode: %s,\n", indentationValues, sipi.ItemCode)) + b.WriteString(fmt.Sprintf("%sPriceID: %s,\n", indentationValues, sipi.PriceID)) + b.WriteString(fmt.Sprintf("%sRegularPrice: %s,\n", indentationValues, sipi.RegularPrice.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sIsTaxAvailable: %s,\n", indentationValues, sipi.IsTaxAvailable)) + b.WriteString(fmt.Sprintf("%sTaxAmount: %s,\n", indentationValues, sipi.TaxAmount.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sTotalAmount: %s,\n", indentationValues, sipi.TotalAmount.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sCurrentBalance: %s,\n", indentationValues, sipi.CurrentBalance.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPostBalance: %s,\n", indentationValues, sipi.PostBalance.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sCurrentRightInfo: %s,\n", indentationValues, sipi.CurrentRightInfo.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPostRightInfo: %s,\n", indentationValues, sipi.PostRightInfo.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemPrepurchaseInfo returns a new ServiceItemPrepurchaseInfo +func NewServiceItemPrepurchaseInfo() *ServiceItemPrepurchaseInfo { + sipi := &ServiceItemPrepurchaseInfo{ + ItemCode: types.NewString(""), + PriceID: types.NewString(""), + RegularPrice: NewServiceItemAmount(), + IsTaxAvailable: types.NewPrimitiveBool(false), + TaxAmount: NewServiceItemAmount(), + TotalAmount: NewServiceItemAmount(), + CurrentBalance: NewServiceItemAmount(), + PostBalance: NewServiceItemAmount(), + CurrentRightInfo: NewServiceItemPrepurchaseRightInfo(), + PostRightInfo: NewServiceItemPrepurchaseRightInfo(), + } + + return sipi +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_prepurchase_right_info.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_prepurchase_right_info.go new file mode 100644 index 0000000..1bc289e --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_prepurchase_right_info.go @@ -0,0 +1,170 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemPrepurchaseRightInfo is a type within the ServiceItem protocol +type ServiceItemPrepurchaseRightInfo struct { + types.Structure + LimitationType *types.PrimitiveU32 + AcquiredCount *types.PrimitiveU32 + UsedCount *types.PrimitiveU32 + ExpiryDate *types.PrimitiveU32 + ExpiredCount *types.PrimitiveU32 + ExpiryCounts *types.List[*types.PrimitiveU32] +} + +// WriteTo writes the ServiceItemPrepurchaseRightInfo to the given writable +func (sipri *ServiceItemPrepurchaseRightInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sipri.LimitationType.WriteTo(contentWritable) + sipri.AcquiredCount.WriteTo(contentWritable) + sipri.UsedCount.WriteTo(contentWritable) + sipri.ExpiryDate.WriteTo(contentWritable) + sipri.ExpiredCount.WriteTo(contentWritable) + sipri.ExpiryCounts.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sipri.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemPrepurchaseRightInfo from the given readable +func (sipri *ServiceItemPrepurchaseRightInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = sipri.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseRightInfo header. %s", err.Error()) + } + + err = sipri.LimitationType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseRightInfo.LimitationType. %s", err.Error()) + } + + err = sipri.AcquiredCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseRightInfo.AcquiredCount. %s", err.Error()) + } + + err = sipri.UsedCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseRightInfo.UsedCount. %s", err.Error()) + } + + err = sipri.ExpiryDate.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseRightInfo.ExpiryDate. %s", err.Error()) + } + + err = sipri.ExpiredCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseRightInfo.ExpiredCount. %s", err.Error()) + } + + err = sipri.ExpiryCounts.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseRightInfo.ExpiryCounts. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemPrepurchaseRightInfo +func (sipri *ServiceItemPrepurchaseRightInfo) Copy() types.RVType { + copied := NewServiceItemPrepurchaseRightInfo() + + copied.StructureVersion = sipri.StructureVersion + copied.LimitationType = sipri.LimitationType.Copy().(*types.PrimitiveU32) + copied.AcquiredCount = sipri.AcquiredCount.Copy().(*types.PrimitiveU32) + copied.UsedCount = sipri.UsedCount.Copy().(*types.PrimitiveU32) + copied.ExpiryDate = sipri.ExpiryDate.Copy().(*types.PrimitiveU32) + copied.ExpiredCount = sipri.ExpiredCount.Copy().(*types.PrimitiveU32) + copied.ExpiryCounts = sipri.ExpiryCounts.Copy().(*types.List[*types.PrimitiveU32]) + + return copied +} + +// Equals checks if the given ServiceItemPrepurchaseRightInfo contains the same data as the current ServiceItemPrepurchaseRightInfo +func (sipri *ServiceItemPrepurchaseRightInfo) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemPrepurchaseRightInfo); !ok { + return false + } + + other := o.(*ServiceItemPrepurchaseRightInfo) + + if sipri.StructureVersion != other.StructureVersion { + return false + } + + if !sipri.LimitationType.Equals(other.LimitationType) { + return false + } + + if !sipri.AcquiredCount.Equals(other.AcquiredCount) { + return false + } + + if !sipri.UsedCount.Equals(other.UsedCount) { + return false + } + + if !sipri.ExpiryDate.Equals(other.ExpiryDate) { + return false + } + + if !sipri.ExpiredCount.Equals(other.ExpiredCount) { + return false + } + + return sipri.ExpiryCounts.Equals(other.ExpiryCounts) +} + +// String returns the string representation of the ServiceItemPrepurchaseRightInfo +func (sipri *ServiceItemPrepurchaseRightInfo) String() string { + return sipri.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemPrepurchaseRightInfo using the provided indentation level +func (sipri *ServiceItemPrepurchaseRightInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemPrepurchaseRightInfo{\n") + b.WriteString(fmt.Sprintf("%sLimitationType: %s,\n", indentationValues, sipri.LimitationType)) + b.WriteString(fmt.Sprintf("%sAcquiredCount: %s,\n", indentationValues, sipri.AcquiredCount)) + b.WriteString(fmt.Sprintf("%sUsedCount: %s,\n", indentationValues, sipri.UsedCount)) + b.WriteString(fmt.Sprintf("%sExpiryDate: %s,\n", indentationValues, sipri.ExpiryDate)) + b.WriteString(fmt.Sprintf("%sExpiredCount: %s,\n", indentationValues, sipri.ExpiredCount)) + b.WriteString(fmt.Sprintf("%sExpiryCounts: %s,\n", indentationValues, sipri.ExpiryCounts)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemPrepurchaseRightInfo returns a new ServiceItemPrepurchaseRightInfo +func NewServiceItemPrepurchaseRightInfo() *ServiceItemPrepurchaseRightInfo { + sipri := &ServiceItemPrepurchaseRightInfo{ + LimitationType: types.NewPrimitiveU32(0), + AcquiredCount: types.NewPrimitiveU32(0), + UsedCount: types.NewPrimitiveU32(0), + ExpiryDate: types.NewPrimitiveU32(0), + ExpiredCount: types.NewPrimitiveU32(0), + ExpiryCounts: types.NewList[*types.PrimitiveU32](), + } + + sipri.ExpiryCounts.Type = types.NewPrimitiveU32(0) + + return sipri +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_purchase_history.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_purchase_history.go new file mode 100644 index 0000000..a4de770 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_purchase_history.go @@ -0,0 +1,128 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemPurchaseHistory is a type within the ServiceItem protocol +type ServiceItemPurchaseHistory struct { + types.Structure + TotalSize *types.PrimitiveU32 + Offset *types.PrimitiveU32 + Transactions *types.List[*ServiceItemTransaction] +} + +// WriteTo writes the ServiceItemPurchaseHistory to the given writable +func (siph *ServiceItemPurchaseHistory) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siph.TotalSize.WriteTo(contentWritable) + siph.Offset.WriteTo(contentWritable) + siph.Transactions.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siph.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemPurchaseHistory from the given readable +func (siph *ServiceItemPurchaseHistory) ExtractFrom(readable types.Readable) error { + var err error + + err = siph.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseHistory header. %s", err.Error()) + } + + err = siph.TotalSize.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseHistory.TotalSize. %s", err.Error()) + } + + err = siph.Offset.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseHistory.Offset. %s", err.Error()) + } + + err = siph.Transactions.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseHistory.Transactions. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemPurchaseHistory +func (siph *ServiceItemPurchaseHistory) Copy() types.RVType { + copied := NewServiceItemPurchaseHistory() + + copied.StructureVersion = siph.StructureVersion + copied.TotalSize = siph.TotalSize.Copy().(*types.PrimitiveU32) + copied.Offset = siph.Offset.Copy().(*types.PrimitiveU32) + copied.Transactions = siph.Transactions.Copy().(*types.List[*ServiceItemTransaction]) + + return copied +} + +// Equals checks if the given ServiceItemPurchaseHistory contains the same data as the current ServiceItemPurchaseHistory +func (siph *ServiceItemPurchaseHistory) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemPurchaseHistory); !ok { + return false + } + + other := o.(*ServiceItemPurchaseHistory) + + if siph.StructureVersion != other.StructureVersion { + return false + } + + if !siph.TotalSize.Equals(other.TotalSize) { + return false + } + + if !siph.Offset.Equals(other.Offset) { + return false + } + + return siph.Transactions.Equals(other.Transactions) +} + +// String returns the string representation of the ServiceItemPurchaseHistory +func (siph *ServiceItemPurchaseHistory) String() string { + return siph.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemPurchaseHistory using the provided indentation level +func (siph *ServiceItemPurchaseHistory) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemPurchaseHistory{\n") + b.WriteString(fmt.Sprintf("%sTotalSize: %s,\n", indentationValues, siph.TotalSize)) + b.WriteString(fmt.Sprintf("%sOffset: %s,\n", indentationValues, siph.Offset)) + b.WriteString(fmt.Sprintf("%sTransactions: %s,\n", indentationValues, siph.Transactions)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemPurchaseHistory returns a new ServiceItemPurchaseHistory +func NewServiceItemPurchaseHistory() *ServiceItemPurchaseHistory { + siph := &ServiceItemPurchaseHistory{ + TotalSize: types.NewPrimitiveU32(0), + Offset: types.NewPrimitiveU32(0), + Transactions: types.NewList[*ServiceItemTransaction](), + } + + siph.Transactions.Type = NewServiceItemTransaction() + + return siph +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_purchase_info.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_purchase_info.go new file mode 100644 index 0000000..977c45e --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_purchase_info.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemPurchaseInfo is a type within the ServiceItem protocol +type ServiceItemPurchaseInfo struct { + types.Structure + TransactionID *types.String + ExtTransactionID *types.String + ItemCode *types.String + PostBalance *ServiceItemAmount +} + +// WriteTo writes the ServiceItemPurchaseInfo to the given writable +func (sipi *ServiceItemPurchaseInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sipi.TransactionID.WriteTo(contentWritable) + sipi.ExtTransactionID.WriteTo(contentWritable) + sipi.ItemCode.WriteTo(contentWritable) + sipi.PostBalance.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sipi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemPurchaseInfo from the given readable +func (sipi *ServiceItemPurchaseInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = sipi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseInfo header. %s", err.Error()) + } + + err = sipi.TransactionID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseInfo.TransactionID. %s", err.Error()) + } + + err = sipi.ExtTransactionID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseInfo.ExtTransactionID. %s", err.Error()) + } + + err = sipi.ItemCode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseInfo.ItemCode. %s", err.Error()) + } + + err = sipi.PostBalance.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseInfo.PostBalance. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemPurchaseInfo +func (sipi *ServiceItemPurchaseInfo) Copy() types.RVType { + copied := NewServiceItemPurchaseInfo() + + copied.StructureVersion = sipi.StructureVersion + copied.TransactionID = sipi.TransactionID.Copy().(*types.String) + copied.ExtTransactionID = sipi.ExtTransactionID.Copy().(*types.String) + copied.ItemCode = sipi.ItemCode.Copy().(*types.String) + copied.PostBalance = sipi.PostBalance.Copy().(*ServiceItemAmount) + + return copied +} + +// Equals checks if the given ServiceItemPurchaseInfo contains the same data as the current ServiceItemPurchaseInfo +func (sipi *ServiceItemPurchaseInfo) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemPurchaseInfo); !ok { + return false + } + + other := o.(*ServiceItemPurchaseInfo) + + if sipi.StructureVersion != other.StructureVersion { + return false + } + + if !sipi.TransactionID.Equals(other.TransactionID) { + return false + } + + if !sipi.ExtTransactionID.Equals(other.ExtTransactionID) { + return false + } + + if !sipi.ItemCode.Equals(other.ItemCode) { + return false + } + + return sipi.PostBalance.Equals(other.PostBalance) +} + +// String returns the string representation of the ServiceItemPurchaseInfo +func (sipi *ServiceItemPurchaseInfo) String() string { + return sipi.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemPurchaseInfo using the provided indentation level +func (sipi *ServiceItemPurchaseInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemPurchaseInfo{\n") + b.WriteString(fmt.Sprintf("%sTransactionID: %s,\n", indentationValues, sipi.TransactionID)) + b.WriteString(fmt.Sprintf("%sExtTransactionID: %s,\n", indentationValues, sipi.ExtTransactionID)) + b.WriteString(fmt.Sprintf("%sItemCode: %s,\n", indentationValues, sipi.ItemCode)) + b.WriteString(fmt.Sprintf("%sPostBalance: %s,\n", indentationValues, sipi.PostBalance.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemPurchaseInfo returns a new ServiceItemPurchaseInfo +func NewServiceItemPurchaseInfo() *ServiceItemPurchaseInfo { + sipi := &ServiceItemPurchaseInfo{ + TransactionID: types.NewString(""), + ExtTransactionID: types.NewString(""), + ItemCode: types.NewString(""), + PostBalance: NewServiceItemAmount(), + } + + return sipi +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_purchase_service_item_param.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_purchase_service_item_param.go new file mode 100644 index 0000000..a733c4a --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_purchase_service_item_param.go @@ -0,0 +1,215 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemPurchaseServiceItemParam is a type within the ServiceItem protocol +type ServiceItemPurchaseServiceItemParam struct { + types.Structure + ItemCode *types.String + PriceID *types.String + ReferenceID *types.String + Balance *types.String + ItemName *types.String + EcServiceToken *types.String + Language *types.String + UniqueID *types.PrimitiveU32 + Platform *types.PrimitiveU8 // * Revision 1 +} + +// WriteTo writes the ServiceItemPurchaseServiceItemParam to the given writable +func (sipsip *ServiceItemPurchaseServiceItemParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sipsip.ItemCode.WriteTo(contentWritable) + sipsip.PriceID.WriteTo(contentWritable) + sipsip.ReferenceID.WriteTo(contentWritable) + sipsip.Balance.WriteTo(contentWritable) + sipsip.ItemName.WriteTo(contentWritable) + sipsip.EcServiceToken.WriteTo(contentWritable) + sipsip.Language.WriteTo(contentWritable) + sipsip.UniqueID.WriteTo(contentWritable) + + if sipsip.StructureVersion >= 1 { + sipsip.Platform.WriteTo(contentWritable) + } + + content := contentWritable.Bytes() + + sipsip.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemPurchaseServiceItemParam from the given readable +func (sipsip *ServiceItemPurchaseServiceItemParam) ExtractFrom(readable types.Readable) error { + var err error + + err = sipsip.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam header. %s", err.Error()) + } + + err = sipsip.ItemCode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam.ItemCode. %s", err.Error()) + } + + err = sipsip.PriceID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam.PriceID. %s", err.Error()) + } + + err = sipsip.ReferenceID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam.ReferenceID. %s", err.Error()) + } + + err = sipsip.Balance.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam.Balance. %s", err.Error()) + } + + err = sipsip.ItemName.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam.ItemName. %s", err.Error()) + } + + err = sipsip.EcServiceToken.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam.EcServiceToken. %s", err.Error()) + } + + err = sipsip.Language.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam.Language. %s", err.Error()) + } + + err = sipsip.UniqueID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam.UniqueID. %s", err.Error()) + } + + if sipsip.StructureVersion >= 1 { + err = sipsip.Platform.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam.Platform. %s", err.Error()) + } + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemPurchaseServiceItemParam +func (sipsip *ServiceItemPurchaseServiceItemParam) Copy() types.RVType { + copied := NewServiceItemPurchaseServiceItemParam() + + copied.StructureVersion = sipsip.StructureVersion + copied.ItemCode = sipsip.ItemCode.Copy().(*types.String) + copied.PriceID = sipsip.PriceID.Copy().(*types.String) + copied.ReferenceID = sipsip.ReferenceID.Copy().(*types.String) + copied.Balance = sipsip.Balance.Copy().(*types.String) + copied.ItemName = sipsip.ItemName.Copy().(*types.String) + copied.EcServiceToken = sipsip.EcServiceToken.Copy().(*types.String) + copied.Language = sipsip.Language.Copy().(*types.String) + copied.UniqueID = sipsip.UniqueID.Copy().(*types.PrimitiveU32) + copied.Platform = sipsip.Platform.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given ServiceItemPurchaseServiceItemParam contains the same data as the current ServiceItemPurchaseServiceItemParam +func (sipsip *ServiceItemPurchaseServiceItemParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemPurchaseServiceItemParam); !ok { + return false + } + + other := o.(*ServiceItemPurchaseServiceItemParam) + + if sipsip.StructureVersion != other.StructureVersion { + return false + } + + if !sipsip.ItemCode.Equals(other.ItemCode) { + return false + } + + if !sipsip.PriceID.Equals(other.PriceID) { + return false + } + + if !sipsip.ReferenceID.Equals(other.ReferenceID) { + return false + } + + if !sipsip.Balance.Equals(other.Balance) { + return false + } + + if !sipsip.ItemName.Equals(other.ItemName) { + return false + } + + if !sipsip.EcServiceToken.Equals(other.EcServiceToken) { + return false + } + + if !sipsip.Language.Equals(other.Language) { + return false + } + + if !sipsip.UniqueID.Equals(other.UniqueID) { + return false + } + + return sipsip.Platform.Equals(other.Platform) +} + +// String returns the string representation of the ServiceItemPurchaseServiceItemParam +func (sipsip *ServiceItemPurchaseServiceItemParam) String() string { + return sipsip.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemPurchaseServiceItemParam using the provided indentation level +func (sipsip *ServiceItemPurchaseServiceItemParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemPurchaseServiceItemParam{\n") + b.WriteString(fmt.Sprintf("%sItemCode: %s,\n", indentationValues, sipsip.ItemCode)) + b.WriteString(fmt.Sprintf("%sPriceID: %s,\n", indentationValues, sipsip.PriceID)) + b.WriteString(fmt.Sprintf("%sReferenceID: %s,\n", indentationValues, sipsip.ReferenceID)) + b.WriteString(fmt.Sprintf("%sBalance: %s,\n", indentationValues, sipsip.Balance)) + b.WriteString(fmt.Sprintf("%sItemName: %s,\n", indentationValues, sipsip.ItemName)) + b.WriteString(fmt.Sprintf("%sEcServiceToken: %s,\n", indentationValues, sipsip.EcServiceToken)) + b.WriteString(fmt.Sprintf("%sLanguage: %s,\n", indentationValues, sipsip.Language)) + b.WriteString(fmt.Sprintf("%sUniqueID: %s,\n", indentationValues, sipsip.UniqueID)) + b.WriteString(fmt.Sprintf("%sPlatform: %s,\n", indentationValues, sipsip.Platform)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemPurchaseServiceItemParam returns a new ServiceItemPurchaseServiceItemParam +func NewServiceItemPurchaseServiceItemParam() *ServiceItemPurchaseServiceItemParam { + sipsip := &ServiceItemPurchaseServiceItemParam{ + ItemCode: types.NewString(""), + PriceID: types.NewString(""), + ReferenceID: types.NewString(""), + Balance: types.NewString(""), + ItemName: types.NewString(""), + EcServiceToken: types.NewString(""), + Language: types.NewString(""), + UniqueID: types.NewPrimitiveU32(0), + Platform: types.NewPrimitiveU8(0), + } + + return sipsip +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_purchase_service_item_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_purchase_service_item_response.go new file mode 100644 index 0000000..753c205 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_purchase_service_item_response.go @@ -0,0 +1,115 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemPurchaseServiceItemResponse is a type within the ServiceItem protocol +type ServiceItemPurchaseServiceItemResponse struct { + types.Structure + *ServiceItemEShopResponse + NullablePurchaseInfo *types.List[*ServiceItemPurchaseInfo] +} + +// WriteTo writes the ServiceItemPurchaseServiceItemResponse to the given writable +func (sipsir *ServiceItemPurchaseServiceItemResponse) WriteTo(writable types.Writable) { + sipsir.ServiceItemEShopResponse.WriteTo(writable) + + contentWritable := writable.CopyNew() + + sipsir.NullablePurchaseInfo.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sipsir.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemPurchaseServiceItemResponse from the given readable +func (sipsir *ServiceItemPurchaseServiceItemResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = sipsir.ServiceItemEShopResponse.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemResponse.ServiceItemEShopResponse. %s", err.Error()) + } + + err = sipsir.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemResponse header. %s", err.Error()) + } + + err = sipsir.NullablePurchaseInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemResponse.NullablePurchaseInfo. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemPurchaseServiceItemResponse +func (sipsir *ServiceItemPurchaseServiceItemResponse) Copy() types.RVType { + copied := NewServiceItemPurchaseServiceItemResponse() + + copied.StructureVersion = sipsir.StructureVersion + copied.ServiceItemEShopResponse = sipsir.ServiceItemEShopResponse.Copy().(*ServiceItemEShopResponse) + copied.NullablePurchaseInfo = sipsir.NullablePurchaseInfo.Copy().(*types.List[*ServiceItemPurchaseInfo]) + + return copied +} + +// Equals checks if the given ServiceItemPurchaseServiceItemResponse contains the same data as the current ServiceItemPurchaseServiceItemResponse +func (sipsir *ServiceItemPurchaseServiceItemResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemPurchaseServiceItemResponse); !ok { + return false + } + + other := o.(*ServiceItemPurchaseServiceItemResponse) + + if sipsir.StructureVersion != other.StructureVersion { + return false + } + + if !sipsir.ServiceItemEShopResponse.Equals(other.ServiceItemEShopResponse) { + return false + } + + return sipsir.NullablePurchaseInfo.Equals(other.NullablePurchaseInfo) +} + +// String returns the string representation of the ServiceItemPurchaseServiceItemResponse +func (sipsir *ServiceItemPurchaseServiceItemResponse) String() string { + return sipsir.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemPurchaseServiceItemResponse using the provided indentation level +func (sipsir *ServiceItemPurchaseServiceItemResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemPurchaseServiceItemResponse{\n") + b.WriteString(fmt.Sprintf("%sServiceItemEShopResponse (parent): %s,\n", indentationValues, sipsir.ServiceItemEShopResponse.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sNullablePurchaseInfo: %s,\n", indentationValues, sipsir.NullablePurchaseInfo)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemPurchaseServiceItemResponse returns a new ServiceItemPurchaseServiceItemResponse +func NewServiceItemPurchaseServiceItemResponse() *ServiceItemPurchaseServiceItemResponse { + sipsir := &ServiceItemPurchaseServiceItemResponse{ + ServiceItemEShopResponse: NewServiceItemEShopResponse(), + NullablePurchaseInfo: types.NewList[*ServiceItemPurchaseInfo](), + } + + sipsir.NullablePurchaseInfo.Type = NewServiceItemPurchaseInfo() + + return sipsir +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_binary.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_binary.go new file mode 100644 index 0000000..9fea0ca --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_binary.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemRightBinary is a type within the ServiceItem protocol +type ServiceItemRightBinary struct { + types.Structure + UseType *types.PrimitiveU8 + RightBinary *types.QBuffer +} + +// WriteTo writes the ServiceItemRightBinary to the given writable +func (sirb *ServiceItemRightBinary) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sirb.UseType.WriteTo(contentWritable) + sirb.RightBinary.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sirb.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemRightBinary from the given readable +func (sirb *ServiceItemRightBinary) ExtractFrom(readable types.Readable) error { + var err error + + err = sirb.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightBinary header. %s", err.Error()) + } + + err = sirb.UseType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightBinary.UseType. %s", err.Error()) + } + + err = sirb.RightBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightBinary.RightBinary. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemRightBinary +func (sirb *ServiceItemRightBinary) Copy() types.RVType { + copied := NewServiceItemRightBinary() + + copied.StructureVersion = sirb.StructureVersion + copied.UseType = sirb.UseType.Copy().(*types.PrimitiveU8) + copied.RightBinary = sirb.RightBinary.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given ServiceItemRightBinary contains the same data as the current ServiceItemRightBinary +func (sirb *ServiceItemRightBinary) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemRightBinary); !ok { + return false + } + + other := o.(*ServiceItemRightBinary) + + if sirb.StructureVersion != other.StructureVersion { + return false + } + + if !sirb.UseType.Equals(other.UseType) { + return false + } + + return sirb.RightBinary.Equals(other.RightBinary) +} + +// String returns the string representation of the ServiceItemRightBinary +func (sirb *ServiceItemRightBinary) String() string { + return sirb.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemRightBinary using the provided indentation level +func (sirb *ServiceItemRightBinary) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemRightBinary{\n") + b.WriteString(fmt.Sprintf("%sUseType: %s,\n", indentationValues, sirb.UseType)) + b.WriteString(fmt.Sprintf("%sRightBinary: %s,\n", indentationValues, sirb.RightBinary)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemRightBinary returns a new ServiceItemRightBinary +func NewServiceItemRightBinary() *ServiceItemRightBinary { + sirb := &ServiceItemRightBinary{ + UseType: types.NewPrimitiveU8(0), + RightBinary: types.NewQBuffer(nil), + } + + return sirb +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_consumption_info.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_consumption_info.go new file mode 100644 index 0000000..b8464b0 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_consumption_info.go @@ -0,0 +1,115 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemRightConsumptionInfo is a type within the ServiceItem protocol +type ServiceItemRightConsumptionInfo struct { + types.Structure + *ServiceItemRightInfo + AccountRights *types.List[*ServiceItemAccountRightConsumption] +} + +// WriteTo writes the ServiceItemRightConsumptionInfo to the given writable +func (sirci *ServiceItemRightConsumptionInfo) WriteTo(writable types.Writable) { + sirci.ServiceItemRightInfo.WriteTo(writable) + + contentWritable := writable.CopyNew() + + sirci.AccountRights.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sirci.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemRightConsumptionInfo from the given readable +func (sirci *ServiceItemRightConsumptionInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = sirci.ServiceItemRightInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightConsumptionInfo.ServiceItemRightInfo. %s", err.Error()) + } + + err = sirci.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightConsumptionInfo header. %s", err.Error()) + } + + err = sirci.AccountRights.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightConsumptionInfo.AccountRights. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemRightConsumptionInfo +func (sirci *ServiceItemRightConsumptionInfo) Copy() types.RVType { + copied := NewServiceItemRightConsumptionInfo() + + copied.StructureVersion = sirci.StructureVersion + copied.ServiceItemRightInfo = sirci.ServiceItemRightInfo.Copy().(*ServiceItemRightInfo) + copied.AccountRights = sirci.AccountRights.Copy().(*types.List[*ServiceItemAccountRightConsumption]) + + return copied +} + +// Equals checks if the given ServiceItemRightConsumptionInfo contains the same data as the current ServiceItemRightConsumptionInfo +func (sirci *ServiceItemRightConsumptionInfo) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemRightConsumptionInfo); !ok { + return false + } + + other := o.(*ServiceItemRightConsumptionInfo) + + if sirci.StructureVersion != other.StructureVersion { + return false + } + + if !sirci.ServiceItemRightInfo.Equals(other.ServiceItemRightInfo) { + return false + } + + return sirci.AccountRights.Equals(other.AccountRights) +} + +// String returns the string representation of the ServiceItemRightConsumptionInfo +func (sirci *ServiceItemRightConsumptionInfo) String() string { + return sirci.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemRightConsumptionInfo using the provided indentation level +func (sirci *ServiceItemRightConsumptionInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemRightConsumptionInfo{\n") + b.WriteString(fmt.Sprintf("%sServiceItemRightInfo (parent): %s,\n", indentationValues, sirci.ServiceItemRightInfo.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sAccountRights: %s,\n", indentationValues, sirci.AccountRights)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemRightConsumptionInfo returns a new ServiceItemRightConsumptionInfo +func NewServiceItemRightConsumptionInfo() *ServiceItemRightConsumptionInfo { + sirci := &ServiceItemRightConsumptionInfo{ + ServiceItemRightInfo: NewServiceItemRightInfo(), + AccountRights: types.NewList[*ServiceItemAccountRightConsumption](), + } + + sirci.AccountRights.Type = NewServiceItemAccountRightConsumption() + + return sirci +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_info.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_info.go new file mode 100644 index 0000000..5657a72 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_info.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemRightInfo is a type within the ServiceItem protocol +type ServiceItemRightInfo struct { + types.Structure + ReferenceID *types.String + ReferenceIDType *types.PrimitiveU32 +} + +// WriteTo writes the ServiceItemRightInfo to the given writable +func (siri *ServiceItemRightInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siri.ReferenceID.WriteTo(contentWritable) + siri.ReferenceIDType.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siri.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemRightInfo from the given readable +func (siri *ServiceItemRightInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = siri.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightInfo header. %s", err.Error()) + } + + err = siri.ReferenceID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightInfo.ReferenceID. %s", err.Error()) + } + + err = siri.ReferenceIDType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightInfo.ReferenceIDType. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemRightInfo +func (siri *ServiceItemRightInfo) Copy() types.RVType { + copied := NewServiceItemRightInfo() + + copied.StructureVersion = siri.StructureVersion + copied.ReferenceID = siri.ReferenceID.Copy().(*types.String) + copied.ReferenceIDType = siri.ReferenceIDType.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given ServiceItemRightInfo contains the same data as the current ServiceItemRightInfo +func (siri *ServiceItemRightInfo) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemRightInfo); !ok { + return false + } + + other := o.(*ServiceItemRightInfo) + + if siri.StructureVersion != other.StructureVersion { + return false + } + + if !siri.ReferenceID.Equals(other.ReferenceID) { + return false + } + + return siri.ReferenceIDType.Equals(other.ReferenceIDType) +} + +// String returns the string representation of the ServiceItemRightInfo +func (siri *ServiceItemRightInfo) String() string { + return siri.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemRightInfo using the provided indentation level +func (siri *ServiceItemRightInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemRightInfo{\n") + b.WriteString(fmt.Sprintf("%sReferenceID: %s,\n", indentationValues, siri.ReferenceID)) + b.WriteString(fmt.Sprintf("%sReferenceIDType: %s,\n", indentationValues, siri.ReferenceIDType)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemRightInfo returns a new ServiceItemRightInfo +func NewServiceItemRightInfo() *ServiceItemRightInfo { + siri := &ServiceItemRightInfo{ + ReferenceID: types.NewString(""), + ReferenceIDType: types.NewPrimitiveU32(0), + } + + return siri +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_infos.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_infos.go new file mode 100644 index 0000000..7a85a48 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_infos.go @@ -0,0 +1,158 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemRightInfos is a type within the ServiceItem protocol +type ServiceItemRightInfos struct { + types.Structure + SupportID *types.String + ConsumptionRightInfos *types.List[*ServiceItemRightConsumptionInfo] + AdditionalTimeRightInfos *types.List[*ServiceItemRightTimeInfo] + PermanentRightInfos *types.List[*ServiceItemRightTimeInfo] + AlreadyPurchasedInitialOnlyItem *types.PrimitiveBool +} + +// WriteTo writes the ServiceItemRightInfos to the given writable +func (siri *ServiceItemRightInfos) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siri.SupportID.WriteTo(contentWritable) + siri.ConsumptionRightInfos.WriteTo(contentWritable) + siri.AdditionalTimeRightInfos.WriteTo(contentWritable) + siri.PermanentRightInfos.WriteTo(contentWritable) + siri.AlreadyPurchasedInitialOnlyItem.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siri.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemRightInfos from the given readable +func (siri *ServiceItemRightInfos) ExtractFrom(readable types.Readable) error { + var err error + + err = siri.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightInfos header. %s", err.Error()) + } + + err = siri.SupportID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightInfos.SupportID. %s", err.Error()) + } + + err = siri.ConsumptionRightInfos.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightInfos.ConsumptionRightInfos. %s", err.Error()) + } + + err = siri.AdditionalTimeRightInfos.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightInfos.AdditionalTimeRightInfos. %s", err.Error()) + } + + err = siri.PermanentRightInfos.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightInfos.PermanentRightInfos. %s", err.Error()) + } + + err = siri.AlreadyPurchasedInitialOnlyItem.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightInfos.AlreadyPurchasedInitialOnlyItem. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemRightInfos +func (siri *ServiceItemRightInfos) Copy() types.RVType { + copied := NewServiceItemRightInfos() + + copied.StructureVersion = siri.StructureVersion + copied.SupportID = siri.SupportID.Copy().(*types.String) + copied.ConsumptionRightInfos = siri.ConsumptionRightInfos.Copy().(*types.List[*ServiceItemRightConsumptionInfo]) + copied.AdditionalTimeRightInfos = siri.AdditionalTimeRightInfos.Copy().(*types.List[*ServiceItemRightTimeInfo]) + copied.PermanentRightInfos = siri.PermanentRightInfos.Copy().(*types.List[*ServiceItemRightTimeInfo]) + copied.AlreadyPurchasedInitialOnlyItem = siri.AlreadyPurchasedInitialOnlyItem.Copy().(*types.PrimitiveBool) + + return copied +} + +// Equals checks if the given ServiceItemRightInfos contains the same data as the current ServiceItemRightInfos +func (siri *ServiceItemRightInfos) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemRightInfos); !ok { + return false + } + + other := o.(*ServiceItemRightInfos) + + if siri.StructureVersion != other.StructureVersion { + return false + } + + if !siri.SupportID.Equals(other.SupportID) { + return false + } + + if !siri.ConsumptionRightInfos.Equals(other.ConsumptionRightInfos) { + return false + } + + if !siri.AdditionalTimeRightInfos.Equals(other.AdditionalTimeRightInfos) { + return false + } + + if !siri.PermanentRightInfos.Equals(other.PermanentRightInfos) { + return false + } + + return siri.AlreadyPurchasedInitialOnlyItem.Equals(other.AlreadyPurchasedInitialOnlyItem) +} + +// String returns the string representation of the ServiceItemRightInfos +func (siri *ServiceItemRightInfos) String() string { + return siri.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemRightInfos using the provided indentation level +func (siri *ServiceItemRightInfos) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemRightInfos{\n") + b.WriteString(fmt.Sprintf("%sSupportID: %s,\n", indentationValues, siri.SupportID)) + b.WriteString(fmt.Sprintf("%sConsumptionRightInfos: %s,\n", indentationValues, siri.ConsumptionRightInfos)) + b.WriteString(fmt.Sprintf("%sAdditionalTimeRightInfos: %s,\n", indentationValues, siri.AdditionalTimeRightInfos)) + b.WriteString(fmt.Sprintf("%sPermanentRightInfos: %s,\n", indentationValues, siri.PermanentRightInfos)) + b.WriteString(fmt.Sprintf("%sAlreadyPurchasedInitialOnlyItem: %s,\n", indentationValues, siri.AlreadyPurchasedInitialOnlyItem)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemRightInfos returns a new ServiceItemRightInfos +func NewServiceItemRightInfos() *ServiceItemRightInfos { + siri := &ServiceItemRightInfos{ + SupportID: types.NewString(""), + ConsumptionRightInfos: types.NewList[*ServiceItemRightConsumptionInfo](), + AdditionalTimeRightInfos: types.NewList[*ServiceItemRightTimeInfo](), + PermanentRightInfos: types.NewList[*ServiceItemRightTimeInfo](), + AlreadyPurchasedInitialOnlyItem: types.NewPrimitiveBool(false), + } + + siri.ConsumptionRightInfos.Type = NewServiceItemRightConsumptionInfo() + siri.AdditionalTimeRightInfos.Type = NewServiceItemRightTimeInfo() + siri.PermanentRightInfos.Type = NewServiceItemRightTimeInfo() + + return siri +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_time_info.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_time_info.go new file mode 100644 index 0000000..c8ebe64 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_right_time_info.go @@ -0,0 +1,115 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemRightTimeInfo is a type within the ServiceItem protocol +type ServiceItemRightTimeInfo struct { + types.Structure + *ServiceItemRightInfo + AccountRights *types.List[*ServiceItemAccountRightTime] +} + +// WriteTo writes the ServiceItemRightTimeInfo to the given writable +func (sirti *ServiceItemRightTimeInfo) WriteTo(writable types.Writable) { + sirti.ServiceItemRightInfo.WriteTo(writable) + + contentWritable := writable.CopyNew() + + sirti.AccountRights.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sirti.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemRightTimeInfo from the given readable +func (sirti *ServiceItemRightTimeInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = sirti.ServiceItemRightInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightTimeInfo.ServiceItemRightInfo. %s", err.Error()) + } + + err = sirti.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightTimeInfo header. %s", err.Error()) + } + + err = sirti.AccountRights.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightTimeInfo.AccountRights. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemRightTimeInfo +func (sirti *ServiceItemRightTimeInfo) Copy() types.RVType { + copied := NewServiceItemRightTimeInfo() + + copied.StructureVersion = sirti.StructureVersion + copied.ServiceItemRightInfo = sirti.ServiceItemRightInfo.Copy().(*ServiceItemRightInfo) + copied.AccountRights = sirti.AccountRights.Copy().(*types.List[*ServiceItemAccountRightTime]) + + return copied +} + +// Equals checks if the given ServiceItemRightTimeInfo contains the same data as the current ServiceItemRightTimeInfo +func (sirti *ServiceItemRightTimeInfo) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemRightTimeInfo); !ok { + return false + } + + other := o.(*ServiceItemRightTimeInfo) + + if sirti.StructureVersion != other.StructureVersion { + return false + } + + if !sirti.ServiceItemRightInfo.Equals(other.ServiceItemRightInfo) { + return false + } + + return sirti.AccountRights.Equals(other.AccountRights) +} + +// String returns the string representation of the ServiceItemRightTimeInfo +func (sirti *ServiceItemRightTimeInfo) String() string { + return sirti.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemRightTimeInfo using the provided indentation level +func (sirti *ServiceItemRightTimeInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemRightTimeInfo{\n") + b.WriteString(fmt.Sprintf("%sServiceItemRightInfo (parent): %s,\n", indentationValues, sirti.ServiceItemRightInfo.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sAccountRights: %s,\n", indentationValues, sirti.AccountRights)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemRightTimeInfo returns a new ServiceItemRightTimeInfo +func NewServiceItemRightTimeInfo() *ServiceItemRightTimeInfo { + sirti := &ServiceItemRightTimeInfo{ + ServiceItemRightInfo: NewServiceItemRightInfo(), + AccountRights: types.NewList[*ServiceItemAccountRightTime](), + } + + sirti.AccountRights.Type = NewServiceItemAccountRightTime() + + return sirti +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_transaction.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_transaction.go new file mode 100644 index 0000000..20d1706 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_transaction.go @@ -0,0 +1,210 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemTransaction is a type within the ServiceItem protocol +type ServiceItemTransaction struct { + types.Structure + TransactionID *types.String + ExtTransactionID *types.String + Time *types.DateTime + TransactionType *types.PrimitiveU32 + TransactionDescription *types.String + TransactionAmount *ServiceItemAmount + ItemCode *types.String + ReferenceID *types.String + Limitation *ServiceItemLimitation +} + +// WriteTo writes the ServiceItemTransaction to the given writable +func (sit *ServiceItemTransaction) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sit.TransactionID.WriteTo(contentWritable) + sit.ExtTransactionID.WriteTo(contentWritable) + sit.Time.WriteTo(contentWritable) + sit.TransactionType.WriteTo(contentWritable) + sit.TransactionDescription.WriteTo(contentWritable) + sit.TransactionAmount.WriteTo(contentWritable) + sit.ItemCode.WriteTo(contentWritable) + sit.ReferenceID.WriteTo(contentWritable) + sit.Limitation.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sit.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemTransaction from the given readable +func (sit *ServiceItemTransaction) ExtractFrom(readable types.Readable) error { + var err error + + err = sit.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction header. %s", err.Error()) + } + + err = sit.TransactionID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.TransactionID. %s", err.Error()) + } + + err = sit.ExtTransactionID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.ExtTransactionID. %s", err.Error()) + } + + err = sit.Time.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.Time. %s", err.Error()) + } + + err = sit.TransactionType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.TransactionType. %s", err.Error()) + } + + err = sit.TransactionDescription.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.TransactionDescription. %s", err.Error()) + } + + err = sit.TransactionAmount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.TransactionAmount. %s", err.Error()) + } + + err = sit.ItemCode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.ItemCode. %s", err.Error()) + } + + err = sit.ReferenceID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.ReferenceID. %s", err.Error()) + } + + err = sit.Limitation.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.Limitation. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemTransaction +func (sit *ServiceItemTransaction) Copy() types.RVType { + copied := NewServiceItemTransaction() + + copied.StructureVersion = sit.StructureVersion + copied.TransactionID = sit.TransactionID.Copy().(*types.String) + copied.ExtTransactionID = sit.ExtTransactionID.Copy().(*types.String) + copied.Time = sit.Time.Copy().(*types.DateTime) + copied.TransactionType = sit.TransactionType.Copy().(*types.PrimitiveU32) + copied.TransactionDescription = sit.TransactionDescription.Copy().(*types.String) + copied.TransactionAmount = sit.TransactionAmount.Copy().(*ServiceItemAmount) + copied.ItemCode = sit.ItemCode.Copy().(*types.String) + copied.ReferenceID = sit.ReferenceID.Copy().(*types.String) + copied.Limitation = sit.Limitation.Copy().(*ServiceItemLimitation) + + return copied +} + +// Equals checks if the given ServiceItemTransaction contains the same data as the current ServiceItemTransaction +func (sit *ServiceItemTransaction) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemTransaction); !ok { + return false + } + + other := o.(*ServiceItemTransaction) + + if sit.StructureVersion != other.StructureVersion { + return false + } + + if !sit.TransactionID.Equals(other.TransactionID) { + return false + } + + if !sit.ExtTransactionID.Equals(other.ExtTransactionID) { + return false + } + + if !sit.Time.Equals(other.Time) { + return false + } + + if !sit.TransactionType.Equals(other.TransactionType) { + return false + } + + if !sit.TransactionDescription.Equals(other.TransactionDescription) { + return false + } + + if !sit.TransactionAmount.Equals(other.TransactionAmount) { + return false + } + + if !sit.ItemCode.Equals(other.ItemCode) { + return false + } + + if !sit.ReferenceID.Equals(other.ReferenceID) { + return false + } + + return sit.Limitation.Equals(other.Limitation) +} + +// String returns the string representation of the ServiceItemTransaction +func (sit *ServiceItemTransaction) String() string { + return sit.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemTransaction using the provided indentation level +func (sit *ServiceItemTransaction) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemTransaction{\n") + b.WriteString(fmt.Sprintf("%sTransactionID: %s,\n", indentationValues, sit.TransactionID)) + b.WriteString(fmt.Sprintf("%sExtTransactionID: %s,\n", indentationValues, sit.ExtTransactionID)) + b.WriteString(fmt.Sprintf("%sTime: %s,\n", indentationValues, sit.Time.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sTransactionType: %s,\n", indentationValues, sit.TransactionType)) + b.WriteString(fmt.Sprintf("%sTransactionDescription: %s,\n", indentationValues, sit.TransactionDescription)) + b.WriteString(fmt.Sprintf("%sTransactionAmount: %s,\n", indentationValues, sit.TransactionAmount.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sItemCode: %s,\n", indentationValues, sit.ItemCode)) + b.WriteString(fmt.Sprintf("%sReferenceID: %s,\n", indentationValues, sit.ReferenceID)) + b.WriteString(fmt.Sprintf("%sLimitation: %s,\n", indentationValues, sit.Limitation.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemTransaction returns a new ServiceItemTransaction +func NewServiceItemTransaction() *ServiceItemTransaction { + sit := &ServiceItemTransaction{ + TransactionID: types.NewString(""), + ExtTransactionID: types.NewString(""), + Time: types.NewDateTime(0), + TransactionType: types.NewPrimitiveU32(0), + TransactionDescription: types.NewString(""), + TransactionAmount: NewServiceItemAmount(), + ItemCode: types.NewString(""), + ReferenceID: types.NewString(""), + Limitation: NewServiceItemLimitation(), + } + + return sit +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_use_service_item_by_account_param.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_use_service_item_by_account_param.go new file mode 100644 index 0000000..f5b886b --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_use_service_item_by_account_param.go @@ -0,0 +1,196 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemUseServiceItemByAccountParam is a type within the ServiceItem protocol +type ServiceItemUseServiceItemByAccountParam struct { + types.Structure + ReferenceIDForUse *types.String + ReferenceIDForRightBinary *types.String + UseType *types.PrimitiveU8 + UseNumber *types.PrimitiveU8 + RightBinary *types.QBuffer + LogMessage *types.String + UniqueID *types.PrimitiveU32 + Platform *types.PrimitiveU8 +} + +// WriteTo writes the ServiceItemUseServiceItemByAccountParam to the given writable +func (siusibap *ServiceItemUseServiceItemByAccountParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siusibap.ReferenceIDForUse.WriteTo(contentWritable) + siusibap.ReferenceIDForRightBinary.WriteTo(contentWritable) + siusibap.UseType.WriteTo(contentWritable) + siusibap.UseNumber.WriteTo(contentWritable) + siusibap.RightBinary.WriteTo(contentWritable) + siusibap.LogMessage.WriteTo(contentWritable) + siusibap.UniqueID.WriteTo(contentWritable) + siusibap.Platform.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siusibap.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemUseServiceItemByAccountParam from the given readable +func (siusibap *ServiceItemUseServiceItemByAccountParam) ExtractFrom(readable types.Readable) error { + var err error + + err = siusibap.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUseServiceItemByAccountParam header. %s", err.Error()) + } + + err = siusibap.ReferenceIDForUse.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUseServiceItemByAccountParam.ReferenceIDForUse. %s", err.Error()) + } + + err = siusibap.ReferenceIDForRightBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUseServiceItemByAccountParam.ReferenceIDForRightBinary. %s", err.Error()) + } + + err = siusibap.UseType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUseServiceItemByAccountParam.UseType. %s", err.Error()) + } + + err = siusibap.UseNumber.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUseServiceItemByAccountParam.UseNumber. %s", err.Error()) + } + + err = siusibap.RightBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUseServiceItemByAccountParam.RightBinary. %s", err.Error()) + } + + err = siusibap.LogMessage.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUseServiceItemByAccountParam.LogMessage. %s", err.Error()) + } + + err = siusibap.UniqueID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUseServiceItemByAccountParam.UniqueID. %s", err.Error()) + } + + err = siusibap.Platform.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUseServiceItemByAccountParam.Platform. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemUseServiceItemByAccountParam +func (siusibap *ServiceItemUseServiceItemByAccountParam) Copy() types.RVType { + copied := NewServiceItemUseServiceItemByAccountParam() + + copied.StructureVersion = siusibap.StructureVersion + copied.ReferenceIDForUse = siusibap.ReferenceIDForUse.Copy().(*types.String) + copied.ReferenceIDForRightBinary = siusibap.ReferenceIDForRightBinary.Copy().(*types.String) + copied.UseType = siusibap.UseType.Copy().(*types.PrimitiveU8) + copied.UseNumber = siusibap.UseNumber.Copy().(*types.PrimitiveU8) + copied.RightBinary = siusibap.RightBinary.Copy().(*types.QBuffer) + copied.LogMessage = siusibap.LogMessage.Copy().(*types.String) + copied.UniqueID = siusibap.UniqueID.Copy().(*types.PrimitiveU32) + copied.Platform = siusibap.Platform.Copy().(*types.PrimitiveU8) + + return copied +} + +// Equals checks if the given ServiceItemUseServiceItemByAccountParam contains the same data as the current ServiceItemUseServiceItemByAccountParam +func (siusibap *ServiceItemUseServiceItemByAccountParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemUseServiceItemByAccountParam); !ok { + return false + } + + other := o.(*ServiceItemUseServiceItemByAccountParam) + + if siusibap.StructureVersion != other.StructureVersion { + return false + } + + if !siusibap.ReferenceIDForUse.Equals(other.ReferenceIDForUse) { + return false + } + + if !siusibap.ReferenceIDForRightBinary.Equals(other.ReferenceIDForRightBinary) { + return false + } + + if !siusibap.UseType.Equals(other.UseType) { + return false + } + + if !siusibap.UseNumber.Equals(other.UseNumber) { + return false + } + + if !siusibap.RightBinary.Equals(other.RightBinary) { + return false + } + + if !siusibap.LogMessage.Equals(other.LogMessage) { + return false + } + + if !siusibap.UniqueID.Equals(other.UniqueID) { + return false + } + + return siusibap.Platform.Equals(other.Platform) +} + +// String returns the string representation of the ServiceItemUseServiceItemByAccountParam +func (siusibap *ServiceItemUseServiceItemByAccountParam) String() string { + return siusibap.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemUseServiceItemByAccountParam using the provided indentation level +func (siusibap *ServiceItemUseServiceItemByAccountParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemUseServiceItemByAccountParam{\n") + b.WriteString(fmt.Sprintf("%sReferenceIDForUse: %s,\n", indentationValues, siusibap.ReferenceIDForUse)) + b.WriteString(fmt.Sprintf("%sReferenceIDForRightBinary: %s,\n", indentationValues, siusibap.ReferenceIDForRightBinary)) + b.WriteString(fmt.Sprintf("%sUseType: %s,\n", indentationValues, siusibap.UseType)) + b.WriteString(fmt.Sprintf("%sUseNumber: %s,\n", indentationValues, siusibap.UseNumber)) + b.WriteString(fmt.Sprintf("%sRightBinary: %s,\n", indentationValues, siusibap.RightBinary)) + b.WriteString(fmt.Sprintf("%sLogMessage: %s,\n", indentationValues, siusibap.LogMessage)) + b.WriteString(fmt.Sprintf("%sUniqueID: %s,\n", indentationValues, siusibap.UniqueID)) + b.WriteString(fmt.Sprintf("%sPlatform: %s,\n", indentationValues, siusibap.Platform)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemUseServiceItemByAccountParam returns a new ServiceItemUseServiceItemByAccountParam +func NewServiceItemUseServiceItemByAccountParam() *ServiceItemUseServiceItemByAccountParam { + siusibap := &ServiceItemUseServiceItemByAccountParam{ + ReferenceIDForUse: types.NewString(""), + ReferenceIDForRightBinary: types.NewString(""), + UseType: types.NewPrimitiveU8(0), + UseNumber: types.NewPrimitiveU8(0), + RightBinary: types.NewQBuffer(nil), + LogMessage: types.NewString(""), + UniqueID: types.NewPrimitiveU32(0), + Platform: types.NewPrimitiveU8(0), + } + + return siusibap +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_use_service_item_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_use_service_item_response.go new file mode 100644 index 0000000..6025019 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_use_service_item_response.go @@ -0,0 +1,115 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemUseServiceItemResponse is a type within the ServiceItem protocol +type ServiceItemUseServiceItemResponse struct { + types.Structure + *ServiceItemEShopResponse + NullableUsedInfo *types.List[*ServiceItemUsedInfo] +} + +// WriteTo writes the ServiceItemUseServiceItemResponse to the given writable +func (siusir *ServiceItemUseServiceItemResponse) WriteTo(writable types.Writable) { + siusir.ServiceItemEShopResponse.WriteTo(writable) + + contentWritable := writable.CopyNew() + + siusir.NullableUsedInfo.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siusir.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemUseServiceItemResponse from the given readable +func (siusir *ServiceItemUseServiceItemResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = siusir.ServiceItemEShopResponse.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUseServiceItemResponse.ServiceItemEShopResponse. %s", err.Error()) + } + + err = siusir.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUseServiceItemResponse header. %s", err.Error()) + } + + err = siusir.NullableUsedInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUseServiceItemResponse.NullableUsedInfo. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemUseServiceItemResponse +func (siusir *ServiceItemUseServiceItemResponse) Copy() types.RVType { + copied := NewServiceItemUseServiceItemResponse() + + copied.StructureVersion = siusir.StructureVersion + copied.ServiceItemEShopResponse = siusir.ServiceItemEShopResponse.Copy().(*ServiceItemEShopResponse) + copied.NullableUsedInfo = siusir.NullableUsedInfo.Copy().(*types.List[*ServiceItemUsedInfo]) + + return copied +} + +// Equals checks if the given ServiceItemUseServiceItemResponse contains the same data as the current ServiceItemUseServiceItemResponse +func (siusir *ServiceItemUseServiceItemResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemUseServiceItemResponse); !ok { + return false + } + + other := o.(*ServiceItemUseServiceItemResponse) + + if siusir.StructureVersion != other.StructureVersion { + return false + } + + if !siusir.ServiceItemEShopResponse.Equals(other.ServiceItemEShopResponse) { + return false + } + + return siusir.NullableUsedInfo.Equals(other.NullableUsedInfo) +} + +// String returns the string representation of the ServiceItemUseServiceItemResponse +func (siusir *ServiceItemUseServiceItemResponse) String() string { + return siusir.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemUseServiceItemResponse using the provided indentation level +func (siusir *ServiceItemUseServiceItemResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemUseServiceItemResponse{\n") + b.WriteString(fmt.Sprintf("%sServiceItemEShopResponse (parent): %s,\n", indentationValues, siusir.ServiceItemEShopResponse.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sNullableUsedInfo: %s,\n", indentationValues, siusir.NullableUsedInfo)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemUseServiceItemResponse returns a new ServiceItemUseServiceItemResponse +func NewServiceItemUseServiceItemResponse() *ServiceItemUseServiceItemResponse { + siusir := &ServiceItemUseServiceItemResponse{ + ServiceItemEShopResponse: NewServiceItemEShopResponse(), + NullableUsedInfo: types.NewList[*ServiceItemUsedInfo](), + } + + siusir.NullableUsedInfo.Type = NewServiceItemUsedInfo() + + return siusir +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_used_info.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_used_info.go new file mode 100644 index 0000000..a18aec4 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_used_info.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemUsedInfo is a type within the ServiceItem protocol +type ServiceItemUsedInfo struct { + types.Structure + AcquiredCount *types.PrimitiveU32 + UsedCount *types.PrimitiveU32 +} + +// WriteTo writes the ServiceItemUsedInfo to the given writable +func (siui *ServiceItemUsedInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siui.AcquiredCount.WriteTo(contentWritable) + siui.UsedCount.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siui.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemUsedInfo from the given readable +func (siui *ServiceItemUsedInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = siui.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUsedInfo header. %s", err.Error()) + } + + err = siui.AcquiredCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUsedInfo.AcquiredCount. %s", err.Error()) + } + + err = siui.UsedCount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUsedInfo.UsedCount. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemUsedInfo +func (siui *ServiceItemUsedInfo) Copy() types.RVType { + copied := NewServiceItemUsedInfo() + + copied.StructureVersion = siui.StructureVersion + copied.AcquiredCount = siui.AcquiredCount.Copy().(*types.PrimitiveU32) + copied.UsedCount = siui.UsedCount.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given ServiceItemUsedInfo contains the same data as the current ServiceItemUsedInfo +func (siui *ServiceItemUsedInfo) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemUsedInfo); !ok { + return false + } + + other := o.(*ServiceItemUsedInfo) + + if siui.StructureVersion != other.StructureVersion { + return false + } + + if !siui.AcquiredCount.Equals(other.AcquiredCount) { + return false + } + + return siui.UsedCount.Equals(other.UsedCount) +} + +// String returns the string representation of the ServiceItemUsedInfo +func (siui *ServiceItemUsedInfo) String() string { + return siui.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemUsedInfo using the provided indentation level +func (siui *ServiceItemUsedInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemUsedInfo{\n") + b.WriteString(fmt.Sprintf("%sAcquiredCount: %s,\n", indentationValues, siui.AcquiredCount)) + b.WriteString(fmt.Sprintf("%sUsedCount: %s,\n", indentationValues, siui.UsedCount)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemUsedInfo returns a new ServiceItemUsedInfo +func NewServiceItemUsedInfo() *ServiceItemUsedInfo { + siui := &ServiceItemUsedInfo{ + AcquiredCount: types.NewPrimitiveU32(0), + UsedCount: types.NewPrimitiveU32(0), + } + + return siui +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_user_info.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_user_info.go new file mode 100644 index 0000000..a611ebb --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/types/service_item_user_info.go @@ -0,0 +1,98 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemUserInfo is a type within the ServiceItem protocol +type ServiceItemUserInfo struct { + types.Structure + ApplicationBuffer *types.QBuffer +} + +// WriteTo writes the ServiceItemUserInfo to the given writable +func (siui *ServiceItemUserInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siui.ApplicationBuffer.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siui.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemUserInfo from the given readable +func (siui *ServiceItemUserInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = siui.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUserInfo header. %s", err.Error()) + } + + err = siui.ApplicationBuffer.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUserInfo.ApplicationBuffer. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemUserInfo +func (siui *ServiceItemUserInfo) Copy() types.RVType { + copied := NewServiceItemUserInfo() + + copied.StructureVersion = siui.StructureVersion + copied.ApplicationBuffer = siui.ApplicationBuffer.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given ServiceItemUserInfo contains the same data as the current ServiceItemUserInfo +func (siui *ServiceItemUserInfo) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemUserInfo); !ok { + return false + } + + other := o.(*ServiceItemUserInfo) + + if siui.StructureVersion != other.StructureVersion { + return false + } + + return siui.ApplicationBuffer.Equals(other.ApplicationBuffer) +} + +// String returns the string representation of the ServiceItemUserInfo +func (siui *ServiceItemUserInfo) String() string { + return siui.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemUserInfo using the provided indentation level +func (siui *ServiceItemUserInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemUserInfo{\n") + b.WriteString(fmt.Sprintf("%sApplicationBuffer: %s,\n", indentationValues, siui.ApplicationBuffer)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemUserInfo returns a new ServiceItemUserInfo +func NewServiceItemUserInfo() *ServiceItemUserInfo { + siui := &ServiceItemUserInfo{ + ApplicationBuffer: types.NewQBuffer(nil), + } + + return siui +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/use_service_item_by_account_request.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/use_service_item_by_account_request.go new file mode 100644 index 0000000..39f24fe --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/use_service_item_by_account_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_team_kirby_clash_deluxe_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/team-kirby-clash-deluxe/types" +) + +func (protocol *Protocol) handleUseServiceItemByAccountRequest(packet nex.PacketInterface) { + if protocol.UseServiceItemByAccountRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::UseServiceItemByAccountRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + useServiceItemByAccountParam := service_item_team_kirby_clash_deluxe_types.NewServiceItemUseServiceItemByAccountParam() + + err := useServiceItemByAccountParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UseServiceItemByAccountRequest(fmt.Errorf("Failed to read useServiceItemByAccountParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UseServiceItemByAccountRequest(nil, packet, callID, useServiceItemByAccountParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/team-kirby-clash-deluxe/use_service_item_by_account_response.go b/nex-protocols-go/service-item/team-kirby-clash-deluxe/use_service_item_by_account_response.go new file mode 100644 index 0000000..66a2bb5 --- /dev/null +++ b/nex-protocols-go/service-item/team-kirby-clash-deluxe/use_service_item_by_account_response.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemTeamKirbyClashDeluxe protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUseServiceItemByAccountResponse(packet nex.PacketInterface) { + if protocol.UseServiceItemByAccountResponse == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemTeamKirbyClashDeluxe::UseServiceItemByAccountResponse not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestID := types.NewPrimitiveU32(0) + + err := requestID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UseServiceItemByAccountResponse(fmt.Errorf("Failed to read requestID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UseServiceItemByAccountResponse(nil, packet, callID, requestID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/end_challenge.go b/nex-protocols-go/service-item/wii-sports-club/end_challenge.go new file mode 100644 index 0000000..6025123 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/end_challenge.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_wii_sports_club_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/wii-sports-club/types" +) + +func (protocol *Protocol) handleEndChallenge(packet nex.PacketInterface) { + if protocol.EndChallenge == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::EndChallenge not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + endChallengeParam := service_item_wii_sports_club_types.NewServiceItemEndChallengeParam() + + err := endChallengeParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.EndChallenge(fmt.Errorf("Failed to read endChallengeParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.EndChallenge(nil, packet, callID, endChallengeParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/get_balance_request.go b/nex-protocols-go/service-item/wii-sports-club/get_balance_request.go new file mode 100644 index 0000000..1e64592 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/get_balance_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_wii_sports_club_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/wii-sports-club/types" +) + +func (protocol *Protocol) handleGetBalanceRequest(packet nex.PacketInterface) { + if protocol.GetBalanceRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::GetBalanceRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + getBalanceParam := service_item_wii_sports_club_types.NewServiceItemGetBalanceParam() + + err := getBalanceParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetBalanceRequest(fmt.Errorf("Failed to read getBalanceParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetBalanceRequest(nil, packet, callID, getBalanceParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/get_balance_response.go b/nex-protocols-go/service-item/wii-sports-club/get_balance_response.go new file mode 100644 index 0000000..fce399e --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/get_balance_response.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetBalanceResponse(packet nex.PacketInterface) { + if protocol.GetBalanceResponse == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::GetBalanceResponse not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestID := types.NewPrimitiveU32(0) + + err := requestID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetBalanceResponse(fmt.Errorf("Failed to read requestID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetBalanceResponse(nil, packet, callID, requestID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/get_notice.go b/nex-protocols-go/service-item/wii-sports-club/get_notice.go new file mode 100644 index 0000000..9843679 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/get_notice.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_wii_sports_club_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/wii-sports-club/types" +) + +func (protocol *Protocol) handleGetNotice(packet nex.PacketInterface) { + if protocol.GetNotice == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::GetNotice not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + getNoticeParam := service_item_wii_sports_club_types.NewServiceItemGetNoticeParam() + + err := getNoticeParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetNotice(fmt.Errorf("Failed to read getNoticeParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetNotice(nil, packet, callID, getNoticeParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/get_prepurchase_info_request.go b/nex-protocols-go/service-item/wii-sports-club/get_prepurchase_info_request.go new file mode 100644 index 0000000..136b0a8 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/get_prepurchase_info_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_wii_sports_club_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/wii-sports-club/types" +) + +func (protocol *Protocol) handleGetPrepurchaseInfoRequest(packet nex.PacketInterface) { + if protocol.GetPrepurchaseInfoRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::GetPrepurchaseInfoRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + getPrepurchaseInfoParam := service_item_wii_sports_club_types.NewServiceItemGetPrepurchaseInfoParam() + + err := getPrepurchaseInfoParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPrepurchaseInfoRequest(fmt.Errorf("Failed to read getPrepurchaseInfoParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetPrepurchaseInfoRequest(nil, packet, callID, getPrepurchaseInfoParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/get_prepurchase_info_response.go b/nex-protocols-go/service-item/wii-sports-club/get_prepurchase_info_response.go new file mode 100644 index 0000000..971bef8 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/get_prepurchase_info_response.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetPrepurchaseInfoResponse(packet nex.PacketInterface) { + if protocol.GetPrepurchaseInfoResponse == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::GetPrepurchaseInfoResponse not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestID := types.NewPrimitiveU32(0) + + err := requestID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPrepurchaseInfoResponse(fmt.Errorf("Failed to read requestID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetPrepurchaseInfoResponse(nil, packet, callID, requestID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/get_purchase_history_request.go b/nex-protocols-go/service-item/wii-sports-club/get_purchase_history_request.go new file mode 100644 index 0000000..a6a4480 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/get_purchase_history_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_wii_sports_club_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/wii-sports-club/types" +) + +func (protocol *Protocol) handleGetPurchaseHistoryRequest(packet nex.PacketInterface) { + if protocol.GetPurchaseHistoryRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::GetPurchaseHistoryRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + getPurchaseHistoryParam := service_item_wii_sports_club_types.NewServiceItemGetPurchaseHistoryParam() + + err := getPurchaseHistoryParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPurchaseHistoryRequest(fmt.Errorf("Failed to read getPurchaseHistoryParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetPurchaseHistoryRequest(nil, packet, callID, getPurchaseHistoryParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/get_purchase_history_response.go b/nex-protocols-go/service-item/wii-sports-club/get_purchase_history_response.go new file mode 100644 index 0000000..c6cef95 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/get_purchase_history_response.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetPurchaseHistoryResponse(packet nex.PacketInterface) { + if protocol.GetPurchaseHistoryResponse == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::GetPurchaseHistoryResponse not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestID := types.NewPrimitiveU32(0) + + err := requestID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPurchaseHistoryResponse(fmt.Errorf("Failed to read requestID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetPurchaseHistoryResponse(nil, packet, callID, requestID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/get_service_item_right_request.go b/nex-protocols-go/service-item/wii-sports-club/get_service_item_right_request.go new file mode 100644 index 0000000..76c3d97 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/get_service_item_right_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_wii_sports_club_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/wii-sports-club/types" +) + +func (protocol *Protocol) handleGetServiceItemRightRequest(packet nex.PacketInterface) { + if protocol.GetServiceItemRightRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::GetServiceItemRightRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + getServiceItemRightParam := service_item_wii_sports_club_types.NewServiceItemGetServiceItemRightParam() + + err := getServiceItemRightParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetServiceItemRightRequest(fmt.Errorf("Failed to read getServiceItemRightParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetServiceItemRightRequest(nil, packet, callID, getServiceItemRightParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/get_service_item_right_response.go b/nex-protocols-go/service-item/wii-sports-club/get_service_item_right_response.go new file mode 100644 index 0000000..1febedc --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/get_service_item_right_response.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetServiceItemRightResponse(packet nex.PacketInterface) { + if protocol.GetServiceItemRightResponse == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::GetServiceItemRightResponse not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestID := types.NewPrimitiveU32(0) + + err := requestID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetServiceItemRightResponse(fmt.Errorf("Failed to read requestID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetServiceItemRightResponse(nil, packet, callID, requestID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/hello.go b/nex-protocols-go/service-item/wii-sports-club/hello.go new file mode 100644 index 0000000..3552d15 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/hello.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleHello(packet nex.PacketInterface) { + if protocol.Hello == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::Hello not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + name := types.NewString("") + + err := name.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.Hello(fmt.Errorf("Failed to read name from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.Hello(nil, packet, callID, name) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/http_get_request.go b/nex-protocols-go/service-item/wii-sports-club/http_get_request.go new file mode 100644 index 0000000..573890c --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/http_get_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_wii_sports_club_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/wii-sports-club/types" +) + +func (protocol *Protocol) handleHTTPGetRequest(packet nex.PacketInterface) { + if protocol.HTTPGetRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::HTTPGetRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + url := service_item_wii_sports_club_types.NewServiceItemHTTPGetParam() + + err := url.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.HTTPGetRequest(fmt.Errorf("Failed to read url from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.HTTPGetRequest(nil, packet, callID, url) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/http_get_response.go b/nex-protocols-go/service-item/wii-sports-club/http_get_response.go new file mode 100644 index 0000000..e23b6f6 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/http_get_response.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleHTTPGetResponse(packet nex.PacketInterface) { + if protocol.HTTPGetResponse == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::HTTPGetResponse not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestID := types.NewPrimitiveU32(0) + + err := requestID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.HTTPGetResponse(fmt.Errorf("Failed to read requestID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.HTTPGetResponse(nil, packet, callID, requestID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/list_service_item_request.go b/nex-protocols-go/service-item/wii-sports-club/list_service_item_request.go new file mode 100644 index 0000000..3c0c87a --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/list_service_item_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_wii_sports_club_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/wii-sports-club/types" +) + +func (protocol *Protocol) handleListServiceItemRequest(packet nex.PacketInterface) { + if protocol.ListServiceItemRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::ListServiceItemRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + listServiceItemParam := service_item_wii_sports_club_types.NewServiceItemListServiceItemParam() + + err := listServiceItemParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ListServiceItemRequest(fmt.Errorf("Failed to read listServiceItemParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ListServiceItemRequest(nil, packet, callID, listServiceItemParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/list_service_item_response.go b/nex-protocols-go/service-item/wii-sports-club/list_service_item_response.go new file mode 100644 index 0000000..51a751d --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/list_service_item_response.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleListServiceItemResponse(packet nex.PacketInterface) { + if protocol.ListServiceItemResponse == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::ListServiceItemResponse not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestID := types.NewPrimitiveU32(0) + + err := requestID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ListServiceItemResponse(fmt.Errorf("Failed to read requestID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ListServiceItemResponse(nil, packet, callID, requestID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/load_user_info.go b/nex-protocols-go/service-item/wii-sports-club/load_user_info.go new file mode 100644 index 0000000..8150cb3 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/load_user_info.go @@ -0,0 +1,29 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleLoadUserInfo(packet nex.PacketInterface) { + if protocol.LoadUserInfo == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::LoadUserInfo not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.LoadUserInfo(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/protocol.go b/nex-protocols-go/service-item/wii-sports-club/protocol.go new file mode 100644 index 0000000..4062f37 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/protocol.go @@ -0,0 +1,215 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item "github.com/PretendoNetwork/nex-protocols-go/v2/service-item" + service_item_wii_sports_club_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/wii-sports-club/types" + "golang.org/x/exp/slices" +) + +const ( + // ProtocolID is the Protocol ID for the Service Item (Wii Sports Club) protocol + ProtocolID = 0x77 + + // MethodHello is the method ID for the Hello method + MethodHello = 0x1 + + // MethodHTTPGetRequest is the method ID for the HTTPGetRequest method + MethodHTTPGetRequest = 0x2 + + // MethodHTTPGetResponse is the method ID for the HTTPGetResponse method + MethodHTTPGetResponse = 0x3 + + // MethodPurchaseServiceItemRequest is the method ID for the PurchaseServiceItemRequest method + MethodPurchaseServiceItemRequest = 0x4 + + // MethodPurchaseServiceItemResponse is the method ID for the PurchaseServiceItemResponse method + MethodPurchaseServiceItemResponse = 0x5 + + // MethodListServiceItemRequest is the method ID for the ListServiceItemRequest method + MethodListServiceItemRequest = 0x6 + + // MethodListServiceItemResponse is the method ID for the ListServiceItemResponse method + MethodListServiceItemResponse = 0x7 + + // MethodGetBalanceRequest is the method ID for the GetBalanceRequest method + MethodGetBalanceRequest = 0x8 + + // MethodGetBalanceResponse is the method ID for the GetBalanceResponse method + MethodGetBalanceResponse = 0x9 + + // MethodGetPrepurchaseInfoRequest is the method ID for the GetPrepurchaseInfoRequest method + MethodGetPrepurchaseInfoRequest = 0xA + + // MethodGetPrepurchaseInfoResponse is the method ID for the GetPrepurchaseInfoResponse method + MethodGetPrepurchaseInfoResponse = 0xB + + // MethodGetServiceItemRightRequest is the method ID for the GetServiceItemRightRequest method + MethodGetServiceItemRightRequest = 0xC + + // MethodGetServiceItemRightResponse is the method ID for the GetServiceItemRightResponse method + MethodGetServiceItemRightResponse = 0xD + + // MethodGetPurchaseHistoryRequest is the method ID for the GetPurchaseHistoryRequest method + MethodGetPurchaseHistoryRequest = 0xE + + // MethodGetPurchaseHistoryResponse is the method ID for the GetPurchaseHistoryResponse method + MethodGetPurchaseHistoryResponse = 0xF + + // MethodGetNotice is the method ID for the GetNotice method + MethodGetNotice = 0x10 + + // MethodUpdateAndGetTicketInfo is the method ID for the UpdateAndGetTicketInfo method + MethodUpdateAndGetTicketInfo = 0x11 + + // MethodLoadUserInfo is the method ID for the LoadUserInfo method + MethodLoadUserInfo = 0x12 + + // MethodSaveUserInfo is the method ID for the SaveUserInfo method + MethodSaveUserInfo = 0x13 + + // MethodStartChallenge is the method ID for the StartChallenge method + MethodStartChallenge = 0x14 + + // MethodEndChallenge is the method ID for the EndChallenge method + MethodEndChallenge = 0x15 + + // MethodRequestTicketRestoration is the method ID for the RequestTicketRestoration method + MethodRequestTicketRestoration = 0x16 +) + +var patchedMethods = []uint32{ + MethodHello, + MethodHTTPGetRequest, + MethodHTTPGetResponse, + MethodPurchaseServiceItemRequest, + MethodPurchaseServiceItemResponse, + MethodListServiceItemRequest, + MethodListServiceItemResponse, + MethodGetBalanceRequest, + MethodGetBalanceResponse, + MethodGetPrepurchaseInfoRequest, + MethodGetPrepurchaseInfoResponse, + MethodGetServiceItemRightRequest, + MethodGetServiceItemRightResponse, + MethodGetPurchaseHistoryRequest, + MethodGetPurchaseHistoryResponse, + MethodGetNotice, + MethodUpdateAndGetTicketInfo, + MethodLoadUserInfo, + MethodSaveUserInfo, + MethodStartChallenge, + MethodEndChallenge, + MethodRequestTicketRestoration, +} + +type serviceItemProtocol = service_item.Protocol + +// Protocol stores all the RMC method handlers for the Service Item (Wii Sports Club) protocol and listens for requests +// Embeds the Service Item protocol +type Protocol struct { + endpoint nex.EndpointInterface + serviceItemProtocol + Hello func(err error, packet nex.PacketInterface, callID uint32, name *types.String) (*nex.RMCMessage, *nex.Error) + HTTPGetRequest func(err error, packet nex.PacketInterface, callID uint32, url *service_item_wii_sports_club_types.ServiceItemHTTPGetParam) (*nex.RMCMessage, *nex.Error) + HTTPGetResponse func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + PurchaseServiceItemRequest func(err error, packet nex.PacketInterface, callID uint32, purchaseServiceItemParam *service_item_wii_sports_club_types.ServiceItemPurchaseServiceItemParam) (*nex.RMCMessage, *nex.Error) + PurchaseServiceItemResponse func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + ListServiceItemRequest func(err error, packet nex.PacketInterface, callID uint32, listServiceItemParam *service_item_wii_sports_club_types.ServiceItemListServiceItemParam) (*nex.RMCMessage, *nex.Error) + ListServiceItemResponse func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetBalanceRequest func(err error, packet nex.PacketInterface, callID uint32, getBalanceParam *service_item_wii_sports_club_types.ServiceItemGetBalanceParam) (*nex.RMCMessage, *nex.Error) + GetBalanceResponse func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetPrepurchaseInfoRequest func(err error, packet nex.PacketInterface, callID uint32, getPrepurchaseInfoParam *service_item_wii_sports_club_types.ServiceItemGetPrepurchaseInfoParam) (*nex.RMCMessage, *nex.Error) + GetPrepurchaseInfoResponse func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetServiceItemRightRequest func(err error, packet nex.PacketInterface, callID uint32, getServiceItemRightParam *service_item_wii_sports_club_types.ServiceItemGetServiceItemRightParam) (*nex.RMCMessage, *nex.Error) + GetServiceItemRightResponse func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetPurchaseHistoryRequest func(err error, packet nex.PacketInterface, callID uint32, getPurchaseHistoryParam *service_item_wii_sports_club_types.ServiceItemGetPurchaseHistoryParam) (*nex.RMCMessage, *nex.Error) + GetPurchaseHistoryResponse func(err error, packet nex.PacketInterface, callID uint32, requestID *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetNotice func(err error, packet nex.PacketInterface, callID uint32, getNoticeParam *service_item_wii_sports_club_types.ServiceItemGetNoticeParam) (*nex.RMCMessage, *nex.Error) + UpdateAndGetTicketInfo func(err error, packet nex.PacketInterface, callID uint32, forceRetrieveFromEShop *types.PrimitiveBool) (*nex.RMCMessage, *nex.Error) + LoadUserInfo func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + SaveUserInfo func(err error, packet nex.PacketInterface, callID uint32, userInfo *service_item_wii_sports_club_types.ServiceItemUserInfo) (*nex.RMCMessage, *nex.Error) + StartChallenge func(err error, packet nex.PacketInterface, callID uint32, startChallengeParam *service_item_wii_sports_club_types.ServiceItemStartChallengeParam) (*nex.RMCMessage, *nex.Error) + EndChallenge func(err error, packet nex.PacketInterface, callID uint32, endChallengeParam *service_item_wii_sports_club_types.ServiceItemEndChallengeParam) (*nex.RMCMessage, *nex.Error) + RequestTicketRestoration func(err error, packet nex.PacketInterface, callID uint32, requestTicketRestorationParam *service_item_wii_sports_club_types.ServiceItemRequestTicketRestorationParam) (*nex.RMCMessage, *nex.Error) +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if !slices.Contains(patchedMethods, message.MethodID) { + protocol.serviceItemProtocol.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodHello: + protocol.handleHello(packet) + case MethodHTTPGetRequest: + protocol.handleHTTPGetRequest(packet) + case MethodHTTPGetResponse: + protocol.handleHTTPGetResponse(packet) + case MethodPurchaseServiceItemRequest: + protocol.handlePurchaseServiceItemRequest(packet) + case MethodPurchaseServiceItemResponse: + protocol.handlePurchaseServiceItemResponse(packet) + case MethodListServiceItemRequest: + protocol.handleListServiceItemRequest(packet) + case MethodListServiceItemResponse: + protocol.handleListServiceItemResponse(packet) + case MethodGetBalanceRequest: + protocol.handleGetBalanceRequest(packet) + case MethodGetBalanceResponse: + protocol.handleGetBalanceResponse(packet) + case MethodGetPrepurchaseInfoRequest: + protocol.handleGetPrepurchaseInfoRequest(packet) + case MethodGetPrepurchaseInfoResponse: + protocol.handleGetPrepurchaseInfoResponse(packet) + case MethodGetServiceItemRightRequest: + protocol.handleGetServiceItemRightRequest(packet) + case MethodGetServiceItemRightResponse: + protocol.handleGetServiceItemRightResponse(packet) + case MethodGetPurchaseHistoryRequest: + protocol.handleGetPurchaseHistoryRequest(packet) + case MethodGetPurchaseHistoryResponse: + protocol.handleGetPurchaseHistoryResponse(packet) + case MethodGetNotice: + protocol.handleGetNotice(packet) + case MethodUpdateAndGetTicketInfo: + protocol.handleUpdateAndGetTicketInfo(packet) + case MethodLoadUserInfo: + protocol.handleLoadUserInfo(packet) + case MethodSaveUserInfo: + protocol.handleSaveUserInfo(packet) + case MethodStartChallenge: + protocol.handleStartChallenge(packet) + case MethodEndChallenge: + protocol.handleEndChallenge(packet) + case MethodRequestTicketRestoration: + protocol.handleRequestTicketRestoration(packet) + default: + errMessage := fmt.Sprintf("Unsupported Service Item (Wii Sports Club) method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new ServiceItemWiiSportsClub protocol +func NewProtocol(endpoint nex.EndpointInterface) *Protocol { + protocol := &Protocol{endpoint: endpoint} + protocol.serviceItemProtocol.SetEndpoint(endpoint) + + return protocol +} diff --git a/nex-protocols-go/service-item/wii-sports-club/purchase_service_item_request.go b/nex-protocols-go/service-item/wii-sports-club/purchase_service_item_request.go new file mode 100644 index 0000000..5156f81 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/purchase_service_item_request.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_wii_sports_club_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/wii-sports-club/types" +) + +func (protocol *Protocol) handlePurchaseServiceItemRequest(packet nex.PacketInterface) { + if protocol.PurchaseServiceItemRequest == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::PurchaseServiceItemRequest not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + purchaseServiceItemParam := service_item_wii_sports_club_types.NewServiceItemPurchaseServiceItemParam() + + err := purchaseServiceItemParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PurchaseServiceItemRequest(fmt.Errorf("Failed to read purchaseServiceItemParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PurchaseServiceItemRequest(nil, packet, callID, purchaseServiceItemParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/purchase_service_item_response.go b/nex-protocols-go/service-item/wii-sports-club/purchase_service_item_response.go new file mode 100644 index 0000000..9033625 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/purchase_service_item_response.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handlePurchaseServiceItemResponse(packet nex.PacketInterface) { + if protocol.PurchaseServiceItemResponse == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::PurchaseServiceItemResponse not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestID := types.NewPrimitiveU32(0) + + err := requestID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PurchaseServiceItemResponse(fmt.Errorf("Failed to read requestID from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PurchaseServiceItemResponse(nil, packet, callID, requestID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/request_ticket_restoration.go b/nex-protocols-go/service-item/wii-sports-club/request_ticket_restoration.go new file mode 100644 index 0000000..e9f0c80 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/request_ticket_restoration.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_wii_sports_club_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/wii-sports-club/types" +) + +func (protocol *Protocol) handleRequestTicketRestoration(packet nex.PacketInterface) { + if protocol.RequestTicketRestoration == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::RequestTicketRestoration not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + requestTicketRestorationParam := service_item_wii_sports_club_types.NewServiceItemRequestTicketRestorationParam() + + err := requestTicketRestorationParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RequestTicketRestoration(fmt.Errorf("Failed to read requestTicketRestorationParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RequestTicketRestoration(nil, packet, callID, requestTicketRestorationParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/save_user_info.go b/nex-protocols-go/service-item/wii-sports-club/save_user_info.go new file mode 100644 index 0000000..6046620 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/save_user_info.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_wii_sports_club_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/wii-sports-club/types" +) + +func (protocol *Protocol) handleSaveUserInfo(packet nex.PacketInterface) { + if protocol.SaveUserInfo == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::SaveUserInfo not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + userInfo := service_item_wii_sports_club_types.NewServiceItemUserInfo() + + err := userInfo.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.SaveUserInfo(fmt.Errorf("Failed to read userInfo from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.SaveUserInfo(nil, packet, callID, userInfo) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/start_challenge.go b/nex-protocols-go/service-item/wii-sports-club/start_challenge.go new file mode 100644 index 0000000..d49e51e --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/start_challenge.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + service_item_wii_sports_club_types "github.com/PretendoNetwork/nex-protocols-go/v2/service-item/wii-sports-club/types" +) + +func (protocol *Protocol) handleStartChallenge(packet nex.PacketInterface) { + if protocol.StartChallenge == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::StartChallenge not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + startChallengeParam := service_item_wii_sports_club_types.NewServiceItemStartChallengeParam() + + err := startChallengeParam.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.StartChallenge(fmt.Errorf("Failed to read startChallengeParam from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.StartChallenge(nil, packet, callID, startChallengeParam) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_account_right.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_account_right.go new file mode 100644 index 0000000..b8ba82d --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_account_right.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemAccountRight is a type within the ServiceItem protocol +type ServiceItemAccountRight struct { + types.Structure + PID *types.PID + Limitation *ServiceItemLimitation +} + +// WriteTo writes the ServiceItemAccountRight to the given writable +func (siar *ServiceItemAccountRight) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siar.PID.WriteTo(contentWritable) + siar.Limitation.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siar.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemAccountRight from the given readable +func (siar *ServiceItemAccountRight) ExtractFrom(readable types.Readable) error { + var err error + + err = siar.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAccountRight header. %s", err.Error()) + } + + err = siar.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAccountRight.PID. %s", err.Error()) + } + + err = siar.Limitation.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAccountRight.Limitation. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemAccountRight +func (siar *ServiceItemAccountRight) Copy() types.RVType { + copied := NewServiceItemAccountRight() + + copied.StructureVersion = siar.StructureVersion + copied.PID = siar.PID.Copy().(*types.PID) + copied.Limitation = siar.Limitation.Copy().(*ServiceItemLimitation) + + return copied +} + +// Equals checks if the given ServiceItemAccountRight contains the same data as the current ServiceItemAccountRight +func (siar *ServiceItemAccountRight) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemAccountRight); !ok { + return false + } + + other := o.(*ServiceItemAccountRight) + + if siar.StructureVersion != other.StructureVersion { + return false + } + + if !siar.PID.Equals(other.PID) { + return false + } + + return siar.Limitation.Equals(other.Limitation) +} + +// String returns the string representation of the ServiceItemAccountRight +func (siar *ServiceItemAccountRight) String() string { + return siar.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemAccountRight using the provided indentation level +func (siar *ServiceItemAccountRight) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemAccountRight{\n") + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, siar.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sLimitation: %s,\n", indentationValues, siar.Limitation.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemAccountRight returns a new ServiceItemAccountRight +func NewServiceItemAccountRight() *ServiceItemAccountRight { + siar := &ServiceItemAccountRight{ + PID: types.NewPID(0), + Limitation: NewServiceItemLimitation(), + } + + return siar +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_amount.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_amount.go new file mode 100644 index 0000000..630b5bb --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_amount.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemAmount is a type within the ServiceItem protocol +type ServiceItemAmount struct { + types.Structure + FormattedAmount *types.String + Currency *types.String + RawValue *types.String +} + +// WriteTo writes the ServiceItemAmount to the given writable +func (sia *ServiceItemAmount) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sia.FormattedAmount.WriteTo(contentWritable) + sia.Currency.WriteTo(contentWritable) + sia.RawValue.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sia.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemAmount from the given readable +func (sia *ServiceItemAmount) ExtractFrom(readable types.Readable) error { + var err error + + err = sia.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAmount header. %s", err.Error()) + } + + err = sia.FormattedAmount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAmount.FormattedAmount. %s", err.Error()) + } + + err = sia.Currency.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAmount.Currency. %s", err.Error()) + } + + err = sia.RawValue.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAmount.RawValue. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemAmount +func (sia *ServiceItemAmount) Copy() types.RVType { + copied := NewServiceItemAmount() + + copied.StructureVersion = sia.StructureVersion + copied.FormattedAmount = sia.FormattedAmount.Copy().(*types.String) + copied.Currency = sia.Currency.Copy().(*types.String) + copied.RawValue = sia.RawValue.Copy().(*types.String) + + return copied +} + +// Equals checks if the given ServiceItemAmount contains the same data as the current ServiceItemAmount +func (sia *ServiceItemAmount) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemAmount); !ok { + return false + } + + other := o.(*ServiceItemAmount) + + if sia.StructureVersion != other.StructureVersion { + return false + } + + if !sia.FormattedAmount.Equals(other.FormattedAmount) { + return false + } + + if !sia.Currency.Equals(other.Currency) { + return false + } + + return sia.RawValue.Equals(other.RawValue) +} + +// String returns the string representation of the ServiceItemAmount +func (sia *ServiceItemAmount) String() string { + return sia.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemAmount using the provided indentation level +func (sia *ServiceItemAmount) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemAmount{\n") + b.WriteString(fmt.Sprintf("%sFormattedAmount: %s,\n", indentationValues, sia.FormattedAmount)) + b.WriteString(fmt.Sprintf("%sCurrency: %s,\n", indentationValues, sia.Currency)) + b.WriteString(fmt.Sprintf("%sRawValue: %s,\n", indentationValues, sia.RawValue)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemAmount returns a new ServiceItemAmount +func NewServiceItemAmount() *ServiceItemAmount { + sia := &ServiceItemAmount{ + FormattedAmount: types.NewString(""), + Currency: types.NewString(""), + RawValue: types.NewString(""), + } + + return sia +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_attribute.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_attribute.go new file mode 100644 index 0000000..6511084 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_attribute.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemAttribute is a type within the ServiceItem protocol +type ServiceItemAttribute struct { + types.Structure + Name *types.String + Value *types.String +} + +// WriteTo writes the ServiceItemAttribute to the given writable +func (sia *ServiceItemAttribute) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sia.Name.WriteTo(contentWritable) + sia.Value.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sia.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemAttribute from the given readable +func (sia *ServiceItemAttribute) ExtractFrom(readable types.Readable) error { + var err error + + err = sia.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAttribute header. %s", err.Error()) + } + + err = sia.Name.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAttribute.Name. %s", err.Error()) + } + + err = sia.Value.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemAttribute.Value. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemAttribute +func (sia *ServiceItemAttribute) Copy() types.RVType { + copied := NewServiceItemAttribute() + + copied.StructureVersion = sia.StructureVersion + copied.Name = sia.Name.Copy().(*types.String) + copied.Value = sia.Value.Copy().(*types.String) + + return copied +} + +// Equals checks if the given ServiceItemAttribute contains the same data as the current ServiceItemAttribute +func (sia *ServiceItemAttribute) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemAttribute); !ok { + return false + } + + other := o.(*ServiceItemAttribute) + + if sia.StructureVersion != other.StructureVersion { + return false + } + + if !sia.Name.Equals(other.Name) { + return false + } + + return sia.Value.Equals(other.Value) +} + +// String returns the string representation of the ServiceItemAttribute +func (sia *ServiceItemAttribute) String() string { + return sia.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemAttribute using the provided indentation level +func (sia *ServiceItemAttribute) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemAttribute{\n") + b.WriteString(fmt.Sprintf("%sName: %s,\n", indentationValues, sia.Name)) + b.WriteString(fmt.Sprintf("%sValue: %s,\n", indentationValues, sia.Value)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemAttribute returns a new ServiceItemAttribute +func NewServiceItemAttribute() *ServiceItemAttribute { + sia := &ServiceItemAttribute{ + Name: types.NewString(""), + Value: types.NewString(""), + } + + return sia +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_catalog.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_catalog.go new file mode 100644 index 0000000..9a00f0c --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_catalog.go @@ -0,0 +1,128 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemCatalog is a type within the ServiceItem protocol +type ServiceItemCatalog struct { + types.Structure + TotalSize *types.PrimitiveU32 + Offset *types.PrimitiveU32 + ListItems *types.List[*ServiceItemListItem] +} + +// WriteTo writes the ServiceItemCatalog to the given writable +func (sic *ServiceItemCatalog) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sic.TotalSize.WriteTo(contentWritable) + sic.Offset.WriteTo(contentWritable) + sic.ListItems.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sic.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemCatalog from the given readable +func (sic *ServiceItemCatalog) ExtractFrom(readable types.Readable) error { + var err error + + err = sic.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemCatalog header. %s", err.Error()) + } + + err = sic.TotalSize.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemCatalog.TotalSize. %s", err.Error()) + } + + err = sic.Offset.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemCatalog.Offset. %s", err.Error()) + } + + err = sic.ListItems.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemCatalog.ListItems. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemCatalog +func (sic *ServiceItemCatalog) Copy() types.RVType { + copied := NewServiceItemCatalog() + + copied.StructureVersion = sic.StructureVersion + copied.TotalSize = sic.TotalSize.Copy().(*types.PrimitiveU32) + copied.Offset = sic.Offset.Copy().(*types.PrimitiveU32) + copied.ListItems = sic.ListItems.Copy().(*types.List[*ServiceItemListItem]) + + return copied +} + +// Equals checks if the given ServiceItemCatalog contains the same data as the current ServiceItemCatalog +func (sic *ServiceItemCatalog) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemCatalog); !ok { + return false + } + + other := o.(*ServiceItemCatalog) + + if sic.StructureVersion != other.StructureVersion { + return false + } + + if !sic.TotalSize.Equals(other.TotalSize) { + return false + } + + if !sic.Offset.Equals(other.Offset) { + return false + } + + return sic.ListItems.Equals(other.ListItems) +} + +// String returns the string representation of the ServiceItemCatalog +func (sic *ServiceItemCatalog) String() string { + return sic.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemCatalog using the provided indentation level +func (sic *ServiceItemCatalog) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemCatalog{\n") + b.WriteString(fmt.Sprintf("%sTotalSize: %s,\n", indentationValues, sic.TotalSize)) + b.WriteString(fmt.Sprintf("%sOffset: %s,\n", indentationValues, sic.Offset)) + b.WriteString(fmt.Sprintf("%sListItems: %s,\n", indentationValues, sic.ListItems)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemCatalog returns a new ServiceItemCatalog +func NewServiceItemCatalog() *ServiceItemCatalog { + sic := &ServiceItemCatalog{ + TotalSize: types.NewPrimitiveU32(0), + Offset: types.NewPrimitiveU32(0), + ListItems: types.NewList[*ServiceItemListItem](), + } + + sic.ListItems.Type = NewServiceItemListItem() + + return sic +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_end_challenge_param.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_end_challenge_param.go new file mode 100644 index 0000000..ec60256 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_end_challenge_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemEndChallengeParam is a type within the ServiceItem protocol +type ServiceItemEndChallengeParam struct { + types.Structure + ChallengeScheduleID *types.PrimitiveU32 + UserInfo *ServiceItemUserInfo +} + +// WriteTo writes the ServiceItemEndChallengeParam to the given writable +func (siecp *ServiceItemEndChallengeParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siecp.ChallengeScheduleID.WriteTo(contentWritable) + siecp.UserInfo.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siecp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemEndChallengeParam from the given readable +func (siecp *ServiceItemEndChallengeParam) ExtractFrom(readable types.Readable) error { + var err error + + err = siecp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEndChallengeParam header. %s", err.Error()) + } + + err = siecp.ChallengeScheduleID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEndChallengeParam.ChallengeScheduleID. %s", err.Error()) + } + + err = siecp.UserInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEndChallengeParam.UserInfo. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemEndChallengeParam +func (siecp *ServiceItemEndChallengeParam) Copy() types.RVType { + copied := NewServiceItemEndChallengeParam() + + copied.StructureVersion = siecp.StructureVersion + copied.ChallengeScheduleID = siecp.ChallengeScheduleID.Copy().(*types.PrimitiveU32) + copied.UserInfo = siecp.UserInfo.Copy().(*ServiceItemUserInfo) + + return copied +} + +// Equals checks if the given ServiceItemEndChallengeParam contains the same data as the current ServiceItemEndChallengeParam +func (siecp *ServiceItemEndChallengeParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemEndChallengeParam); !ok { + return false + } + + other := o.(*ServiceItemEndChallengeParam) + + if siecp.StructureVersion != other.StructureVersion { + return false + } + + if !siecp.ChallengeScheduleID.Equals(other.ChallengeScheduleID) { + return false + } + + return siecp.UserInfo.Equals(other.UserInfo) +} + +// String returns the string representation of the ServiceItemEndChallengeParam +func (siecp *ServiceItemEndChallengeParam) String() string { + return siecp.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemEndChallengeParam using the provided indentation level +func (siecp *ServiceItemEndChallengeParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemEndChallengeParam{\n") + b.WriteString(fmt.Sprintf("%sChallengeScheduleID: %s,\n", indentationValues, siecp.ChallengeScheduleID)) + b.WriteString(fmt.Sprintf("%sUserInfo: %s,\n", indentationValues, siecp.UserInfo.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemEndChallengeParam returns a new ServiceItemEndChallengeParam +func NewServiceItemEndChallengeParam() *ServiceItemEndChallengeParam { + siecp := &ServiceItemEndChallengeParam{ + ChallengeScheduleID: types.NewPrimitiveU32(0), + UserInfo: NewServiceItemUserInfo(), + } + + return siecp +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_eshop_response.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_eshop_response.go new file mode 100644 index 0000000..2bcca34 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_eshop_response.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemEShopResponse is a type within the ServiceItem protocol +type ServiceItemEShopResponse struct { + types.Structure + HTTPStatus *types.PrimitiveU32 + ErrorCode *types.PrimitiveU32 + CorrelationID *types.String +} + +// WriteTo writes the ServiceItemEShopResponse to the given writable +func (siesr *ServiceItemEShopResponse) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siesr.HTTPStatus.WriteTo(contentWritable) + siesr.ErrorCode.WriteTo(contentWritable) + siesr.CorrelationID.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siesr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemEShopResponse from the given readable +func (siesr *ServiceItemEShopResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = siesr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEShopResponse header. %s", err.Error()) + } + + err = siesr.HTTPStatus.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEShopResponse.HTTPStatus. %s", err.Error()) + } + + err = siesr.ErrorCode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEShopResponse.ErrorCode. %s", err.Error()) + } + + err = siesr.CorrelationID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEShopResponse.CorrelationID. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemEShopResponse +func (siesr *ServiceItemEShopResponse) Copy() types.RVType { + copied := NewServiceItemEShopResponse() + + copied.StructureVersion = siesr.StructureVersion + copied.HTTPStatus = siesr.HTTPStatus.Copy().(*types.PrimitiveU32) + copied.ErrorCode = siesr.ErrorCode.Copy().(*types.PrimitiveU32) + copied.CorrelationID = siesr.CorrelationID.Copy().(*types.String) + + return copied +} + +// Equals checks if the given ServiceItemEShopResponse contains the same data as the current ServiceItemEShopResponse +func (siesr *ServiceItemEShopResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemEShopResponse); !ok { + return false + } + + other := o.(*ServiceItemEShopResponse) + + if siesr.StructureVersion != other.StructureVersion { + return false + } + + if !siesr.HTTPStatus.Equals(other.HTTPStatus) { + return false + } + + if !siesr.ErrorCode.Equals(other.ErrorCode) { + return false + } + + return siesr.CorrelationID.Equals(other.CorrelationID) +} + +// String returns the string representation of the ServiceItemEShopResponse +func (siesr *ServiceItemEShopResponse) String() string { + return siesr.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemEShopResponse using the provided indentation level +func (siesr *ServiceItemEShopResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemEShopResponse{\n") + b.WriteString(fmt.Sprintf("%sHTTPStatus: %s,\n", indentationValues, siesr.HTTPStatus)) + b.WriteString(fmt.Sprintf("%sErrorCode: %s,\n", indentationValues, siesr.ErrorCode)) + b.WriteString(fmt.Sprintf("%sCorrelationID: %s,\n", indentationValues, siesr.CorrelationID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemEShopResponse returns a new ServiceItemEShopResponse +func NewServiceItemEShopResponse() *ServiceItemEShopResponse { + siesr := &ServiceItemEShopResponse{ + HTTPStatus: types.NewPrimitiveU32(0), + ErrorCode: types.NewPrimitiveU32(0), + CorrelationID: types.NewString(""), + } + + return siesr +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_event.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_event.go new file mode 100644 index 0000000..c4adb03 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_event.go @@ -0,0 +1,196 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemEvent is a type within the ServiceItem protocol +type ServiceItemEvent struct { + types.Structure + EventID *types.PrimitiveU64 + ParamInt *types.PrimitiveS32 + ParamString *types.String + ParamBinary *types.QBuffer + PresentTicketType *types.PrimitiveU32 + PresentTicketNum *types.PrimitiveU32 + TimeBegin *types.DateTime + TimeEnd *types.DateTime +} + +// WriteTo writes the ServiceItemEvent to the given writable +func (sie *ServiceItemEvent) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sie.EventID.WriteTo(contentWritable) + sie.ParamInt.WriteTo(contentWritable) + sie.ParamString.WriteTo(contentWritable) + sie.ParamBinary.WriteTo(contentWritable) + sie.PresentTicketType.WriteTo(contentWritable) + sie.PresentTicketNum.WriteTo(contentWritable) + sie.TimeBegin.WriteTo(contentWritable) + sie.TimeEnd.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sie.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemEvent from the given readable +func (sie *ServiceItemEvent) ExtractFrom(readable types.Readable) error { + var err error + + err = sie.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEvent header. %s", err.Error()) + } + + err = sie.EventID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEvent.EventID. %s", err.Error()) + } + + err = sie.ParamInt.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEvent.ParamInt. %s", err.Error()) + } + + err = sie.ParamString.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEvent.ParamString. %s", err.Error()) + } + + err = sie.ParamBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEvent.ParamBinary. %s", err.Error()) + } + + err = sie.PresentTicketType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEvent.PresentTicketType. %s", err.Error()) + } + + err = sie.PresentTicketNum.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEvent.PresentTicketNum. %s", err.Error()) + } + + err = sie.TimeBegin.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEvent.TimeBegin. %s", err.Error()) + } + + err = sie.TimeEnd.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemEvent.TimeEnd. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemEvent +func (sie *ServiceItemEvent) Copy() types.RVType { + copied := NewServiceItemEvent() + + copied.StructureVersion = sie.StructureVersion + copied.EventID = sie.EventID.Copy().(*types.PrimitiveU64) + copied.ParamInt = sie.ParamInt.Copy().(*types.PrimitiveS32) + copied.ParamString = sie.ParamString.Copy().(*types.String) + copied.ParamBinary = sie.ParamBinary.Copy().(*types.QBuffer) + copied.PresentTicketType = sie.PresentTicketType.Copy().(*types.PrimitiveU32) + copied.PresentTicketNum = sie.PresentTicketNum.Copy().(*types.PrimitiveU32) + copied.TimeBegin = sie.TimeBegin.Copy().(*types.DateTime) + copied.TimeEnd = sie.TimeEnd.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given ServiceItemEvent contains the same data as the current ServiceItemEvent +func (sie *ServiceItemEvent) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemEvent); !ok { + return false + } + + other := o.(*ServiceItemEvent) + + if sie.StructureVersion != other.StructureVersion { + return false + } + + if !sie.EventID.Equals(other.EventID) { + return false + } + + if !sie.ParamInt.Equals(other.ParamInt) { + return false + } + + if !sie.ParamString.Equals(other.ParamString) { + return false + } + + if !sie.ParamBinary.Equals(other.ParamBinary) { + return false + } + + if !sie.PresentTicketType.Equals(other.PresentTicketType) { + return false + } + + if !sie.PresentTicketNum.Equals(other.PresentTicketNum) { + return false + } + + if !sie.TimeBegin.Equals(other.TimeBegin) { + return false + } + + return sie.TimeEnd.Equals(other.TimeEnd) +} + +// String returns the string representation of the ServiceItemEvent +func (sie *ServiceItemEvent) String() string { + return sie.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemEvent using the provided indentation level +func (sie *ServiceItemEvent) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemEvent{\n") + b.WriteString(fmt.Sprintf("%sEventID: %s,\n", indentationValues, sie.EventID)) + b.WriteString(fmt.Sprintf("%sParamInt: %s,\n", indentationValues, sie.ParamInt)) + b.WriteString(fmt.Sprintf("%sParamString: %s,\n", indentationValues, sie.ParamString)) + b.WriteString(fmt.Sprintf("%sParamBinary: %s,\n", indentationValues, sie.ParamBinary)) + b.WriteString(fmt.Sprintf("%sPresentTicketType: %s,\n", indentationValues, sie.PresentTicketType)) + b.WriteString(fmt.Sprintf("%sPresentTicketNum: %s,\n", indentationValues, sie.PresentTicketNum)) + b.WriteString(fmt.Sprintf("%sTimeBegin: %s,\n", indentationValues, sie.TimeBegin.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sTimeEnd: %s,\n", indentationValues, sie.TimeEnd.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemEvent returns a new ServiceItemEvent +func NewServiceItemEvent() *ServiceItemEvent { + sie := &ServiceItemEvent{ + EventID: types.NewPrimitiveU64(0), + ParamInt: types.NewPrimitiveS32(0), + ParamString: types.NewString(""), + ParamBinary: types.NewQBuffer(nil), + PresentTicketType: types.NewPrimitiveU32(0), + PresentTicketNum: types.NewPrimitiveU32(0), + TimeBegin: types.NewDateTime(0), + TimeEnd: types.NewDateTime(0), + } + + return sie +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_balance_param.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_balance_param.go new file mode 100644 index 0000000..b71d188 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_balance_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetBalanceParam is a type within the ServiceItem protocol +type ServiceItemGetBalanceParam struct { + types.Structure + Language *types.String + TitleID *types.String +} + +// WriteTo writes the ServiceItemGetBalanceParam to the given writable +func (sigbp *ServiceItemGetBalanceParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sigbp.Language.WriteTo(contentWritable) + sigbp.TitleID.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sigbp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetBalanceParam from the given readable +func (sigbp *ServiceItemGetBalanceParam) ExtractFrom(readable types.Readable) error { + var err error + + err = sigbp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetBalanceParam header. %s", err.Error()) + } + + err = sigbp.Language.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetBalanceParam.Language. %s", err.Error()) + } + + err = sigbp.TitleID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetBalanceParam.TitleID. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetBalanceParam +func (sigbp *ServiceItemGetBalanceParam) Copy() types.RVType { + copied := NewServiceItemGetBalanceParam() + + copied.StructureVersion = sigbp.StructureVersion + copied.Language = sigbp.Language.Copy().(*types.String) + copied.TitleID = sigbp.TitleID.Copy().(*types.String) + + return copied +} + +// Equals checks if the given ServiceItemGetBalanceParam contains the same data as the current ServiceItemGetBalanceParam +func (sigbp *ServiceItemGetBalanceParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetBalanceParam); !ok { + return false + } + + other := o.(*ServiceItemGetBalanceParam) + + if sigbp.StructureVersion != other.StructureVersion { + return false + } + + if !sigbp.Language.Equals(other.Language) { + return false + } + + return sigbp.TitleID.Equals(other.TitleID) +} + +// String returns the string representation of the ServiceItemGetBalanceParam +func (sigbp *ServiceItemGetBalanceParam) String() string { + return sigbp.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetBalanceParam using the provided indentation level +func (sigbp *ServiceItemGetBalanceParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetBalanceParam{\n") + b.WriteString(fmt.Sprintf("%sLanguage: %s,\n", indentationValues, sigbp.Language)) + b.WriteString(fmt.Sprintf("%sTitleID: %s,\n", indentationValues, sigbp.TitleID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetBalanceParam returns a new ServiceItemGetBalanceParam +func NewServiceItemGetBalanceParam() *ServiceItemGetBalanceParam { + sigbp := &ServiceItemGetBalanceParam{ + Language: types.NewString(""), + TitleID: types.NewString(""), + } + + return sigbp +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_balance_response.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_balance_response.go new file mode 100644 index 0000000..f274469 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_balance_response.go @@ -0,0 +1,115 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetBalanceResponse is a type within the ServiceItem protocol +type ServiceItemGetBalanceResponse struct { + types.Structure + *ServiceItemEShopResponse + NullableBalance *types.List[*ServiceItemAmount] +} + +// WriteTo writes the ServiceItemGetBalanceResponse to the given writable +func (sigbr *ServiceItemGetBalanceResponse) WriteTo(writable types.Writable) { + sigbr.ServiceItemEShopResponse.WriteTo(writable) + + contentWritable := writable.CopyNew() + + sigbr.NullableBalance.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sigbr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetBalanceResponse from the given readable +func (sigbr *ServiceItemGetBalanceResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = sigbr.ServiceItemEShopResponse.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetBalanceResponse.ServiceItemEShopResponse. %s", err.Error()) + } + + err = sigbr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetBalanceResponse header. %s", err.Error()) + } + + err = sigbr.NullableBalance.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetBalanceResponse.NullableBalance. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetBalanceResponse +func (sigbr *ServiceItemGetBalanceResponse) Copy() types.RVType { + copied := NewServiceItemGetBalanceResponse() + + copied.StructureVersion = sigbr.StructureVersion + copied.ServiceItemEShopResponse = sigbr.ServiceItemEShopResponse.Copy().(*ServiceItemEShopResponse) + copied.NullableBalance = sigbr.NullableBalance.Copy().(*types.List[*ServiceItemAmount]) + + return copied +} + +// Equals checks if the given ServiceItemGetBalanceResponse contains the same data as the current ServiceItemGetBalanceResponse +func (sigbr *ServiceItemGetBalanceResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetBalanceResponse); !ok { + return false + } + + other := o.(*ServiceItemGetBalanceResponse) + + if sigbr.StructureVersion != other.StructureVersion { + return false + } + + if !sigbr.ServiceItemEShopResponse.Equals(other.ServiceItemEShopResponse) { + return false + } + + return sigbr.NullableBalance.Equals(other.NullableBalance) +} + +// String returns the string representation of the ServiceItemGetBalanceResponse +func (sigbr *ServiceItemGetBalanceResponse) String() string { + return sigbr.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetBalanceResponse using the provided indentation level +func (sigbr *ServiceItemGetBalanceResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetBalanceResponse{\n") + b.WriteString(fmt.Sprintf("%sServiceItemEShopResponse (parent): %s,\n", indentationValues, sigbr.ServiceItemEShopResponse.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sNullableBalance: %s,\n", indentationValues, sigbr.NullableBalance)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetBalanceResponse returns a new ServiceItemGetBalanceResponse +func NewServiceItemGetBalanceResponse() *ServiceItemGetBalanceResponse { + sigbr := &ServiceItemGetBalanceResponse{ + ServiceItemEShopResponse: NewServiceItemEShopResponse(), + NullableBalance: types.NewList[*ServiceItemAmount](), + } + + sigbr.NullableBalance.Type = NewServiceItemAmount() + + return sigbr +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_notice_param.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_notice_param.go new file mode 100644 index 0000000..132a815 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_notice_param.go @@ -0,0 +1,98 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetNoticeParam is a type within the ServiceItem protocol +type ServiceItemGetNoticeParam struct { + types.Structure + NoticeType *types.PrimitiveU32 +} + +// WriteTo writes the ServiceItemGetNoticeParam to the given writable +func (signp *ServiceItemGetNoticeParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + signp.NoticeType.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + signp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetNoticeParam from the given readable +func (signp *ServiceItemGetNoticeParam) ExtractFrom(readable types.Readable) error { + var err error + + err = signp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetNoticeParam header. %s", err.Error()) + } + + err = signp.NoticeType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetNoticeParam.NoticeType. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetNoticeParam +func (signp *ServiceItemGetNoticeParam) Copy() types.RVType { + copied := NewServiceItemGetNoticeParam() + + copied.StructureVersion = signp.StructureVersion + copied.NoticeType = signp.NoticeType.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given ServiceItemGetNoticeParam contains the same data as the current ServiceItemGetNoticeParam +func (signp *ServiceItemGetNoticeParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetNoticeParam); !ok { + return false + } + + other := o.(*ServiceItemGetNoticeParam) + + if signp.StructureVersion != other.StructureVersion { + return false + } + + return signp.NoticeType.Equals(other.NoticeType) +} + +// String returns the string representation of the ServiceItemGetNoticeParam +func (signp *ServiceItemGetNoticeParam) String() string { + return signp.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetNoticeParam using the provided indentation level +func (signp *ServiceItemGetNoticeParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetNoticeParam{\n") + b.WriteString(fmt.Sprintf("%sNoticeType: %s,\n", indentationValues, signp.NoticeType)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetNoticeParam returns a new ServiceItemGetNoticeParam +func NewServiceItemGetNoticeParam() *ServiceItemGetNoticeParam { + signp := &ServiceItemGetNoticeParam{ + NoticeType: types.NewPrimitiveU32(0), + } + + return signp +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_prepurchase_info_param.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_prepurchase_info_param.go new file mode 100644 index 0000000..736ed27 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_prepurchase_info_param.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetPrepurchaseInfoParam is a type within the ServiceItem protocol +type ServiceItemGetPrepurchaseInfoParam struct { + types.Structure + ItemCode *types.String + Language *types.String + TitleID *types.String +} + +// WriteTo writes the ServiceItemGetPrepurchaseInfoParam to the given writable +func (sigpip *ServiceItemGetPrepurchaseInfoParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sigpip.ItemCode.WriteTo(contentWritable) + sigpip.Language.WriteTo(contentWritable) + sigpip.TitleID.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sigpip.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetPrepurchaseInfoParam from the given readable +func (sigpip *ServiceItemGetPrepurchaseInfoParam) ExtractFrom(readable types.Readable) error { + var err error + + err = sigpip.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPrepurchaseInfoParam header. %s", err.Error()) + } + + err = sigpip.ItemCode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPrepurchaseInfoParam.ItemCode. %s", err.Error()) + } + + err = sigpip.Language.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPrepurchaseInfoParam.Language. %s", err.Error()) + } + + err = sigpip.TitleID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPrepurchaseInfoParam.TitleID. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetPrepurchaseInfoParam +func (sigpip *ServiceItemGetPrepurchaseInfoParam) Copy() types.RVType { + copied := NewServiceItemGetPrepurchaseInfoParam() + + copied.StructureVersion = sigpip.StructureVersion + copied.ItemCode = sigpip.ItemCode.Copy().(*types.String) + copied.Language = sigpip.Language.Copy().(*types.String) + copied.TitleID = sigpip.TitleID.Copy().(*types.String) + + return copied +} + +// Equals checks if the given ServiceItemGetPrepurchaseInfoParam contains the same data as the current ServiceItemGetPrepurchaseInfoParam +func (sigpip *ServiceItemGetPrepurchaseInfoParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetPrepurchaseInfoParam); !ok { + return false + } + + other := o.(*ServiceItemGetPrepurchaseInfoParam) + + if sigpip.StructureVersion != other.StructureVersion { + return false + } + + if !sigpip.ItemCode.Equals(other.ItemCode) { + return false + } + + if !sigpip.Language.Equals(other.Language) { + return false + } + + return sigpip.TitleID.Equals(other.TitleID) +} + +// String returns the string representation of the ServiceItemGetPrepurchaseInfoParam +func (sigpip *ServiceItemGetPrepurchaseInfoParam) String() string { + return sigpip.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetPrepurchaseInfoParam using the provided indentation level +func (sigpip *ServiceItemGetPrepurchaseInfoParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetPrepurchaseInfoParam{\n") + b.WriteString(fmt.Sprintf("%sItemCode: %s,\n", indentationValues, sigpip.ItemCode)) + b.WriteString(fmt.Sprintf("%sLanguage: %s,\n", indentationValues, sigpip.Language)) + b.WriteString(fmt.Sprintf("%sTitleID: %s,\n", indentationValues, sigpip.TitleID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetPrepurchaseInfoParam returns a new ServiceItemGetPrepurchaseInfoParam +func NewServiceItemGetPrepurchaseInfoParam() *ServiceItemGetPrepurchaseInfoParam { + sigpip := &ServiceItemGetPrepurchaseInfoParam{ + ItemCode: types.NewString(""), + Language: types.NewString(""), + TitleID: types.NewString(""), + } + + return sigpip +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_prepurchase_info_response.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_prepurchase_info_response.go new file mode 100644 index 0000000..222f513 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_prepurchase_info_response.go @@ -0,0 +1,115 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetPrepurchaseInfoResponse is a type within the ServiceItem protocol +type ServiceItemGetPrepurchaseInfoResponse struct { + types.Structure + *ServiceItemEShopResponse + NullablePrepurchaseInfo *types.List[*ServiceItemPrepurchaseInfo] +} + +// WriteTo writes the ServiceItemGetPrepurchaseInfoResponse to the given writable +func (sigpir *ServiceItemGetPrepurchaseInfoResponse) WriteTo(writable types.Writable) { + sigpir.ServiceItemEShopResponse.WriteTo(writable) + + contentWritable := writable.CopyNew() + + sigpir.NullablePrepurchaseInfo.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sigpir.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetPrepurchaseInfoResponse from the given readable +func (sigpir *ServiceItemGetPrepurchaseInfoResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = sigpir.ServiceItemEShopResponse.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPrepurchaseInfoResponse.ServiceItemEShopResponse. %s", err.Error()) + } + + err = sigpir.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPrepurchaseInfoResponse header. %s", err.Error()) + } + + err = sigpir.NullablePrepurchaseInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPrepurchaseInfoResponse.NullablePrepurchaseInfo. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetPrepurchaseInfoResponse +func (sigpir *ServiceItemGetPrepurchaseInfoResponse) Copy() types.RVType { + copied := NewServiceItemGetPrepurchaseInfoResponse() + + copied.StructureVersion = sigpir.StructureVersion + copied.ServiceItemEShopResponse = sigpir.ServiceItemEShopResponse.Copy().(*ServiceItemEShopResponse) + copied.NullablePrepurchaseInfo = sigpir.NullablePrepurchaseInfo.Copy().(*types.List[*ServiceItemPrepurchaseInfo]) + + return copied +} + +// Equals checks if the given ServiceItemGetPrepurchaseInfoResponse contains the same data as the current ServiceItemGetPrepurchaseInfoResponse +func (sigpir *ServiceItemGetPrepurchaseInfoResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetPrepurchaseInfoResponse); !ok { + return false + } + + other := o.(*ServiceItemGetPrepurchaseInfoResponse) + + if sigpir.StructureVersion != other.StructureVersion { + return false + } + + if !sigpir.ServiceItemEShopResponse.Equals(other.ServiceItemEShopResponse) { + return false + } + + return sigpir.NullablePrepurchaseInfo.Equals(other.NullablePrepurchaseInfo) +} + +// String returns the string representation of the ServiceItemGetPrepurchaseInfoResponse +func (sigpir *ServiceItemGetPrepurchaseInfoResponse) String() string { + return sigpir.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetPrepurchaseInfoResponse using the provided indentation level +func (sigpir *ServiceItemGetPrepurchaseInfoResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetPrepurchaseInfoResponse{\n") + b.WriteString(fmt.Sprintf("%sServiceItemEShopResponse (parent): %s,\n", indentationValues, sigpir.ServiceItemEShopResponse.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sNullablePrepurchaseInfo: %s,\n", indentationValues, sigpir.NullablePrepurchaseInfo)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetPrepurchaseInfoResponse returns a new ServiceItemGetPrepurchaseInfoResponse +func NewServiceItemGetPrepurchaseInfoResponse() *ServiceItemGetPrepurchaseInfoResponse { + sigpir := &ServiceItemGetPrepurchaseInfoResponse{ + ServiceItemEShopResponse: NewServiceItemEShopResponse(), + NullablePrepurchaseInfo: types.NewList[*ServiceItemPrepurchaseInfo](), + } + + sigpir.NullablePrepurchaseInfo.Type = NewServiceItemPrepurchaseInfo() + + return sigpir +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_purchase_history_param.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_purchase_history_param.go new file mode 100644 index 0000000..fe70bee --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_purchase_history_param.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetPurchaseHistoryParam is a type within the ServiceItem protocol +type ServiceItemGetPurchaseHistoryParam struct { + types.Structure + Language *types.String + Offset *types.PrimitiveU32 + Size *types.PrimitiveU32 + TitleID *types.String +} + +// WriteTo writes the ServiceItemGetPurchaseHistoryParam to the given writable +func (sigphp *ServiceItemGetPurchaseHistoryParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sigphp.Language.WriteTo(contentWritable) + sigphp.Offset.WriteTo(contentWritable) + sigphp.Size.WriteTo(contentWritable) + sigphp.TitleID.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sigphp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetPurchaseHistoryParam from the given readable +func (sigphp *ServiceItemGetPurchaseHistoryParam) ExtractFrom(readable types.Readable) error { + var err error + + err = sigphp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPurchaseHistoryParam header. %s", err.Error()) + } + + err = sigphp.Language.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPurchaseHistoryParam.Language. %s", err.Error()) + } + + err = sigphp.Offset.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPurchaseHistoryParam.Offset. %s", err.Error()) + } + + err = sigphp.Size.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPurchaseHistoryParam.Size. %s", err.Error()) + } + + err = sigphp.TitleID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPurchaseHistoryParam.TitleID. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetPurchaseHistoryParam +func (sigphp *ServiceItemGetPurchaseHistoryParam) Copy() types.RVType { + copied := NewServiceItemGetPurchaseHistoryParam() + + copied.StructureVersion = sigphp.StructureVersion + copied.Language = sigphp.Language.Copy().(*types.String) + copied.Offset = sigphp.Offset.Copy().(*types.PrimitiveU32) + copied.Size = sigphp.Size.Copy().(*types.PrimitiveU32) + copied.TitleID = sigphp.TitleID.Copy().(*types.String) + + return copied +} + +// Equals checks if the given ServiceItemGetPurchaseHistoryParam contains the same data as the current ServiceItemGetPurchaseHistoryParam +func (sigphp *ServiceItemGetPurchaseHistoryParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetPurchaseHistoryParam); !ok { + return false + } + + other := o.(*ServiceItemGetPurchaseHistoryParam) + + if sigphp.StructureVersion != other.StructureVersion { + return false + } + + if !sigphp.Language.Equals(other.Language) { + return false + } + + if !sigphp.Offset.Equals(other.Offset) { + return false + } + + if !sigphp.Size.Equals(other.Size) { + return false + } + + return sigphp.TitleID.Equals(other.TitleID) +} + +// String returns the string representation of the ServiceItemGetPurchaseHistoryParam +func (sigphp *ServiceItemGetPurchaseHistoryParam) String() string { + return sigphp.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetPurchaseHistoryParam using the provided indentation level +func (sigphp *ServiceItemGetPurchaseHistoryParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetPurchaseHistoryParam{\n") + b.WriteString(fmt.Sprintf("%sLanguage: %s,\n", indentationValues, sigphp.Language)) + b.WriteString(fmt.Sprintf("%sOffset: %s,\n", indentationValues, sigphp.Offset)) + b.WriteString(fmt.Sprintf("%sSize: %s,\n", indentationValues, sigphp.Size)) + b.WriteString(fmt.Sprintf("%sTitleID: %s,\n", indentationValues, sigphp.TitleID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetPurchaseHistoryParam returns a new ServiceItemGetPurchaseHistoryParam +func NewServiceItemGetPurchaseHistoryParam() *ServiceItemGetPurchaseHistoryParam { + sigphp := &ServiceItemGetPurchaseHistoryParam{ + Language: types.NewString(""), + Offset: types.NewPrimitiveU32(0), + Size: types.NewPrimitiveU32(0), + TitleID: types.NewString(""), + } + + return sigphp +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_purchase_history_response.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_purchase_history_response.go new file mode 100644 index 0000000..4cf460e --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_purchase_history_response.go @@ -0,0 +1,115 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetPurchaseHistoryResponse is a type within the ServiceItem protocol +type ServiceItemGetPurchaseHistoryResponse struct { + types.Structure + *ServiceItemEShopResponse + NullablePurchaseHistory *types.List[*ServiceItemPurchaseHistory] +} + +// WriteTo writes the ServiceItemGetPurchaseHistoryResponse to the given writable +func (sigphr *ServiceItemGetPurchaseHistoryResponse) WriteTo(writable types.Writable) { + sigphr.ServiceItemEShopResponse.WriteTo(writable) + + contentWritable := writable.CopyNew() + + sigphr.NullablePurchaseHistory.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sigphr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetPurchaseHistoryResponse from the given readable +func (sigphr *ServiceItemGetPurchaseHistoryResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = sigphr.ServiceItemEShopResponse.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPurchaseHistoryResponse.ServiceItemEShopResponse. %s", err.Error()) + } + + err = sigphr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPurchaseHistoryResponse header. %s", err.Error()) + } + + err = sigphr.NullablePurchaseHistory.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetPurchaseHistoryResponse.NullablePurchaseHistory. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetPurchaseHistoryResponse +func (sigphr *ServiceItemGetPurchaseHistoryResponse) Copy() types.RVType { + copied := NewServiceItemGetPurchaseHistoryResponse() + + copied.StructureVersion = sigphr.StructureVersion + copied.ServiceItemEShopResponse = sigphr.ServiceItemEShopResponse.Copy().(*ServiceItemEShopResponse) + copied.NullablePurchaseHistory = sigphr.NullablePurchaseHistory.Copy().(*types.List[*ServiceItemPurchaseHistory]) + + return copied +} + +// Equals checks if the given ServiceItemGetPurchaseHistoryResponse contains the same data as the current ServiceItemGetPurchaseHistoryResponse +func (sigphr *ServiceItemGetPurchaseHistoryResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetPurchaseHistoryResponse); !ok { + return false + } + + other := o.(*ServiceItemGetPurchaseHistoryResponse) + + if sigphr.StructureVersion != other.StructureVersion { + return false + } + + if !sigphr.ServiceItemEShopResponse.Equals(other.ServiceItemEShopResponse) { + return false + } + + return sigphr.NullablePurchaseHistory.Equals(other.NullablePurchaseHistory) +} + +// String returns the string representation of the ServiceItemGetPurchaseHistoryResponse +func (sigphr *ServiceItemGetPurchaseHistoryResponse) String() string { + return sigphr.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetPurchaseHistoryResponse using the provided indentation level +func (sigphr *ServiceItemGetPurchaseHistoryResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetPurchaseHistoryResponse{\n") + b.WriteString(fmt.Sprintf("%sServiceItemEShopResponse (parent): %s,\n", indentationValues, sigphr.ServiceItemEShopResponse.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sNullablePurchaseHistory: %s,\n", indentationValues, sigphr.NullablePurchaseHistory)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetPurchaseHistoryResponse returns a new ServiceItemGetPurchaseHistoryResponse +func NewServiceItemGetPurchaseHistoryResponse() *ServiceItemGetPurchaseHistoryResponse { + sigphr := &ServiceItemGetPurchaseHistoryResponse{ + ServiceItemEShopResponse: NewServiceItemEShopResponse(), + NullablePurchaseHistory: types.NewList[*ServiceItemPurchaseHistory](), + } + + sigphr.NullablePurchaseHistory.Type = NewServiceItemPurchaseHistory() + + return sigphr +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_service_item_right_param.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_service_item_right_param.go new file mode 100644 index 0000000..653cc20 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_service_item_right_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetServiceItemRightParam is a type within the ServiceItem protocol +type ServiceItemGetServiceItemRightParam struct { + types.Structure + ReferenceID *types.String + TitleID *types.String +} + +// WriteTo writes the ServiceItemGetServiceItemRightParam to the given writable +func (sigsirp *ServiceItemGetServiceItemRightParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sigsirp.ReferenceID.WriteTo(contentWritable) + sigsirp.TitleID.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sigsirp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetServiceItemRightParam from the given readable +func (sigsirp *ServiceItemGetServiceItemRightParam) ExtractFrom(readable types.Readable) error { + var err error + + err = sigsirp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetServiceItemRightParam header. %s", err.Error()) + } + + err = sigsirp.ReferenceID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetServiceItemRightParam.ReferenceID. %s", err.Error()) + } + + err = sigsirp.TitleID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetServiceItemRightParam.TitleID. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetServiceItemRightParam +func (sigsirp *ServiceItemGetServiceItemRightParam) Copy() types.RVType { + copied := NewServiceItemGetServiceItemRightParam() + + copied.StructureVersion = sigsirp.StructureVersion + copied.ReferenceID = sigsirp.ReferenceID.Copy().(*types.String) + copied.TitleID = sigsirp.TitleID.Copy().(*types.String) + + return copied +} + +// Equals checks if the given ServiceItemGetServiceItemRightParam contains the same data as the current ServiceItemGetServiceItemRightParam +func (sigsirp *ServiceItemGetServiceItemRightParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetServiceItemRightParam); !ok { + return false + } + + other := o.(*ServiceItemGetServiceItemRightParam) + + if sigsirp.StructureVersion != other.StructureVersion { + return false + } + + if !sigsirp.ReferenceID.Equals(other.ReferenceID) { + return false + } + + return sigsirp.TitleID.Equals(other.TitleID) +} + +// String returns the string representation of the ServiceItemGetServiceItemRightParam +func (sigsirp *ServiceItemGetServiceItemRightParam) String() string { + return sigsirp.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetServiceItemRightParam using the provided indentation level +func (sigsirp *ServiceItemGetServiceItemRightParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetServiceItemRightParam{\n") + b.WriteString(fmt.Sprintf("%sReferenceID: %s,\n", indentationValues, sigsirp.ReferenceID)) + b.WriteString(fmt.Sprintf("%sTitleID: %s,\n", indentationValues, sigsirp.TitleID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetServiceItemRightParam returns a new ServiceItemGetServiceItemRightParam +func NewServiceItemGetServiceItemRightParam() *ServiceItemGetServiceItemRightParam { + sigsirp := &ServiceItemGetServiceItemRightParam{ + ReferenceID: types.NewString(""), + TitleID: types.NewString(""), + } + + return sigsirp +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_service_item_right_response.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_service_item_right_response.go new file mode 100644 index 0000000..804af19 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_get_service_item_right_response.go @@ -0,0 +1,115 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemGetServiceItemRightResponse is a type within the ServiceItem protocol +type ServiceItemGetServiceItemRightResponse struct { + types.Structure + *ServiceItemEShopResponse + NullableRightInfos *types.List[*ServiceItemRightInfos] +} + +// WriteTo writes the ServiceItemGetServiceItemRightResponse to the given writable +func (sigsirr *ServiceItemGetServiceItemRightResponse) WriteTo(writable types.Writable) { + sigsirr.ServiceItemEShopResponse.WriteTo(writable) + + contentWritable := writable.CopyNew() + + sigsirr.NullableRightInfos.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sigsirr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemGetServiceItemRightResponse from the given readable +func (sigsirr *ServiceItemGetServiceItemRightResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = sigsirr.ServiceItemEShopResponse.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetServiceItemRightResponse.ServiceItemEShopResponse. %s", err.Error()) + } + + err = sigsirr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetServiceItemRightResponse header. %s", err.Error()) + } + + err = sigsirr.NullableRightInfos.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemGetServiceItemRightResponse.NullableRightInfos. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemGetServiceItemRightResponse +func (sigsirr *ServiceItemGetServiceItemRightResponse) Copy() types.RVType { + copied := NewServiceItemGetServiceItemRightResponse() + + copied.StructureVersion = sigsirr.StructureVersion + copied.ServiceItemEShopResponse = sigsirr.ServiceItemEShopResponse.Copy().(*ServiceItemEShopResponse) + copied.NullableRightInfos = sigsirr.NullableRightInfos.Copy().(*types.List[*ServiceItemRightInfos]) + + return copied +} + +// Equals checks if the given ServiceItemGetServiceItemRightResponse contains the same data as the current ServiceItemGetServiceItemRightResponse +func (sigsirr *ServiceItemGetServiceItemRightResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemGetServiceItemRightResponse); !ok { + return false + } + + other := o.(*ServiceItemGetServiceItemRightResponse) + + if sigsirr.StructureVersion != other.StructureVersion { + return false + } + + if !sigsirr.ServiceItemEShopResponse.Equals(other.ServiceItemEShopResponse) { + return false + } + + return sigsirr.NullableRightInfos.Equals(other.NullableRightInfos) +} + +// String returns the string representation of the ServiceItemGetServiceItemRightResponse +func (sigsirr *ServiceItemGetServiceItemRightResponse) String() string { + return sigsirr.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemGetServiceItemRightResponse using the provided indentation level +func (sigsirr *ServiceItemGetServiceItemRightResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemGetServiceItemRightResponse{\n") + b.WriteString(fmt.Sprintf("%sServiceItemEShopResponse (parent): %s,\n", indentationValues, sigsirr.ServiceItemEShopResponse.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sNullableRightInfos: %s,\n", indentationValues, sigsirr.NullableRightInfos)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemGetServiceItemRightResponse returns a new ServiceItemGetServiceItemRightResponse +func NewServiceItemGetServiceItemRightResponse() *ServiceItemGetServiceItemRightResponse { + sigsirr := &ServiceItemGetServiceItemRightResponse{ + ServiceItemEShopResponse: NewServiceItemEShopResponse(), + NullableRightInfos: types.NewList[*ServiceItemRightInfos](), + } + + sigsirr.NullableRightInfos.Type = NewServiceItemRightInfos() + + return sigsirr +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_http_get_param.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_http_get_param.go new file mode 100644 index 0000000..e436cd5 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_http_get_param.go @@ -0,0 +1,98 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemHTTPGetParam is a type within the ServiceItem protocol +type ServiceItemHTTPGetParam struct { + types.Structure + URL *types.String +} + +// WriteTo writes the ServiceItemHTTPGetParam to the given writable +func (sihttpgp *ServiceItemHTTPGetParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sihttpgp.URL.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sihttpgp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemHTTPGetParam from the given readable +func (sihttpgp *ServiceItemHTTPGetParam) ExtractFrom(readable types.Readable) error { + var err error + + err = sihttpgp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemHTTPGetParam header. %s", err.Error()) + } + + err = sihttpgp.URL.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemHTTPGetParam.URL. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemHTTPGetParam +func (sihttpgp *ServiceItemHTTPGetParam) Copy() types.RVType { + copied := NewServiceItemHTTPGetParam() + + copied.StructureVersion = sihttpgp.StructureVersion + copied.URL = sihttpgp.URL.Copy().(*types.String) + + return copied +} + +// Equals checks if the given ServiceItemHTTPGetParam contains the same data as the current ServiceItemHTTPGetParam +func (sihttpgp *ServiceItemHTTPGetParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemHTTPGetParam); !ok { + return false + } + + other := o.(*ServiceItemHTTPGetParam) + + if sihttpgp.StructureVersion != other.StructureVersion { + return false + } + + return sihttpgp.URL.Equals(other.URL) +} + +// String returns the string representation of the ServiceItemHTTPGetParam +func (sihttpgp *ServiceItemHTTPGetParam) String() string { + return sihttpgp.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemHTTPGetParam using the provided indentation level +func (sihttpgp *ServiceItemHTTPGetParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemHTTPGetParam{\n") + b.WriteString(fmt.Sprintf("%sURL: %s,\n", indentationValues, sihttpgp.URL)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemHTTPGetParam returns a new ServiceItemHTTPGetParam +func NewServiceItemHTTPGetParam() *ServiceItemHTTPGetParam { + sihttpgp := &ServiceItemHTTPGetParam{ + URL: types.NewString(""), + } + + return sihttpgp +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_http_get_response.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_http_get_response.go new file mode 100644 index 0000000..cb46db5 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_http_get_response.go @@ -0,0 +1,98 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemHTTPGetResponse is a type within the ServiceItem protocol +type ServiceItemHTTPGetResponse struct { + types.Structure + Response *types.QBuffer +} + +// WriteTo writes the ServiceItemHTTPGetResponse to the given writable +func (sihttpgr *ServiceItemHTTPGetResponse) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sihttpgr.Response.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sihttpgr.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemHTTPGetResponse from the given readable +func (sihttpgr *ServiceItemHTTPGetResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = sihttpgr.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemHTTPGetResponse header. %s", err.Error()) + } + + err = sihttpgr.Response.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemHTTPGetResponse.Response. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemHTTPGetResponse +func (sihttpgr *ServiceItemHTTPGetResponse) Copy() types.RVType { + copied := NewServiceItemHTTPGetResponse() + + copied.StructureVersion = sihttpgr.StructureVersion + copied.Response = sihttpgr.Response.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given ServiceItemHTTPGetResponse contains the same data as the current ServiceItemHTTPGetResponse +func (sihttpgr *ServiceItemHTTPGetResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemHTTPGetResponse); !ok { + return false + } + + other := o.(*ServiceItemHTTPGetResponse) + + if sihttpgr.StructureVersion != other.StructureVersion { + return false + } + + return sihttpgr.Response.Equals(other.Response) +} + +// String returns the string representation of the ServiceItemHTTPGetResponse +func (sihttpgr *ServiceItemHTTPGetResponse) String() string { + return sihttpgr.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemHTTPGetResponse using the provided indentation level +func (sihttpgr *ServiceItemHTTPGetResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemHTTPGetResponse{\n") + b.WriteString(fmt.Sprintf("%sResponse: %s,\n", indentationValues, sihttpgr.Response)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemHTTPGetResponse returns a new ServiceItemHTTPGetResponse +func NewServiceItemHTTPGetResponse() *ServiceItemHTTPGetResponse { + sihttpgr := &ServiceItemHTTPGetResponse{ + Response: types.NewQBuffer(nil), + } + + return sihttpgr +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_limitation.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_limitation.go new file mode 100644 index 0000000..1d8a03e --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_limitation.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemLimitation is a type within the ServiceItem protocol +type ServiceItemLimitation struct { + types.Structure + LimitationType *types.PrimitiveU32 + LimitationValue *types.PrimitiveU32 +} + +// WriteTo writes the ServiceItemLimitation to the given writable +func (sil *ServiceItemLimitation) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sil.LimitationType.WriteTo(contentWritable) + sil.LimitationValue.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sil.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemLimitation from the given readable +func (sil *ServiceItemLimitation) ExtractFrom(readable types.Readable) error { + var err error + + err = sil.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemLimitation header. %s", err.Error()) + } + + err = sil.LimitationType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemLimitation.LimitationType. %s", err.Error()) + } + + err = sil.LimitationValue.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemLimitation.LimitationValue. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemLimitation +func (sil *ServiceItemLimitation) Copy() types.RVType { + copied := NewServiceItemLimitation() + + copied.StructureVersion = sil.StructureVersion + copied.LimitationType = sil.LimitationType.Copy().(*types.PrimitiveU32) + copied.LimitationValue = sil.LimitationValue.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given ServiceItemLimitation contains the same data as the current ServiceItemLimitation +func (sil *ServiceItemLimitation) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemLimitation); !ok { + return false + } + + other := o.(*ServiceItemLimitation) + + if sil.StructureVersion != other.StructureVersion { + return false + } + + if !sil.LimitationType.Equals(other.LimitationType) { + return false + } + + return sil.LimitationValue.Equals(other.LimitationValue) +} + +// String returns the string representation of the ServiceItemLimitation +func (sil *ServiceItemLimitation) String() string { + return sil.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemLimitation using the provided indentation level +func (sil *ServiceItemLimitation) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemLimitation{\n") + b.WriteString(fmt.Sprintf("%sLimitationType: %s,\n", indentationValues, sil.LimitationType)) + b.WriteString(fmt.Sprintf("%sLimitationValue: %s,\n", indentationValues, sil.LimitationValue)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemLimitation returns a new ServiceItemLimitation +func NewServiceItemLimitation() *ServiceItemLimitation { + sil := &ServiceItemLimitation{ + LimitationType: types.NewPrimitiveU32(0), + LimitationValue: types.NewPrimitiveU32(0), + } + + return sil +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_list_item.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_list_item.go new file mode 100644 index 0000000..18c3e9c --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_list_item.go @@ -0,0 +1,170 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemListItem is a type within the ServiceItem protocol +type ServiceItemListItem struct { + types.Structure + ItemCode *types.String + RegularPrice *ServiceItemAmount + TaxExcluded *types.PrimitiveBool + InitialPurchaseOnly *types.PrimitiveBool + Limitation *ServiceItemLimitation + Attributes *types.List[*ServiceItemAttribute] +} + +// WriteTo writes the ServiceItemListItem to the given writable +func (sili *ServiceItemListItem) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sili.ItemCode.WriteTo(contentWritable) + sili.RegularPrice.WriteTo(contentWritable) + sili.TaxExcluded.WriteTo(contentWritable) + sili.InitialPurchaseOnly.WriteTo(contentWritable) + sili.Limitation.WriteTo(contentWritable) + sili.Attributes.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sili.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemListItem from the given readable +func (sili *ServiceItemListItem) ExtractFrom(readable types.Readable) error { + var err error + + err = sili.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListItem header. %s", err.Error()) + } + + err = sili.ItemCode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListItem.ItemCode. %s", err.Error()) + } + + err = sili.RegularPrice.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListItem.RegularPrice. %s", err.Error()) + } + + err = sili.TaxExcluded.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListItem.TaxExcluded. %s", err.Error()) + } + + err = sili.InitialPurchaseOnly.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListItem.InitialPurchaseOnly. %s", err.Error()) + } + + err = sili.Limitation.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListItem.Limitation. %s", err.Error()) + } + + err = sili.Attributes.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListItem.Attributes. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemListItem +func (sili *ServiceItemListItem) Copy() types.RVType { + copied := NewServiceItemListItem() + + copied.StructureVersion = sili.StructureVersion + copied.ItemCode = sili.ItemCode.Copy().(*types.String) + copied.RegularPrice = sili.RegularPrice.Copy().(*ServiceItemAmount) + copied.TaxExcluded = sili.TaxExcluded.Copy().(*types.PrimitiveBool) + copied.InitialPurchaseOnly = sili.InitialPurchaseOnly.Copy().(*types.PrimitiveBool) + copied.Limitation = sili.Limitation.Copy().(*ServiceItemLimitation) + copied.Attributes = sili.Attributes.Copy().(*types.List[*ServiceItemAttribute]) + + return copied +} + +// Equals checks if the given ServiceItemListItem contains the same data as the current ServiceItemListItem +func (sili *ServiceItemListItem) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemListItem); !ok { + return false + } + + other := o.(*ServiceItemListItem) + + if sili.StructureVersion != other.StructureVersion { + return false + } + + if !sili.ItemCode.Equals(other.ItemCode) { + return false + } + + if !sili.RegularPrice.Equals(other.RegularPrice) { + return false + } + + if !sili.TaxExcluded.Equals(other.TaxExcluded) { + return false + } + + if !sili.InitialPurchaseOnly.Equals(other.InitialPurchaseOnly) { + return false + } + + if !sili.Limitation.Equals(other.Limitation) { + return false + } + + return sili.Attributes.Equals(other.Attributes) +} + +// String returns the string representation of the ServiceItemListItem +func (sili *ServiceItemListItem) String() string { + return sili.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemListItem using the provided indentation level +func (sili *ServiceItemListItem) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemListItem{\n") + b.WriteString(fmt.Sprintf("%sItemCode: %s,\n", indentationValues, sili.ItemCode)) + b.WriteString(fmt.Sprintf("%sRegularPrice: %s,\n", indentationValues, sili.RegularPrice.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sTaxExcluded: %s,\n", indentationValues, sili.TaxExcluded)) + b.WriteString(fmt.Sprintf("%sInitialPurchaseOnly: %s,\n", indentationValues, sili.InitialPurchaseOnly)) + b.WriteString(fmt.Sprintf("%sLimitation: %s,\n", indentationValues, sili.Limitation.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sAttributes: %s,\n", indentationValues, sili.Attributes)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemListItem returns a new ServiceItemListItem +func NewServiceItemListItem() *ServiceItemListItem { + sili := &ServiceItemListItem{ + ItemCode: types.NewString(""), + RegularPrice: NewServiceItemAmount(), + TaxExcluded: types.NewPrimitiveBool(false), + InitialPurchaseOnly: types.NewPrimitiveBool(false), + Limitation: NewServiceItemLimitation(), + Attributes: types.NewList[*ServiceItemAttribute](), + } + + sili.Attributes.Type = NewServiceItemAttribute() + + return sili +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_list_service_item_param.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_list_service_item_param.go new file mode 100644 index 0000000..ad86a2f --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_list_service_item_param.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemListServiceItemParam is a type within the ServiceItem protocol +type ServiceItemListServiceItemParam struct { + types.Structure + Language *types.String + Offset *types.PrimitiveU32 + Size *types.PrimitiveU32 + TitleID *types.String +} + +// WriteTo writes the ServiceItemListServiceItemParam to the given writable +func (silsip *ServiceItemListServiceItemParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + silsip.Language.WriteTo(contentWritable) + silsip.Offset.WriteTo(contentWritable) + silsip.Size.WriteTo(contentWritable) + silsip.TitleID.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + silsip.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemListServiceItemParam from the given readable +func (silsip *ServiceItemListServiceItemParam) ExtractFrom(readable types.Readable) error { + var err error + + err = silsip.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemParam header. %s", err.Error()) + } + + err = silsip.Language.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemParam.Language. %s", err.Error()) + } + + err = silsip.Offset.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemParam.Offset. %s", err.Error()) + } + + err = silsip.Size.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemParam.Size. %s", err.Error()) + } + + err = silsip.TitleID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemParam.TitleID. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemListServiceItemParam +func (silsip *ServiceItemListServiceItemParam) Copy() types.RVType { + copied := NewServiceItemListServiceItemParam() + + copied.StructureVersion = silsip.StructureVersion + copied.Language = silsip.Language.Copy().(*types.String) + copied.Offset = silsip.Offset.Copy().(*types.PrimitiveU32) + copied.Size = silsip.Size.Copy().(*types.PrimitiveU32) + copied.TitleID = silsip.TitleID.Copy().(*types.String) + + return copied +} + +// Equals checks if the given ServiceItemListServiceItemParam contains the same data as the current ServiceItemListServiceItemParam +func (silsip *ServiceItemListServiceItemParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemListServiceItemParam); !ok { + return false + } + + other := o.(*ServiceItemListServiceItemParam) + + if silsip.StructureVersion != other.StructureVersion { + return false + } + + if !silsip.Language.Equals(other.Language) { + return false + } + + if !silsip.Offset.Equals(other.Offset) { + return false + } + + if !silsip.Size.Equals(other.Size) { + return false + } + + return silsip.TitleID.Equals(other.TitleID) +} + +// String returns the string representation of the ServiceItemListServiceItemParam +func (silsip *ServiceItemListServiceItemParam) String() string { + return silsip.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemListServiceItemParam using the provided indentation level +func (silsip *ServiceItemListServiceItemParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemListServiceItemParam{\n") + b.WriteString(fmt.Sprintf("%sLanguage: %s,\n", indentationValues, silsip.Language)) + b.WriteString(fmt.Sprintf("%sOffset: %s,\n", indentationValues, silsip.Offset)) + b.WriteString(fmt.Sprintf("%sSize: %s,\n", indentationValues, silsip.Size)) + b.WriteString(fmt.Sprintf("%sTitleID: %s,\n", indentationValues, silsip.TitleID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemListServiceItemParam returns a new ServiceItemListServiceItemParam +func NewServiceItemListServiceItemParam() *ServiceItemListServiceItemParam { + silsip := &ServiceItemListServiceItemParam{ + Language: types.NewString(""), + Offset: types.NewPrimitiveU32(0), + Size: types.NewPrimitiveU32(0), + TitleID: types.NewString(""), + } + + return silsip +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_list_service_item_response.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_list_service_item_response.go new file mode 100644 index 0000000..a47e9fa --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_list_service_item_response.go @@ -0,0 +1,115 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemListServiceItemResponse is a type within the ServiceItem protocol +type ServiceItemListServiceItemResponse struct { + types.Structure + *ServiceItemEShopResponse + NullableCatalog *types.List[*ServiceItemCatalog] +} + +// WriteTo writes the ServiceItemListServiceItemResponse to the given writable +func (silsir *ServiceItemListServiceItemResponse) WriteTo(writable types.Writable) { + silsir.ServiceItemEShopResponse.WriteTo(writable) + + contentWritable := writable.CopyNew() + + silsir.NullableCatalog.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + silsir.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemListServiceItemResponse from the given readable +func (silsir *ServiceItemListServiceItemResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = silsir.ServiceItemEShopResponse.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemResponse.ServiceItemEShopResponse. %s", err.Error()) + } + + err = silsir.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemResponse header. %s", err.Error()) + } + + err = silsir.NullableCatalog.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemListServiceItemResponse.NullableCatalog. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemListServiceItemResponse +func (silsir *ServiceItemListServiceItemResponse) Copy() types.RVType { + copied := NewServiceItemListServiceItemResponse() + + copied.StructureVersion = silsir.StructureVersion + copied.ServiceItemEShopResponse = silsir.ServiceItemEShopResponse.Copy().(*ServiceItemEShopResponse) + copied.NullableCatalog = silsir.NullableCatalog.Copy().(*types.List[*ServiceItemCatalog]) + + return copied +} + +// Equals checks if the given ServiceItemListServiceItemResponse contains the same data as the current ServiceItemListServiceItemResponse +func (silsir *ServiceItemListServiceItemResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemListServiceItemResponse); !ok { + return false + } + + other := o.(*ServiceItemListServiceItemResponse) + + if silsir.StructureVersion != other.StructureVersion { + return false + } + + if !silsir.ServiceItemEShopResponse.Equals(other.ServiceItemEShopResponse) { + return false + } + + return silsir.NullableCatalog.Equals(other.NullableCatalog) +} + +// String returns the string representation of the ServiceItemListServiceItemResponse +func (silsir *ServiceItemListServiceItemResponse) String() string { + return silsir.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemListServiceItemResponse using the provided indentation level +func (silsir *ServiceItemListServiceItemResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemListServiceItemResponse{\n") + b.WriteString(fmt.Sprintf("%sServiceItemEShopResponse (parent): %s,\n", indentationValues, silsir.ServiceItemEShopResponse.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sNullableCatalog: %s,\n", indentationValues, silsir.NullableCatalog)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemListServiceItemResponse returns a new ServiceItemListServiceItemResponse +func NewServiceItemListServiceItemResponse() *ServiceItemListServiceItemResponse { + silsir := &ServiceItemListServiceItemResponse{ + ServiceItemEShopResponse: NewServiceItemEShopResponse(), + NullableCatalog: types.NewList[*ServiceItemCatalog](), + } + + silsir.NullableCatalog.Type = NewServiceItemCatalog() + + return silsir +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_notice.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_notice.go new file mode 100644 index 0000000..d169741 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_notice.go @@ -0,0 +1,182 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemNotice is a type within the ServiceItem protocol +type ServiceItemNotice struct { + types.Structure + ScheduleID *types.PrimitiveU64 + ScheduleType *types.PrimitiveU32 + ParamInt *types.PrimitiveS32 + ParamString *types.String + ParamBinary *types.QBuffer + TimeBegin *types.DateTime + TimeEnd *types.DateTime +} + +// WriteTo writes the ServiceItemNotice to the given writable +func (sin *ServiceItemNotice) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sin.ScheduleID.WriteTo(contentWritable) + sin.ScheduleType.WriteTo(contentWritable) + sin.ParamInt.WriteTo(contentWritable) + sin.ParamString.WriteTo(contentWritable) + sin.ParamBinary.WriteTo(contentWritable) + sin.TimeBegin.WriteTo(contentWritable) + sin.TimeEnd.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sin.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemNotice from the given readable +func (sin *ServiceItemNotice) ExtractFrom(readable types.Readable) error { + var err error + + err = sin.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemNotice header. %s", err.Error()) + } + + err = sin.ScheduleID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemNotice.ScheduleID. %s", err.Error()) + } + + err = sin.ScheduleType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemNotice.ScheduleType. %s", err.Error()) + } + + err = sin.ParamInt.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemNotice.ParamInt. %s", err.Error()) + } + + err = sin.ParamString.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemNotice.ParamString. %s", err.Error()) + } + + err = sin.ParamBinary.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemNotice.ParamBinary. %s", err.Error()) + } + + err = sin.TimeBegin.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemNotice.TimeBegin. %s", err.Error()) + } + + err = sin.TimeEnd.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemNotice.TimeEnd. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemNotice +func (sin *ServiceItemNotice) Copy() types.RVType { + copied := NewServiceItemNotice() + + copied.StructureVersion = sin.StructureVersion + copied.ScheduleID = sin.ScheduleID.Copy().(*types.PrimitiveU64) + copied.ScheduleType = sin.ScheduleType.Copy().(*types.PrimitiveU32) + copied.ParamInt = sin.ParamInt.Copy().(*types.PrimitiveS32) + copied.ParamString = sin.ParamString.Copy().(*types.String) + copied.ParamBinary = sin.ParamBinary.Copy().(*types.QBuffer) + copied.TimeBegin = sin.TimeBegin.Copy().(*types.DateTime) + copied.TimeEnd = sin.TimeEnd.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given ServiceItemNotice contains the same data as the current ServiceItemNotice +func (sin *ServiceItemNotice) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemNotice); !ok { + return false + } + + other := o.(*ServiceItemNotice) + + if sin.StructureVersion != other.StructureVersion { + return false + } + + if !sin.ScheduleID.Equals(other.ScheduleID) { + return false + } + + if !sin.ScheduleType.Equals(other.ScheduleType) { + return false + } + + if !sin.ParamInt.Equals(other.ParamInt) { + return false + } + + if !sin.ParamString.Equals(other.ParamString) { + return false + } + + if !sin.ParamBinary.Equals(other.ParamBinary) { + return false + } + + if !sin.TimeBegin.Equals(other.TimeBegin) { + return false + } + + return sin.TimeEnd.Equals(other.TimeEnd) +} + +// String returns the string representation of the ServiceItemNotice +func (sin *ServiceItemNotice) String() string { + return sin.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemNotice using the provided indentation level +func (sin *ServiceItemNotice) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemNotice{\n") + b.WriteString(fmt.Sprintf("%sScheduleID: %s,\n", indentationValues, sin.ScheduleID)) + b.WriteString(fmt.Sprintf("%sScheduleType: %s,\n", indentationValues, sin.ScheduleType)) + b.WriteString(fmt.Sprintf("%sParamInt: %s,\n", indentationValues, sin.ParamInt)) + b.WriteString(fmt.Sprintf("%sParamString: %s,\n", indentationValues, sin.ParamString)) + b.WriteString(fmt.Sprintf("%sParamBinary: %s,\n", indentationValues, sin.ParamBinary)) + b.WriteString(fmt.Sprintf("%sTimeBegin: %s,\n", indentationValues, sin.TimeBegin.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sTimeEnd: %s,\n", indentationValues, sin.TimeEnd.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemNotice returns a new ServiceItemNotice +func NewServiceItemNotice() *ServiceItemNotice { + sin := &ServiceItemNotice{ + ScheduleID: types.NewPrimitiveU64(0), + ScheduleType: types.NewPrimitiveU32(0), + ParamInt: types.NewPrimitiveS32(0), + ParamString: types.NewString(""), + ParamBinary: types.NewQBuffer(nil), + TimeBegin: types.NewDateTime(0), + TimeEnd: types.NewDateTime(0), + } + + return sin +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_prepurchase_info.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_prepurchase_info.go new file mode 100644 index 0000000..6b0be3b --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_prepurchase_info.go @@ -0,0 +1,196 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemPrepurchaseInfo is a type within the ServiceItem protocol +type ServiceItemPrepurchaseInfo struct { + types.Structure + ItemCode *types.String + PriceID *types.String + RegularPrice *ServiceItemAmount + IsTaxAvailable *types.PrimitiveBool + TaxAmount *ServiceItemAmount + TotalAmount *ServiceItemAmount + CurrentBalance *ServiceItemAmount + PostBalance *ServiceItemAmount +} + +// WriteTo writes the ServiceItemPrepurchaseInfo to the given writable +func (sipi *ServiceItemPrepurchaseInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sipi.ItemCode.WriteTo(contentWritable) + sipi.PriceID.WriteTo(contentWritable) + sipi.RegularPrice.WriteTo(contentWritable) + sipi.IsTaxAvailable.WriteTo(contentWritable) + sipi.TaxAmount.WriteTo(contentWritable) + sipi.TotalAmount.WriteTo(contentWritable) + sipi.CurrentBalance.WriteTo(contentWritable) + sipi.PostBalance.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sipi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemPrepurchaseInfo from the given readable +func (sipi *ServiceItemPrepurchaseInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = sipi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo header. %s", err.Error()) + } + + err = sipi.ItemCode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.ItemCode. %s", err.Error()) + } + + err = sipi.PriceID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.PriceID. %s", err.Error()) + } + + err = sipi.RegularPrice.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.RegularPrice. %s", err.Error()) + } + + err = sipi.IsTaxAvailable.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.IsTaxAvailable. %s", err.Error()) + } + + err = sipi.TaxAmount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.TaxAmount. %s", err.Error()) + } + + err = sipi.TotalAmount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.TotalAmount. %s", err.Error()) + } + + err = sipi.CurrentBalance.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.CurrentBalance. %s", err.Error()) + } + + err = sipi.PostBalance.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPrepurchaseInfo.PostBalance. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemPrepurchaseInfo +func (sipi *ServiceItemPrepurchaseInfo) Copy() types.RVType { + copied := NewServiceItemPrepurchaseInfo() + + copied.StructureVersion = sipi.StructureVersion + copied.ItemCode = sipi.ItemCode.Copy().(*types.String) + copied.PriceID = sipi.PriceID.Copy().(*types.String) + copied.RegularPrice = sipi.RegularPrice.Copy().(*ServiceItemAmount) + copied.IsTaxAvailable = sipi.IsTaxAvailable.Copy().(*types.PrimitiveBool) + copied.TaxAmount = sipi.TaxAmount.Copy().(*ServiceItemAmount) + copied.TotalAmount = sipi.TotalAmount.Copy().(*ServiceItemAmount) + copied.CurrentBalance = sipi.CurrentBalance.Copy().(*ServiceItemAmount) + copied.PostBalance = sipi.PostBalance.Copy().(*ServiceItemAmount) + + return copied +} + +// Equals checks if the given ServiceItemPrepurchaseInfo contains the same data as the current ServiceItemPrepurchaseInfo +func (sipi *ServiceItemPrepurchaseInfo) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemPrepurchaseInfo); !ok { + return false + } + + other := o.(*ServiceItemPrepurchaseInfo) + + if sipi.StructureVersion != other.StructureVersion { + return false + } + + if !sipi.ItemCode.Equals(other.ItemCode) { + return false + } + + if !sipi.PriceID.Equals(other.PriceID) { + return false + } + + if !sipi.RegularPrice.Equals(other.RegularPrice) { + return false + } + + if !sipi.IsTaxAvailable.Equals(other.IsTaxAvailable) { + return false + } + + if !sipi.TaxAmount.Equals(other.TaxAmount) { + return false + } + + if !sipi.TotalAmount.Equals(other.TotalAmount) { + return false + } + + if !sipi.CurrentBalance.Equals(other.CurrentBalance) { + return false + } + + return sipi.PostBalance.Equals(other.PostBalance) +} + +// String returns the string representation of the ServiceItemPrepurchaseInfo +func (sipi *ServiceItemPrepurchaseInfo) String() string { + return sipi.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemPrepurchaseInfo using the provided indentation level +func (sipi *ServiceItemPrepurchaseInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemPrepurchaseInfo{\n") + b.WriteString(fmt.Sprintf("%sItemCode: %s,\n", indentationValues, sipi.ItemCode)) + b.WriteString(fmt.Sprintf("%sPriceID: %s,\n", indentationValues, sipi.PriceID)) + b.WriteString(fmt.Sprintf("%sRegularPrice: %s,\n", indentationValues, sipi.RegularPrice.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sIsTaxAvailable: %s,\n", indentationValues, sipi.IsTaxAvailable)) + b.WriteString(fmt.Sprintf("%sTaxAmount: %s,\n", indentationValues, sipi.TaxAmount.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sTotalAmount: %s,\n", indentationValues, sipi.TotalAmount.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sCurrentBalance: %s,\n", indentationValues, sipi.CurrentBalance.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sPostBalance: %s,\n", indentationValues, sipi.PostBalance.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemPrepurchaseInfo returns a new ServiceItemPrepurchaseInfo +func NewServiceItemPrepurchaseInfo() *ServiceItemPrepurchaseInfo { + sipi := &ServiceItemPrepurchaseInfo{ + ItemCode: types.NewString(""), + PriceID: types.NewString(""), + RegularPrice: NewServiceItemAmount(), + IsTaxAvailable: types.NewPrimitiveBool(false), + TaxAmount: NewServiceItemAmount(), + TotalAmount: NewServiceItemAmount(), + CurrentBalance: NewServiceItemAmount(), + PostBalance: NewServiceItemAmount(), + } + + return sipi +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_purchace_info.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_purchace_info.go new file mode 100644 index 0000000..d6667a5 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_purchace_info.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemPurchaceInfo is a type within the ServiceItem protocol +type ServiceItemPurchaceInfo struct { + types.Structure + TransactionID *types.String + ExtTransactionID *types.String + ItemCode *types.String + PostBalance *ServiceItemAmount +} + +// WriteTo writes the ServiceItemPurchaceInfo to the given writable +func (sipi *ServiceItemPurchaceInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sipi.TransactionID.WriteTo(contentWritable) + sipi.ExtTransactionID.WriteTo(contentWritable) + sipi.ItemCode.WriteTo(contentWritable) + sipi.PostBalance.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sipi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemPurchaceInfo from the given readable +func (sipi *ServiceItemPurchaceInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = sipi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaceInfo header. %s", err.Error()) + } + + err = sipi.TransactionID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaceInfo.TransactionID. %s", err.Error()) + } + + err = sipi.ExtTransactionID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaceInfo.ExtTransactionID. %s", err.Error()) + } + + err = sipi.ItemCode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaceInfo.ItemCode. %s", err.Error()) + } + + err = sipi.PostBalance.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaceInfo.PostBalance. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemPurchaceInfo +func (sipi *ServiceItemPurchaceInfo) Copy() types.RVType { + copied := NewServiceItemPurchaceInfo() + + copied.StructureVersion = sipi.StructureVersion + copied.TransactionID = sipi.TransactionID.Copy().(*types.String) + copied.ExtTransactionID = sipi.ExtTransactionID.Copy().(*types.String) + copied.ItemCode = sipi.ItemCode.Copy().(*types.String) + copied.PostBalance = sipi.PostBalance.Copy().(*ServiceItemAmount) + + return copied +} + +// Equals checks if the given ServiceItemPurchaceInfo contains the same data as the current ServiceItemPurchaceInfo +func (sipi *ServiceItemPurchaceInfo) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemPurchaceInfo); !ok { + return false + } + + other := o.(*ServiceItemPurchaceInfo) + + if sipi.StructureVersion != other.StructureVersion { + return false + } + + if !sipi.TransactionID.Equals(other.TransactionID) { + return false + } + + if !sipi.ExtTransactionID.Equals(other.ExtTransactionID) { + return false + } + + if !sipi.ItemCode.Equals(other.ItemCode) { + return false + } + + return sipi.PostBalance.Equals(other.PostBalance) +} + +// String returns the string representation of the ServiceItemPurchaceInfo +func (sipi *ServiceItemPurchaceInfo) String() string { + return sipi.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemPurchaceInfo using the provided indentation level +func (sipi *ServiceItemPurchaceInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemPurchaceInfo{\n") + b.WriteString(fmt.Sprintf("%sTransactionID: %s,\n", indentationValues, sipi.TransactionID)) + b.WriteString(fmt.Sprintf("%sExtTransactionID: %s,\n", indentationValues, sipi.ExtTransactionID)) + b.WriteString(fmt.Sprintf("%sItemCode: %s,\n", indentationValues, sipi.ItemCode)) + b.WriteString(fmt.Sprintf("%sPostBalance: %s,\n", indentationValues, sipi.PostBalance.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemPurchaceInfo returns a new ServiceItemPurchaceInfo +func NewServiceItemPurchaceInfo() *ServiceItemPurchaceInfo { + sipi := &ServiceItemPurchaceInfo{ + TransactionID: types.NewString(""), + ExtTransactionID: types.NewString(""), + ItemCode: types.NewString(""), + PostBalance: NewServiceItemAmount(), + } + + return sipi +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_purchase_history.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_purchase_history.go new file mode 100644 index 0000000..a4de770 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_purchase_history.go @@ -0,0 +1,128 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemPurchaseHistory is a type within the ServiceItem protocol +type ServiceItemPurchaseHistory struct { + types.Structure + TotalSize *types.PrimitiveU32 + Offset *types.PrimitiveU32 + Transactions *types.List[*ServiceItemTransaction] +} + +// WriteTo writes the ServiceItemPurchaseHistory to the given writable +func (siph *ServiceItemPurchaseHistory) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siph.TotalSize.WriteTo(contentWritable) + siph.Offset.WriteTo(contentWritable) + siph.Transactions.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siph.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemPurchaseHistory from the given readable +func (siph *ServiceItemPurchaseHistory) ExtractFrom(readable types.Readable) error { + var err error + + err = siph.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseHistory header. %s", err.Error()) + } + + err = siph.TotalSize.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseHistory.TotalSize. %s", err.Error()) + } + + err = siph.Offset.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseHistory.Offset. %s", err.Error()) + } + + err = siph.Transactions.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseHistory.Transactions. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemPurchaseHistory +func (siph *ServiceItemPurchaseHistory) Copy() types.RVType { + copied := NewServiceItemPurchaseHistory() + + copied.StructureVersion = siph.StructureVersion + copied.TotalSize = siph.TotalSize.Copy().(*types.PrimitiveU32) + copied.Offset = siph.Offset.Copy().(*types.PrimitiveU32) + copied.Transactions = siph.Transactions.Copy().(*types.List[*ServiceItemTransaction]) + + return copied +} + +// Equals checks if the given ServiceItemPurchaseHistory contains the same data as the current ServiceItemPurchaseHistory +func (siph *ServiceItemPurchaseHistory) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemPurchaseHistory); !ok { + return false + } + + other := o.(*ServiceItemPurchaseHistory) + + if siph.StructureVersion != other.StructureVersion { + return false + } + + if !siph.TotalSize.Equals(other.TotalSize) { + return false + } + + if !siph.Offset.Equals(other.Offset) { + return false + } + + return siph.Transactions.Equals(other.Transactions) +} + +// String returns the string representation of the ServiceItemPurchaseHistory +func (siph *ServiceItemPurchaseHistory) String() string { + return siph.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemPurchaseHistory using the provided indentation level +func (siph *ServiceItemPurchaseHistory) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemPurchaseHistory{\n") + b.WriteString(fmt.Sprintf("%sTotalSize: %s,\n", indentationValues, siph.TotalSize)) + b.WriteString(fmt.Sprintf("%sOffset: %s,\n", indentationValues, siph.Offset)) + b.WriteString(fmt.Sprintf("%sTransactions: %s,\n", indentationValues, siph.Transactions)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemPurchaseHistory returns a new ServiceItemPurchaseHistory +func NewServiceItemPurchaseHistory() *ServiceItemPurchaseHistory { + siph := &ServiceItemPurchaseHistory{ + TotalSize: types.NewPrimitiveU32(0), + Offset: types.NewPrimitiveU32(0), + Transactions: types.NewList[*ServiceItemTransaction](), + } + + siph.Transactions.Type = NewServiceItemTransaction() + + return siph +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_purchase_service_item_param.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_purchase_service_item_param.go new file mode 100644 index 0000000..c1c490a --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_purchase_service_item_param.go @@ -0,0 +1,196 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemPurchaseServiceItemParam is a type within the ServiceItem protocol +type ServiceItemPurchaseServiceItemParam struct { + types.Structure + ItemCode *types.String + PriceID *types.String + ReferenceID *types.String + Balance *types.String + ItemName *types.String + EcServiceToken *types.String + Language *types.String + TitleID *types.String +} + +// WriteTo writes the ServiceItemPurchaseServiceItemParam to the given writable +func (sipsip *ServiceItemPurchaseServiceItemParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sipsip.ItemCode.WriteTo(contentWritable) + sipsip.PriceID.WriteTo(contentWritable) + sipsip.ReferenceID.WriteTo(contentWritable) + sipsip.Balance.WriteTo(contentWritable) + sipsip.ItemName.WriteTo(contentWritable) + sipsip.EcServiceToken.WriteTo(contentWritable) + sipsip.Language.WriteTo(contentWritable) + sipsip.TitleID.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sipsip.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemPurchaseServiceItemParam from the given readable +func (sipsip *ServiceItemPurchaseServiceItemParam) ExtractFrom(readable types.Readable) error { + var err error + + err = sipsip.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam header. %s", err.Error()) + } + + err = sipsip.ItemCode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam.ItemCode. %s", err.Error()) + } + + err = sipsip.PriceID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam.PriceID. %s", err.Error()) + } + + err = sipsip.ReferenceID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam.ReferenceID. %s", err.Error()) + } + + err = sipsip.Balance.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam.Balance. %s", err.Error()) + } + + err = sipsip.ItemName.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam.ItemName. %s", err.Error()) + } + + err = sipsip.EcServiceToken.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam.EcServiceToken. %s", err.Error()) + } + + err = sipsip.Language.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam.Language. %s", err.Error()) + } + + err = sipsip.TitleID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemParam.TitleID. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemPurchaseServiceItemParam +func (sipsip *ServiceItemPurchaseServiceItemParam) Copy() types.RVType { + copied := NewServiceItemPurchaseServiceItemParam() + + copied.StructureVersion = sipsip.StructureVersion + copied.ItemCode = sipsip.ItemCode.Copy().(*types.String) + copied.PriceID = sipsip.PriceID.Copy().(*types.String) + copied.ReferenceID = sipsip.ReferenceID.Copy().(*types.String) + copied.Balance = sipsip.Balance.Copy().(*types.String) + copied.ItemName = sipsip.ItemName.Copy().(*types.String) + copied.EcServiceToken = sipsip.EcServiceToken.Copy().(*types.String) + copied.Language = sipsip.Language.Copy().(*types.String) + copied.TitleID = sipsip.TitleID.Copy().(*types.String) + + return copied +} + +// Equals checks if the given ServiceItemPurchaseServiceItemParam contains the same data as the current ServiceItemPurchaseServiceItemParam +func (sipsip *ServiceItemPurchaseServiceItemParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemPurchaseServiceItemParam); !ok { + return false + } + + other := o.(*ServiceItemPurchaseServiceItemParam) + + if sipsip.StructureVersion != other.StructureVersion { + return false + } + + if !sipsip.ItemCode.Equals(other.ItemCode) { + return false + } + + if !sipsip.PriceID.Equals(other.PriceID) { + return false + } + + if !sipsip.ReferenceID.Equals(other.ReferenceID) { + return false + } + + if !sipsip.Balance.Equals(other.Balance) { + return false + } + + if !sipsip.ItemName.Equals(other.ItemName) { + return false + } + + if !sipsip.EcServiceToken.Equals(other.EcServiceToken) { + return false + } + + if !sipsip.Language.Equals(other.Language) { + return false + } + + return sipsip.TitleID.Equals(other.TitleID) +} + +// String returns the string representation of the ServiceItemPurchaseServiceItemParam +func (sipsip *ServiceItemPurchaseServiceItemParam) String() string { + return sipsip.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemPurchaseServiceItemParam using the provided indentation level +func (sipsip *ServiceItemPurchaseServiceItemParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemPurchaseServiceItemParam{\n") + b.WriteString(fmt.Sprintf("%sItemCode: %s,\n", indentationValues, sipsip.ItemCode)) + b.WriteString(fmt.Sprintf("%sPriceID: %s,\n", indentationValues, sipsip.PriceID)) + b.WriteString(fmt.Sprintf("%sReferenceID: %s,\n", indentationValues, sipsip.ReferenceID)) + b.WriteString(fmt.Sprintf("%sBalance: %s,\n", indentationValues, sipsip.Balance)) + b.WriteString(fmt.Sprintf("%sItemName: %s,\n", indentationValues, sipsip.ItemName)) + b.WriteString(fmt.Sprintf("%sEcServiceToken: %s,\n", indentationValues, sipsip.EcServiceToken)) + b.WriteString(fmt.Sprintf("%sLanguage: %s,\n", indentationValues, sipsip.Language)) + b.WriteString(fmt.Sprintf("%sTitleID: %s,\n", indentationValues, sipsip.TitleID)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemPurchaseServiceItemParam returns a new ServiceItemPurchaseServiceItemParam +func NewServiceItemPurchaseServiceItemParam() *ServiceItemPurchaseServiceItemParam { + sipsip := &ServiceItemPurchaseServiceItemParam{ + ItemCode: types.NewString(""), + PriceID: types.NewString(""), + ReferenceID: types.NewString(""), + Balance: types.NewString(""), + ItemName: types.NewString(""), + EcServiceToken: types.NewString(""), + Language: types.NewString(""), + TitleID: types.NewString(""), + } + + return sipsip +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_purchase_service_item_response.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_purchase_service_item_response.go new file mode 100644 index 0000000..03607e6 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_purchase_service_item_response.go @@ -0,0 +1,115 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemPurchaseServiceItemResponse is a type within the ServiceItem protocol +type ServiceItemPurchaseServiceItemResponse struct { + types.Structure + *ServiceItemEShopResponse + NullablePurchaceInfo *types.List[*ServiceItemPurchaceInfo] +} + +// WriteTo writes the ServiceItemPurchaseServiceItemResponse to the given writable +func (sipsir *ServiceItemPurchaseServiceItemResponse) WriteTo(writable types.Writable) { + sipsir.ServiceItemEShopResponse.WriteTo(writable) + + contentWritable := writable.CopyNew() + + sipsir.NullablePurchaceInfo.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sipsir.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemPurchaseServiceItemResponse from the given readable +func (sipsir *ServiceItemPurchaseServiceItemResponse) ExtractFrom(readable types.Readable) error { + var err error + + err = sipsir.ServiceItemEShopResponse.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemResponse.ServiceItemEShopResponse. %s", err.Error()) + } + + err = sipsir.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemResponse header. %s", err.Error()) + } + + err = sipsir.NullablePurchaceInfo.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemPurchaseServiceItemResponse.NullablePurchaceInfo. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemPurchaseServiceItemResponse +func (sipsir *ServiceItemPurchaseServiceItemResponse) Copy() types.RVType { + copied := NewServiceItemPurchaseServiceItemResponse() + + copied.StructureVersion = sipsir.StructureVersion + copied.ServiceItemEShopResponse = sipsir.ServiceItemEShopResponse.Copy().(*ServiceItemEShopResponse) + copied.NullablePurchaceInfo = sipsir.NullablePurchaceInfo.Copy().(*types.List[*ServiceItemPurchaceInfo]) + + return copied +} + +// Equals checks if the given ServiceItemPurchaseServiceItemResponse contains the same data as the current ServiceItemPurchaseServiceItemResponse +func (sipsir *ServiceItemPurchaseServiceItemResponse) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemPurchaseServiceItemResponse); !ok { + return false + } + + other := o.(*ServiceItemPurchaseServiceItemResponse) + + if sipsir.StructureVersion != other.StructureVersion { + return false + } + + if !sipsir.ServiceItemEShopResponse.Equals(other.ServiceItemEShopResponse) { + return false + } + + return sipsir.NullablePurchaceInfo.Equals(other.NullablePurchaceInfo) +} + +// String returns the string representation of the ServiceItemPurchaseServiceItemResponse +func (sipsir *ServiceItemPurchaseServiceItemResponse) String() string { + return sipsir.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemPurchaseServiceItemResponse using the provided indentation level +func (sipsir *ServiceItemPurchaseServiceItemResponse) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemPurchaseServiceItemResponse{\n") + b.WriteString(fmt.Sprintf("%sServiceItemEShopResponse (parent): %s,\n", indentationValues, sipsir.ServiceItemEShopResponse.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sNullablePurchaceInfo: %s,\n", indentationValues, sipsir.NullablePurchaceInfo)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemPurchaseServiceItemResponse returns a new ServiceItemPurchaseServiceItemResponse +func NewServiceItemPurchaseServiceItemResponse() *ServiceItemPurchaseServiceItemResponse { + sipsir := &ServiceItemPurchaseServiceItemResponse{ + ServiceItemEShopResponse: NewServiceItemEShopResponse(), + NullablePurchaceInfo: types.NewList[*ServiceItemPurchaceInfo](), + } + + sipsir.NullablePurchaceInfo.Type = NewServiceItemPurchaceInfo() + + return sipsir +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_request_ticket_restoration_param.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_request_ticket_restoration_param.go new file mode 100644 index 0000000..9f988a5 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_request_ticket_restoration_param.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemRequestTicketRestorationParam is a type within the ServiceItem protocol +type ServiceItemRequestTicketRestorationParam struct { + types.Structure + TicketType *types.PrimitiveU32 + NumTicket *types.PrimitiveU32 +} + +// WriteTo writes the ServiceItemRequestTicketRestorationParam to the given writable +func (sirtrp *ServiceItemRequestTicketRestorationParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sirtrp.TicketType.WriteTo(contentWritable) + sirtrp.NumTicket.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sirtrp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemRequestTicketRestorationParam from the given readable +func (sirtrp *ServiceItemRequestTicketRestorationParam) ExtractFrom(readable types.Readable) error { + var err error + + err = sirtrp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRequestTicketRestorationParam header. %s", err.Error()) + } + + err = sirtrp.TicketType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRequestTicketRestorationParam.TicketType. %s", err.Error()) + } + + err = sirtrp.NumTicket.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRequestTicketRestorationParam.NumTicket. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemRequestTicketRestorationParam +func (sirtrp *ServiceItemRequestTicketRestorationParam) Copy() types.RVType { + copied := NewServiceItemRequestTicketRestorationParam() + + copied.StructureVersion = sirtrp.StructureVersion + copied.TicketType = sirtrp.TicketType.Copy().(*types.PrimitiveU32) + copied.NumTicket = sirtrp.NumTicket.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given ServiceItemRequestTicketRestorationParam contains the same data as the current ServiceItemRequestTicketRestorationParam +func (sirtrp *ServiceItemRequestTicketRestorationParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemRequestTicketRestorationParam); !ok { + return false + } + + other := o.(*ServiceItemRequestTicketRestorationParam) + + if sirtrp.StructureVersion != other.StructureVersion { + return false + } + + if !sirtrp.TicketType.Equals(other.TicketType) { + return false + } + + return sirtrp.NumTicket.Equals(other.NumTicket) +} + +// String returns the string representation of the ServiceItemRequestTicketRestorationParam +func (sirtrp *ServiceItemRequestTicketRestorationParam) String() string { + return sirtrp.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemRequestTicketRestorationParam using the provided indentation level +func (sirtrp *ServiceItemRequestTicketRestorationParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemRequestTicketRestorationParam{\n") + b.WriteString(fmt.Sprintf("%sTicketType: %s,\n", indentationValues, sirtrp.TicketType)) + b.WriteString(fmt.Sprintf("%sNumTicket: %s,\n", indentationValues, sirtrp.NumTicket)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemRequestTicketRestorationParam returns a new ServiceItemRequestTicketRestorationParam +func NewServiceItemRequestTicketRestorationParam() *ServiceItemRequestTicketRestorationParam { + sirtrp := &ServiceItemRequestTicketRestorationParam{ + TicketType: types.NewPrimitiveU32(0), + NumTicket: types.NewPrimitiveU32(0), + } + + return sirtrp +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_right_info.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_right_info.go new file mode 100644 index 0000000..f1c5c7d --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_right_info.go @@ -0,0 +1,114 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemRightInfo is a type within the ServiceItem protocol +type ServiceItemRightInfo struct { + types.Structure + ReferenceID *types.String + AccountRights *types.List[*ServiceItemAccountRight] +} + +// WriteTo writes the ServiceItemRightInfo to the given writable +func (siri *ServiceItemRightInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siri.ReferenceID.WriteTo(contentWritable) + siri.AccountRights.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siri.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemRightInfo from the given readable +func (siri *ServiceItemRightInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = siri.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightInfo header. %s", err.Error()) + } + + err = siri.ReferenceID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightInfo.ReferenceID. %s", err.Error()) + } + + err = siri.AccountRights.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightInfo.AccountRights. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemRightInfo +func (siri *ServiceItemRightInfo) Copy() types.RVType { + copied := NewServiceItemRightInfo() + + copied.StructureVersion = siri.StructureVersion + copied.ReferenceID = siri.ReferenceID.Copy().(*types.String) + copied.AccountRights = siri.AccountRights.Copy().(*types.List[*ServiceItemAccountRight]) + + return copied +} + +// Equals checks if the given ServiceItemRightInfo contains the same data as the current ServiceItemRightInfo +func (siri *ServiceItemRightInfo) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemRightInfo); !ok { + return false + } + + other := o.(*ServiceItemRightInfo) + + if siri.StructureVersion != other.StructureVersion { + return false + } + + if !siri.ReferenceID.Equals(other.ReferenceID) { + return false + } + + return siri.AccountRights.Equals(other.AccountRights) +} + +// String returns the string representation of the ServiceItemRightInfo +func (siri *ServiceItemRightInfo) String() string { + return siri.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemRightInfo using the provided indentation level +func (siri *ServiceItemRightInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemRightInfo{\n") + b.WriteString(fmt.Sprintf("%sReferenceID: %s,\n", indentationValues, siri.ReferenceID)) + b.WriteString(fmt.Sprintf("%sAccountRights: %s,\n", indentationValues, siri.AccountRights)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemRightInfo returns a new ServiceItemRightInfo +func NewServiceItemRightInfo() *ServiceItemRightInfo { + siri := &ServiceItemRightInfo{ + ReferenceID: types.NewString(""), + AccountRights: types.NewList[*ServiceItemAccountRight](), + } + + siri.AccountRights.Type = NewServiceItemAccountRight() + + return siri +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_right_infos.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_right_infos.go new file mode 100644 index 0000000..3d3f4f3 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_right_infos.go @@ -0,0 +1,100 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemRightInfos is a type within the ServiceItem protocol +type ServiceItemRightInfos struct { + types.Structure + RightInfos *types.List[*ServiceItemRightInfo] +} + +// WriteTo writes the ServiceItemRightInfos to the given writable +func (siri *ServiceItemRightInfos) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siri.RightInfos.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siri.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemRightInfos from the given readable +func (siri *ServiceItemRightInfos) ExtractFrom(readable types.Readable) error { + var err error + + err = siri.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightInfos header. %s", err.Error()) + } + + err = siri.RightInfos.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemRightInfos.RightInfos. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemRightInfos +func (siri *ServiceItemRightInfos) Copy() types.RVType { + copied := NewServiceItemRightInfos() + + copied.StructureVersion = siri.StructureVersion + copied.RightInfos = siri.RightInfos.Copy().(*types.List[*ServiceItemRightInfo]) + + return copied +} + +// Equals checks if the given ServiceItemRightInfos contains the same data as the current ServiceItemRightInfos +func (siri *ServiceItemRightInfos) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemRightInfos); !ok { + return false + } + + other := o.(*ServiceItemRightInfos) + + if siri.StructureVersion != other.StructureVersion { + return false + } + + return siri.RightInfos.Equals(other.RightInfos) +} + +// String returns the string representation of the ServiceItemRightInfos +func (siri *ServiceItemRightInfos) String() string { + return siri.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemRightInfos using the provided indentation level +func (siri *ServiceItemRightInfos) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemRightInfos{\n") + b.WriteString(fmt.Sprintf("%sRightInfos: %s,\n", indentationValues, siri.RightInfos)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemRightInfos returns a new ServiceItemRightInfos +func NewServiceItemRightInfos() *ServiceItemRightInfos { + siri := &ServiceItemRightInfos{ + RightInfos: types.NewList[*ServiceItemRightInfo](), + } + + siri.RightInfos.Type = NewServiceItemRightInfo() + + return siri +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_start_challenge_param.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_start_challenge_param.go new file mode 100644 index 0000000..d5fe131 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_start_challenge_param.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemStartChallengeParam is a type within the ServiceItem protocol +type ServiceItemStartChallengeParam struct { + types.Structure + ChallengeScheduleID *types.PrimitiveU32 + TicketType *types.PrimitiveU32 + NumTicket *types.PrimitiveU32 +} + +// WriteTo writes the ServiceItemStartChallengeParam to the given writable +func (siscp *ServiceItemStartChallengeParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siscp.ChallengeScheduleID.WriteTo(contentWritable) + siscp.TicketType.WriteTo(contentWritable) + siscp.NumTicket.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siscp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemStartChallengeParam from the given readable +func (siscp *ServiceItemStartChallengeParam) ExtractFrom(readable types.Readable) error { + var err error + + err = siscp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemStartChallengeParam header. %s", err.Error()) + } + + err = siscp.ChallengeScheduleID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemStartChallengeParam.ChallengeScheduleID. %s", err.Error()) + } + + err = siscp.TicketType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemStartChallengeParam.TicketType. %s", err.Error()) + } + + err = siscp.NumTicket.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemStartChallengeParam.NumTicket. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemStartChallengeParam +func (siscp *ServiceItemStartChallengeParam) Copy() types.RVType { + copied := NewServiceItemStartChallengeParam() + + copied.StructureVersion = siscp.StructureVersion + copied.ChallengeScheduleID = siscp.ChallengeScheduleID.Copy().(*types.PrimitiveU32) + copied.TicketType = siscp.TicketType.Copy().(*types.PrimitiveU32) + copied.NumTicket = siscp.NumTicket.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given ServiceItemStartChallengeParam contains the same data as the current ServiceItemStartChallengeParam +func (siscp *ServiceItemStartChallengeParam) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemStartChallengeParam); !ok { + return false + } + + other := o.(*ServiceItemStartChallengeParam) + + if siscp.StructureVersion != other.StructureVersion { + return false + } + + if !siscp.ChallengeScheduleID.Equals(other.ChallengeScheduleID) { + return false + } + + if !siscp.TicketType.Equals(other.TicketType) { + return false + } + + return siscp.NumTicket.Equals(other.NumTicket) +} + +// String returns the string representation of the ServiceItemStartChallengeParam +func (siscp *ServiceItemStartChallengeParam) String() string { + return siscp.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemStartChallengeParam using the provided indentation level +func (siscp *ServiceItemStartChallengeParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemStartChallengeParam{\n") + b.WriteString(fmt.Sprintf("%sChallengeScheduleID: %s,\n", indentationValues, siscp.ChallengeScheduleID)) + b.WriteString(fmt.Sprintf("%sTicketType: %s,\n", indentationValues, siscp.TicketType)) + b.WriteString(fmt.Sprintf("%sNumTicket: %s,\n", indentationValues, siscp.NumTicket)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemStartChallengeParam returns a new ServiceItemStartChallengeParam +func NewServiceItemStartChallengeParam() *ServiceItemStartChallengeParam { + siscp := &ServiceItemStartChallengeParam{ + ChallengeScheduleID: types.NewPrimitiveU32(0), + TicketType: types.NewPrimitiveU32(0), + NumTicket: types.NewPrimitiveU32(0), + } + + return siscp +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_ticket_info.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_ticket_info.go new file mode 100644 index 0000000..2c54b10 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_ticket_info.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemTicketInfo is a type within the ServiceItem protocol +type ServiceItemTicketInfo struct { + types.Structure + TicketType *types.PrimitiveU32 + NumTotal *types.PrimitiveU32 +} + +// WriteTo writes the ServiceItemTicketInfo to the given writable +func (siti *ServiceItemTicketInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siti.TicketType.WriteTo(contentWritable) + siti.NumTotal.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siti.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemTicketInfo from the given readable +func (siti *ServiceItemTicketInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = siti.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTicketInfo header. %s", err.Error()) + } + + err = siti.TicketType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTicketInfo.TicketType. %s", err.Error()) + } + + err = siti.NumTotal.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTicketInfo.NumTotal. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemTicketInfo +func (siti *ServiceItemTicketInfo) Copy() types.RVType { + copied := NewServiceItemTicketInfo() + + copied.StructureVersion = siti.StructureVersion + copied.TicketType = siti.TicketType.Copy().(*types.PrimitiveU32) + copied.NumTotal = siti.NumTotal.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given ServiceItemTicketInfo contains the same data as the current ServiceItemTicketInfo +func (siti *ServiceItemTicketInfo) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemTicketInfo); !ok { + return false + } + + other := o.(*ServiceItemTicketInfo) + + if siti.StructureVersion != other.StructureVersion { + return false + } + + if !siti.TicketType.Equals(other.TicketType) { + return false + } + + return siti.NumTotal.Equals(other.NumTotal) +} + +// String returns the string representation of the ServiceItemTicketInfo +func (siti *ServiceItemTicketInfo) String() string { + return siti.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemTicketInfo using the provided indentation level +func (siti *ServiceItemTicketInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemTicketInfo{\n") + b.WriteString(fmt.Sprintf("%sTicketType: %s,\n", indentationValues, siti.TicketType)) + b.WriteString(fmt.Sprintf("%sNumTotal: %s,\n", indentationValues, siti.NumTotal)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemTicketInfo returns a new ServiceItemTicketInfo +func NewServiceItemTicketInfo() *ServiceItemTicketInfo { + siti := &ServiceItemTicketInfo{ + TicketType: types.NewPrimitiveU32(0), + NumTotal: types.NewPrimitiveU32(0), + } + + return siti +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_transaction.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_transaction.go new file mode 100644 index 0000000..20d1706 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_transaction.go @@ -0,0 +1,210 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemTransaction is a type within the ServiceItem protocol +type ServiceItemTransaction struct { + types.Structure + TransactionID *types.String + ExtTransactionID *types.String + Time *types.DateTime + TransactionType *types.PrimitiveU32 + TransactionDescription *types.String + TransactionAmount *ServiceItemAmount + ItemCode *types.String + ReferenceID *types.String + Limitation *ServiceItemLimitation +} + +// WriteTo writes the ServiceItemTransaction to the given writable +func (sit *ServiceItemTransaction) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sit.TransactionID.WriteTo(contentWritable) + sit.ExtTransactionID.WriteTo(contentWritable) + sit.Time.WriteTo(contentWritable) + sit.TransactionType.WriteTo(contentWritable) + sit.TransactionDescription.WriteTo(contentWritable) + sit.TransactionAmount.WriteTo(contentWritable) + sit.ItemCode.WriteTo(contentWritable) + sit.ReferenceID.WriteTo(contentWritable) + sit.Limitation.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sit.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemTransaction from the given readable +func (sit *ServiceItemTransaction) ExtractFrom(readable types.Readable) error { + var err error + + err = sit.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction header. %s", err.Error()) + } + + err = sit.TransactionID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.TransactionID. %s", err.Error()) + } + + err = sit.ExtTransactionID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.ExtTransactionID. %s", err.Error()) + } + + err = sit.Time.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.Time. %s", err.Error()) + } + + err = sit.TransactionType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.TransactionType. %s", err.Error()) + } + + err = sit.TransactionDescription.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.TransactionDescription. %s", err.Error()) + } + + err = sit.TransactionAmount.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.TransactionAmount. %s", err.Error()) + } + + err = sit.ItemCode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.ItemCode. %s", err.Error()) + } + + err = sit.ReferenceID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.ReferenceID. %s", err.Error()) + } + + err = sit.Limitation.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemTransaction.Limitation. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemTransaction +func (sit *ServiceItemTransaction) Copy() types.RVType { + copied := NewServiceItemTransaction() + + copied.StructureVersion = sit.StructureVersion + copied.TransactionID = sit.TransactionID.Copy().(*types.String) + copied.ExtTransactionID = sit.ExtTransactionID.Copy().(*types.String) + copied.Time = sit.Time.Copy().(*types.DateTime) + copied.TransactionType = sit.TransactionType.Copy().(*types.PrimitiveU32) + copied.TransactionDescription = sit.TransactionDescription.Copy().(*types.String) + copied.TransactionAmount = sit.TransactionAmount.Copy().(*ServiceItemAmount) + copied.ItemCode = sit.ItemCode.Copy().(*types.String) + copied.ReferenceID = sit.ReferenceID.Copy().(*types.String) + copied.Limitation = sit.Limitation.Copy().(*ServiceItemLimitation) + + return copied +} + +// Equals checks if the given ServiceItemTransaction contains the same data as the current ServiceItemTransaction +func (sit *ServiceItemTransaction) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemTransaction); !ok { + return false + } + + other := o.(*ServiceItemTransaction) + + if sit.StructureVersion != other.StructureVersion { + return false + } + + if !sit.TransactionID.Equals(other.TransactionID) { + return false + } + + if !sit.ExtTransactionID.Equals(other.ExtTransactionID) { + return false + } + + if !sit.Time.Equals(other.Time) { + return false + } + + if !sit.TransactionType.Equals(other.TransactionType) { + return false + } + + if !sit.TransactionDescription.Equals(other.TransactionDescription) { + return false + } + + if !sit.TransactionAmount.Equals(other.TransactionAmount) { + return false + } + + if !sit.ItemCode.Equals(other.ItemCode) { + return false + } + + if !sit.ReferenceID.Equals(other.ReferenceID) { + return false + } + + return sit.Limitation.Equals(other.Limitation) +} + +// String returns the string representation of the ServiceItemTransaction +func (sit *ServiceItemTransaction) String() string { + return sit.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemTransaction using the provided indentation level +func (sit *ServiceItemTransaction) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemTransaction{\n") + b.WriteString(fmt.Sprintf("%sTransactionID: %s,\n", indentationValues, sit.TransactionID)) + b.WriteString(fmt.Sprintf("%sExtTransactionID: %s,\n", indentationValues, sit.ExtTransactionID)) + b.WriteString(fmt.Sprintf("%sTime: %s,\n", indentationValues, sit.Time.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sTransactionType: %s,\n", indentationValues, sit.TransactionType)) + b.WriteString(fmt.Sprintf("%sTransactionDescription: %s,\n", indentationValues, sit.TransactionDescription)) + b.WriteString(fmt.Sprintf("%sTransactionAmount: %s,\n", indentationValues, sit.TransactionAmount.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sItemCode: %s,\n", indentationValues, sit.ItemCode)) + b.WriteString(fmt.Sprintf("%sReferenceID: %s,\n", indentationValues, sit.ReferenceID)) + b.WriteString(fmt.Sprintf("%sLimitation: %s,\n", indentationValues, sit.Limitation.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemTransaction returns a new ServiceItemTransaction +func NewServiceItemTransaction() *ServiceItemTransaction { + sit := &ServiceItemTransaction{ + TransactionID: types.NewString(""), + ExtTransactionID: types.NewString(""), + Time: types.NewDateTime(0), + TransactionType: types.NewPrimitiveU32(0), + TransactionDescription: types.NewString(""), + TransactionAmount: NewServiceItemAmount(), + ItemCode: types.NewString(""), + ReferenceID: types.NewString(""), + Limitation: NewServiceItemLimitation(), + } + + return sit +} diff --git a/nex-protocols-go/service-item/wii-sports-club/types/service_item_user_info.go b/nex-protocols-go/service-item/wii-sports-club/types/service_item_user_info.go new file mode 100644 index 0000000..2073a75 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/types/service_item_user_info.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the ServiceItem protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ServiceItemUserInfo is a type within the ServiceItem protocol +type ServiceItemUserInfo struct { + types.Structure + NumTotalEntryTicket *types.PrimitiveU32 + ApplicationBuffer *types.QBuffer +} + +// WriteTo writes the ServiceItemUserInfo to the given writable +func (siui *ServiceItemUserInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + siui.NumTotalEntryTicket.WriteTo(contentWritable) + siui.ApplicationBuffer.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + siui.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ServiceItemUserInfo from the given readable +func (siui *ServiceItemUserInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = siui.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUserInfo header. %s", err.Error()) + } + + err = siui.NumTotalEntryTicket.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUserInfo.NumTotalEntryTicket. %s", err.Error()) + } + + err = siui.ApplicationBuffer.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ServiceItemUserInfo.ApplicationBuffer. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ServiceItemUserInfo +func (siui *ServiceItemUserInfo) Copy() types.RVType { + copied := NewServiceItemUserInfo() + + copied.StructureVersion = siui.StructureVersion + copied.NumTotalEntryTicket = siui.NumTotalEntryTicket.Copy().(*types.PrimitiveU32) + copied.ApplicationBuffer = siui.ApplicationBuffer.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given ServiceItemUserInfo contains the same data as the current ServiceItemUserInfo +func (siui *ServiceItemUserInfo) Equals(o types.RVType) bool { + if _, ok := o.(*ServiceItemUserInfo); !ok { + return false + } + + other := o.(*ServiceItemUserInfo) + + if siui.StructureVersion != other.StructureVersion { + return false + } + + if !siui.NumTotalEntryTicket.Equals(other.NumTotalEntryTicket) { + return false + } + + return siui.ApplicationBuffer.Equals(other.ApplicationBuffer) +} + +// String returns the string representation of the ServiceItemUserInfo +func (siui *ServiceItemUserInfo) String() string { + return siui.FormatToString(0) +} + +// FormatToString pretty-prints the ServiceItemUserInfo using the provided indentation level +func (siui *ServiceItemUserInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ServiceItemUserInfo{\n") + b.WriteString(fmt.Sprintf("%sNumTotalEntryTicket: %s,\n", indentationValues, siui.NumTotalEntryTicket)) + b.WriteString(fmt.Sprintf("%sApplicationBuffer: %s,\n", indentationValues, siui.ApplicationBuffer)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewServiceItemUserInfo returns a new ServiceItemUserInfo +func NewServiceItemUserInfo() *ServiceItemUserInfo { + siui := &ServiceItemUserInfo{ + NumTotalEntryTicket: types.NewPrimitiveU32(0), + ApplicationBuffer: types.NewQBuffer(nil), + } + + return siui +} diff --git a/nex-protocols-go/service-item/wii-sports-club/update_and_get_ticket_info.go b/nex-protocols-go/service-item/wii-sports-club/update_and_get_ticket_info.go new file mode 100644 index 0000000..3a2a621 --- /dev/null +++ b/nex-protocols-go/service-item/wii-sports-club/update_and_get_ticket_info.go @@ -0,0 +1,47 @@ +// Package protocol implements the ServiceItemWiiSportsClub protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateAndGetTicketInfo(packet nex.PacketInterface) { + if protocol.UpdateAndGetTicketInfo == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ServiceItemWiiSportsClub::UpdateAndGetTicketInfo not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + forceRetrieveFromEShop := types.NewPrimitiveBool(false) + + err := forceRetrieveFromEShop.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateAndGetTicketInfo(fmt.Errorf("Failed to read forceRetrieveFromEShop from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateAndGetTicketInfo(nil, packet, callID, forceRetrieveFromEShop) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/shop/nintendo-badge-arcade/get_riv_token.go b/nex-protocols-go/shop/nintendo-badge-arcade/get_riv_token.go new file mode 100644 index 0000000..96fc84f --- /dev/null +++ b/nex-protocols-go/shop/nintendo-badge-arcade/get_riv_token.go @@ -0,0 +1,60 @@ +// Package protocol implements the Nintendo Badge Arcade Shop protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetRivToken(packet nex.PacketInterface) { + if protocol.GetRivToken == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ShopNintendoBadgeArcade::GetRivToken not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + itemCode := types.NewString("") + referenceID := types.NewQBuffer(nil) + + var err error + + err = itemCode.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRivToken(fmt.Errorf("Failed to read itemCode from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = referenceID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetRivToken(fmt.Errorf("Failed to read referenceID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetRivToken(nil, packet, callID, itemCode, referenceID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/shop/nintendo-badge-arcade/post_play_log.go b/nex-protocols-go/shop/nintendo-badge-arcade/post_play_log.go new file mode 100644 index 0000000..bb292f1 --- /dev/null +++ b/nex-protocols-go/shop/nintendo-badge-arcade/post_play_log.go @@ -0,0 +1,47 @@ +// Package protocol implements the Nintendo Badge Arcade Shop protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + shop_nintendo_badge_arcade_types "github.com/PretendoNetwork/nex-protocols-go/v2/shop/nintendo-badge-arcade/types" +) + +func (protocol *Protocol) handlePostPlayLog(packet nex.PacketInterface) { + if protocol.PostPlayLog == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "ShopNintendoBadgeArcade::PostPlayLog not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := shop_nintendo_badge_arcade_types.NewShopPostPlayLogParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PostPlayLog(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PostPlayLog(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/shop/nintendo-badge-arcade/protocol.go b/nex-protocols-go/shop/nintendo-badge-arcade/protocol.go new file mode 100644 index 0000000..3a3919b --- /dev/null +++ b/nex-protocols-go/shop/nintendo-badge-arcade/protocol.go @@ -0,0 +1,75 @@ +// Package protocol implements the Nintendo Badge Arcade Shop protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + shop "github.com/PretendoNetwork/nex-protocols-go/v2/shop" + shop_nintendo_badge_arcade_types "github.com/PretendoNetwork/nex-protocols-go/v2/shop/nintendo-badge-arcade/types" + "golang.org/x/exp/slices" +) + +const ( + // ProtocolID is the Protocol ID for the Shop (Nintendo Badge Arcade) protocol + ProtocolID = 0xC8 + + // MethodGetRivToken is the method ID for GetRivToken + MethodGetRivToken = 0x1 + + // MethodPostPlayLog is the method ID for PostPlayLog + MethodPostPlayLog = 0x2 +) + +var patchedMethods = []uint32{ + MethodGetRivToken, + MethodPostPlayLog, +} + +type shopProtocol = shop.Protocol + +// Protocol stores all the RMC method handlers for the Shop (Nintendo Badge Arcade) protocol and listens for requests +// Embeds the Shop protocol +type Protocol struct { + endpoint nex.EndpointInterface + shopProtocol + GetRivToken func(err error, packet nex.PacketInterface, callID uint32, itemCode *types.String, referenceID *types.QBuffer) (*nex.RMCMessage, *nex.Error) + PostPlayLog func(err error, packet nex.PacketInterface, callID uint32, param *shop_nintendo_badge_arcade_types.ShopPostPlayLogParam) (*nex.RMCMessage, *nex.Error) +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if !slices.Contains(patchedMethods, message.MethodID) { + protocol.shopProtocol.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodGetRivToken: + protocol.handleGetRivToken(packet) + case MethodPostPlayLog: + protocol.handlePostPlayLog(packet) + default: + errMessage := fmt.Sprintf("Unsupported ShopNintendoBadgeArcade method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Shop (Nintendo Badge Arcade) +func NewProtocol(endpoint nex.EndpointInterface) *Protocol { + protocol := &Protocol{endpoint: endpoint} + protocol.shopProtocol.SetEndpoint(endpoint) + + return protocol +} diff --git a/nex-protocols-go/shop/nintendo-badge-arcade/types/shop_post_play_log_param.go b/nex-protocols-go/shop/nintendo-badge-arcade/types/shop_post_play_log_param.go new file mode 100644 index 0000000..7cf5922 --- /dev/null +++ b/nex-protocols-go/shop/nintendo-badge-arcade/types/shop_post_play_log_param.go @@ -0,0 +1,128 @@ +// Package types implements all the types used by the ShopNintendoBadgeArcade protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ShopPostPlayLogParam is a type within the ShopNintendoBadgeArcade protocol +type ShopPostPlayLogParam struct { + types.Structure + Unknown1 *types.List[*types.PrimitiveU32] + Timestamp *types.DateTime + Unknown2 *types.String +} + +// WriteTo writes the ShopPostPlayLogParam to the given writable +func (spplp *ShopPostPlayLogParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + spplp.Unknown1.WriteTo(contentWritable) + spplp.Timestamp.WriteTo(contentWritable) + spplp.Unknown2.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + spplp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ShopPostPlayLogParam from the given readable +func (spplp *ShopPostPlayLogParam) ExtractFrom(readable types.Readable) error { + var err error + + err = spplp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ShopPostPlayLogParam header. %s", err.Error()) + } + + err = spplp.Unknown1.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ShopPostPlayLogParam.Unknown1. %s", err.Error()) + } + + err = spplp.Timestamp.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ShopPostPlayLogParam.Timestamp. %s", err.Error()) + } + + err = spplp.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ShopPostPlayLogParam.Unknown2. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ShopPostPlayLogParam +func (spplp *ShopPostPlayLogParam) Copy() types.RVType { + copied := NewShopPostPlayLogParam() + + copied.StructureVersion = spplp.StructureVersion + copied.Unknown1 = spplp.Unknown1.Copy().(*types.List[*types.PrimitiveU32]) + copied.Timestamp = spplp.Timestamp.Copy().(*types.DateTime) + copied.Unknown2 = spplp.Unknown2.Copy().(*types.String) + + return copied +} + +// Equals checks if the given ShopPostPlayLogParam contains the same data as the current ShopPostPlayLogParam +func (spplp *ShopPostPlayLogParam) Equals(o types.RVType) bool { + if _, ok := o.(*ShopPostPlayLogParam); !ok { + return false + } + + other := o.(*ShopPostPlayLogParam) + + if spplp.StructureVersion != other.StructureVersion { + return false + } + + if !spplp.Unknown1.Equals(other.Unknown1) { + return false + } + + if !spplp.Timestamp.Equals(other.Timestamp) { + return false + } + + return spplp.Unknown2.Equals(other.Unknown2) +} + +// String returns the string representation of the ShopPostPlayLogParam +func (spplp *ShopPostPlayLogParam) String() string { + return spplp.FormatToString(0) +} + +// FormatToString pretty-prints the ShopPostPlayLogParam using the provided indentation level +func (spplp *ShopPostPlayLogParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ShopPostPlayLogParam{\n") + b.WriteString(fmt.Sprintf("%sUnknown1: %s,\n", indentationValues, spplp.Unknown1)) + b.WriteString(fmt.Sprintf("%sTimestamp: %s,\n", indentationValues, spplp.Timestamp.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, spplp.Unknown2)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewShopPostPlayLogParam returns a new ShopPostPlayLogParam +func NewShopPostPlayLogParam() *ShopPostPlayLogParam { + spplp := &ShopPostPlayLogParam{ + Unknown1: types.NewList[*types.PrimitiveU32](), + Timestamp: types.NewDateTime(0), + Unknown2: types.NewString(""), + } + + spplp.Unknown1.Type = types.NewPrimitiveU32(0) + + return spplp +} diff --git a/nex-protocols-go/shop/protocol.go b/nex-protocols-go/shop/protocol.go new file mode 100644 index 0000000..d9bcd3a --- /dev/null +++ b/nex-protocols-go/shop/protocol.go @@ -0,0 +1,58 @@ +// Package protocol implements the Shop protocol +package protocol + +// * Stubbed, Kinnay documents this as being game-specific for Pokemon bank however Badge Arcade and Pokemon gen 7 uses this protocol as well +// TODO - Figure out more about this protocol, unsure if anything here is right + +import ( + "fmt" + "slices" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the Protocol ID for the Shop protocol + ProtocolID = 0xC8 +) + +// Protocol stores all the RMC method handlers for the Shop protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + default: + errMessage := fmt.Sprintf("Shop method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} diff --git a/nex-protocols-go/shop/types/shop_item.go b/nex-protocols-go/shop/types/shop_item.go new file mode 100644 index 0000000..2d9c0d9 --- /dev/null +++ b/nex-protocols-go/shop/types/shop_item.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the Shop protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ShopItem is a type within the Shop protocol +type ShopItem struct { + types.Structure + ItemID *types.PrimitiveU32 + ReferenceID *types.QBuffer + ServiceName *types.String + ItemCode *types.String +} + +// WriteTo writes the ShopItem to the given writable +func (si *ShopItem) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + si.ItemID.WriteTo(contentWritable) + si.ReferenceID.WriteTo(contentWritable) + si.ServiceName.WriteTo(contentWritable) + si.ItemCode.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + si.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ShopItem from the given readable +func (si *ShopItem) ExtractFrom(readable types.Readable) error { + var err error + + err = si.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ShopItem header. %s", err.Error()) + } + + err = si.ItemID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ShopItem.ItemID. %s", err.Error()) + } + + err = si.ReferenceID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ShopItem.ReferenceID. %s", err.Error()) + } + + err = si.ServiceName.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ShopItem.ServiceName. %s", err.Error()) + } + + err = si.ItemCode.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ShopItem.ItemCode. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ShopItem +func (si *ShopItem) Copy() types.RVType { + copied := NewShopItem() + + copied.StructureVersion = si.StructureVersion + copied.ItemID = si.ItemID.Copy().(*types.PrimitiveU32) + copied.ReferenceID = si.ReferenceID.Copy().(*types.QBuffer) + copied.ServiceName = si.ServiceName.Copy().(*types.String) + copied.ItemCode = si.ItemCode.Copy().(*types.String) + + return copied +} + +// Equals checks if the given ShopItem contains the same data as the current ShopItem +func (si *ShopItem) Equals(o types.RVType) bool { + if _, ok := o.(*ShopItem); !ok { + return false + } + + other := o.(*ShopItem) + + if si.StructureVersion != other.StructureVersion { + return false + } + + if !si.ItemID.Equals(other.ItemID) { + return false + } + + if !si.ReferenceID.Equals(other.ReferenceID) { + return false + } + + if !si.ServiceName.Equals(other.ServiceName) { + return false + } + + return si.ItemCode.Equals(other.ItemCode) +} + +// String returns the string representation of the ShopItem +func (si *ShopItem) String() string { + return si.FormatToString(0) +} + +// FormatToString pretty-prints the ShopItem using the provided indentation level +func (si *ShopItem) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ShopItem{\n") + b.WriteString(fmt.Sprintf("%sItemID: %s,\n", indentationValues, si.ItemID)) + b.WriteString(fmt.Sprintf("%sReferenceID: %s,\n", indentationValues, si.ReferenceID)) + b.WriteString(fmt.Sprintf("%sServiceName: %s,\n", indentationValues, si.ServiceName)) + b.WriteString(fmt.Sprintf("%sItemCode: %s,\n", indentationValues, si.ItemCode)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewShopItem returns a new ShopItem +func NewShopItem() *ShopItem { + si := &ShopItem{ + ItemID: types.NewPrimitiveU32(0), + ReferenceID: types.NewQBuffer(nil), + ServiceName: types.NewString(""), + ItemCode: types.NewString(""), + } + + return si +} diff --git a/nex-protocols-go/shop/types/shop_item_rights.go b/nex-protocols-go/shop/types/shop_item_rights.go new file mode 100644 index 0000000..f60fe91 --- /dev/null +++ b/nex-protocols-go/shop/types/shop_item_rights.go @@ -0,0 +1,126 @@ +// Package types implements all the types used by the Shop protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// ShopItemRights is a type within the Shop protocol +type ShopItemRights struct { + types.Structure + ReferenceID *types.QBuffer + ItemType *types.PrimitiveS8 + Attribute *types.PrimitiveU32 +} + +// WriteTo writes the ShopItemRights to the given writable +func (sir *ShopItemRights) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sir.ReferenceID.WriteTo(contentWritable) + sir.ItemType.WriteTo(contentWritable) + sir.Attribute.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sir.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the ShopItemRights from the given readable +func (sir *ShopItemRights) ExtractFrom(readable types.Readable) error { + var err error + + err = sir.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ShopItemRights header. %s", err.Error()) + } + + err = sir.ReferenceID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ShopItemRights.ReferenceID. %s", err.Error()) + } + + err = sir.ItemType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ShopItemRights.ItemType. %s", err.Error()) + } + + err = sir.Attribute.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract ShopItemRights.Attribute. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of ShopItemRights +func (sir *ShopItemRights) Copy() types.RVType { + copied := NewShopItemRights() + + copied.StructureVersion = sir.StructureVersion + copied.ReferenceID = sir.ReferenceID.Copy().(*types.QBuffer) + copied.ItemType = sir.ItemType.Copy().(*types.PrimitiveS8) + copied.Attribute = sir.Attribute.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given ShopItemRights contains the same data as the current ShopItemRights +func (sir *ShopItemRights) Equals(o types.RVType) bool { + if _, ok := o.(*ShopItemRights); !ok { + return false + } + + other := o.(*ShopItemRights) + + if sir.StructureVersion != other.StructureVersion { + return false + } + + if !sir.ReferenceID.Equals(other.ReferenceID) { + return false + } + + if !sir.ItemType.Equals(other.ItemType) { + return false + } + + return sir.Attribute.Equals(other.Attribute) +} + +// String returns the string representation of the ShopItemRights +func (sir *ShopItemRights) String() string { + return sir.FormatToString(0) +} + +// FormatToString pretty-prints the ShopItemRights using the provided indentation level +func (sir *ShopItemRights) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("ShopItemRights{\n") + b.WriteString(fmt.Sprintf("%sReferenceID: %s,\n", indentationValues, sir.ReferenceID)) + b.WriteString(fmt.Sprintf("%sItemType: %s,\n", indentationValues, sir.ItemType)) + b.WriteString(fmt.Sprintf("%sAttribute: %s,\n", indentationValues, sir.Attribute)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewShopItemRights returns a new ShopItemRights +func NewShopItemRights() *ShopItemRights { + sir := &ShopItemRights{ + ReferenceID: types.NewQBuffer(nil), + ItemType: types.NewPrimitiveS8(0), + Attribute: types.NewPrimitiveU32(0), + } + + return sir +} diff --git a/nex-protocols-go/storage-manager/acquire_card_id.go b/nex-protocols-go/storage-manager/acquire_card_id.go new file mode 100644 index 0000000..4df4f85 --- /dev/null +++ b/nex-protocols-go/storage-manager/acquire_card_id.go @@ -0,0 +1,29 @@ +// Package protocol implements the StorageManager protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAcquireCardID(packet nex.PacketInterface) { + if protocol.AcquireCardID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "StorageManager::AcquireCardID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.AcquireCardID(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/storage-manager/activate_with_card_id.go b/nex-protocols-go/storage-manager/activate_with_card_id.go new file mode 100644 index 0000000..fbd3afa --- /dev/null +++ b/nex-protocols-go/storage-manager/activate_with_card_id.go @@ -0,0 +1,60 @@ +// Package protocol implements the StorageManager protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleActivateWithCardID(packet nex.PacketInterface) { + if protocol.ActivateWithCardID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "StorageManager::ActivateWithCardID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + unknown := types.NewPrimitiveU8(0) + cardID := types.NewPrimitiveU64(0) + + var err error + + err = unknown.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ActivateWithCardID(fmt.Errorf("Failed to read unknown from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = cardID.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.ActivateWithCardID(fmt.Errorf("Failed to read cardID from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.ActivateWithCardID(nil, packet, callID, unknown, cardID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/storage-manager/protocol.go b/nex-protocols-go/storage-manager/protocol.go new file mode 100644 index 0000000..80a65eb --- /dev/null +++ b/nex-protocols-go/storage-manager/protocol.go @@ -0,0 +1,91 @@ +// Package protocol implements the StorageManager protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the StorageManager protocol + ProtocolID = 0x6E + + // MethodAcquireCardID is the method ID for the method AcquireCardID + MethodAcquireCardID = 0x4 + + // MethodActivateWithCardID is the method ID for the method ActivateWithCardID + MethodActivateWithCardID = 0x5 +) + +// Protocol stores all the RMC method handlers for the StorageManager protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + AcquireCardID func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + ActivateWithCardID func(err error, packet nex.PacketInterface, callID uint32, unknown *types.PrimitiveU8, cardID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the StorageManager protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerAcquireCardID(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerActivateWithCardID(handler func(err error, packet nex.PacketInterface, callID uint32, unknown *types.PrimitiveU8, cardID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerAcquireCardID sets the handler for the AcquireCardID method +func (protocol *Protocol) SetHandlerAcquireCardID(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.AcquireCardID = handler +} + +// SetHandlerActivateWithCardID sets the handler for the ActivateWithCardID method +func (protocol *Protocol) SetHandlerActivateWithCardID(handler func(err error, packet nex.PacketInterface, callID uint32, unknown *types.PrimitiveU8, cardID *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.ActivateWithCardID = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodAcquireCardID: + protocol.handleAcquireCardID(packet) + case MethodActivateWithCardID: + protocol.handleActivateWithCardID(packet) + default: + errMessage := fmt.Sprintf("Unsupported StorageManager method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new StorageManager protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/subscriber/delete_content.go b/nex-protocols-go/subscriber/delete_content.go new file mode 100644 index 0000000..422dda2 --- /dev/null +++ b/nex-protocols-go/subscriber/delete_content.go @@ -0,0 +1,61 @@ +// Package protocol implements the Subscriber protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleDeleteContent(packet nex.PacketInterface) { + if protocol.DeleteContent == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Subscriber::DeleteContent not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + unknown1 := types.NewList[*types.String]() + unknown1.Type = types.NewString("") + unknown2 := types.NewPrimitiveU64(0) + + var err error + + err = unknown1.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteContent(fmt.Errorf("Failed to read unknown1 from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = unknown2.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.DeleteContent(fmt.Errorf("Failed to read unknown2 from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.DeleteContent(nil, packet, callID, unknown1, unknown2) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscriber/follow.go b/nex-protocols-go/subscriber/follow.go new file mode 100644 index 0000000..ef63ac3 --- /dev/null +++ b/nex-protocols-go/subscriber/follow.go @@ -0,0 +1,31 @@ +// Package protocol implements the Subscriber protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleFollow(packet nex.PacketInterface) { + if protocol.Follow == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Subscriber::Follow not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("Subscriber::Follow STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.Follow(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscriber/get_content.go b/nex-protocols-go/subscriber/get_content.go new file mode 100644 index 0000000..f32b513 --- /dev/null +++ b/nex-protocols-go/subscriber/get_content.go @@ -0,0 +1,47 @@ +// Package protocol implements the Subscriber protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + subscriber_types "github.com/PretendoNetwork/nex-protocols-go/v2/subscriber/types" +) + +func (protocol *Protocol) handleGetContent(packet nex.PacketInterface) { + if protocol.GetContent == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Subscriber::GetContent not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := subscriber_types.NewSubscriberGetContentParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetContent(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetContent(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscriber/get_content_multi.go b/nex-protocols-go/subscriber/get_content_multi.go new file mode 100644 index 0000000..4af1cc6 --- /dev/null +++ b/nex-protocols-go/subscriber/get_content_multi.go @@ -0,0 +1,49 @@ +// Package protocol implements the Subscriber protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + subscriber_types "github.com/PretendoNetwork/nex-protocols-go/v2/subscriber/types" +) + +func (protocol *Protocol) handleGetContentMulti(packet nex.PacketInterface) { + if protocol.GetContentMulti == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Subscriber::GetContentMulti not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + params := types.NewList[*subscriber_types.SubscriberGetContentParam]() + params.Type = subscriber_types.NewSubscriberGetContentParam() + + err := params.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetContentMulti(fmt.Errorf("Failed to read params from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetContentMulti(nil, packet, callID, params) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscriber/get_follower.go b/nex-protocols-go/subscriber/get_follower.go new file mode 100644 index 0000000..8bee89c --- /dev/null +++ b/nex-protocols-go/subscriber/get_follower.go @@ -0,0 +1,31 @@ +// Package protocol implements the Subscriber protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetFollower(packet nex.PacketInterface) { + if protocol.GetFollower == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Subscriber::GetFollower not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("Subscriber::GetFollower STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetFollower(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscriber/get_following.go b/nex-protocols-go/subscriber/get_following.go new file mode 100644 index 0000000..d22228d --- /dev/null +++ b/nex-protocols-go/subscriber/get_following.go @@ -0,0 +1,31 @@ +// Package protocol implements the Subscriber protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetFollowing(packet nex.PacketInterface) { + if protocol.GetFollowing == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Subscriber::GetFollowing not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("Subscriber::GetFollowing STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetFollowing(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscriber/get_friend_user_statuses.go b/nex-protocols-go/subscriber/get_friend_user_statuses.go new file mode 100644 index 0000000..86a3c9d --- /dev/null +++ b/nex-protocols-go/subscriber/get_friend_user_statuses.go @@ -0,0 +1,48 @@ +// Package protocol implements the Subscriber protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetFriendUserStatuses(packet nex.PacketInterface) { + if protocol.GetFriendUserStatuses == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Subscriber::GetFriendUserStatuses not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + unknown := types.NewList[*types.PrimitiveU8]() + unknown.Type = types.NewPrimitiveU8(0) + + err := unknown.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetFriendUserStatuses(fmt.Errorf("Failed to read unknown from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetFriendUserStatuses(nil, packet, callID, unknown) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscriber/get_num_followers.go b/nex-protocols-go/subscriber/get_num_followers.go new file mode 100644 index 0000000..63bb86e --- /dev/null +++ b/nex-protocols-go/subscriber/get_num_followers.go @@ -0,0 +1,31 @@ +// Package protocol implements the Subscriber protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetNumFollowers(packet nex.PacketInterface) { + if protocol.GetNumFollowers == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Subscriber::GetNumFollowers not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("Subscriber::GetNumFollowers STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetNumFollowers(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscriber/get_timeline.go b/nex-protocols-go/subscriber/get_timeline.go new file mode 100644 index 0000000..897fbe1 --- /dev/null +++ b/nex-protocols-go/subscriber/get_timeline.go @@ -0,0 +1,31 @@ +// Package protocol implements the Subscriber protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetTimeline(packet nex.PacketInterface) { + if protocol.GetTimeline == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Subscriber::GetTimeline not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("Subscriber::GetTimeline STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetTimeline(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscriber/get_user_statuses.go b/nex-protocols-go/subscriber/get_user_statuses.go new file mode 100644 index 0000000..f0f1892 --- /dev/null +++ b/nex-protocols-go/subscriber/get_user_statuses.go @@ -0,0 +1,62 @@ +// Package protocol implements the Subscriber protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetUserStatuses(packet nex.PacketInterface) { + if protocol.GetUserStatuses == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Subscriber::GetUserStatuses not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pids := types.NewList[*types.PID]() + pids.Type = types.NewPID(0) + unknown := types.NewList[*types.PrimitiveU8]() + unknown.Type = types.NewPrimitiveU8(0) + + var err error + + err = pids.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetUserStatuses(fmt.Errorf("Failed to read pids from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = unknown.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetUserStatuses(fmt.Errorf("Failed to read unknown from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetUserStatuses(nil, packet, callID, pids, unknown) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscriber/hello.go b/nex-protocols-go/subscriber/hello.go new file mode 100644 index 0000000..ed46341 --- /dev/null +++ b/nex-protocols-go/subscriber/hello.go @@ -0,0 +1,47 @@ +// Package protocol implements the Subscriber protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleHello(packet nex.PacketInterface) { + if protocol.Hello == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Subscriber::Hello not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + unknown := types.NewString("") + + err := unknown.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.Hello(fmt.Errorf("Failed to read unknown from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.Hello(nil, packet, callID, unknown) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscriber/post_content.go b/nex-protocols-go/subscriber/post_content.go new file mode 100644 index 0000000..3237237 --- /dev/null +++ b/nex-protocols-go/subscriber/post_content.go @@ -0,0 +1,47 @@ +// Package protocol implements the Subscriber protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + subscriber_types "github.com/PretendoNetwork/nex-protocols-go/v2/subscriber/types" +) + +func (protocol *Protocol) handlePostContent(packet nex.PacketInterface) { + if protocol.PostContent == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Subscriber::PostContent not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + param := subscriber_types.NewSubscriberPostContentParam() + + err := param.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.PostContent(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.PostContent(nil, packet, callID, param) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscriber/protocol.go b/nex-protocols-go/subscriber/protocol.go new file mode 100644 index 0000000..afdf24d --- /dev/null +++ b/nex-protocols-go/subscriber/protocol.go @@ -0,0 +1,248 @@ +// Package protocol implements the Subscriber protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + subscriber_types "github.com/PretendoNetwork/nex-protocols-go/v2/subscriber/types" +) + +const ( + // ProtocolID is the protocol ID for the Subscriber protocol + ProtocolID = 0x6E + + // MethodHello is the method ID for the method Hello + MethodHello = 0x1 + + // MethodPostContent is the method ID for the method PostContent + MethodPostContent = 0x2 + + // MethodGetContent is the method ID for the method GetContent + MethodGetContent = 0x3 + + // MethodFollow is the method ID for the method Follow + MethodFollow = 0x4 + + // MethodUnfollowAllAndFollow is the method ID for the method UnfollowAllAndFollow + MethodUnfollowAllAndFollow = 0x5 + + // MethodUnfollow is the method ID for the method Unfollow + MethodUnfollow = 0x6 + + // MethodGetFollowing is the method ID for the method GetFollowing + MethodGetFollowing = 0x7 + + // MethodGetFollower is the method ID for the method GetFollower + MethodGetFollower = 0x8 + + // MethodGetNumFollowers is the method ID for the method GetNumFollowers + MethodGetNumFollowers = 0x9 + + // MethodGetTimeline is the method ID for the method GetTimeline + MethodGetTimeline = 0xA + + // MethodDeleteContent is the method ID for the method DeleteContent + MethodDeleteContent = 0xB + + // MethodGetContentMulti is the method ID for the method GetContentMulti + MethodGetContentMulti = 0xC + + // MethodUpdateUserStatus is the method ID for the method UpdateUserStatus + MethodUpdateUserStatus = 0xD + + // MethodGetFriendUserStatuses is the method ID for the method GetFriendUserStatuses + MethodGetFriendUserStatuses = 0xE + + // MethodGetUserStatuses is the method ID for the method GetUserStatuses + MethodGetUserStatuses = 0xF +) + +// Protocol stores all the RMC method handlers for the Subscriber protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + Hello func(err error, packet nex.PacketInterface, callID uint32, unknown *types.String) (*nex.RMCMessage, *nex.Error) + PostContent func(err error, packet nex.PacketInterface, callID uint32, param *subscriber_types.SubscriberPostContentParam) (*nex.RMCMessage, *nex.Error) + GetContent func(err error, packet nex.PacketInterface, callID uint32, param *subscriber_types.SubscriberGetContentParam) (*nex.RMCMessage, *nex.Error) + Follow func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + UnfollowAllAndFollow func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + Unfollow func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + GetFollowing func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + GetFollower func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + GetNumFollowers func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + GetTimeline func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error) + DeleteContent func(err error, packet nex.PacketInterface, callID uint32, unknown1 *types.List[*types.String], unknown2 *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error) + GetContentMulti func(err error, packet nex.PacketInterface, callID uint32, params *types.List[*subscriber_types.SubscriberGetContentParam]) (*nex.RMCMessage, *nex.Error) + UpdateUserStatus func(err error, packet nex.PacketInterface, callID uint32, unknown1 *types.List[*subscriber_types.Unknown], unknown2 *types.List[*types.PrimitiveU8]) (*nex.RMCMessage, *nex.Error) + GetFriendUserStatuses func(err error, packet nex.PacketInterface, callID uint32, unknown *types.List[*types.PrimitiveU8]) (*nex.RMCMessage, *nex.Error) + GetUserStatuses func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID], unknown *types.List[*types.PrimitiveU8]) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Subscriber protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerHello(handler func(err error, packet nex.PacketInterface, callID uint32, unknown *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerPostContent(handler func(err error, packet nex.PacketInterface, callID uint32, param *subscriber_types.SubscriberPostContentParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetContent(handler func(err error, packet nex.PacketInterface, callID uint32, param *subscriber_types.SubscriberGetContentParam) (*nex.RMCMessage, *nex.Error)) + SetHandlerFollow(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) + SetHandlerUnfollowAllAndFollow(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) + SetHandlerUnfollow(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetFollowing(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetFollower(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetNumFollowers(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetTimeline(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) + SetHandlerDeleteContent(handler func(err error, packet nex.PacketInterface, callID uint32, unknown1 *types.List[*types.String], unknown2 *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetContentMulti(handler func(err error, packet nex.PacketInterface, callID uint32, params *types.List[*subscriber_types.SubscriberGetContentParam]) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateUserStatus(handler func(err error, packet nex.PacketInterface, callID uint32, unknown1 *types.List[*subscriber_types.Unknown], unknown2 *types.List[*types.PrimitiveU8]) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetFriendUserStatuses(handler func(err error, packet nex.PacketInterface, callID uint32, unknown *types.List[*types.PrimitiveU8]) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetUserStatuses(handler func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID], unknown *types.List[*types.PrimitiveU8]) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerHello sets the handler for the Hello method +func (protocol *Protocol) SetHandlerHello(handler func(err error, packet nex.PacketInterface, callID uint32, unknown *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.Hello = handler +} + +// SetHandlerPostContent sets the handler for the PostContent method +func (protocol *Protocol) SetHandlerPostContent(handler func(err error, packet nex.PacketInterface, callID uint32, param *subscriber_types.SubscriberPostContentParam) (*nex.RMCMessage, *nex.Error)) { + protocol.PostContent = handler +} + +// SetHandlerGetContent sets the handler for the GetContent method +func (protocol *Protocol) SetHandlerGetContent(handler func(err error, packet nex.PacketInterface, callID uint32, param *subscriber_types.SubscriberGetContentParam) (*nex.RMCMessage, *nex.Error)) { + protocol.GetContent = handler +} + +// SetHandlerFollow sets the handler for the Follow method +func (protocol *Protocol) SetHandlerFollow(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) { + protocol.Follow = handler +} + +// SetHandlerUnfollowAllAndFollow sets the handler for the UnfollowAllAndFollow method +func (protocol *Protocol) SetHandlerUnfollowAllAndFollow(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) { + protocol.UnfollowAllAndFollow = handler +} + +// SetHandlerUnfollow sets the handler for the Unfollow method +func (protocol *Protocol) SetHandlerUnfollow(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) { + protocol.Unfollow = handler +} + +// SetHandlerGetFollowing sets the handler for the GetFollowing method +func (protocol *Protocol) SetHandlerGetFollowing(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) { + protocol.GetFollowing = handler +} + +// SetHandlerGetFollower sets the handler for the GetFollower method +func (protocol *Protocol) SetHandlerGetFollower(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) { + protocol.GetFollower = handler +} + +// SetHandlerGetNumFollowers sets the handler for the GetNumFollowers method +func (protocol *Protocol) SetHandlerGetNumFollowers(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) { + protocol.GetNumFollowers = handler +} + +// SetHandlerGetTimeline sets the handler for the GetTimeline method +func (protocol *Protocol) SetHandlerGetTimeline(handler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) (*nex.RMCMessage, *nex.Error)) { + protocol.GetTimeline = handler +} + +// SetHandlerDeleteContent sets the handler for the DeleteContent method +func (protocol *Protocol) SetHandlerDeleteContent(handler func(err error, packet nex.PacketInterface, callID uint32, unknown1 *types.List[*types.String], unknown2 *types.PrimitiveU64) (*nex.RMCMessage, *nex.Error)) { + protocol.DeleteContent = handler +} + +// SetHandlerGetContentMulti sets the handler for the GetContentMulti method +func (protocol *Protocol) SetHandlerGetContentMulti(handler func(err error, packet nex.PacketInterface, callID uint32, params *types.List[*subscriber_types.SubscriberGetContentParam]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetContentMulti = handler +} + +// SetHandlerUpdateUserStatus sets the handler for the UpdateUserStatus method +func (protocol *Protocol) SetHandlerUpdateUserStatus(handler func(err error, packet nex.PacketInterface, callID uint32, unknown1 *types.List[*subscriber_types.Unknown], unknown2 *types.List[*types.PrimitiveU8]) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateUserStatus = handler +} + +// SetHandlerGetFriendUserStatuses sets the handler for the GetFriendUserStatuses method +func (protocol *Protocol) SetHandlerGetFriendUserStatuses(handler func(err error, packet nex.PacketInterface, callID uint32, unknown *types.List[*types.PrimitiveU8]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetFriendUserStatuses = handler +} + +// SetHandlerGetUserStatuses sets the handler for the GetUserStatuses method +func (protocol *Protocol) SetHandlerGetUserStatuses(handler func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PID], unknown *types.List[*types.PrimitiveU8]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetUserStatuses = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodHello: + protocol.handleHello(packet) + case MethodPostContent: + protocol.handlePostContent(packet) + case MethodGetContent: + protocol.handleGetContent(packet) + case MethodFollow: + protocol.handleFollow(packet) + case MethodUnfollowAllAndFollow: + protocol.handleUnfollowAllAndFollow(packet) + case MethodUnfollow: + protocol.handleUnfollow(packet) + case MethodGetFollowing: + protocol.handleGetFollowing(packet) + case MethodGetFollower: + protocol.handleGetFollower(packet) + case MethodGetNumFollowers: + protocol.handleGetNumFollowers(packet) + case MethodGetTimeline: + protocol.handleGetTimeline(packet) + case MethodDeleteContent: + protocol.handleDeleteContent(packet) + case MethodGetContentMulti: + protocol.handleGetContentMulti(packet) + case MethodUpdateUserStatus: + protocol.handleUpdateUserStatus(packet) + case MethodGetFriendUserStatuses: + protocol.handleGetFriendUserStatuses(packet) + case MethodGetUserStatuses: + protocol.handleGetUserStatuses(packet) + default: + errMessage := fmt.Sprintf("Unsupported Subscriber method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Subscriber protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/subscriber/types/subscriber_content.go b/nex-protocols-go/subscriber/types/subscriber_content.go new file mode 100644 index 0000000..a70ad83 --- /dev/null +++ b/nex-protocols-go/subscriber/types/subscriber_content.go @@ -0,0 +1,170 @@ +// Package types implements all the types used by the Shop protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// SubscriberContent is a type within the Shop protocol +type SubscriberContent struct { + types.Structure + Unknown1 *types.PrimitiveU64 + Unknown2 *types.String + Unknown3 *types.Buffer + Unknown4 *types.PrimitiveU64 + Unknown5 *types.List[*types.String] + Unknown6 *types.DateTime +} + +// WriteTo writes the SubscriberContent to the given writable +func (sc *SubscriberContent) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sc.Unknown1.WriteTo(contentWritable) + sc.Unknown2.WriteTo(contentWritable) + sc.Unknown3.WriteTo(contentWritable) + sc.Unknown4.WriteTo(contentWritable) + sc.Unknown5.WriteTo(contentWritable) + sc.Unknown6.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sc.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the SubscriberContent from the given readable +func (sc *SubscriberContent) ExtractFrom(readable types.Readable) error { + var err error + + err = sc.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberContent header. %s", err.Error()) + } + + err = sc.Unknown1.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberContent.Unknown1. %s", err.Error()) + } + + err = sc.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberContent.Unknown2. %s", err.Error()) + } + + err = sc.Unknown3.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberContent.Unknown3. %s", err.Error()) + } + + err = sc.Unknown4.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberContent.Unknown4. %s", err.Error()) + } + + err = sc.Unknown5.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberContent.Unknown5. %s", err.Error()) + } + + err = sc.Unknown6.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberContent.Unknown6. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of SubscriberContent +func (sc *SubscriberContent) Copy() types.RVType { + copied := NewSubscriberContent() + + copied.StructureVersion = sc.StructureVersion + copied.Unknown1 = sc.Unknown1.Copy().(*types.PrimitiveU64) + copied.Unknown2 = sc.Unknown2.Copy().(*types.String) + copied.Unknown3 = sc.Unknown3.Copy().(*types.Buffer) + copied.Unknown4 = sc.Unknown4.Copy().(*types.PrimitiveU64) + copied.Unknown5 = sc.Unknown5.Copy().(*types.List[*types.String]) + copied.Unknown6 = sc.Unknown6.Copy().(*types.DateTime) + + return copied +} + +// Equals checks if the given SubscriberContent contains the same data as the current SubscriberContent +func (sc *SubscriberContent) Equals(o types.RVType) bool { + if _, ok := o.(*SubscriberContent); !ok { + return false + } + + other := o.(*SubscriberContent) + + if sc.StructureVersion != other.StructureVersion { + return false + } + + if !sc.Unknown1.Equals(other.Unknown1) { + return false + } + + if !sc.Unknown2.Equals(other.Unknown2) { + return false + } + + if !sc.Unknown3.Equals(other.Unknown3) { + return false + } + + if !sc.Unknown4.Equals(other.Unknown4) { + return false + } + + if !sc.Unknown5.Equals(other.Unknown5) { + return false + } + + return sc.Unknown6.Equals(other.Unknown6) +} + +// String returns the string representation of the SubscriberContent +func (sc *SubscriberContent) String() string { + return sc.FormatToString(0) +} + +// FormatToString pretty-prints the SubscriberContent using the provided indentation level +func (sc *SubscriberContent) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("SubscriberContent{\n") + b.WriteString(fmt.Sprintf("%sUnknown1: %s,\n", indentationValues, sc.Unknown1)) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, sc.Unknown2)) + b.WriteString(fmt.Sprintf("%sUnknown3: %s,\n", indentationValues, sc.Unknown3)) + b.WriteString(fmt.Sprintf("%sUnknown4: %s,\n", indentationValues, sc.Unknown4)) + b.WriteString(fmt.Sprintf("%sUnknown5: %s,\n", indentationValues, sc.Unknown5)) + b.WriteString(fmt.Sprintf("%sUnknown6: %s,\n", indentationValues, sc.Unknown6.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewSubscriberContent returns a new SubscriberContent +func NewSubscriberContent() *SubscriberContent { + sc := &SubscriberContent{ + Unknown1: types.NewPrimitiveU64(0), + Unknown2: types.NewString(""), + Unknown3: types.NewBuffer(nil), + Unknown4: types.NewPrimitiveU64(0), + Unknown5: types.NewList[*types.String](), + Unknown6: types.NewDateTime(0), + } + + sc.Unknown5.Type = types.NewString("") + + return sc +} diff --git a/nex-protocols-go/subscriber/types/subscriber_get_content_param.go b/nex-protocols-go/subscriber/types/subscriber_get_content_param.go new file mode 100644 index 0000000..0fa3789 --- /dev/null +++ b/nex-protocols-go/subscriber/types/subscriber_get_content_param.go @@ -0,0 +1,140 @@ +// Package types implements all the types used by the Shop protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// SubscriberGetContentParam is a type within the Shop protocol +type SubscriberGetContentParam struct { + types.Structure + Unknown1 *types.String + Unknown2 *types.PrimitiveU32 + Unknown3 *types.PrimitiveU32 + Unknown4 *types.PrimitiveU64 +} + +// WriteTo writes the SubscriberGetContentParam to the given writable +func (sgcp *SubscriberGetContentParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + sgcp.Unknown1.WriteTo(contentWritable) + sgcp.Unknown2.WriteTo(contentWritable) + sgcp.Unknown3.WriteTo(contentWritable) + sgcp.Unknown4.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + sgcp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the SubscriberGetContentParam from the given readable +func (sgcp *SubscriberGetContentParam) ExtractFrom(readable types.Readable) error { + var err error + + err = sgcp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberGetContentParam header. %s", err.Error()) + } + + err = sgcp.Unknown1.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberGetContentParam.Unknown1. %s", err.Error()) + } + + err = sgcp.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberGetContentParam.Unknown2. %s", err.Error()) + } + + err = sgcp.Unknown3.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberGetContentParam.Unknown3. %s", err.Error()) + } + + err = sgcp.Unknown4.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberGetContentParam.Unknown4. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of SubscriberGetContentParam +func (sgcp *SubscriberGetContentParam) Copy() types.RVType { + copied := NewSubscriberGetContentParam() + + copied.StructureVersion = sgcp.StructureVersion + copied.Unknown1 = sgcp.Unknown1.Copy().(*types.String) + copied.Unknown2 = sgcp.Unknown2.Copy().(*types.PrimitiveU32) + copied.Unknown3 = sgcp.Unknown3.Copy().(*types.PrimitiveU32) + copied.Unknown4 = sgcp.Unknown4.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given SubscriberGetContentParam contains the same data as the current SubscriberGetContentParam +func (sgcp *SubscriberGetContentParam) Equals(o types.RVType) bool { + if _, ok := o.(*SubscriberGetContentParam); !ok { + return false + } + + other := o.(*SubscriberGetContentParam) + + if sgcp.StructureVersion != other.StructureVersion { + return false + } + + if !sgcp.Unknown1.Equals(other.Unknown1) { + return false + } + + if !sgcp.Unknown2.Equals(other.Unknown2) { + return false + } + + if !sgcp.Unknown3.Equals(other.Unknown3) { + return false + } + + return sgcp.Unknown4.Equals(other.Unknown4) +} + +// String returns the string representation of the SubscriberGetContentParam +func (sgcp *SubscriberGetContentParam) String() string { + return sgcp.FormatToString(0) +} + +// FormatToString pretty-prints the SubscriberGetContentParam using the provided indentation level +func (sgcp *SubscriberGetContentParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("SubscriberGetContentParam{\n") + b.WriteString(fmt.Sprintf("%sUnknown1: %s,\n", indentationValues, sgcp.Unknown1)) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, sgcp.Unknown2)) + b.WriteString(fmt.Sprintf("%sUnknown3: %s,\n", indentationValues, sgcp.Unknown3)) + b.WriteString(fmt.Sprintf("%sUnknown4: %s,\n", indentationValues, sgcp.Unknown4)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewSubscriberGetContentParam returns a new SubscriberGetContentParam +func NewSubscriberGetContentParam() *SubscriberGetContentParam { + sgcp := &SubscriberGetContentParam{ + Unknown1: types.NewString(""), + Unknown2: types.NewPrimitiveU32(0), + Unknown3: types.NewPrimitiveU32(0), + Unknown4: types.NewPrimitiveU64(0), + } + + return sgcp +} diff --git a/nex-protocols-go/subscriber/types/subscriber_post_content_param.go b/nex-protocols-go/subscriber/types/subscriber_post_content_param.go new file mode 100644 index 0000000..dd3cab1 --- /dev/null +++ b/nex-protocols-go/subscriber/types/subscriber_post_content_param.go @@ -0,0 +1,128 @@ +// Package types implements all the types used by the Shop protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// SubscriberPostContentParam is a type within the Shop protocol +type SubscriberPostContentParam struct { + types.Structure + Unknown1 *types.List[*types.String] + Unknown2 *types.String + Unknown3 *types.QBuffer +} + +// WriteTo writes the SubscriberPostContentParam to the given writable +func (spcp *SubscriberPostContentParam) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + spcp.Unknown1.WriteTo(contentWritable) + spcp.Unknown2.WriteTo(contentWritable) + spcp.Unknown3.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + spcp.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the SubscriberPostContentParam from the given readable +func (spcp *SubscriberPostContentParam) ExtractFrom(readable types.Readable) error { + var err error + + err = spcp.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberPostContentParam header. %s", err.Error()) + } + + err = spcp.Unknown1.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberPostContentParam.Unknown1. %s", err.Error()) + } + + err = spcp.Unknown2.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberPostContentParam.Unknown2. %s", err.Error()) + } + + err = spcp.Unknown3.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberPostContentParam.Unknown3. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of SubscriberPostContentParam +func (spcp *SubscriberPostContentParam) Copy() types.RVType { + copied := NewSubscriberPostContentParam() + + copied.StructureVersion = spcp.StructureVersion + copied.Unknown1 = spcp.Unknown1.Copy().(*types.List[*types.String]) + copied.Unknown2 = spcp.Unknown2.Copy().(*types.String) + copied.Unknown3 = spcp.Unknown3.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given SubscriberPostContentParam contains the same data as the current SubscriberPostContentParam +func (spcp *SubscriberPostContentParam) Equals(o types.RVType) bool { + if _, ok := o.(*SubscriberPostContentParam); !ok { + return false + } + + other := o.(*SubscriberPostContentParam) + + if spcp.StructureVersion != other.StructureVersion { + return false + } + + if !spcp.Unknown1.Equals(other.Unknown1) { + return false + } + + if !spcp.Unknown2.Equals(other.Unknown2) { + return false + } + + return spcp.Unknown3.Equals(other.Unknown3) +} + +// String returns the string representation of the SubscriberPostContentParam +func (spcp *SubscriberPostContentParam) String() string { + return spcp.FormatToString(0) +} + +// FormatToString pretty-prints the SubscriberPostContentParam using the provided indentation level +func (spcp *SubscriberPostContentParam) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("SubscriberPostContentParam{\n") + b.WriteString(fmt.Sprintf("%sUnknown1: %s,\n", indentationValues, spcp.Unknown1)) + b.WriteString(fmt.Sprintf("%sUnknown2: %s,\n", indentationValues, spcp.Unknown2)) + b.WriteString(fmt.Sprintf("%sUnknown3: %s,\n", indentationValues, spcp.Unknown3)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewSubscriberPostContentParam returns a new SubscriberPostContentParam +func NewSubscriberPostContentParam() *SubscriberPostContentParam { + spcp := &SubscriberPostContentParam{ + Unknown1: types.NewList[*types.String](), + Unknown2: types.NewString(""), + Unknown3: types.NewQBuffer(nil), + } + + spcp.Unknown1.Type = types.NewString("") + + return spcp +} diff --git a/nex-protocols-go/subscriber/types/subscriber_user_status_info.go b/nex-protocols-go/subscriber/types/subscriber_user_status_info.go new file mode 100644 index 0000000..cf86815 --- /dev/null +++ b/nex-protocols-go/subscriber/types/subscriber_user_status_info.go @@ -0,0 +1,114 @@ +// Package types implements all the types used by the Shop protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// SubscriberUserStatusInfo is a type within the Shop protocol +type SubscriberUserStatusInfo struct { + types.Structure + PID *types.PID + Unknown *types.List[*types.QBuffer] +} + +// WriteTo writes the SubscriberUserStatusInfo to the given writable +func (susi *SubscriberUserStatusInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + susi.PID.WriteTo(contentWritable) + susi.Unknown.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + susi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the SubscriberUserStatusInfo from the given readable +func (susi *SubscriberUserStatusInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = susi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberUserStatusInfo header. %s", err.Error()) + } + + err = susi.PID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberUserStatusInfo.PID. %s", err.Error()) + } + + err = susi.Unknown.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract SubscriberUserStatusInfo.Unknown. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of SubscriberUserStatusInfo +func (susi *SubscriberUserStatusInfo) Copy() types.RVType { + copied := NewSubscriberUserStatusInfo() + + copied.StructureVersion = susi.StructureVersion + copied.PID = susi.PID.Copy().(*types.PID) + copied.Unknown = susi.Unknown.Copy().(*types.List[*types.QBuffer]) + + return copied +} + +// Equals checks if the given SubscriberUserStatusInfo contains the same data as the current SubscriberUserStatusInfo +func (susi *SubscriberUserStatusInfo) Equals(o types.RVType) bool { + if _, ok := o.(*SubscriberUserStatusInfo); !ok { + return false + } + + other := o.(*SubscriberUserStatusInfo) + + if susi.StructureVersion != other.StructureVersion { + return false + } + + if !susi.PID.Equals(other.PID) { + return false + } + + return susi.Unknown.Equals(other.Unknown) +} + +// String returns the string representation of the SubscriberUserStatusInfo +func (susi *SubscriberUserStatusInfo) String() string { + return susi.FormatToString(0) +} + +// FormatToString pretty-prints the SubscriberUserStatusInfo using the provided indentation level +func (susi *SubscriberUserStatusInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("SubscriberUserStatusInfo{\n") + b.WriteString(fmt.Sprintf("%sPID: %s,\n", indentationValues, susi.PID.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sUnknown: %s,\n", indentationValues, susi.Unknown)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewSubscriberUserStatusInfo returns a new SubscriberUserStatusInfo +func NewSubscriberUserStatusInfo() *SubscriberUserStatusInfo { + susi := &SubscriberUserStatusInfo{ + PID: types.NewPID(0), + Unknown: types.NewList[*types.QBuffer](), + } + + susi.Unknown.Type = types.NewQBuffer(nil) + + return susi +} diff --git a/nex-protocols-go/subscriber/types/unknown.go b/nex-protocols-go/subscriber/types/unknown.go new file mode 100644 index 0000000..5ae7bb6 --- /dev/null +++ b/nex-protocols-go/subscriber/types/unknown.go @@ -0,0 +1,98 @@ +// Package types implements all the types used by the Shop protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// Unknown is a type within the Shop protocol +type Unknown struct { + types.Structure + Unknown *types.QBuffer +} + +// WriteTo writes the Unknown to the given writable +func (u *Unknown) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + u.Unknown.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + u.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the Unknown from the given readable +func (u *Unknown) ExtractFrom(readable types.Readable) error { + var err error + + err = u.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Unknown header. %s", err.Error()) + } + + err = u.Unknown.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract Unknown.Unknown. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of Unknown +func (u *Unknown) Copy() types.RVType { + copied := NewUnknown() + + copied.StructureVersion = u.StructureVersion + copied.Unknown = u.Unknown.Copy().(*types.QBuffer) + + return copied +} + +// Equals checks if the given Unknown contains the same data as the current Unknown +func (u *Unknown) Equals(o types.RVType) bool { + if _, ok := o.(*Unknown); !ok { + return false + } + + other := o.(*Unknown) + + if u.StructureVersion != other.StructureVersion { + return false + } + + return u.Unknown.Equals(other.Unknown) +} + +// String returns the string representation of the Unknown +func (u *Unknown) String() string { + return u.FormatToString(0) +} + +// FormatToString pretty-prints the Unknown using the provided indentation level +func (u *Unknown) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("Unknown{\n") + b.WriteString(fmt.Sprintf("%sUnknown: %s,\n", indentationValues, u.Unknown)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewUnknown returns a new Unknown +func NewUnknown() *Unknown { + u := &Unknown{ + Unknown: types.NewQBuffer(nil), + } + + return u +} diff --git a/nex-protocols-go/subscriber/unfollow.go b/nex-protocols-go/subscriber/unfollow.go new file mode 100644 index 0000000..a8373a2 --- /dev/null +++ b/nex-protocols-go/subscriber/unfollow.go @@ -0,0 +1,31 @@ +// Package protocol implements the Subscriber protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUnfollow(packet nex.PacketInterface) { + if protocol.Unfollow == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Subscriber::Unfollow not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("Subscriber::Unfollow STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.Unfollow(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscriber/unfollow_all_and_follow.go b/nex-protocols-go/subscriber/unfollow_all_and_follow.go new file mode 100644 index 0000000..1e6fc57 --- /dev/null +++ b/nex-protocols-go/subscriber/unfollow_all_and_follow.go @@ -0,0 +1,31 @@ +// Package protocol implements the Subscriber protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUnfollowAllAndFollow(packet nex.PacketInterface) { + if protocol.UnfollowAllAndFollow == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Subscriber::UnfollowAllAndFollow not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + globals.Logger.Warning("Subscriber::UnfollowAllAndFollow STUBBED") + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.UnfollowAllAndFollow(nil, packet, callID, packet.Payload()) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscriber/update_user_status.go b/nex-protocols-go/subscriber/update_user_status.go new file mode 100644 index 0000000..8067e74 --- /dev/null +++ b/nex-protocols-go/subscriber/update_user_status.go @@ -0,0 +1,63 @@ +// Package protocol implements the Subscriber protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + subscriber_types "github.com/PretendoNetwork/nex-protocols-go/v2/subscriber/types" +) + +func (protocol *Protocol) handleUpdateUserStatus(packet nex.PacketInterface) { + if protocol.UpdateUserStatus == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Subscriber::UpdateUserStatus not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + unknown1 := types.NewList[*subscriber_types.Unknown]() + unknown1.Type = subscriber_types.NewUnknown() + unknown2 := types.NewList[*types.PrimitiveU8]() + unknown2.Type = types.NewPrimitiveU8(0) + + var err error + + err = unknown1.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateUserStatus(fmt.Errorf("Failed to read unknown1 from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = unknown2.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateUserStatus(fmt.Errorf("Failed to read unknown2 from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.UpdateUserStatus(nil, packet, callID, unknown1, unknown2) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscription/create_my_subscription_data.go b/nex-protocols-go/subscription/create_my_subscription_data.go new file mode 100644 index 0000000..4073faa --- /dev/null +++ b/nex-protocols-go/subscription/create_my_subscription_data.go @@ -0,0 +1,52 @@ +// Package protocol implements the Subscription protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleCreateMySubscriptionData(packet nex.PacketInterface) { + if protocol.CreateMySubscriptionData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "SubscriptionProtocol::CreateMySubscriptionData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + unk := types.NewPrimitiveU64(0) + + err := unk.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.CreateMySubscriptionData(fmt.Errorf("Failed to read unk from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + // * This is done since the server doesn't need to care about the data here (it's game-specific), + // * so we just pass it along to store however the handler wants + // TODO - Is this really the best way to do this? + content := parametersStream.ReadRemaining() + + rmcMessage, rmcError := protocol.CreateMySubscriptionData(nil, packet, callID, unk, content) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscription/get_active_player_subscription_data.go b/nex-protocols-go/subscription/get_active_player_subscription_data.go new file mode 100644 index 0000000..643f34d --- /dev/null +++ b/nex-protocols-go/subscription/get_active_player_subscription_data.go @@ -0,0 +1,29 @@ +// Package protocol implements the Subscription protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetActivePlayerSubscriptionData(packet nex.PacketInterface) { + if protocol.GetActivePlayerSubscriptionData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "SubscriptionProtocol::GetActivePlayerSubscriptionData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetActivePlayerSubscriptionData(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscription/get_friend_subscription_data.go b/nex-protocols-go/subscription/get_friend_subscription_data.go new file mode 100644 index 0000000..3488330 --- /dev/null +++ b/nex-protocols-go/subscription/get_friend_subscription_data.go @@ -0,0 +1,29 @@ +// Package protocol implements the Subscription protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetFriendSubscriptionData(packet nex.PacketInterface) { + if protocol.GetFriendSubscriptionData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "SubscriptionProtocol::GetFriendSubscriptionData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetFriendSubscriptionData(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscription/get_privacy_levels.go b/nex-protocols-go/subscription/get_privacy_levels.go new file mode 100644 index 0000000..a098f59 --- /dev/null +++ b/nex-protocols-go/subscription/get_privacy_levels.go @@ -0,0 +1,29 @@ +// Package protocol implements the Subscription protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetPrivacyLevels(packet nex.PacketInterface) { + if protocol.GetPrivacyLevels == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "SubscriptionProtocol::GetPrivacyLevels not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetPrivacyLevels(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscription/get_subscription_data.go b/nex-protocols-go/subscription/get_subscription_data.go new file mode 100644 index 0000000..0bb3f18 --- /dev/null +++ b/nex-protocols-go/subscription/get_subscription_data.go @@ -0,0 +1,48 @@ +// Package protocol implements the Subscription protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetSubscriptionData(packet nex.PacketInterface) { + if protocol.GetSubscriptionData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "SubscriptionProtocol::GetSubscriptionData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + pids := types.NewList[*types.PrimitiveU32]() + pids.Type = types.NewPrimitiveU32(0) + + err := pids.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetSubscriptionData(fmt.Errorf("Failed to read pids from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetSubscriptionData(nil, packet, callID, pids) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscription/get_target_subscription_data.go b/nex-protocols-go/subscription/get_target_subscription_data.go new file mode 100644 index 0000000..165377b --- /dev/null +++ b/nex-protocols-go/subscription/get_target_subscription_data.go @@ -0,0 +1,29 @@ +// Package protocol implements the Subscription protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetTargetSubscriptionData(packet nex.PacketInterface) { + if protocol.GetTargetSubscriptionData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "SubscriptionProtocol::GetTargetSubscriptionData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetTargetSubscriptionData(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscription/protocol.go b/nex-protocols-go/subscription/protocol.go new file mode 100644 index 0000000..67d8c79 --- /dev/null +++ b/nex-protocols-go/subscription/protocol.go @@ -0,0 +1,184 @@ +// Package protocol implements the Subscription protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the Subscription protocol + ProtocolID = 0x75 + + // MethodCreateMySubscriptionData is the method ID for the method CreateMySubscriptionDataID + MethodCreateMySubscriptionData = 0x1 + + // MethodUpdateMySubscriptionData is the method ID for the method UpdateMySubscriptionData + MethodUpdateMySubscriptionData = 0x2 + + // MethodClearMySubscriptionData is the method ID for the method ClearMySubscriptionDataID + MethodClearMySubscriptionData = 0x3 + + // MethodAddTarget is the method ID for the method AddTarget + MethodAddTarget = 0x4 + + // MethodDeleteTarget is the method ID for the method DeleteTarget + MethodDeleteTarget = 0x5 + + // MethodClearTarget is the method ID for the method ClearTarget + MethodClearTarget = 0x6 + + // MethodGetFriendSubscriptionData is the method ID for the method GetFriendSubscriptionData + MethodGetFriendSubscriptionData = 0x7 + + // MethodGetTargetSubscriptionData is the method ID for the method GetTargetSubscriptionData + MethodGetTargetSubscriptionData = 0x8 + + // MethodGetActivePlayerSubscriptionData is the method ID for the method GetActivePlayerSubscriptionData + MethodGetActivePlayerSubscriptionData = 0x9 + + // MethodGetSubscriptionData is the method ID for the method GetSubscriptionData + MethodGetSubscriptionData = 0xA + + // MethodReplaceTargetAndGetSubscriptionData is the method ID for the method ReplaceTargetAndGetSubscriptionData + MethodReplaceTargetAndGetSubscriptionData = 0xB + + // MethodSetPrivacyLevel is the method ID for the method SetPrivacyLevel + MethodSetPrivacyLevel = 0xC + + // MethodGetPrivacyLevel is the method ID for the method GetPrivacyLevel + MethodGetPrivacyLevel = 0xD + + // MethodGetSubscriptionUserFriendList is the method ID for the method GetSubscriptionUserFriendList + MethodGetSubscriptionUserFriendList = 0xE + + // MethodGetPrivacyLevels is the method ID for the method GetPrivacyLevels + MethodGetPrivacyLevels = 0xF +) + +// Protocol handles the Subscription nex protocol +type Protocol struct { + endpoint nex.EndpointInterface + CreateMySubscriptionData func(err error, packet nex.PacketInterface, callID uint32, unk *types.PrimitiveU64, content []byte) (*nex.RMCMessage, *nex.Error) + UpdateMySubscriptionData func(err error, packet nex.PacketInterface, callID uint32, unk *types.PrimitiveU32, content []byte) (*nex.RMCMessage, *nex.Error) + GetFriendSubscriptionData func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + GetTargetSubscriptionData func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + GetActivePlayerSubscriptionData func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + GetSubscriptionData func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error) + ReplaceTargetAndGetSubscriptionData func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + GetPrivacyLevels func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Subscription protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerCreateMySubscriptionData(handler func(err error, packet nex.PacketInterface, callID uint32, unk *types.PrimitiveU64, content []byte) (*nex.RMCMessage, *nex.Error)) + SetHandlerUpdateMySubscriptionData(handler func(err error, packet nex.PacketInterface, callID uint32, unk *types.PrimitiveU32, content []byte) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetFriendSubscriptionData(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetTargetSubscriptionData(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetActivePlayerSubscriptionData(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetSubscriptionData(handler func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) + SetHandlerReplaceTargetAndGetSubscriptionData(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetPrivacyLevels(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerCreateMySubscriptionData sets the handler for the CreateMySubscriptionData method +func (protocol *Protocol) SetHandlerCreateMySubscriptionData(handler func(err error, packet nex.PacketInterface, callID uint32, unk *types.PrimitiveU64, content []byte) (*nex.RMCMessage, *nex.Error)) { + protocol.CreateMySubscriptionData = handler +} + +// SetHandlerUpdateMySubscriptionData sets the handler for the UpdateMySubscriptionData method +func (protocol *Protocol) SetHandlerUpdateMySubscriptionData(handler func(err error, packet nex.PacketInterface, callID uint32, unk *types.PrimitiveU32, content []byte) (*nex.RMCMessage, *nex.Error)) { + protocol.UpdateMySubscriptionData = handler +} + +// SetHandlerGetFriendSubscriptionData sets the handler for the GetFriendSubscriptionData method +func (protocol *Protocol) SetHandlerGetFriendSubscriptionData(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetFriendSubscriptionData = handler +} + +// SetHandlerGetTargetSubscriptionData sets the handler for the GetTargetSubscriptionData method +func (protocol *Protocol) SetHandlerGetTargetSubscriptionData(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetTargetSubscriptionData = handler +} + +// SetHandlerGetActivePlayerSubscriptionData sets the handler for the GetActivePlayerSubscriptionData method +func (protocol *Protocol) SetHandlerGetActivePlayerSubscriptionData(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetActivePlayerSubscriptionData = handler +} + +// SetHandlerGetSubscriptionData sets the handler for the GetSubscriptionData method +func (protocol *Protocol) SetHandlerGetSubscriptionData(handler func(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error)) { + protocol.GetSubscriptionData = handler +} + +// SetHandlerReplaceTargetAndGetSubscriptionData sets the handler for the ReplaceTargetAndGetSubscriptionData method +func (protocol *Protocol) SetHandlerReplaceTargetAndGetSubscriptionData(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.ReplaceTargetAndGetSubscriptionData = handler +} + +// SetHandlerGetPrivacyLevels sets the handler for the GetPrivacyLevels method +func (protocol *Protocol) SetHandlerGetPrivacyLevels(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetPrivacyLevels = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodCreateMySubscriptionData: + protocol.handleCreateMySubscriptionData(packet) + case MethodUpdateMySubscriptionData: + protocol.handleUpdateMySubscriptionData(packet) + case MethodGetFriendSubscriptionData: + protocol.handleGetFriendSubscriptionData(packet) + case MethodGetTargetSubscriptionData: + protocol.handleGetTargetSubscriptionData(packet) + case MethodGetActivePlayerSubscriptionData: + protocol.handleGetActivePlayerSubscriptionData(packet) + case MethodGetSubscriptionData: + protocol.handleGetSubscriptionData(packet) + case MethodReplaceTargetAndGetSubscriptionData: + protocol.handleReplaceTargetAndGetSubscriptionData(packet) + case MethodGetPrivacyLevels: + protocol.handleGetPrivacyLevels(packet) + default: + errMessage := fmt.Sprintf("Unsupported Subscription method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/subscription/replace_target_and_get_subscription_data.go b/nex-protocols-go/subscription/replace_target_and_get_subscription_data.go new file mode 100644 index 0000000..e4c8c69 --- /dev/null +++ b/nex-protocols-go/subscription/replace_target_and_get_subscription_data.go @@ -0,0 +1,29 @@ +// Package protocol implements the Subscription protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleReplaceTargetAndGetSubscriptionData(packet nex.PacketInterface) { + if protocol.ReplaceTargetAndGetSubscriptionData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "SubscriptionProtocol::ReplaceTargetAndGetSubscriptionData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.ReplaceTargetAndGetSubscriptionData(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/subscription/update_my_subscription_data.go b/nex-protocols-go/subscription/update_my_subscription_data.go new file mode 100644 index 0000000..bf0023e --- /dev/null +++ b/nex-protocols-go/subscription/update_my_subscription_data.go @@ -0,0 +1,52 @@ +// Package protocol implements the Subscription protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleUpdateMySubscriptionData(packet nex.PacketInterface) { + if protocol.UpdateMySubscriptionData == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "SubscriptionProtocol::UpdateMySubscriptionData not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + unk := types.NewPrimitiveU32(0) + + err := unk.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.UpdateMySubscriptionData(fmt.Errorf("Failed to read unk from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + // * This is done since the server doesn't need to care about the data here (it's game-specific), + // * so we just pass it along to store however the handler wants + // TODO - Is this really the best way to do this? + content := parametersStream.ReadRemaining() + + rmcMessage, rmcError := protocol.UpdateMySubscriptionData(nil, packet, callID, unk, content) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ticket-granting/get_name.go b/nex-protocols-go/ticket-granting/get_name.go new file mode 100644 index 0000000..7ef85f8 --- /dev/null +++ b/nex-protocols-go/ticket-granting/get_name.go @@ -0,0 +1,47 @@ +// Package protocol implements the Ticket Granting protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetName(packet nex.PacketInterface) { + if protocol.GetName == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "TicketGranting::GetName not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + id := types.NewPID(0) + + err := id.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetName(fmt.Errorf("Failed to read id from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetName(nil, packet, callID, id) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ticket-granting/get_pid.go b/nex-protocols-go/ticket-granting/get_pid.go new file mode 100644 index 0000000..653d1e6 --- /dev/null +++ b/nex-protocols-go/ticket-granting/get_pid.go @@ -0,0 +1,47 @@ +// Package protocol implements the Ticket Granting protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetPID(packet nex.PacketInterface) { + if protocol.GetPID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "TicketGranting::GetPID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strUserName := types.NewString("") + + err := strUserName.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetPID(fmt.Errorf("Failed to read strUserName from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetPID(nil, packet, callID, strUserName) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ticket-granting/login.go b/nex-protocols-go/ticket-granting/login.go new file mode 100644 index 0000000..48c798d --- /dev/null +++ b/nex-protocols-go/ticket-granting/login.go @@ -0,0 +1,47 @@ +// Package protocol implements the Ticket Granting protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleLogin(packet nex.PacketInterface) { + if protocol.Login == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "TicketGranting::Login not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strUserName := types.NewString("") + + err := strUserName.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.Login(fmt.Errorf("Failed to read strUserName from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.Login(nil, packet, callID, strUserName) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ticket-granting/login_ex.go b/nex-protocols-go/ticket-granting/login_ex.go new file mode 100644 index 0000000..4a890fb --- /dev/null +++ b/nex-protocols-go/ticket-granting/login_ex.go @@ -0,0 +1,60 @@ +// Package protocol implements the Ticket Granting protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleLoginEx(packet nex.PacketInterface) { + if protocol.LoginEx == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "TicketGranting::LoginEx not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + strUserName := types.NewString("") + oExtraData := types.NewAnyDataHolder() + + var err error + + err = strUserName.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.LoginEx(fmt.Errorf("Failed to read strUserName from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = oExtraData.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.LoginEx(fmt.Errorf("Failed to read oExtraData from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.LoginEx(nil, packet, callID, strUserName, oExtraData) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ticket-granting/login_with_context.go b/nex-protocols-go/ticket-granting/login_with_context.go new file mode 100644 index 0000000..611d8dc --- /dev/null +++ b/nex-protocols-go/ticket-granting/login_with_context.go @@ -0,0 +1,29 @@ +// Package protocol implements the Ticket Granting protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleLoginWithContext(packet nex.PacketInterface) { + if protocol.LoginWithContext == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "TicketGranting::LoginWithContext not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.LoginWithContext(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ticket-granting/protocol.go b/nex-protocols-go/ticket-granting/protocol.go new file mode 100644 index 0000000..4455411 --- /dev/null +++ b/nex-protocols-go/ticket-granting/protocol.go @@ -0,0 +1,139 @@ +// Package protocol implements the Ticket Granting protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +const ( + // ProtocolID is the protocol ID for the Ticket Granting protocol + ProtocolID = 0xA + + // MethodLogin is the method ID for the method Login + MethodLogin = 0x1 + + // MethodLoginEx is the method ID for the method LoginEx + MethodLoginEx = 0x2 + + // MethodRequestTicket is the method ID for the method RequestTicket + MethodRequestTicket = 0x3 + + // MethodGetPID is the method ID for the method GetPID + MethodGetPID = 0x4 + + // MethodGetName is the method ID for the method GetName + MethodGetName = 0x5 + + // MethodLoginWithContext is the method ID for the method LoginWithContext + MethodLoginWithContext = 0x6 +) + +// Protocol stores all the RMC method handlers for the Ticket Granting protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + Login func(err error, packet nex.PacketInterface, callID uint32, strUserName *types.String) (*nex.RMCMessage, *nex.Error) + LoginEx func(err error, packet nex.PacketInterface, callID uint32, strUserName *types.String, oExtraData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error) + RequestTicket func(err error, packet nex.PacketInterface, callID uint32, idSource *types.PID, idTarget *types.PID) (*nex.RMCMessage, *nex.Error) + GetPID func(err error, packet nex.PacketInterface, callID uint32, strUserName *types.String) (*nex.RMCMessage, *nex.Error) + GetName func(err error, packet nex.PacketInterface, callID uint32, id *types.PID) (*nex.RMCMessage, *nex.Error) + LoginWithContext func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Ticket Granting protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerLogin(handler func(err error, packet nex.PacketInterface, callID uint32, strUserName *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerLoginEx(handler func(err error, packet nex.PacketInterface, callID uint32, strUserName *types.String, oExtraData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) + SetHandlerRequestTicket(handler func(err error, packet nex.PacketInterface, callID uint32, idSource *types.PID, idTarget *types.PID) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetPID(handler func(err error, packet nex.PacketInterface, callID uint32, strUserName *types.String) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetName(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PID) (*nex.RMCMessage, *nex.Error)) + SetHandlerLoginWithContext(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerLogin sets the handler for the Login method +func (protocol *Protocol) SetHandlerLogin(handler func(err error, packet nex.PacketInterface, callID uint32, strUserName *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.Login = handler +} + +// SetHandlerLoginEx sets the handler for the LoginEx method +func (protocol *Protocol) SetHandlerLoginEx(handler func(err error, packet nex.PacketInterface, callID uint32, strUserName *types.String, oExtraData *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error)) { + protocol.LoginEx = handler +} + +// SetHandlerRequestTicket sets the handler for the RequestTicket method +func (protocol *Protocol) SetHandlerRequestTicket(handler func(err error, packet nex.PacketInterface, callID uint32, idSource *types.PID, idTarget *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.RequestTicket = handler +} + +// SetHandlerGetPID sets the handler for the GetPID method +func (protocol *Protocol) SetHandlerGetPID(handler func(err error, packet nex.PacketInterface, callID uint32, strUserName *types.String) (*nex.RMCMessage, *nex.Error)) { + protocol.GetPID = handler +} + +// SetHandlerGetName sets the handler for the GetName method +func (protocol *Protocol) SetHandlerGetName(handler func(err error, packet nex.PacketInterface, callID uint32, id *types.PID) (*nex.RMCMessage, *nex.Error)) { + protocol.GetName = handler +} + +// SetHandlerLoginWithContext sets the handler for the LoginWithContext method +func (protocol *Protocol) SetHandlerLoginWithContext(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.LoginWithContext = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodLogin: + protocol.handleLogin(packet) + case MethodLoginEx: + protocol.handleLoginEx(packet) + case MethodRequestTicket: + protocol.handleRequestTicket(packet) + case MethodGetPID: + protocol.handleGetPID(packet) + case MethodGetName: + protocol.handleGetName(packet) + case MethodLoginWithContext: + protocol.handleLoginWithContext(packet) + default: + errMessage := fmt.Sprintf("Unsupported Ticket Granting method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Ticket Granting protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/ticket-granting/request_ticket.go b/nex-protocols-go/ticket-granting/request_ticket.go new file mode 100644 index 0000000..4ed6ebb --- /dev/null +++ b/nex-protocols-go/ticket-granting/request_ticket.go @@ -0,0 +1,60 @@ +// Package protocol implements the Ticket Granting protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleRequestTicket(packet nex.PacketInterface) { + if protocol.RequestTicket == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "TicketGranting::RequestTicket not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + idSource := types.NewPID(0) + idTarget := types.NewPID(0) + + var err error + + err = idSource.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RequestTicket(fmt.Errorf("Failed to read idSource from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + err = idTarget.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.RequestTicket(fmt.Errorf("Failed to read idTarget from parameters. %s", err.Error()), packet, callID, nil, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.RequestTicket(nil, packet, callID, idSource, idTarget) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/ticket-granting/types/authentication_info.go b/nex-protocols-go/ticket-granting/types/authentication_info.go new file mode 100644 index 0000000..b4ebf12 --- /dev/null +++ b/nex-protocols-go/ticket-granting/types/authentication_info.go @@ -0,0 +1,167 @@ +// Package types implements all the types used by the TicketGranting protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// AuthenticationInfo is a type within the TicketGranting protocol +type AuthenticationInfo struct { + types.Structure + *types.Data + Token *types.String + NGSVersion *types.PrimitiveU32 + TokenType *types.PrimitiveU8 + ServerVersion *types.PrimitiveU32 +} + +// WriteTo writes the AuthenticationInfo to the given writable +func (ai *AuthenticationInfo) WriteTo(writable types.Writable) { + stream := writable.(*nex.ByteStreamOut) + libraryVersion := stream.LibraryVersions.Main + + ai.Data.WriteTo(writable) + + contentWritable := writable.CopyNew() + + ai.Token.WriteTo(contentWritable) + ai.NGSVersion.WriteTo(contentWritable) + + if libraryVersion.GreaterOrEqual("3.0.0") { + ai.TokenType.WriteTo(contentWritable) + ai.ServerVersion.WriteTo(contentWritable) + } + + content := contentWritable.Bytes() + + ai.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the AuthenticationInfo from the given readable +func (ai *AuthenticationInfo) ExtractFrom(readable types.Readable) error { + stream := readable.(*nex.ByteStreamIn) + libraryVersion := stream.LibraryVersions.Main + + var err error + + err = ai.Data.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AuthenticationInfo.Data. %s", err.Error()) + } + + err = ai.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AuthenticationInfo header. %s", err.Error()) + } + + err = ai.Token.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AuthenticationInfo.Token. %s", err.Error()) + } + + err = ai.NGSVersion.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AuthenticationInfo.NGSVersion. %s", err.Error()) + } + + if libraryVersion.GreaterOrEqual("3.0.0") { + err = ai.TokenType.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AuthenticationInfo.TokenType. %s", err.Error()) + } + + err = ai.ServerVersion.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract AuthenticationInfo.ServerVersion. %s", err.Error()) + } + } + + return nil +} + +// Copy returns a new copied instance of AuthenticationInfo +func (ai *AuthenticationInfo) Copy() types.RVType { + copied := NewAuthenticationInfo() + + copied.StructureVersion = ai.StructureVersion + copied.Data = ai.Data.Copy().(*types.Data) + copied.Token = ai.Token.Copy().(*types.String) + copied.NGSVersion = ai.NGSVersion.Copy().(*types.PrimitiveU32) + copied.TokenType = ai.TokenType.Copy().(*types.PrimitiveU8) + copied.ServerVersion = ai.ServerVersion.Copy().(*types.PrimitiveU32) + + return copied +} + +// Equals checks if the given AuthenticationInfo contains the same data as the current AuthenticationInfo +func (ai *AuthenticationInfo) Equals(o types.RVType) bool { + if _, ok := o.(*AuthenticationInfo); !ok { + return false + } + + other := o.(*AuthenticationInfo) + + if ai.StructureVersion != other.StructureVersion { + return false + } + + if !ai.Data.Equals(other.Data) { + return false + } + + if !ai.Token.Equals(other.Token) { + return false + } + + if !ai.NGSVersion.Equals(other.NGSVersion) { + return false + } + + if !ai.TokenType.Equals(other.TokenType) { + return false + } + + return ai.ServerVersion.Equals(other.ServerVersion) +} + +// String returns the string representation of the AuthenticationInfo +func (ai *AuthenticationInfo) String() string { + return ai.FormatToString(0) +} + +// FormatToString pretty-prints the AuthenticationInfo using the provided indentation level +func (ai *AuthenticationInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("AuthenticationInfo{\n") + b.WriteString(fmt.Sprintf("%sData (parent): %s,\n", indentationValues, ai.Data.FormatToString(indentationLevel+1))) + b.WriteString(fmt.Sprintf("%sToken: %s,\n", indentationValues, ai.Token)) + b.WriteString(fmt.Sprintf("%sNGSVersion: %s,\n", indentationValues, ai.NGSVersion)) + b.WriteString(fmt.Sprintf("%sTokenType: %s,\n", indentationValues, ai.TokenType)) + b.WriteString(fmt.Sprintf("%sServerVersion: %s,\n", indentationValues, ai.ServerVersion)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewAuthenticationInfo returns a new AuthenticationInfo +func NewAuthenticationInfo() *AuthenticationInfo { + ai := &AuthenticationInfo{ + Data: types.NewData(), + Token: types.NewString(""), + NGSVersion: types.NewPrimitiveU32(0), + TokenType: types.NewPrimitiveU8(0), + ServerVersion: types.NewPrimitiveU32(0), + } + + return ai +} diff --git a/nex-protocols-go/ticket-granting/types/nintendo_login_data.go b/nex-protocols-go/ticket-granting/types/nintendo_login_data.go new file mode 100644 index 0000000..ab8b3af --- /dev/null +++ b/nex-protocols-go/ticket-granting/types/nintendo_login_data.go @@ -0,0 +1,98 @@ +// Package types implements all the types used by the TicketGranting protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// NintendoLoginData is a type within the TicketGranting protocol +type NintendoLoginData struct { + types.Structure + Token *types.String +} + +// WriteTo writes the NintendoLoginData to the given writable +func (nld *NintendoLoginData) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + nld.Token.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + nld.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the NintendoLoginData from the given readable +func (nld *NintendoLoginData) ExtractFrom(readable types.Readable) error { + var err error + + err = nld.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoLoginData header. %s", err.Error()) + } + + err = nld.Token.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract NintendoLoginData.Token. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of NintendoLoginData +func (nld *NintendoLoginData) Copy() types.RVType { + copied := NewNintendoLoginData() + + copied.StructureVersion = nld.StructureVersion + copied.Token = nld.Token.Copy().(*types.String) + + return copied +} + +// Equals checks if the given NintendoLoginData contains the same data as the current NintendoLoginData +func (nld *NintendoLoginData) Equals(o types.RVType) bool { + if _, ok := o.(*NintendoLoginData); !ok { + return false + } + + other := o.(*NintendoLoginData) + + if nld.StructureVersion != other.StructureVersion { + return false + } + + return nld.Token.Equals(other.Token) +} + +// String returns the string representation of the NintendoLoginData +func (nld *NintendoLoginData) String() string { + return nld.FormatToString(0) +} + +// FormatToString pretty-prints the NintendoLoginData using the provided indentation level +func (nld *NintendoLoginData) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("NintendoLoginData{\n") + b.WriteString(fmt.Sprintf("%sToken: %s,\n", indentationValues, nld.Token)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewNintendoLoginData returns a new NintendoLoginData +func NewNintendoLoginData() *NintendoLoginData { + nld := &NintendoLoginData{ + Token: types.NewString(""), + } + + return nld +} diff --git a/nex-protocols-go/utility/acquire_nex_unique_id.go b/nex-protocols-go/utility/acquire_nex_unique_id.go new file mode 100644 index 0000000..13d7930 --- /dev/null +++ b/nex-protocols-go/utility/acquire_nex_unique_id.go @@ -0,0 +1,29 @@ +// Package protocol implements the Utility protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAcquireNexUniqueID(packet nex.PacketInterface) { + if protocol.AcquireNexUniqueID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Utility::AcquireNexUniqueID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.AcquireNexUniqueID(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/utility/acquire_nex_unique_id_with_password.go b/nex-protocols-go/utility/acquire_nex_unique_id_with_password.go new file mode 100644 index 0000000..cde8f29 --- /dev/null +++ b/nex-protocols-go/utility/acquire_nex_unique_id_with_password.go @@ -0,0 +1,29 @@ +// Package protocol implements the Utility protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleAcquireNexUniqueIDWithPassword(packet nex.PacketInterface) { + if protocol.AcquireNexUniqueIDWithPassword == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Utility::AcquireNexUniqueIDWithPassword not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.AcquireNexUniqueIDWithPassword(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/utility/associate_nex_unique_id_with_my_principal_id.go b/nex-protocols-go/utility/associate_nex_unique_id_with_my_principal_id.go new file mode 100644 index 0000000..dbe853f --- /dev/null +++ b/nex-protocols-go/utility/associate_nex_unique_id_with_my_principal_id.go @@ -0,0 +1,47 @@ +// Package protocol implements the Utility protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + utility_types "github.com/PretendoNetwork/nex-protocols-go/v2/utility/types" +) + +func (protocol *Protocol) handleAssociateNexUniqueIDWithMyPrincipalID(packet nex.PacketInterface) { + if protocol.AssociateNexUniqueIDWithMyPrincipalID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Utility::AssociateNexUniqueIDWithMyPrincipalID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uniqueIDInfo := utility_types.NewUniqueIDInfo() + + err := uniqueIDInfo.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AssociateNexUniqueIDWithMyPrincipalID(fmt.Errorf("Failed to read uniqueIDInfo from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AssociateNexUniqueIDWithMyPrincipalID(nil, packet, callID, uniqueIDInfo) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/utility/associate_nex_unique_ids_with_my_principal_id.go b/nex-protocols-go/utility/associate_nex_unique_ids_with_my_principal_id.go new file mode 100644 index 0000000..51a9acd --- /dev/null +++ b/nex-protocols-go/utility/associate_nex_unique_ids_with_my_principal_id.go @@ -0,0 +1,49 @@ +// Package protocol implements the Utility protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + utility_types "github.com/PretendoNetwork/nex-protocols-go/v2/utility/types" +) + +func (protocol *Protocol) handleAssociateNexUniqueIDsWithMyPrincipalID(packet nex.PacketInterface) { + if protocol.AssociateNexUniqueIDsWithMyPrincipalID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Utility::AssociateNexUniqueIDsWithMyPrincipalID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + uniqueIDInfo := types.NewList[*utility_types.UniqueIDInfo]() + uniqueIDInfo.Type = utility_types.NewUniqueIDInfo() + + err := uniqueIDInfo.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.AssociateNexUniqueIDsWithMyPrincipalID(fmt.Errorf("Failed to read uniqueIDInfo from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.AssociateNexUniqueIDsWithMyPrincipalID(nil, packet, callID, uniqueIDInfo) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/utility/get_associated_nex_unique_id_with_my_principal_id.go b/nex-protocols-go/utility/get_associated_nex_unique_id_with_my_principal_id.go new file mode 100644 index 0000000..4b817a2 --- /dev/null +++ b/nex-protocols-go/utility/get_associated_nex_unique_id_with_my_principal_id.go @@ -0,0 +1,29 @@ +// Package protocol implements the Utility protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetAssociatedNexUniqueIDWithMyPrincipalID(packet nex.PacketInterface) { + if protocol.GetAssociatedNexUniqueIDWithMyPrincipalID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Utility::GetAssociatedNexUniqueIDWithMyPrincipalID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetAssociatedNexUniqueIDWithMyPrincipalID(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/utility/get_associated_nex_unique_ids_with_my_principal_id.go b/nex-protocols-go/utility/get_associated_nex_unique_ids_with_my_principal_id.go new file mode 100644 index 0000000..f0d3552 --- /dev/null +++ b/nex-protocols-go/utility/get_associated_nex_unique_ids_with_my_principal_id.go @@ -0,0 +1,29 @@ +// Package protocol implements the Utility protocol +package protocol + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetAssociatedNexUniqueIDsWithMyPrincipalID(packet nex.PacketInterface) { + if protocol.GetAssociatedNexUniqueIDsWithMyPrincipalID == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Utility::GetAssociatedNexUniqueIDsWithMyPrincipalID not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + + rmcMessage, rmcError := protocol.GetAssociatedNexUniqueIDsWithMyPrincipalID(nil, packet, callID) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/utility/get_integer_settings.go b/nex-protocols-go/utility/get_integer_settings.go new file mode 100644 index 0000000..7723bc2 --- /dev/null +++ b/nex-protocols-go/utility/get_integer_settings.go @@ -0,0 +1,47 @@ +// Package protocol implements the Utility protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetIntegerSettings(packet nex.PacketInterface) { + if protocol.GetIntegerSettings == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Utility::GetIntegerSettings not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + integerSettingIndex := types.NewPrimitiveU32(0) + + err := integerSettingIndex.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetIntegerSettings(fmt.Errorf("Failed to read integerSettingIndex from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetIntegerSettings(nil, packet, callID, integerSettingIndex) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/utility/get_string_settings.go b/nex-protocols-go/utility/get_string_settings.go new file mode 100644 index 0000000..1927f75 --- /dev/null +++ b/nex-protocols-go/utility/get_string_settings.go @@ -0,0 +1,47 @@ +// Package protocol implements the Utility protocol +package protocol + +import ( + "fmt" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" +) + +func (protocol *Protocol) handleGetStringSettings(packet nex.PacketInterface) { + if protocol.GetStringSettings == nil { + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, "Utility::GetStringSettings not implemented") + + globals.Logger.Warning(err.Message) + globals.RespondError(packet, ProtocolID, err) + + return + } + + request := packet.RMCMessage() + callID := request.CallID + parameters := request.Parameters + endpoint := packet.Sender().Endpoint() + parametersStream := nex.NewByteStreamIn(parameters, endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + stringSettingIndex := types.NewPrimitiveU32(0) + + err := stringSettingIndex.ExtractFrom(parametersStream) + if err != nil { + _, rmcError := protocol.GetStringSettings(fmt.Errorf("Failed to read stringSettingIndex from parameters. %s", err.Error()), packet, callID, nil) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + } + + return + } + + rmcMessage, rmcError := protocol.GetStringSettings(nil, packet, callID, stringSettingIndex) + if rmcError != nil { + globals.RespondError(packet, ProtocolID, rmcError) + return + } + + globals.Respond(packet, rmcMessage) +} diff --git a/nex-protocols-go/utility/protocol.go b/nex-protocols-go/utility/protocol.go new file mode 100644 index 0000000..975185c --- /dev/null +++ b/nex-protocols-go/utility/protocol.go @@ -0,0 +1,164 @@ +// Package protocol implements the Utility protocol +package protocol + +import ( + "fmt" + "slices" + + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/nex-protocols-go/v2/globals" + utility_types "github.com/PretendoNetwork/nex-protocols-go/v2/utility/types" +) + +const ( + // ProtocolID is the protocol ID for the Utility protocol + ProtocolID = 0x6E + + // MethodAcquireNexUniqueID is the method ID for the method AcquireNexUniqueID + MethodAcquireNexUniqueID = 0x1 + + // MethodAcquireNexUniqueIDWithPassword is the method ID for the method AcquireNexUniqueIDWithPassword + MethodAcquireNexUniqueIDWithPassword = 0x2 + + // MethodAssociateNexUniqueIDWithMyPrincipalID is the method ID for the method AssociateNexUniqueIDWithMyPrincipalID + MethodAssociateNexUniqueIDWithMyPrincipalID = 0x3 + + // MethodAssociateNexUniqueIDsWithMyPrincipalID is the method ID for the method AssociateNexUniqueIDsWithMyPrincipalID + MethodAssociateNexUniqueIDsWithMyPrincipalID = 0x4 + + // MethodGetAssociatedNexUniqueIDWithMyPrincipalID is the method ID for the method GetAssociatedNexUniqueIDWithMyPrincipalID + MethodGetAssociatedNexUniqueIDWithMyPrincipalID = 0x5 + + // MethodGetAssociatedNexUniqueIDsWithMyPrincipalID is the method ID for the method GetAssociatedNexUniqueIDsWithMyPrincipalID + MethodGetAssociatedNexUniqueIDsWithMyPrincipalID = 0x6 + + // MethodGetIntegerSettings is the method ID for the method GetIntegerSettings + MethodGetIntegerSettings = 0x7 + + // MethodGetStringSettings is the method ID for the method GetStringSettings + MethodGetStringSettings = 0x8 +) + +// Protocol stores all the RMC method handlers for the Utility protocol and listens for requests +type Protocol struct { + endpoint nex.EndpointInterface + AcquireNexUniqueID func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + AcquireNexUniqueIDWithPassword func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + AssociateNexUniqueIDWithMyPrincipalID func(err error, packet nex.PacketInterface, callID uint32, uniqueIDInfo *utility_types.UniqueIDInfo) (*nex.RMCMessage, *nex.Error) + AssociateNexUniqueIDsWithMyPrincipalID func(err error, packet nex.PacketInterface, callID uint32, uniqueIDInfo *types.List[*utility_types.UniqueIDInfo]) (*nex.RMCMessage, *nex.Error) + GetAssociatedNexUniqueIDWithMyPrincipalID func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + GetAssociatedNexUniqueIDsWithMyPrincipalID func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) + GetIntegerSettings func(err error, packet nex.PacketInterface, callID uint32, integerSettingIndex *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + GetStringSettings func(err error, packet nex.PacketInterface, callID uint32, stringSettingIndex *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error) + Patches nex.ServiceProtocol + PatchedMethods []uint32 +} + +// Interface implements the methods present on the Utility protocol struct +type Interface interface { + Endpoint() nex.EndpointInterface + SetEndpoint(endpoint nex.EndpointInterface) + SetHandlerAcquireNexUniqueID(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerAcquireNexUniqueIDWithPassword(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerAssociateNexUniqueIDWithMyPrincipalID(handler func(err error, packet nex.PacketInterface, callID uint32, uniqueIDInfo *utility_types.UniqueIDInfo) (*nex.RMCMessage, *nex.Error)) + SetHandlerAssociateNexUniqueIDsWithMyPrincipalID(handler func(err error, packet nex.PacketInterface, callID uint32, uniqueIDInfo *types.List[*utility_types.UniqueIDInfo]) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetAssociatedNexUniqueIDWithMyPrincipalID(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetAssociatedNexUniqueIDsWithMyPrincipalID(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetIntegerSettings(handler func(err error, packet nex.PacketInterface, callID uint32, integerSettingIndex *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) + SetHandlerGetStringSettings(handler func(err error, packet nex.PacketInterface, callID uint32, stringSettingIndex *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) +} + +// Endpoint returns the endpoint implementing the protocol +func (protocol *Protocol) Endpoint() nex.EndpointInterface { + return protocol.endpoint +} + +// SetEndpoint sets the endpoint implementing the protocol +func (protocol *Protocol) SetEndpoint(endpoint nex.EndpointInterface) { + protocol.endpoint = endpoint +} + +// SetHandlerAcquireNexUniqueID sets the handler for the AcquireNexUniqueID method +func (protocol *Protocol) SetHandlerAcquireNexUniqueID(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.AcquireNexUniqueID = handler +} + +// SetHandlerAcquireNexUniqueIDWithPassword sets the handler for the AcquireNexUniqueIDWithPassword method +func (protocol *Protocol) SetHandlerAcquireNexUniqueIDWithPassword(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.AcquireNexUniqueIDWithPassword = handler +} + +// SetHandlerAssociateNexUniqueIDWithMyPrincipalID sets the handler for the AssociateNexUniqueIDWithMyPrincipalID method +func (protocol *Protocol) SetHandlerAssociateNexUniqueIDWithMyPrincipalID(handler func(err error, packet nex.PacketInterface, callID uint32, uniqueIDInfo *utility_types.UniqueIDInfo) (*nex.RMCMessage, *nex.Error)) { + protocol.AssociateNexUniqueIDWithMyPrincipalID = handler +} + +// SetHandlerAssociateNexUniqueIDsWithMyPrincipalID sets the handler for the AssociateNexUniqueIDsWithMyPrincipalID method +func (protocol *Protocol) SetHandlerAssociateNexUniqueIDsWithMyPrincipalID(handler func(err error, packet nex.PacketInterface, callID uint32, uniqueIDInfo *types.List[*utility_types.UniqueIDInfo]) (*nex.RMCMessage, *nex.Error)) { + protocol.AssociateNexUniqueIDsWithMyPrincipalID = handler +} + +// SetHandlerGetAssociatedNexUniqueIDWithMyPrincipalID sets the handler for the GetAssociatedNexUniqueIDWithMyPrincipalID method +func (protocol *Protocol) SetHandlerGetAssociatedNexUniqueIDWithMyPrincipalID(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetAssociatedNexUniqueIDWithMyPrincipalID = handler +} + +// SetHandlerGetAssociatedNexUniqueIDsWithMyPrincipalID sets the handler for the GetAssociatedNexUniqueIDsWithMyPrincipalID method +func (protocol *Protocol) SetHandlerGetAssociatedNexUniqueIDsWithMyPrincipalID(handler func(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetAssociatedNexUniqueIDsWithMyPrincipalID = handler +} + +// SetHandlerGetIntegerSettings sets the handler for the GetIntegerSettings method +func (protocol *Protocol) SetHandlerGetIntegerSettings(handler func(err error, packet nex.PacketInterface, callID uint32, integerSettingIndex *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetIntegerSettings = handler +} + +// SetHandlerGetStringSettings sets the handler for the GetStringSettings method +func (protocol *Protocol) SetHandlerGetStringSettings(handler func(err error, packet nex.PacketInterface, callID uint32, stringSettingIndex *types.PrimitiveU32) (*nex.RMCMessage, *nex.Error)) { + protocol.GetStringSettings = handler +} + +// HandlePacket sends the packet to the correct RMC method handler +func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) { + message := packet.RMCMessage() + + if !message.IsRequest || message.ProtocolID != ProtocolID { + return + } + + if protocol.Patches != nil && slices.Contains(protocol.PatchedMethods, message.MethodID) { + protocol.Patches.HandlePacket(packet) + return + } + + switch message.MethodID { + case MethodAcquireNexUniqueID: + protocol.handleAcquireNexUniqueID(packet) + case MethodAcquireNexUniqueIDWithPassword: + protocol.handleAcquireNexUniqueIDWithPassword(packet) + case MethodAssociateNexUniqueIDWithMyPrincipalID: + protocol.handleAssociateNexUniqueIDWithMyPrincipalID(packet) + case MethodAssociateNexUniqueIDsWithMyPrincipalID: + protocol.handleAssociateNexUniqueIDsWithMyPrincipalID(packet) + case MethodGetAssociatedNexUniqueIDWithMyPrincipalID: + protocol.handleGetAssociatedNexUniqueIDWithMyPrincipalID(packet) + case MethodGetAssociatedNexUniqueIDsWithMyPrincipalID: + protocol.handleGetAssociatedNexUniqueIDsWithMyPrincipalID(packet) + case MethodGetIntegerSettings: + protocol.handleGetIntegerSettings(packet) + case MethodGetStringSettings: + protocol.handleGetStringSettings(packet) + default: + errMessage := fmt.Sprintf("Unsupported Utility method ID: %#v\n", message.MethodID) + err := nex.NewError(nex.ResultCodes.Core.NotImplemented, errMessage) + + globals.RespondError(packet, ProtocolID, err) + globals.Logger.Warning(err.Message) + } +} + +// NewProtocol returns a new Utility protocol +func NewProtocol() *Protocol { + return &Protocol{} +} diff --git a/nex-protocols-go/utility/types/unique_id_info.go b/nex-protocols-go/utility/types/unique_id_info.go new file mode 100644 index 0000000..6493bf9 --- /dev/null +++ b/nex-protocols-go/utility/types/unique_id_info.go @@ -0,0 +1,112 @@ +// Package types implements all the types used by the Utility protocol +package types + +import ( + "fmt" + "strings" + + "github.com/PretendoNetwork/nex-go/v2/types" +) + +// UniqueIDInfo is a type within the Utility protocol +type UniqueIDInfo struct { + types.Structure + NEXUniqueID *types.PrimitiveU64 + NEXUniqueIDPassword *types.PrimitiveU64 +} + +// WriteTo writes the UniqueIDInfo to the given writable +func (uidi *UniqueIDInfo) WriteTo(writable types.Writable) { + contentWritable := writable.CopyNew() + + uidi.NEXUniqueID.WriteTo(contentWritable) + uidi.NEXUniqueIDPassword.WriteTo(contentWritable) + + content := contentWritable.Bytes() + + uidi.WriteHeaderTo(writable, uint32(len(content))) + + writable.Write(content) +} + +// ExtractFrom extracts the UniqueIDInfo from the given readable +func (uidi *UniqueIDInfo) ExtractFrom(readable types.Readable) error { + var err error + + err = uidi.ExtractHeaderFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UniqueIDInfo header. %s", err.Error()) + } + + err = uidi.NEXUniqueID.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UniqueIDInfo.NEXUniqueID. %s", err.Error()) + } + + err = uidi.NEXUniqueIDPassword.ExtractFrom(readable) + if err != nil { + return fmt.Errorf("Failed to extract UniqueIDInfo.NEXUniqueIDPassword. %s", err.Error()) + } + + return nil +} + +// Copy returns a new copied instance of UniqueIDInfo +func (uidi *UniqueIDInfo) Copy() types.RVType { + copied := NewUniqueIDInfo() + + copied.StructureVersion = uidi.StructureVersion + copied.NEXUniqueID = uidi.NEXUniqueID.Copy().(*types.PrimitiveU64) + copied.NEXUniqueIDPassword = uidi.NEXUniqueIDPassword.Copy().(*types.PrimitiveU64) + + return copied +} + +// Equals checks if the given UniqueIDInfo contains the same data as the current UniqueIDInfo +func (uidi *UniqueIDInfo) Equals(o types.RVType) bool { + if _, ok := o.(*UniqueIDInfo); !ok { + return false + } + + other := o.(*UniqueIDInfo) + + if uidi.StructureVersion != other.StructureVersion { + return false + } + + if !uidi.NEXUniqueID.Equals(other.NEXUniqueID) { + return false + } + + return uidi.NEXUniqueIDPassword.Equals(other.NEXUniqueIDPassword) +} + +// String returns the string representation of the UniqueIDInfo +func (uidi *UniqueIDInfo) String() string { + return uidi.FormatToString(0) +} + +// FormatToString pretty-prints the UniqueIDInfo using the provided indentation level +func (uidi *UniqueIDInfo) FormatToString(indentationLevel int) string { + indentationValues := strings.Repeat("\t", indentationLevel+1) + indentationEnd := strings.Repeat("\t", indentationLevel) + + var b strings.Builder + + b.WriteString("UniqueIDInfo{\n") + b.WriteString(fmt.Sprintf("%sNEXUniqueID: %s,\n", indentationValues, uidi.NEXUniqueID)) + b.WriteString(fmt.Sprintf("%sNEXUniqueIDPassword: %s,\n", indentationValues, uidi.NEXUniqueIDPassword)) + b.WriteString(fmt.Sprintf("%s}", indentationEnd)) + + return b.String() +} + +// NewUniqueIDInfo returns a new UniqueIDInfo +func NewUniqueIDInfo() *UniqueIDInfo { + uidi := &UniqueIDInfo{ + NEXUniqueID: types.NewPrimitiveU64(0), + NEXUniqueIDPassword: types.NewPrimitiveU64(0), + } + + return uidi +} diff --git a/nex/authentication.go b/nex/authentication.go index 5fef2a9..8f40965 100644 --- a/nex/authentication.go +++ b/nex/authentication.go @@ -3,35 +3,40 @@ package nex import ( "fmt" "os" + "strconv" - nex "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-go/v2" "github.com/PretendoNetwork/pokemon-gen6/globals" ) var serverBuildString string func StartAuthenticationServer() { - globals.AuthenticationServer = nex.NewServer() - globals.AuthenticationServer.SetPRUDPVersion(1) - globals.AuthenticationServer.SetPRUDPProtocolMinorVersion(3) - globals.AuthenticationServer.SetDefaultNEXVersion(&nex.NEXVersion{ - Major: 3, - Minor: 3, - Patch: 0, - }) - globals.AuthenticationServer.SetKerberosPassword(globals.KerberosPassword) - globals.AuthenticationServer.SetAccessKey("876138df") - - globals.AuthenticationServer.On("Data", func(packet *nex.PacketV1) { - request := packet.RMCRequest() - - fmt.Println("==Pokemon X/Y/OR/AS (Gen 6) - Auth==") - fmt.Printf("Protocol ID: %#v\n", request.ProtocolID()) - fmt.Printf("Method ID: %#v\n", request.MethodID()) - fmt.Println("===============") + globals.AuthenticationServer = nex.NewPRUDPServer() + + globals.AuthenticationEndpoint = nex.NewPRUDPEndPoint(1) + globals.AuthenticationEndpoint.ServerAccount = globals.AuthenticationServerAccount + globals.AuthenticationEndpoint.AccountDetailsByPID = globals.AccountDetailsByPID + globals.AuthenticationEndpoint.AccountDetailsByUsername = globals.AccountDetailsByUsername + // * The default silence time is too low for Mario Kart 7, so we set a higher value + globals.AuthenticationEndpoint.DefaultStreamSettings.MaxSilenceTime = 20000 + globals.AuthenticationServer.BindPRUDPEndPoint(globals.AuthenticationEndpoint) + + globals.AuthenticationServer.LibraryVersions.SetDefault(nex.NewLibraryVersion(3, 3, 0)) + globals.AuthenticationServer.AccessKey = "876138df" + + globals.AuthenticationEndpoint.OnData(func(packet nex.PacketInterface) { + request := packet.RMCMessage() + + fmt.Println("=== POKEGEN6 - Auth ===") + fmt.Printf("Protocol ID: %#v\n", request.ProtocolID) + fmt.Printf("Method ID: %#v\n", request.MethodID) + fmt.Println("==================") }) registerCommonAuthenticationServerProtocols() - globals.AuthenticationServer.Listen(fmt.Sprintf(":%s", os.Getenv("PN_POKEGEN6_AUTHENTICATION_SERVER_PORT"))) + port, _ := strconv.Atoi(os.Getenv("PN_POKEGEN6_AUTHENTICATION_SERVER_PORT")) + + globals.AuthenticationServer.Listen(port) } diff --git a/nex/matchmake-extension/common/cleanup_search_matchmake_session.go b/nex/matchmake-extension/common/cleanup_search_matchmake_session.go new file mode 100644 index 0000000..aada4b4 --- /dev/null +++ b/nex/matchmake-extension/common/cleanup_search_matchmake_session.go @@ -0,0 +1,14 @@ +package nex_matchmake_extension_common + +import ( + "github.com/PretendoNetwork/nex-go/v2/types" + matchmaking_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" +) + +func CleanupSearchMatchmakeSession(matchmakeSession *matchmaking_types.MatchmakeSession) { + // Cleanup VR + matchmakeSession.Attributes.SetIndex(1, types.NewPrimitiveU32(0)) + + // Cleanup participation count + matchmakeSession.ParticipationCount.Value = 0 +} diff --git a/nex/message-delivery/deliver_message.go b/nex/message-delivery/deliver_message.go new file mode 100644 index 0000000..62b9d80 --- /dev/null +++ b/nex/message-delivery/deliver_message.go @@ -0,0 +1,77 @@ +package nex_message_delivery + +import ( + "encoding/hex" + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/constants" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/pokemon-gen6/globals" + message_delivery "github.com/PretendoNetwork/nex-protocols-go/v2/message-delivery" + messaging_types "github.com/PretendoNetwork/nex-protocols-go/v2/messaging/types" + "fmt" + "strconv" +) + +func DeliverMessage(err error, packet nex.PacketInterface, callID uint32, oUserMessage *types.AnyDataHolder) (*nex.RMCMessage, *nex.Error) { + if err != nil { + globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, err.Error()) + } + + client := packet.Sender() + + endpoint := client.Endpoint().(*nex.PRUDPEndPoint) + server := endpoint.Server + + /*recipientPid := fmt.Sprintf("%.8x",(oUserMessage.(*nexproto.TextMessage).UserMessage.M_messageRecipient.M_principalID)) + recipientPidString := recipientPid[6:8] + recipientPid[4:6] + recipientPid[2:4] + recipientPid[0:2] + senderPid := fmt.Sprintf("%.8x",(client.PID())) + senderPidString := senderPid[6:8] + senderPid[4:6] + senderPid[2:4] + senderPid[0:2]*/ + + oUserMessage.ObjectData.(*messaging_types.TextMessage).UserMessage.StrSender = types.NewString(strconv.Itoa(int(client.PID().Value()))) + oUserMessage.ObjectData.(*messaging_types.TextMessage).UserMessage.PIDSender = client.PID() + //hexData, _ := hex.DecodeString("0C00546578744D65737361676500560000005200000000000000"+recipientPidString+"0100000000000000"+senderPidString+"D01952961F00000000000000010000001400537562736372697074696F6E4D616E61676572000B00313837363834313330350009005570646174696E6700") + + messageStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + oUserMessage.WriteTo(messageStream) + + messageRequest := nex.NewRMCRequest(endpoint) + messageRequest.ProtocolID = message_delivery.ProtocolID + messageRequest.CallID = 0xffffffff + messageRequest.MethodID = message_delivery.MethodDeliverMessage + messageRequest.Parameters = messageStream.Bytes() + + messageRequestBytes := messageRequest.Bytes() + + fmt.Println(hex.EncodeToString(messageRequest.Parameters)) + + //fmt.Println(uint32(oUserMessage.(*nexproto.TextMessage).UserMessage.M_messageRecipient.M_principalID)) + fmt.Println(uint32(oUserMessage.ObjectData.(*messaging_types.TextMessage).UserMessage.UIIDRecipient.Value)) + target := endpoint.FindConnectionByPID(uint64(oUserMessage.ObjectData.(*messaging_types.TextMessage).UserMessage.UIIDRecipient.Value)) + + var messagePacket nex.PRUDPPacketInterface + + if target.DefaultPRUDPVersion == 0 { + messagePacket, _ = nex.NewPRUDPPacketV0(server, target, nil) + } else { + messagePacket, _ = nex.NewPRUDPPacketV1(server, target, nil) + } + + messagePacket.SetType(constants.DataPacket) + messagePacket.AddFlag(constants.PacketFlagNeedsAck) + messagePacket.AddFlag(constants.PacketFlagReliable) + messagePacket.SetSourceVirtualPortStreamType(target.StreamType) + messagePacket.SetSourceVirtualPortStreamID(endpoint.StreamID) + messagePacket.SetDestinationVirtualPortStreamType(target.StreamType) + messagePacket.SetDestinationVirtualPortStreamID(target.StreamID) + messagePacket.SetPayload(messageRequestBytes) + + server.Send(messagePacket) + + rmcResponse := nex.NewRMCSuccess(globals.SecureEndpoint, nil) + rmcResponse.ProtocolID = message_delivery.ProtocolID + rmcResponse.MethodID = message_delivery.MethodDeliverMessage + rmcResponse.CallID = callID + + return rmcResponse, nil +} diff --git a/nex/pokemon-pss/unk1.go b/nex/pokemon-pss/unk1.go new file mode 100644 index 0000000..c06e228 --- /dev/null +++ b/nex/pokemon-pss/unk1.go @@ -0,0 +1,52 @@ +package nex_subscription + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/pokemon-gen6/globals" + pokemon_pss "github.com/PretendoNetwork/nex-protocols-go/v2/pokemon-pss" +) + +func Unk1(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, err.Error()) + } + + client := packet.Sender() + + endpoint := client.Endpoint().(*nex.PRUDPEndPoint) + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + types.NewPrimitiveU32(2259334670).WriteTo(rmcResponseStream) + types.NewPrimitiveU32(0).WriteTo(rmcResponseStream) + types.NewString("e00d70431ddca6ae").WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = pokemon_pss.ProtocolID + rmcResponse.MethodID = pokemon_pss.MethodUnk1 + rmcResponse.CallID = callID + + return rmcResponse, nil + + /*rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) + rmcResponse.SetSuccess(subscription.MethodGetFriendSubscriptionData, rmcResponseBody) + + rmcResponseBytes := rmcResponse.Bytes() + + responsePacket, _ := nex.NewPacketV1(client, nil) + + responsePacket.SetVersion(1) + responsePacket.SetSource(0xA1) + responsePacket.SetDestination(0xAF) + responsePacket.SetType(nex.DataPacket) + responsePacket.SetPayload(rmcResponseBytes) + + responsePacket.AddFlag(nex.FlagNeedsAck) + responsePacket.AddFlag(nex.FlagReliable) + + globals.SecureServer.Send(responsePacket)*/ +} diff --git a/nex/pokemon-pss/unk2.go b/nex/pokemon-pss/unk2.go new file mode 100644 index 0000000..c32f526 --- /dev/null +++ b/nex/pokemon-pss/unk2.go @@ -0,0 +1,43 @@ +package nex_subscription + +import ( + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/pokemon-gen6/globals" + pokemon_pss "github.com/PretendoNetwork/nex-protocols-go/v2/pokemon-pss" +) + +func Unk2(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, err.Error()) + } + + client := packet.Sender() + + endpoint := client.Endpoint().(*nex.PRUDPEndPoint) + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = pokemon_pss.ProtocolID + rmcResponse.MethodID = pokemon_pss.MethodUnk2 + rmcResponse.CallID = callID + + return rmcResponse, nil + + /*rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) + rmcResponse.SetSuccess(subscription.MethodGetFriendSubscriptionData, rmcResponseBody) + + rmcResponseBytes := rmcResponse.Bytes() + + responsePacket, _ := nex.NewPacketV1(client, nil) + + responsePacket.SetVersion(1) + responsePacket.SetSource(0xA1) + responsePacket.SetDestination(0xAF) + responsePacket.SetType(nex.DataPacket) + responsePacket.SetPayload(rmcResponseBytes) + + responsePacket.AddFlag(nex.FlagNeedsAck) + responsePacket.AddFlag(nex.FlagReliable) + + globals.SecureServer.Send(responsePacket)*/ +} diff --git a/nex/register_common_authentication_server_protocols.go b/nex/register_common_authentication_server_protocols.go index a2d7f06..95f9a96 100644 --- a/nex/register_common_authentication_server_protocols.go +++ b/nex/register_common_authentication_server_protocols.go @@ -2,27 +2,33 @@ package nex import ( "os" + "strconv" - nex "github.com/PretendoNetwork/nex-go" - ticket_granting "github.com/PretendoNetwork/nex-protocols-common-go/ticket-granting" "github.com/PretendoNetwork/pokemon-gen6/globals" + "github.com/PretendoNetwork/nex-go/v2/constants" + "github.com/PretendoNetwork/nex-go/v2/types" + common_ticket_granting "github.com/PretendoNetwork/nex-protocols-common-go/v2/ticket-granting" + ticket_granting "github.com/PretendoNetwork/nex-protocols-go/v2/ticket-granting" ) func registerCommonAuthenticationServerProtocols() { - ticketGrantingProtocol := ticket_granting.NewCommonTicketGrantingProtocol(globals.AuthenticationServer) + ticketGrantingProtocol := ticket_granting.NewProtocol() + globals.AuthenticationEndpoint.RegisterServiceProtocol(ticketGrantingProtocol) + commonTicketGrantingProtocol := common_ticket_granting.NewCommonProtocol(ticketGrantingProtocol) - secureStationURL := nex.NewStationURL("") - secureStationURL.SetScheme("prudps") - secureStationURL.SetAddress(os.Getenv("PN_POKEGEN6_SECURE_SERVER_HOST")) - secureStationURL.SetPort(61005) - secureStationURL.SetCID(1) - secureStationURL.SetPID(2) - secureStationURL.SetSID(1) - secureStationURL.SetStream(10) - secureStationURL.SetType(2) + port, _ := strconv.Atoi(os.Getenv("PN_POKEGEN6_SECURE_SERVER_PORT")) - ticketGrantingProtocol.SetSecureStationURL(secureStationURL) - ticketGrantingProtocol.SetBuildName(serverBuildString) + secureStationURL := types.NewStationURL("") + secureStationURL.SetURLType(constants.StationURLPRUDPS) + secureStationURL.SetAddress(os.Getenv("PN_POKEGEN6_SECURE_SERVER_HOST")) + secureStationURL.SetPortNumber(uint16(port)) + secureStationURL.SetConnectionID(1) + secureStationURL.SetPrincipalID(types.NewPID(2)) + secureStationURL.SetStreamID(1) + secureStationURL.SetStreamType(constants.StreamTypeRVSecure) + secureStationURL.SetType(uint8(constants.StationURLFlagPublic)) - globals.AuthenticationServer.SetPasswordFromPIDFunction(globals.PasswordFromPID) + commonTicketGrantingProtocol.SecureStationURL = secureStationURL + commonTicketGrantingProtocol.BuildName = types.NewString(serverBuildString) + commonTicketGrantingProtocol.SecureServerAccount = globals.SecureServerAccount } diff --git a/nex/register_common_secure_server_protocols.go b/nex/register_common_secure_server_protocols.go index 9a1cbc8..da05ab1 100644 --- a/nex/register_common_secure_server_protocols.go +++ b/nex/register_common_secure_server_protocols.go @@ -1,18 +1,53 @@ package nex import ( - secureconnection "github.com/PretendoNetwork/nex-protocols-common-go/secure-connection" - matchmaking "github.com/PretendoNetwork/nex-protocols-common-go/matchmaking" - matchmakingext "github.com/PretendoNetwork/nex-protocols-common-go/matchmaking-ext" - matchmakeextension "github.com/PretendoNetwork/nex-protocols-common-go/matchmake-extension" - nattraversal "github.com/PretendoNetwork/nex-protocols-common-go/nat-traversal" "github.com/PretendoNetwork/pokemon-gen6/globals" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" + common_matchmake_extension "github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension" + match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" + common_match_making "github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making" + match_making_ext "github.com/PretendoNetwork/nex-protocols-go/v2/match-making-ext" + common_match_making_ext "github.com/PretendoNetwork/nex-protocols-common-go/v2/match-making-ext" + nat_traversal "github.com/PretendoNetwork/nex-protocols-go/v2/nat-traversal" + common_nat_traversal "github.com/PretendoNetwork/nex-protocols-common-go/v2/nat-traversal" + secure "github.com/PretendoNetwork/nex-protocols-go/v2/secure-connection" + common_secure "github.com/PretendoNetwork/nex-protocols-common-go/v2/secure-connection" + utility "github.com/PretendoNetwork/nex-protocols-go/v2/utility" + common_utility "github.com/PretendoNetwork/nex-protocols-common-go/v2/utility" + + nex_matchmake_extension_common "github.com/PretendoNetwork/pokemon-gen6/nex/matchmake-extension/common" ) +func GenerateNEXUniqueID() uint64 { + return 0 +} + func registerCommonSecureServerProtocols() { - secureconnection.NewCommonSecureConnectionProtocol(globals.SecureServer) - matchmaking.NewCommonMatchMakingProtocol(globals.SecureServer) - matchmakingext.NewCommonMatchMakingExtProtocol(globals.SecureServer) - matchmakeextension.NewCommonMatchmakeExtensionProtocol(globals.SecureServer) - nattraversal.NewCommonNATTraversalProtocol(globals.SecureServer) + secureProtocol := secure.NewProtocol() + globals.SecureEndpoint.RegisterServiceProtocol(secureProtocol) + common_secure.NewCommonProtocol(secureProtocol) + + natTraversalProtocol := nat_traversal.NewProtocol() + globals.SecureEndpoint.RegisterServiceProtocol(natTraversalProtocol) + common_nat_traversal.NewCommonProtocol(natTraversalProtocol) + + matchMakingProtocol := match_making.NewProtocol() + globals.SecureEndpoint.RegisterServiceProtocol(matchMakingProtocol) + common_match_making.NewCommonProtocol(matchMakingProtocol) + + matchMakingExtProtocol := match_making_ext.NewProtocol() + globals.SecureEndpoint.RegisterServiceProtocol(matchMakingExtProtocol) + common_match_making_ext.NewCommonProtocol(matchMakingExtProtocol) + + matchmakeExtensionProtocol := matchmake_extension.NewProtocol() + globals.SecureEndpoint.RegisterServiceProtocol(matchmakeExtensionProtocol) + commonMatchmakeExtensionProtocol := common_matchmake_extension.NewCommonProtocol(matchmakeExtensionProtocol) + + commonMatchmakeExtensionProtocol.CleanupSearchMatchmakeSession = nex_matchmake_extension_common.CleanupSearchMatchmakeSession + + utilityProtocol := utility.NewProtocol() + globals.SecureEndpoint.RegisterServiceProtocol(utilityProtocol) + commonUtilityProtocol := common_utility.NewCommonProtocol(utilityProtocol) + + commonUtilityProtocol.GenerateNEXUniqueID = GenerateNEXUniqueID } diff --git a/nex/register_secure_server_nex_protocols.go b/nex/register_secure_server_nex_protocols.go index e5a1511..35d6105 100644 --- a/nex/register_secure_server_nex_protocols.go +++ b/nex/register_secure_server_nex_protocols.go @@ -1,20 +1,41 @@ package nex import ( - "github.com/PretendoNetwork/nex-protocols-go/subscription" "github.com/PretendoNetwork/pokemon-gen6/globals" + datastore "github.com/PretendoNetwork/nex-protocols-go/v2/datastore" + message_delivery "github.com/PretendoNetwork/nex-protocols-go/v2/message-delivery" + subscription "github.com/PretendoNetwork/nex-protocols-go/v2/subscription" + pokemon_pss "github.com/PretendoNetwork/nex-protocols-go/v2/pokemon-pss" + + nex_message_delivery "github.com/PretendoNetwork/pokemon-gen6/nex/message-delivery" nex_subscription "github.com/PretendoNetwork/pokemon-gen6/nex/subscription" + nex_pokemon_pss "github.com/PretendoNetwork/pokemon-gen6/nex/pokemon-pss" ) func registerSecureServerNEXProtocols() { - subscriptionProtocol := subscription.NewSubscriptionProtocol(globals.SecureServer) - - subscriptionProtocol.CreateMySubscriptionData(nex_subscription.CreateMySubscriptionData) - subscriptionProtocol.UpdateMySubscriptionData(nex_subscription.UpdateMySubscriptionData) - subscriptionProtocol.GetFriendSubscriptionData(nex_subscription.GetFriendSubscriptionData) - subscriptionProtocol.GetTargetSubscriptionData(nex_subscription.GetTargetSubscriptionData) - subscriptionProtocol.GetActivePlayerSubscriptionData(nex_subscription.GetActivePlayerSubscriptionData) - subscriptionProtocol.GetSubscriptionData(nex_subscription.GetSubscriptionData) - subscriptionProtocol.ReplaceTargetAndGetSubscriptionData(nex_subscription.ReplaceTargetAndGetSubscriptionData) - subscriptionProtocol.GetPrivacyLevels(nex_subscription.GetPrivacyLevels) + datastoreProtocol := datastore.NewProtocol() + globals.SecureEndpoint.RegisterServiceProtocol(datastoreProtocol) + + messageDeliveryProtocol := message_delivery.NewProtocol() + globals.SecureEndpoint.RegisterServiceProtocol(messageDeliveryProtocol) + + messageDeliveryProtocol.DeliverMessage = nex_message_delivery.DeliverMessage + + subscriptionProtocol := subscription.NewProtocol() + globals.SecureEndpoint.RegisterServiceProtocol(subscriptionProtocol) + + subscriptionProtocol.CreateMySubscriptionData = nex_subscription.CreateMySubscriptionData + subscriptionProtocol.UpdateMySubscriptionData = nex_subscription.UpdateMySubscriptionData + subscriptionProtocol.GetFriendSubscriptionData = nex_subscription.GetFriendSubscriptionData + subscriptionProtocol.GetTargetSubscriptionData = nex_subscription.GetTargetSubscriptionData + subscriptionProtocol.GetActivePlayerSubscriptionData = nex_subscription.GetActivePlayerSubscriptionData + subscriptionProtocol.GetSubscriptionData = nex_subscription.GetSubscriptionData + subscriptionProtocol.ReplaceTargetAndGetSubscriptionData = nex_subscription.ReplaceTargetAndGetSubscriptionData + subscriptionProtocol.GetPrivacyLevels = nex_subscription.GetPrivacyLevels + + pssProtocol := pokemon_pss.NewProtocol() + globals.SecureEndpoint.RegisterServiceProtocol(pssProtocol) + + pssProtocol.Unk1 = nex_pokemon_pss.Unk1 + pssProtocol.Unk2 = nex_pokemon_pss.Unk2 } diff --git a/nex/secure.go b/nex/secure.go index e2921e3..9c3fb53 100644 --- a/nex/secure.go +++ b/nex/secure.go @@ -3,36 +3,42 @@ package nex import ( "fmt" "os" + "strconv" - nex "github.com/PretendoNetwork/nex-go" + nex "github.com/PretendoNetwork/nex-go/v2" "github.com/PretendoNetwork/pokemon-gen6/globals" ) func StartSecureServer() { - globals.SecureServer = nex.NewServer() - globals.SecureServer.SetPRUDPVersion(1) - globals.SecureServer.SetPRUDPProtocolMinorVersion(3) - globals.SecureServer.SetDefaultNEXVersion(&nex.NEXVersion{ - Major: 3, - Minor: 3, - Patch: 0, - }) - globals.SecureServer.SetKerberosPassword(globals.KerberosPassword) - globals.SecureServer.SetAccessKey("876138df") + globals.SecureServer = nex.NewPRUDPServer() + + globals.SecureEndpoint = nex.NewPRUDPEndPoint(1) + globals.SecureEndpoint.IsSecureEndPoint = true + globals.SecureEndpoint.ServerAccount = globals.SecureServerAccount + globals.SecureEndpoint.AccountDetailsByPID = globals.AccountDetailsByPID + globals.SecureEndpoint.AccountDetailsByUsername = globals.AccountDetailsByUsername + // * The default silence time is too low for Mario Kart 7, so we set a higher value + globals.SecureEndpoint.DefaultStreamSettings.MaxSilenceTime = 20000 + globals.SecureServer.BindPRUDPEndPoint(globals.SecureEndpoint) + + globals.SecureServer.LibraryVersions.SetDefault(nex.NewLibraryVersion(3, 3, 0)) + globals.SecureServer.AccessKey = "876138df" globals.Timeline = make(map[uint32][]uint8) - globals.SecureServer.On("Data", func(packet *nex.PacketV1) { - request := packet.RMCRequest() + globals.SecureEndpoint.OnData(func(packet nex.PacketInterface) { + request := packet.RMCMessage() - fmt.Println("==Pokemon X/Y/OR/AS (Gen 6) - Secure==") - fmt.Printf("Protocol ID: %#v\n", request.ProtocolID()) - fmt.Printf("Method ID: %#v\n", request.MethodID()) - fmt.Println("===============") + fmt.Println("=== POKEGEN6 - Secure ===") + fmt.Printf("Protocol ID: %#v\n", request.ProtocolID) + fmt.Printf("Method ID: %#v\n", request.MethodID) + fmt.Println("====================") }) registerCommonSecureServerProtocols() registerSecureServerNEXProtocols() - globals.SecureServer.Listen(fmt.Sprintf(":%s", os.Getenv("PN_POKEGEN6_SECURE_SERVER_PORT"))) + port, _ := strconv.Atoi(os.Getenv("PN_POKEGEN6_SECURE_SERVER_PORT")) + + globals.SecureServer.Listen(port) } diff --git a/nex/subscription/create_my_subscription_data.go b/nex/subscription/create_my_subscription_data.go index c2ae811..7c09c99 100644 --- a/nex/subscription/create_my_subscription_data.go +++ b/nex/subscription/create_my_subscription_data.go @@ -1,28 +1,28 @@ package nex_subscription import ( - nex "github.com/PretendoNetwork/nex-go" + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" "github.com/PretendoNetwork/pokemon-gen6/globals" - "github.com/PretendoNetwork/nex-protocols-go/subscription" + subscription "github.com/PretendoNetwork/nex-protocols-go/v2/subscription" ) -func CreateMySubscriptionData(err error, client *nex.Client, callID uint32, unk uint64, content []byte) { - globals.Timeline[client.PID()] = content - rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) - rmcResponse.SetSuccess(subscription.MethodCreateMySubscriptionData, nil) +func CreateMySubscriptionData(err error, packet nex.PacketInterface, callID uint32, unk *types.PrimitiveU64, content []byte) (*nex.RMCMessage, *nex.Error) { + if err != nil { + globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, err.Error()) + } - rmcResponseBytes := rmcResponse.Bytes() + client := packet.Sender() - responsePacket, _ := nex.NewPacketV1(client, nil) + endpoint := client.Endpoint().(*nex.PRUDPEndPoint) - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) + globals.Timeline[client.PID().LegacyValue()] = content - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = subscription.ProtocolID + rmcResponse.MethodID = subscription.MethodCreateMySubscriptionData + rmcResponse.CallID = callID - globals.SecureServer.Send(responsePacket) + return rmcResponse, nil } diff --git a/nex/subscription/get_active_player_subscription_data.go b/nex/subscription/get_active_player_subscription_data.go index 28e7ec9..2bf4d54 100644 --- a/nex/subscription/get_active_player_subscription_data.go +++ b/nex/subscription/get_active_player_subscription_data.go @@ -3,25 +3,45 @@ package nex_subscription import ( "encoding/hex" "fmt" - nex "github.com/PretendoNetwork/nex-go" + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" "github.com/PretendoNetwork/pokemon-gen6/globals" - "github.com/PretendoNetwork/nex-protocols-go/subscription" + subscription "github.com/PretendoNetwork/nex-protocols-go/v2/subscription" ) -func GetActivePlayerSubscriptionData(err error, client *nex.Client, callID uint32) { - rmcResponseStream := nex.NewStreamOut(globals.SecureServer) +func GetActivePlayerSubscriptionData(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, err.Error()) + } + + client := packet.Sender() + + endpoint := client.Endpoint().(*nex.PRUDPEndPoint) - rmcResponseStream.WriteUInt32LE(uint32(len(globals.Timeline))) + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + types.NewPrimitiveU32(uint32(len(globals.Timeline))).WriteTo(rmcResponseStream) for clientPID := range globals.Timeline { + types.NewPrimitiveU32(clientPID).WriteTo(rmcResponseStream) + //rmcResponseStream.WriteUInt32LE(clientPID) for j := 0; j < len(globals.Timeline[clientPID]); j++ { - rmcResponseStream.WriteUInt8(globals.Timeline[clientPID][j]) + types.NewPrimitiveU8(globals.Timeline[clientPID][j]).WriteTo(rmcResponseStream) + //rmcResponseStream.WriteUInt8(globals.Timeline[clientPID][j]) } } rmcResponseBody := rmcResponseStream.Bytes() fmt.Println(hex.EncodeToString(rmcResponseBody)) - rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = subscription.ProtocolID + rmcResponse.MethodID = subscription.MethodGetActivePlayerSubscriptionData + rmcResponse.CallID = callID + + return rmcResponse, nil + + /*rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) rmcResponse.SetSuccess(subscription.MethodGetActivePlayerSubscriptionData, rmcResponseBody) rmcResponseBytes := rmcResponse.Bytes() @@ -37,5 +57,5 @@ func GetActivePlayerSubscriptionData(err error, client *nex.Client, callID uint3 responsePacket.AddFlag(nex.FlagNeedsAck) responsePacket.AddFlag(nex.FlagReliable) - globals.SecureServer.Send(responsePacket) + globals.SecureServer.Send(responsePacket)*/ } diff --git a/nex/subscription/get_friend_subscription_data.go b/nex/subscription/get_friend_subscription_data.go index ac96ad9..5ad7ff1 100644 --- a/nex/subscription/get_friend_subscription_data.go +++ b/nex/subscription/get_friend_subscription_data.go @@ -1,19 +1,36 @@ package nex_subscription import ( - nex "github.com/PretendoNetwork/nex-go" + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" "github.com/PretendoNetwork/pokemon-gen6/globals" - "github.com/PretendoNetwork/nex-protocols-go/subscription" + subscription "github.com/PretendoNetwork/nex-protocols-go/v2/subscription" ) -func GetFriendSubscriptionData(err error, client *nex.Client, callID uint32) { - rmcResponseStream := nex.NewStreamOut(globals.SecureServer) +func GetFriendSubscriptionData(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, err.Error()) + } - rmcResponseStream.WriteUInt32LE(0) + client := packet.Sender() + + endpoint := client.Endpoint().(*nex.PRUDPEndPoint) + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + types.NewPrimitiveU32(0).WriteTo(rmcResponseStream) rmcResponseBody := rmcResponseStream.Bytes() - rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = subscription.ProtocolID + rmcResponse.MethodID = subscription.MethodGetFriendSubscriptionData + rmcResponse.CallID = callID + + return rmcResponse, nil + + /*rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) rmcResponse.SetSuccess(subscription.MethodGetFriendSubscriptionData, rmcResponseBody) rmcResponseBytes := rmcResponse.Bytes() @@ -29,5 +46,5 @@ func GetFriendSubscriptionData(err error, client *nex.Client, callID uint32) { responsePacket.AddFlag(nex.FlagNeedsAck) responsePacket.AddFlag(nex.FlagReliable) - globals.SecureServer.Send(responsePacket) + globals.SecureServer.Send(responsePacket)*/ } diff --git a/nex/subscription/get_privacy_levels.go b/nex/subscription/get_privacy_levels.go index 3246009..20d2496 100644 --- a/nex/subscription/get_privacy_levels.go +++ b/nex/subscription/get_privacy_levels.go @@ -1,13 +1,29 @@ package nex_subscription import ( - nex "github.com/PretendoNetwork/nex-go" + nex "github.com/PretendoNetwork/nex-go/v2" "github.com/PretendoNetwork/pokemon-gen6/globals" - "github.com/PretendoNetwork/nex-protocols-go/subscription" + subscription "github.com/PretendoNetwork/nex-protocols-go/v2/subscription" ) -func GetPrivacyLevels(err error, client *nex.Client, callID uint32) { - rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) +func GetPrivacyLevels(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, err.Error()) + } + + client := packet.Sender() + + endpoint := client.Endpoint().(*nex.PRUDPEndPoint) + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = subscription.ProtocolID + rmcResponse.MethodID = subscription.MethodGetPrivacyLevels + rmcResponse.CallID = callID + + return rmcResponse, nil + + /*rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) rmcResponse.SetSuccess(subscription.MethodGetPrivacyLevels, nil) rmcResponseBytes := rmcResponse.Bytes() @@ -23,5 +39,5 @@ func GetPrivacyLevels(err error, client *nex.Client, callID uint32) { responsePacket.AddFlag(nex.FlagNeedsAck) responsePacket.AddFlag(nex.FlagReliable) - globals.SecureServer.Send(responsePacket) + globals.SecureServer.Send(responsePacket)*/ } diff --git a/nex/subscription/get_subscription_data.go b/nex/subscription/get_subscription_data.go index 8a5919f..be3c32d 100644 --- a/nex/subscription/get_subscription_data.go +++ b/nex/subscription/get_subscription_data.go @@ -1,22 +1,34 @@ package nex_subscription import ( - nex "github.com/PretendoNetwork/nex-go" + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" "encoding/hex" "fmt" "github.com/PretendoNetwork/pokemon-gen6/globals" - "github.com/PretendoNetwork/nex-protocols-go/subscription" + subscription "github.com/PretendoNetwork/nex-protocols-go/v2/subscription" ) -func GetSubscriptionData(err error, client *nex.Client, callID uint32, pids []uint32) { - rmcResponseStream := nex.NewStreamOut(globals.SecureServer) +func GetSubscriptionData(err error, packet nex.PacketInterface, callID uint32, pids *types.List[*types.PrimitiveU32]) (*nex.RMCMessage, *nex.Error) { + if err != nil { + globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, err.Error()) + } + + client := packet.Sender() + + endpoint := client.Endpoint().(*nex.PRUDPEndPoint) - for _, pid := range pids { + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + for _, pid := range pids.Slice() { fmt.Println(pid) - content := globals.Timeline[pid] - rmcResponseStream.WriteUInt32LE(1) + content := globals.Timeline[pid.Value] + types.NewPrimitiveU32(1).WriteTo(rmcResponseStream) + types.NewPrimitiveU32(pid.Value).WriteTo(rmcResponseStream) for i := 0; i < len(content); i++ { - rmcResponseStream.WriteUInt8(content[i]) + types.NewPrimitiveU8(content[i]).WriteTo(rmcResponseStream) + //rmcResponseStream.WriteUInt8(content[i]) } } @@ -24,7 +36,14 @@ func GetSubscriptionData(err error, client *nex.Client, callID uint32, pids []ui _ = rmcResponseBody fmt.Println(hex.EncodeToString(rmcResponseBody)) - rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = subscription.ProtocolID + rmcResponse.MethodID = subscription.MethodGetSubscriptionData + rmcResponse.CallID = callID + + return rmcResponse, nil + + /*rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) rmcResponse.SetSuccess(subscription.MethodGetSubscriptionData, rmcResponseBody) rmcResponseBytes := rmcResponse.Bytes() @@ -40,5 +59,5 @@ func GetSubscriptionData(err error, client *nex.Client, callID uint32, pids []ui responsePacket.AddFlag(nex.FlagNeedsAck) responsePacket.AddFlag(nex.FlagReliable) - globals.SecureServer.Send(responsePacket) + globals.SecureServer.Send(responsePacket)*/ } diff --git a/nex/subscription/get_target_subscription_data.go b/nex/subscription/get_target_subscription_data.go index 4eb6193..0797c00 100644 --- a/nex/subscription/get_target_subscription_data.go +++ b/nex/subscription/get_target_subscription_data.go @@ -1,19 +1,36 @@ package nex_subscription import ( - nex "github.com/PretendoNetwork/nex-go" + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" "github.com/PretendoNetwork/pokemon-gen6/globals" - "github.com/PretendoNetwork/nex-protocols-go/subscription" + subscription "github.com/PretendoNetwork/nex-protocols-go/v2/subscription" ) -func GetTargetSubscriptionData(err error, client *nex.Client, callID uint32) { - rmcResponseStream := nex.NewStreamOut(globals.SecureServer) +func GetTargetSubscriptionData(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, err.Error()) + } - rmcResponseStream.WriteUInt32LE(0) + client := packet.Sender() + + endpoint := client.Endpoint().(*nex.PRUDPEndPoint) + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + types.NewPrimitiveU32(0).WriteTo(rmcResponseStream) rmcResponseBody := rmcResponseStream.Bytes() - rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = subscription.ProtocolID + rmcResponse.MethodID = subscription.MethodGetTargetSubscriptionData + rmcResponse.CallID = callID + + return rmcResponse, nil + + /*rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) rmcResponse.SetSuccess(subscription.MethodGetTargetSubscriptionData, rmcResponseBody) rmcResponseBytes := rmcResponse.Bytes() @@ -29,5 +46,5 @@ func GetTargetSubscriptionData(err error, client *nex.Client, callID uint32) { responsePacket.AddFlag(nex.FlagNeedsAck) responsePacket.AddFlag(nex.FlagReliable) - globals.SecureServer.Send(responsePacket) + globals.SecureServer.Send(responsePacket)*/ } diff --git a/nex/subscription/replace_target_and_get_subscription_data.go b/nex/subscription/replace_target_and_get_subscription_data.go index 89da4fa..c782eb8 100644 --- a/nex/subscription/replace_target_and_get_subscription_data.go +++ b/nex/subscription/replace_target_and_get_subscription_data.go @@ -1,19 +1,36 @@ package nex_subscription import ( - nex "github.com/PretendoNetwork/nex-go" + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" "github.com/PretendoNetwork/pokemon-gen6/globals" - "github.com/PretendoNetwork/nex-protocols-go/subscription" + subscription "github.com/PretendoNetwork/nex-protocols-go/v2/subscription" ) -func ReplaceTargetAndGetSubscriptionData(err error, client *nex.Client, callID uint32) { - rmcResponseStream := nex.NewStreamOut(globals.SecureServer) +func ReplaceTargetAndGetSubscriptionData(err error, packet nex.PacketInterface, callID uint32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, err.Error()) + } - rmcResponseStream.WriteUInt32LE(0) + client := packet.Sender() + + endpoint := client.Endpoint().(*nex.PRUDPEndPoint) + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + types.NewPrimitiveU32(0).WriteTo(rmcResponseStream) rmcResponseBody := rmcResponseStream.Bytes() - rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = subscription.ProtocolID + rmcResponse.MethodID = subscription.MethodReplaceTargetAndGetSubscriptionData + rmcResponse.CallID = callID + + return rmcResponse, nil + + /*rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) rmcResponse.SetSuccess(subscription.MethodReplaceTargetAndGetSubscriptionData, rmcResponseBody) rmcResponseBytes := rmcResponse.Bytes() @@ -29,5 +46,5 @@ func ReplaceTargetAndGetSubscriptionData(err error, client *nex.Client, callID u responsePacket.AddFlag(nex.FlagNeedsAck) responsePacket.AddFlag(nex.FlagReliable) - globals.SecureServer.Send(responsePacket) + globals.SecureServer.Send(responsePacket)*/ } diff --git a/nex/subscription/update_my_subscription_data.go b/nex/subscription/update_my_subscription_data.go index 6b237e5..e3929f5 100644 --- a/nex/subscription/update_my_subscription_data.go +++ b/nex/subscription/update_my_subscription_data.go @@ -1,15 +1,43 @@ package nex_subscription import ( - nex "github.com/PretendoNetwork/nex-go" + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" "github.com/PretendoNetwork/pokemon-gen6/globals" - "github.com/PretendoNetwork/nex-protocols-go/subscription" + subscription "github.com/PretendoNetwork/nex-protocols-go/v2/subscription" ) -func UpdateMySubscriptionData(err error, client *nex.Client, callID uint32, unk uint32, content []byte) { - globals.Timeline[client.PID()] = content +func UpdateMySubscriptionData(err error, packet nex.PacketInterface, callID uint32, unk *types.PrimitiveU32, content []byte) (*nex.RMCMessage, *nex.Error) { + if err != nil { + globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, err.Error()) + } - rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) + client := packet.Sender() + + endpoint := client.Endpoint().(*nex.PRUDPEndPoint) + + globals.Timeline[client.PID().LegacyValue()] = content + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = subscription.ProtocolID + rmcResponse.MethodID = subscription.MethodUpdateMySubscriptionData + rmcResponse.CallID = callID + + return rmcResponse, nil + + /*if err != nil { + globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, err.Error()) + } + + client := packet.Sender() + + endpoint := client.Endpoint().(*nex.PRUDPEndPoint) + server := endpoint.Server + globals.Timeline[client.PID()] = content*/ + + /*rmcResponse := nex.NewRMCResponse(subscription.ProtocolID, callID) rmcResponse.SetSuccess(subscription.MethodUpdateMySubscriptionData, nil) rmcResponseBytes := rmcResponse.Bytes() @@ -25,5 +53,5 @@ func UpdateMySubscriptionData(err error, client *nex.Client, callID uint32, unk responsePacket.AddFlag(nex.FlagNeedsAck) responsePacket.AddFlag(nex.FlagReliable) - globals.SecureServer.Send(responsePacket) + globals.SecureServer.Send(responsePacket)*/ }