Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring of chat struct #8013

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Singe-Horizontal
Copy link
Contributor

@Singe-Horizontal Singe-Horizontal commented Nov 16, 2023

Refactoring of chat struct

Converted C constructs to modern cpp

  • Conversion of regular arrays to std::array, that allows iterating and holds size info
  • Conversion of functions to class methods when appropriate
  • Conversion of Macros to inline constexpr for easier:
    • Scoping
    • Rebuild
    • Debugging
  • Declaration and definition on the same line, the closest to where it's used
  • Removed class-specifiers when possible
    Converted unused int return types to void

Added namespace chats::
Applied google guidelines for naming conventions

  • CamelCase for structs, classes, typedefs, templates and functions
  • Underscore for local variables and namespaces
  • A trailing _ for private members

Converted C constructs to modern cpp
 * Conversion of regular arrays to std::array, that allows iterating and size info
 * Conversion of functions to class methods when appropriate
 * Conversion of Macros to inline constexpr for easier:
   ** Scoping
   ** Rebuild
   ** Debugging
 * Declaration and definition on the same line, the closest to where it's used
 * Removed class-specifiers when possible
Converted unused int return types to void
Added namespace chats::
Applied google guidelines for naming conventions
 * CamelCase for structs, classes, typedefs, templates and functions
 * Underscore for local variables and namespaces
 * A trailing _ for private members
Copy link
Member

@vstumpf vstumpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Havent checked most of the chat.cpp changes, will do in the future

struct block_list* owner;
uint32 min_level; // minimum base level to join
uint32 max_level; // maximum base level allowed to join
std::array<map_session_data*,MAX_CHAT_USERS> usersd;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want an array here? can we use a vector instead? or is it so we don't have to change too much of the implementation

int chat_changechatowner(map_session_data* sd, const char* nextownername);
int chat_changechatstatus(map_session_data* sd, const char* title, const char* pass, int limit, bool pub);
int chat_kickchat(map_session_data* sd, const char* kickusername);
void TriggerEvent();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a nitpick, but we have more methods that are camelCase than PascalCase, I like the former more imo

Comment on lines +20 to +21
uint32 users; // current user count
uint32 limit; // join limit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why to increase the storage of these?
if it's to keep in line with MAX_CHAT_USERS, we can either change the storage type of MAX_CHAT_USERS, or have some static_assert comparing with std::numeric_limit<decltype(ChatData::users)>::max()


nullpo_ret(sd);
ChatData* cd = (ChatData*)map_id2bl(chatid);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should replace every usage of (ChatData*)map_id2bl(chatid) with map_id2cd(chatid); we get the BL_CAST for free

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants