goto-bus-stop / aocmultiny

[wip] Tiny NAT-traversing Age of Empires 2 Multiplayer client.
GNU General Public License v3.0
6 stars 1 forks source link

dplib: DPServiceProvider class #22

Closed goto-bus-stop closed 8 years ago

goto-bus-stop commented 8 years ago

New thing for dplib: a base class for DPlay service providers. DPServiceProvider would be a wrapper around IDirectPlaySP, minus the Get- and SetSPData methods (which will be used to associate the DPServiceProvider to IDirectPlaySP instances internally).

Implement Service Provider callbacks as virtual methods in the subclass.

class MyServiceProvider: public dplib::DPServiceProvider {
private:
  SomeProxiedConnection connection;
public:
  virtual HRESULT Open (DPSP_OPENDATA* data) {
    // Can use `this` to store stuff, instead of SetSPData and GetSPData.
    this->connection.open("http://myproxy.com");
    return DP_OK;
  }
  virtual HRESULT Send (DPSP_SENDDATA* data) {
    this->connection.send(data->idPlayerTo, data->lpMessage, data->dwMessageSize);
    return DP_OK;
  }
};

Then, SPInit will be something like:

HRESULT WINAPI SPInit (SPINITDATA* data) {
  auto sp = new MyServiceProvider(data);
  return sp->init();
}

DPServiceProvider could also provide overloads for hooks. Eg, it could turn EnumSessions from EnumSessions (DPSP_ENUMSESSIONSDATA* data) into EnumSessions (void* message, int size, bool returnStatus).

class DPServiceProvider {
public:
  HRESULT EnumSessions (void* message, int size, bool returnStatus);
  HRESULT EnumSessions (DPSP_ENUMSESSIONSDATA* data) {
    this->EnumSessions(
      data->lpMessage,
      data->dwMessageSize,
      data->bReturnStatus
    );
  }
};

And subclasses could choose to either use the simplified overloaded fn, or the raw DirectPlay-style struct parameter.

Likely methods:

EnumSessions
Reply
Send
CreatePlayer
DeletePlayer
GetAddress
GetCaps
Open
Close // actually DPlay's CloseEx hook
Shutdown // actually DPlay's ShutdownEx hook
GetAddressChoices
SendEx // could refer to the same Send() overload as Send() by default
SendToGroupEx // or just SendToGroup
Cancel
GetMessageQueue

DPlay's CloseEx and ShutdownEx would have to be used instead of its Close and Shutdown, because the standard Close and Shutdown hooks don't get the IDirectPlaySP interface passed in, so we couldn't use GetSPData to retrieve the DPServiceProvider instance.