Setup Photon Chat

DG GageDG Gage
edited June 2015 in Photon Chat
C++, used with Realtime, for Unreal Engine 4. Everything with Realtime is working perfectly. So for Chat.....

Not sure what I'm missing, but I don't seem to be getting a connectReturn when trying to connect to Photon Chat. My logic is based off of the LoadBalancing demo for UE4 and the Chat demo code.

So I create a ChatListener instance (a class that derives from ExitGames::Chat::Listener), an ExitGames::Chat::Client instance called chatClient, send chatClient over to the ChatListener class for use there, send the "connecting message" over to BaseView for debug display, and then call connect(*serverAddress) from the chatClient. Server address is "ns.exitgames.com:5058". I am using my AppID for Chat for this, while using my Realtime AppID for connecting to the lobby over there.

However, the callbacks connectReturn and connectionErrorReturn don't do anything. Nothing at all, as if a connection is not even being attempted. The only thing that happens is onStateChange returns state "PeerCreated". I'm new to this, so I'm not sure what to make of that info.

ChatListener.h
class ChatListener : public ExitGames::Chat::Listener
{
	ExitGames::Chat::Client* chatClient;
	BaseView* view;
public:
	ChatListener(BaseView* view);
	~ChatListener()
	{
		delete view;
	}

	void setChatClient(ExitGames::Chat::Client* chatClient)
	{
		this->chatClient = chatClient;
	}

Code to connect to chat
void APhotonLBClient::connectToChat(FString account)
{
	chatListener = new ChatListener(this);
	chatClient = new ExitGames::Chat::Client(*chatListener, *ChatAppID, *appVersion, ExitGames::Common::JString(*account));
	chatListener->setChatClient(chatClient);

	info("Connecting to chat...");
	chatClient->connect(*serverAddress);
}

I'm probably just missing something simple. But that's all I need, is just a how-to for connecting to Chat with C++ :) the docs really aren't helpful at all for this.

Comments

  • Hi DG Gage.

    This is a known bug in the Photon Chat Client library hat has been fixed with the 4.0.3.0 release.

    In versions prior to 4.0.3.0 connectReturn() is not getting called at all, not matter if the connect-attempt has been successful or not.
    As a workaround you can treat a call to Listener::onStateChange() with the passed state being equal to ClientState::ConnectedToFrontEnd as acknowledgement of a successful connect.

    From 4.0.3.0 onwards Listener::connectReturn() gets called correctly.

    Your timing is just perfect: 4.0.3.0 got released in our download section half an hour ago.
  • Still getting nothing on connectReturn and all other returns, and the state now returns nothing as well. It calls onStateChange, but the state is apparently null so it displays nothing.

    What could be causing this? I updated everything to the new version. All the incs and libs
  • It does indeed seem to be connecting. Calling any online function without being connected crashes the game. If I do connect(), followed by disconnect(), it does not crash the game. However, even disconnect() returns no callbacks and also gives a null state when calling onStateChange.

    Hmmmmm. Is this a problem on my end or Photon? Obviously, not being able to determine in-game whether or not it's connected will pose a giant fatal problem of the game crashing for anyone who didn't originally connect.

    Any ideas what's going on here?

    Everything with Realtime works just fine after the update.
  • Are you calling Chat::Client::service() regularly?
    In your case of having a Chat instance and a LoadBalancing instance, both, Chat::Client::service() and LoadBalancing::Client::service() need to get called.
    Calling any online function without being connected crashes the game.
    That should not happen. Could you provide us with a self-contained reproduction case for that crash, please?
  • Kaiserludi wrote:
    Are you calling Chat::Client::service() regularly?
    In your case of having a Chat instance and a LoadBalancing instance, both, Chat::Client::service() and LoadBalancing::Client::service() need to get called.

    :? ...... I did not set that up for Chat. Now that I did, it connects and returns callbacks just fine. Wow. What a silly mistake.
    Kaiserludi wrote:
    That should not happen. Could you provide us with a self-contained reproduction case for that crash, please?

    I believe it's a UE4 issue. All I know is that if I ever call on an online Photon service without first being connected, the engine crashes. I have logic in the game that prevents that with connected bools, but without them, it just crashes. Not sure what to tell you on reproducing that. I guess let me know what info you need and I'll give it to you.

    EDIT: Actually I think it's because my command to connect to the server is also where the client and listener are instantiated. I'm guessing it's crashing because it's trying to call a function on a null instance. Does that sound right? I could instantiate them on Begin Play and see what happens.

    EDIT 2: Yep. That's exactly what it was. I wanted to wait to create the instances so the game could feed in the unique player ID for Photon, but some quick logic changes allow that to happen automatically on Begin Play, or prompt the user to create an account (which generates the ID behind the scenes) before using Photon services. Once the ID is created, it automatically generates those client and listener instances with the ID info.

    Thanks for your help as always :)
  • OK, so the crash reason just was calling a function on a not yet constructed instance?

    OK, that's fine then. It should not crash when just not being connected yet, but well, if the class is not even constructed yet, then that is a totally different story . So this is not a problem with Photon, but the crash would have happened with any non Photon related class.
  • Photon Realtime and Chat are working just fine, yes :) my problems here were noob-related

    The timing on that update was pretty stellar though!
Sign In or Register to comment.