You can't do this this way because in order to get at the EXPOSE'd
interface, you'd have to loadlibrary the .dll which implements it.
Since the client .dll and server .dll are already both loaded by the
engine, you'd be looking at another instance of the .dll which wouldn't
work for you.

If you are making a single player game, then you can punch a hole from
client to server by sending the interface ptr through a cvar,
usermessage, or CUserCmd data slot (since everything is in the same
process space, you can probably get away with this in single player).
It's a _huge_ hack to do this and won't work for multiplayer games or
dedicated servers for obvious reasons.

I think we might have a way for the engine to load a single "shared"
.dll and provide the CreateInterfaceFn factory to both the client and
game server .dlls, but that might not be in the SDK code line yet.

The preferred method would be for the client to send network messages to
your server, the server acts on those (invokes your test interface), and
responds with network messages back to the client.  It's a form of
remote procedure call.  You just have to assume arbitrary latency in
getting return values or having the messages handled.

Yahn

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Matt Young
Sent: Thursday, April 05, 2007 10:31 PM
To: [email protected]
Subject: [hlcoders] Exposing Interfaces

Hello all,

After looking at all the interface documentation, I am still stuck.
What I am trying to do is expose a custom interface located on the
server to be accessed by the client, like the IVEngineServer.  Here is
the code I am attempting to get working (I stripped it down for
readability).  This code compiles but crashes during runtime.  The
overall purpose of this is to allow communication between the client and
server, but if there is a better or more correct way of doing this,
please let me know.  Thanks a lot!

In src/gameshared, ITestInterface.h
    #ifndef PB_ITEST_INTERFACE_H
    #define PB_ITEST_INTERFACE_H
    #include "cbase.h"
    #define ITEST_INTERFACE_NAME "TESTINTERFACE001"

    abstract_class ITestInterface
    {
    public:
      virtual bool Message(char* msg) = 0;
    };
    #endif

In src/dlls, TestInterface.h
    #ifndef TEST_INTERFACE_H
    #define TEST_INTERFACE_H
    #include "cbase.h"
    #include "ITestInterface.h"

    class TestInterface : public ITestInterface
    {
    public:
      TestInterface(){};
      ~TestInterface(){};

      //ITestInterface methods
      virtual bool Message(char* msg);
    };
    static TestInterface* test_interface;
    EXPOSE_SINGLE_INTERFACE_GLOBALVAR(TestInterface, ITestInterface,
ITEST_INTERFACE_NAME, test_interface);
    bool TestInterface::Message(char* msg)
    {
      Msg("The message, %s, was received\n.", msg);
      return true;
    }
    #endif

In cdll_client_int.h, I extern the interface
    extern ITestInterface *test_interface;

Then from within a class in src/cdll which should simply display the
message "Yay!"
    test_interface->Message("Yay!");

_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives,
please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders


_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to