Why are my private messages not sending and also disconnecting me from photon chat

When I try to send a message with SendPrivateMessage, it says the message was sent, but then a few seconds later says the chat state is disconnected. It doesn't actually call OnDisconnected and the other client never receives the message. When i try to send messages after this is says they cant be sent.

Here is my code

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

using System;

using UnityEngine.EventSystems;

using Steamworks;

using NaughtyAttributes;

using UnityEngine.UIElements;

using Photon.Realtime;

using Photon.Chat;

using Photon.Pun;

using UnityEngine.Events;

using ExitGames.Client.Photon;

using TMPro;


public class PartyManager : MonoBehaviorSingleton<PartyManager>, IChatClientListener

{

  //public static PartyManager Instance;


  [Header("Refrences")]

  public GameObject friendDisplayPrefab;

  public Transform contentParent;


  [Header("Data")]


  [ReadOnly]

  public CSteamID steamID;


  [ReadOnly]

  public List<FriendInfo> friendsInfo = new List<FriendInfo>();


  [ReadOnly]

  public int friendCount = 0;


  [ReadOnly]

  public Party currentParty;


  List<FriendDisplay> friendDisplays = new List<FriendDisplay>();


  private List<string> outgoingRequests = new List<string>();

  private List<string> incomingRequests = new List<string>();


  ChatClient chatClient;


  const string APP_ID = "cc5a255e-014a-46d5-9625-d9e3707a61dc";


  private void OnEnable()

  {

    //if(Instance != null)

    //{

    //  Destroy(Instance);

    //  Instance = this;

    //}


    if (SteamManager.Initialized)

    {

      steamID = SteamUser.GetSteamID();

      currentParty = new Party(new FriendInfo(SteamFriends.GetPersonaName(), steamID));

    }

     

    UpdateFriends();



    DontDestroyOnLoad(gameObject);


    chatClient = new ChatClient(this);

    chatClient.ChatRegion = "EU";

    chatClient.Connect(APP_ID, "1.0", new Photon.Chat.AuthenticationValues(SteamUser.GetSteamID().ToString()));

  }


  public void UpdateFriends()

  {

    foreach(FriendDisplay friendDisplay in friendDisplays)

    {

      Destroy(friendDisplay.gameObject);

    }

    friendDisplays.Clear();

    friendsInfo.Clear();

    friendCount = SteamFriends.GetFriendCount(EFriendFlags.k_EFriendFlagImmediate);

    for (int i = 0; i < friendCount; i++)

    {

      CSteamID friendSteamID = SteamFriends.GetFriendByIndex(i, EFriendFlags.k_EFriendFlagImmediate);

      FriendGameInfo_t friendGameInfo = new FriendGameInfo_t();

      SteamFriends.GetFriendGamePlayed(friendSteamID, out friendGameInfo);

      if(!friendSteamID.Equals(SteamUser.GetSteamID())) friendsInfo.Add(new FriendInfo(SteamFriends.GetFriendPersonaName(friendSteamID), friendSteamID));

    }

    UpdateDisplay();

    Debug.Log(steamID);

    //Debug.Log(chatClient.AuthValues.ToString());

  }


  public void UpdateDisplay()

  {

    foreach(FriendInfo friendInfo in friendsInfo)

    {

      GameObject friendDisplay = Instantiate(friendDisplayPrefab, contentParent);

      friendDisplay.GetComponent<FriendDisplay>().SetFriendInfo(friendInfo);

      friendDisplay.GetComponent<FriendDisplay>().button.onClick.RemoveAllListeners();

      friendDisplay.GetComponent<FriendDisplay>().button.onClick.AddListener(InviteToParty(friendDisplay.GetComponent<FriendDisplay>()));

      friendDisplays.Add(friendDisplay.GetComponent<FriendDisplay>());

    }

  }


  public UnityAction InviteToParty(FriendDisplay disp)

  {

    UnityAction action = null;

    action = () =>

    {

      if(!chatClient.SendPrivateMessage(disp.info.steamID.ToString(), $"party_invite#{steamID.ToString()}"))

      {

        Debug.Log($"Message to ({disp.info.ToString()}) not sent properly");

      }

    };

    return action;

  }


  public void InviteToParty(TMP_InputField disp)

  {

    if (!chatClient.SendPrivateMessage(disp.text, $"party_invite#{steamID.ToString()}"))

    {

      Debug.Log($"Message to ({disp.text}) not sent properly");

    }

    else

    {

      Debug.Log("Message sent!");

    }

  }



  // Start is called before the first frame update

  void Start()

  {

     

  }


  // Update is called once per frame

  void Update()

  {

    chatClient.Service();

  }


  public void DebugReturn(DebugLevel level, string message)

  {

     

  }


  public void OnDisconnected()

  {

    Debug.LogWarning("Disconnected from photon chat");

    chatClient.Connect(APP_ID, "1.0", new Photon.Chat.AuthenticationValues(steamID.ToString()));

  }


  public void OnConnected()

  {

    Debug.Log("Connected to photon chat");

  }


  public void OnChatStateChange(ChatState state)

  {

    Debug.Log($"Chat state changed, now ({state})");

    if(state == ChatState.Disconnected)

    {

      chatClient.Connect(APP_ID, "1.0", new Photon.Chat.AuthenticationValues(steamID.ToString()));

    }

  }


  public void OnGetMessages(string channelName, string[] senders, object[] messages)

  {

     

  }


  public void OnPrivateMessage(string sender, object message, string channelName)

  {

    Debug.Log($"Recieved message from {sender} saying {message}");

  }


  public void OnSubscribed(string[] channels, bool[] results)

  {

     

  }


  public void OnUnsubscribed(string[] channels)

  {

     

  }


  public void OnStatusUpdate(string user, int status, bool gotMessage, object message)

  {

     

  }


  public void OnUserSubscribed(string channel, string user)

  {

     

  }


  public void OnUserUnsubscribed(string channel, string user)

  {

     

  }

}


public class Party

{

  public FriendInfo leader = new FriendInfo();

  public List<FriendInfo> members = new List<FriendInfo>();


  public bool isLeader

  {

    get

    {

      return leader.Equals(SteamUser.GetSteamID());

    }

  }


  public Party(FriendInfo leader, List<FriendInfo> members)

  {

    this.leader = leader;

    this.members = members;

  }


  public Party(FriendInfo leader)

  {

    this.leader = leader;

    members = new List<FriendInfo>();

  }



  public override string ToString()

  {

    return $"leader: {leader}, members: {members}";

  }

}


[System.Serializable]

public struct FriendInfo

{

  public CSteamID steamID;


  public string name;


  public FriendInfo(string name, CSteamID id)

  {

    this.name = name;

    this.steamID = id;

  }


  public override string ToString()

  {

    return $"name: {name}, steamid: {steamID}";

  }

}

It is a very strange problem and i'm not sure what to do about it

Best Answer

  • Tobias
    Tobias admin
    Answer ✓

    Are you sure you are using a Chat typed AppId?

    If so, mail us the AppId and we'll look into the logs once.

Answers

  • Tobias
    Tobias admin
    Answer ✓

    Are you sure you are using a Chat typed AppId?

    If so, mail us the AppId and we'll look into the logs once.

  • nix
    nix
    edited March 2023

    Thank you, that actually was my problem. I was using the pun appid. I switched to the chat appid and it works as excpected

  • I will try to look into why no proper error log popped up. It may depend on some settings...