/* dpnet.dll
 *
 * Copyright 2002, 2003 TransGaming Technologies
 *
 * David Hammerton (david@transgaming.com)
 */

#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "winreg.h"
#include "objbase.h"
#include "wine/debug.h"
#include "winerror.h"

#include "dplay8.h"
#include "dplay8_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(dplay);

static ICOM_VTABLE(IDirectPlay8Server) directPlay8ServerVT;

HRESULT WINAPI DirectPlay8Server_QueryInterface(PDIRECTPLAY8SERVER iface,
                                                REFIID riid, LPVOID *obj)
{
    ICOM_THIS(IDirectPlay8ServerImpl, iface);
    TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), obj);
    if (IsEqualGUID(&IID_IUnknown, riid) ||
        IsEqualGUID(&IID_IDirectPlay8Server, riid))
    {
        This->ref++;
        *obj = This;
        return S_OK;
    }
    else
    {
        FIXME("(%p)->(%s, %p): no interface\n", iface, debugstr_guid(riid), obj);
        return E_NOINTERFACE;
    }
}

ULONG WINAPI DirectPlay8Server_AddRef(PDIRECTPLAY8SERVER iface)
{
    ICOM_THIS(IDirectPlay8ServerImpl, iface);
    TRACE("(%p)->()\n", iface);
    return ++This->ref;
}

ULONG WINAPI DirectPlay8Server_Release(PDIRECTPLAY8SERVER iface)
{
    ICOM_THIS(IDirectPlay8ServerImpl, iface);
    TRACE("(%p)->()\n", iface);
    if (--This->ref) return This->ref;

    FIXME("destroy this and everything\n");

    HeapFree(GetProcessHeap(), 0, This);
    return 0;
}

HRESULT DPNET_CreateDirectPlay8Server(IUnknown *pOuter, REFIID riid, LPVOID *ppobj)
{
    IDirectPlay8ServerImpl *ipDP8S;
    HRESULT hr;
    TRACE("()\n");
    ipDP8S = (IDirectPlay8ServerImpl *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
                                          sizeof(IDirectPlay8ServerImpl));
    if (ipDP8S == NULL) return E_OUTOFMEMORY;
    ICOM_VTBL(ipDP8S) = &directPlay8ServerVT;
    IDirectPlay8Server_AddRef((IDirectPlay8Server *)ipDP8S);
    TRACE("Created new object: %p\n", ipDP8S);
    hr = IDirectPlay8Server_QueryInterface((IDirectPlay8Server *)ipDP8S, riid, ppobj);
    IDirectPlay8Server_Release((IDirectPlay8Server *)ipDP8S);
    if (SUCCEEDED(hr))
        return S_OK;
    else
        return E_NOINTERFACE;
}

static ICOM_VTABLE(IDirectPlay8Server) directPlay8ServerVT =
{
    ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
    DirectPlay8Server_QueryInterface,
    DirectPlay8Server_AddRef,
    DirectPlay8Server_Release,
    (void*)0xdead4004, /* Initilize */
    (void*)0xdead4005, /* EnumServiceProviers */
    (void*)0xdead4006, /* CancelAsyncOperation */
    (void*)0xdead4007, /* GetSendQueueInfo */
    (void*)0xdead4008, /* GetApplicationDesc */
    (void*)0xdead4009, /* SetServerInfo */
    (void*)0xdead400a, /* GetClientInfo */
    (void*)0xdead400b, /* GetClientAddress */
    (void*)0xdead400c, /* GetLocalHostAddresses */
    (void*)0xdead400d, /* SetApplicationDesc */
    (void*)0xdead400e, /* Host */
    (void*)0xdead400f, /* SendTo */
    (void*)0xdead4010, /* CreateGroup */
    (void*)0xdead4011, /* DestroyGroup */
    (void*)0xdead4012, /* AddPlayerToGroup */
    (void*)0xdead4013, /* RemovePlayerFromGroup */
    (void*)0xdead4014, /* SetGroupInfo */
    (void*)0xdead4015, /* GetGroupInfo */
    (void*)0xdead4016, /* EnumPlayersAndGroups */
    (void*)0xdead4017, /* Close */
    (void*)0xdead4018, /* DestroyClient */
    (void*)0xdead4019, /* ReturnBuffer */
    (void*)0xdead401a, /* GetPlayerContext */
    (void*)0xdead401b, /* GetGroupContext */
    (void*)0xdead401c, /* SetCaps */
    (void*)0xdead401d, /* GetCaps */
    (void*)0xdead401e, /* GetConnectionInfo */
    (void*)0xdead401f  /* RegisterLobby */
};


