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: fluent DPAddress creation #18

Closed goto-bus-stop closed 8 years ago

goto-bus-stop commented 8 years ago

Currently dplib hardcodes TCP/IP or libnice service provider addresses, which is a bit restrictive (although you're unlikely to use anything other than TCP/IP from the defaults, but who knows).

Idea:

Shorthands for common stuff:

DPAddress::ip("164.145.25.145"); // → tcp/ip address with a specific IP
DPAddress::ip(); // tcp/ip address with empty IP, for hosting sessions

Address builder for other stuff:

class DPAddress {
public:
  DPAddress (GUID serviceProviderGuid);
  DPAddress* add (GUID dataType, void* data, int dataSize);
  DPAddress* add (GUID dataType, string str) {
    return add(dataType, str.c_str(), str.length());
  }
};

// tcp/ip address with an IP component
new DPAddress(DPSPGUID_TCPIP)
  ->add(DPAID_INet, "164.145.25.145");
// libnice service provider address with custom signaling and STUN servers, and a known host SDP
new DPAddress(DPSPGUID_NICE)
  ->add(DPAID_ICESignalingServer, "aocmultiny.net:7788")
  ->add(DPAID_ICETURN, "turn.l.google.com:6345")
  ->add(DPAID_ICESDP, hostSdp, hostSdpLen);
// or even, but not sure if this is doable with types and stuff:
new DPAddress(DPSPGUID_NICE, {
  { DPAID_ICESignalingServer, "aocmultiny.net:7788" },
  { DPAID_ICETURN, "turn.l.google.com:6345" },
  { DPAID_ICESDP, hostSdp, hostSdpLen },
});