Chess Chat system#
Chat is a way for users to communicate with each other during a game. Though AXR has a chat system in place, its data is temporary. For persistent chat; “Chess” utilizes the AXR mail system.
Like Leaderboards “Chess” utilizes this functionality to get and send data.
In “Chess” to send messages there’s:
WebServices.instance.SendMessage(MessageData message, Action<object[]> onComplete = null)
This in turn calls:
AXRSendMessage(message)
Inside AXRSendMessage, messages are pushed to the server using the MessageService. The MessageService is apart of AXR’s Social suite of functionality.
To utilize it; first a reference to the service must be created:
MessageService messageService = _serviceFactory.GetService<MessageService>();
Next a new Message object must be created. Similar to the Ticket object the Message object can be instantiated and populated at the same time:
1Message message = new Message()
2{
3 Subject = _sessionId,
4 SenderUid = _user.Uid,
5 ReceiverUid = _opponent.Uid,
6 Body = data.message
7};
In “Chess” the session id of the current session is used as the subject. The Subject field is used as a search parameter to only pull messages related to the current session:
Subject = _sessionId,
The SenderUid is a required field and is defined as the local user Uid. In chess that is stored in the _user instance variable:
SenderUid = _user.Uid,
The ReceiverUid is also a required field and is the id of the player who will be receiving the message. In “Chess” that is the local players opponent, it is stored in the _opponent instance variable:
ReceiverUid = _opponent.Uid,
Lastly the Body field is the content of the message. In “Chess”, there is no content validation or filtering related to messages sent between players.
To receive messages the Webservices class uses:
GetMessages()
Which in turn calls:
AXRGetMessages()
In “Chess”, AXRGetMessages() is also called in OnSessionChange.
Inside AXRGetMessages(), a reference to the message service is also required:
MessageService service = _serviceFactory.GetService<MessageService>();
The MessageService is used to pull all sent messages of the local logged in user:
List<Message> messages = await service.FindSent();
Then is used to pull all messages received by the local logged in user:
messages.AddRange(await service.FindInbox());
These messages are filtered by the subject which is defined by the sessionID using Linq:
messages = messages.Where(m => m.Subject == _sessionId).ToList();
I hope this post helps others get up to speed and comfortable with some of the base frameworks of XBE implementation; allowing for ease of transition to or learning this framework.