For the challenge friend method I have this approach:
1) User sends a invitation request to server:
Code: Select all
//Challenge a user! (Client Side.. Unity)
void ChallengeUser(int userId){
//Then invite the user of your choice
ISFSObject invitation = new SFSObject ();
invitation.PutInt ("userId", userId);
sfs.Send (new ExtensionRequest ("challengeUser", invitation, sfs.LastJoinedRoom));
}
2) Server handles the request and sends a game challenge to a specific user (invitation)
Request Handler
Code: Select all
//Server side request handler
public class ChallengeUserHandler extends BaseClientRequestHandler {
@Override
public void handleClientRequest(User sender, ISFSObject params) {
User invitee = this.getApi().getUserById(params.getInt("userId"));
Invitation invitation = new SFSInvitation(sender, invitee, 50);
//send this invitation
((CuberLobbyExtension) this.getParentExtension()).sendGameChallenge(invitation);
}
}
Lobby Extension that Sends the invitation and handles the callback
Code: Select all
//Invitations
public void sendGameChallenge(Invitation inv) {
this.getGameApi().sendInvitation(inv, new InvitationCallback() {
@Override
public void onAccepted(Invitation invitation, ISFSObject params) {
//user accepted invitation
CreateRoomSettings roomSettings= new CreateRoomSettings();
roomSettings.isGame();
roomSettings.setName("HAHAHROOM");
roomSettings.setMaxUsers(2);
Zone zone = getParentZone();
try {
getApi().createRoom(zone, roomSettings, inv.getInviter());
} catch (SFSCreateRoomException e) {
// TODO Auto-generated catch block
trace("Error creating room...");
}
}
@Override
public void onExpired(Invitation invitation) {
}
@Override
public void onRefused(Invitation invitation, ISFSObject params) {
}
});
}
This is all I have so far.. I don't really know where to go from here. I am thinking after the room is created I send both the inviter and invitee a response that makes them join a room... Is this correct? Also, would like to know how to create rooms with random unique names (maybe hash ids...) that get deleted when game is done...
As for the random opponent matching, I have not even begun on that... Maybe save for later discussion...
Thanks in advance!