Пример #1
0
    /// <summary>
    /// For this client, we change states after joining a lobby or room was successfuly done.
    /// Also, properties of other users in a chat room (fetched with GetProperties) are cached.
    /// </summary>
    /// <remarks>
    /// Called when an operation from this client was executed and produced a result.
    /// Will be called when this client calls Peer.Service() or DispatchIncomingCommands().
    /// </remarks>
    public override void OnOperationResponse(OperationResponse operationResponse)
    {
        base.OnOperationResponse(operationResponse);

        // to take a look at the inside of any operation result, we could log it out as string this way
        //this.DebugReturn(SupportClass.HashtableToString(returnValues));

        switch (operationResponse.OperationCode)
        {
        case (byte)LiteOpCode.Join:
            if (this.ChatState == ChatStateOption.JoiningChatRoom)
            {
                // on joining a chatroom: get properties of everyone else in the room
                // the result of this operation is handled below
                this.Peer.OpGetProperties(0);
                this.ChatState = ChatStateOption.InChatRoom;
            }
            if (this.ChatState == ChatStateOption.JoiningLobbyRoom)
            {
                this.ChatState = ChatStateOption.InLobbyRoom;
            }
            break;

        case (byte)LiteOpCode.GetProperties:
            // the result of operation GetProperties contains two interesting hashtables: one for actors and one for the room properties
            // this demo uses a property per actor for the name, so we are caching the complete list we just got

            Hashtable actorProps = operationResponse[(byte)LiteOpKey.ActorProperties] as Hashtable;
            this.ActorProperties = actorProps;      // updates (name changes, new users) are sent by the server as event and merged in to this
            break;
        }
    }
Пример #2
0
 /// <summary>
 /// This wrapper method joins a lobby and set the fitting state (this helps us remember what sort of room we joined).
 /// </summary>
 /// <remarks>
 /// By convention of the LiteLobby server, any room that ends on "_lobby" is a lobby, not a regular room.
 /// We don't enforce the ending here, so calling this method must adhere to conventions, too.
 /// </remarks>
 /// <param name="lobbyName"></param>
 public void JoinLobby(string lobbyName)
 {
     this.LobbyName     = lobbyName;
     this.RoomName      = lobbyName;
     this.ChatState     = ChatStateOption.JoiningLobbyRoom;
     this.RoomHashtable = new Hashtable();
     this.Peer.OpJoin(lobbyName);
 }
Пример #3
0
    /// <summary>
    /// Wraps a call to LiteLobbyPeer.OpJoinFromLobby with an even nicer signature and adds the properties as needed.
    /// This method changes the ChatState to JoiningChatRoom.
    /// </summary>
    /// <remarks>
    /// Obviously the OpJoinFromLobby method could also be changed to accept the name, instead of the property hash.
    /// I wanted to keep that method's signature generic. Not it simply accepts any properties and this class provides them.
    /// </remarks>
    /// <param name="roomName">A chat room name to join.</param>
    public void JoinRoomFromLobby(string roomName)
    {
        this.RoomName        = roomName;
        this.ChatState       = ChatStateOption.JoiningChatRoom;
        this.ActorProperties = new Hashtable();

        Hashtable props = new Hashtable()
        {
            { ChatActorProperties.Name, this.UserName }
        };

        this.Peer.OpJoinFromLobby(this.RoomName, this.LobbyName, props, true);
    }
Пример #4
0
    /// <summary>
    /// On this level, only the connect and disconnect status callbacks are interesting and used.
    /// But we call the base-classes callback as well, which handles states in more detail.
    /// </summary>
    /// <remarks>Described in the Unity Reference doc: Photon-DotNet-Client-Documentation_v6-1-0.pdf</remarks>
    /// <param name="statusCode"></param>
    public override void OnStatusChanged(StatusCode statusCode)
    {
        base.OnStatusChanged(statusCode);

        switch (statusCode)
        {
        case StatusCode.Connect:
            ChatState = ChatStateOption.OutsideOfRooms;
            break;

        case StatusCode.Disconnect:
            ChatState = ChatStateOption.Offline;
            break;

        default:
            DebugReturn("StatusCode not handled: " + statusCode);
            break;
        }
    }
Пример #5
0
 /// <summary>
 /// Calls OpLeave (which can be used in lobby and any other room alike) and sets a state.
 /// </summary>
 public void LeaveRoom()
 {
     this.Peer.OpLeave();
     this.ChatState = ChatStateOption.OutsideOfRooms;
 }