Skip to content

Commit

Permalink
refactor(State): remove unused onDataHandlers property
Browse files Browse the repository at this point in the history
  • Loading branch information
drazisil committed Oct 12, 2024
1 parent 4cc5a36 commit 49defc2
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 76 deletions.
20 changes: 0 additions & 20 deletions packages/gateway/src/GatewayServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,26 +305,6 @@ export class Gateway {
/** @type {Gateway | undefined} */
Gateway._instance = undefined;

/**
* Registers various data handlers to the provided state.
*
* This function adds handlers for different types of data, such as login data,
* chat data, persona data, lobby data, and transaction data. Each handler is
* associated with a specific code.
*
* @param state - The initial state to which the data handlers will be added.
* @returns The updated state with all the data handlers registered.
*/
function registerDataHandlers(state: State) {
state = addOnDataHandler(state, 8226, receiveLoginData);
state = addOnDataHandler(state, 8227, receiveChatData);
state = addOnDataHandler(state, 8228, receivePersonaData);
state = addOnDataHandler(state, 7003, receiveLobbyData);
state = addOnDataHandler(state, 9000, receiveChatData);
state = addOnDataHandler(state, 43300, receiveTransactionsData);
return state;
}

/**
* Get a singleton instance of GatewayServer
*
Expand Down
2 changes: 0 additions & 2 deletions packages/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export {
addSession,
createInitialState,
fetchStateFromDatabase,
addOnDataHandler,
getOnDataHandler,
addEncryption,
getEncryption,
McosSession,
Expand Down
54 changes: 0 additions & 54 deletions packages/shared/src/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ export interface State {
encryptions: Record<string, McosEncryption>;
sessions: Record<string, McosSession>;
// queuedConnections: Record<string, WrappedSocket>;
onDataHandlers: Record<string, OnDataHandler>;
save: (state?: State) => void;
}

Expand Down Expand Up @@ -212,7 +211,6 @@ export function createInitialState({
encryptions: {},
sessions: {},
// queuedConnections: {},
onDataHandlers: {},
save: function (state?: State) {
if (typeof state === "undefined") {
state = this as State;
Expand All @@ -226,58 +224,6 @@ export function createInitialState({
};
}

/**
* Add a data handler to the state.
*
* This function adds a data handler to the state.
* The returned state is a new state object, and the original state is not
* modified. You should then call the save function on the new state to update
* the database.
*
* @param {State} state The state to add the data handler to.
* @param {number} port The port to add the data handler for.
* @param {OnDataHandler} handler The data
* handler to
* add.
* @returns {State} The state with the data handler added.
*/
export function addOnDataHandler(
state: State,
port: number,
handler: OnDataHandler,
): State {
const onDataHandlers = state.onDataHandlers;
onDataHandlers[port.toString()] = handler;
const newState = {
...state,
onDataHandlers,
};
return newState;
}

/**
* Get a data handler for a port from the state.
*
* This function gets a data handler for a port from the state.
*
* @param {State} state The state to get the data handler from.
* @param {number} port The port to get the data handler for.
* @returns {OnDataHandler | undefined} The
* data
* handler
* for the
* given port,
* or undefined
* if no data
* handler exists
*/
export function getOnDataHandler(
state: State,
port: number,
): OnDataHandler | undefined {
return state.onDataHandlers[port.toString()];
}

/**
* Add an encryption to the state.
*
Expand Down

0 comments on commit 49defc2

Please sign in to comment.