Ejemplo n.º 1
0
 // Invoked when any sign in operation has completed
 private void DidLogin(Gamer newGamer)
 {
     if (Gamer != null) {
         Debug.LogWarning("Current gamer " + Gamer.GamerId + " has been dismissed");
         Loop.Stop();
     }
     Gamer = newGamer;
     Loop = Gamer.StartEventLoop();
     Loop.ReceivedEvent += Loop_ReceivedEvent;
     Debug.Log("Signed in successfully (ID = " + Gamer.GamerId + ")");
 }
Ejemplo n.º 2
0
	// Invoked when any sign in operation has completed
	private void DidLogin(Gamer newGamer) {
		if (Gamer != null) {
			Debug.LogWarning("Current gamer " + Gamer.GamerId + " has been dismissed");
			Loop.Stop();
		}
		Gamer = newGamer;
		Loop = Gamer.StartEventLoop();
		Loop.ReceivedEvent += Loop_ReceivedEvent;
		Debug.Log("Signed in successfully (ID = " + Gamer.GamerId + ")");
		// Keep login in persistent memory to restore next time
		PlayerPrefs.SetString("GamerInfo", new GamerInfo(Gamer).ToJson());
		// Notify others
		if (GamerChanged != null) GamerChanged(this, new EventArgs());
	}
Ejemplo n.º 3
0
	private void Loop_ReceivedEvent(DomainEventLoop sender, EventLoopArgs e) {
		Debug.Log("Received event of type " + e.Message.Type + ": " + e.Message.ToJson());
	}
Ejemplo n.º 4
0
 public static void NotifyReceivedMessage(DomainEventLoop sender, EventLoopArgs args)
 {
     if (gotDomainLoopEvent != null) gotDomainLoopEvent(sender, args);
 }
Ejemplo n.º 5
0
 private void ReceivedLoopEvent(DomainEventLoop sender, EventLoopArgs e)
 {
     if (e.Message["type"].AsString() == "godchildren" && onGotGodchild != null) {
         onGotGodchild(new GotGodchildEvent(e.Message));
     }
 }
Ejemplo n.º 6
0
 private void CheckEventLoopNeeded()
 {
     if (onGotGodchild != null) {
         // Register if needed
         if (RegisteredEventLoop == null) {
             RegisteredEventLoop = Cotc.GetEventLoopFor(Gamer.GamerId, domain);
             if (RegisteredEventLoop == null) {
                 Common.LogWarning("No pop event loop for domain " + domain + ", community events will not work");
             }
             else {
                 RegisteredEventLoop.ReceivedEvent += this.ReceivedLoopEvent;
             }
         }
     }
     else if (RegisteredEventLoop != null) {
         // Unregister from event loop
         RegisteredEventLoop.ReceivedEvent -= this.ReceivedLoopEvent;
         RegisteredEventLoop = null;
     }
 }
Ejemplo n.º 7
0
        private void ReceivedLoopEvent(DomainEventLoop sender, EventLoopArgs e)
        {
            // Ignore events not for us
            if (!e.Message["type"].AsString().StartsWith("match.")) return;
            Lock(() => {
                // Update last event ID
                if (e.Message["event"].Has("_id")) {
                    LastEventId = e.Message["event"]["_id"];
                }

                switch (e.Message["type"].AsString()) {
                    case "match.join":
                        var joinEvent = new MatchJoinEvent(Gamer, e.Message);
                        Players.AddRange(joinEvent.PlayersJoined);
                        if (onPlayerJoined != null) onPlayerJoined(this, joinEvent);
                        break;
                    case "match.leave":
                        var leaveEvent = new MatchLeaveEvent(Gamer, e.Message);
                        foreach (var p in leaveEvent.PlayersLeft) Players.Remove(p);
                        if (onPlayerLeft != null) onPlayerLeft(this, leaveEvent);
                        break;
                    case "match.finish":
                        Status = MatchStatus.Finished;
                        if (onMatchFinished != null) onMatchFinished(this, new MatchFinishEvent(Gamer, e.Message));
                        break;
                    case "match.move":
                        var moveEvent = new MatchMoveEvent(Gamer, e.Message);
                        Moves.Add(new MatchMove(moveEvent.PlayerId, moveEvent.MoveData));
                        if (onMovePosted != null) onMovePosted(this, moveEvent);
                        break;
                    case "match.shoedraw":
                        if (onShoeDrawn != null) onShoeDrawn(this, new MatchShoeDrawnEvent(Gamer, e.Message));
                        break;
                    case "match.invite":	// Do not notify them since we are already playing the match
                        break;
                    default:
                        Common.LogError("Unknown match event type " + e.Message["type"]);
                        break;
                }
            });
        }
Ejemplo n.º 8
0
 private void CheckEventLoopNeeded()
 {
     // One event registered?
     if (onMatchFinished != null || onPlayerJoined != null || onPlayerLeft != null || onMovePosted != null || onShoeDrawn != null) {
         // Register event loop if not already
         if (RegisteredEventLoop == null) {
             RegisteredEventLoop = Cotc.GetEventLoopFor(Gamer.GamerId, Domain);
             if (RegisteredEventLoop == null) {
                 Common.LogWarning("No pop event loop for match " + MatchId + " on domain " + Domain + ", match events/updates will not work");
             }
             else {
                 RegisteredEventLoop.ReceivedEvent += this.ReceivedLoopEvent;
             }
         }
     }
     else if (RegisteredEventLoop != null) {
         // Unregister from event loop
         RegisteredEventLoop.ReceivedEvent -= this.ReceivedLoopEvent;
         RegisteredEventLoop = null;
     }
 }
Ejemplo n.º 9
0
 private void ReceivedLoopEvent(DomainEventLoop sender, EventLoopArgs e)
 {
     string type = e.Message["type"];
     if (type.StartsWith("friend.") && onFriendStatusChange != null) {
         string status = type.Substring(7 /* friend. */);
         onFriendStatusChange(new FriendStatusChangeEvent(status, e.Message));
     }
 }
Ejemplo n.º 10
0
 private void ReceivedLoopEvent(DomainEventLoop sender, EventLoopArgs e)
 {
     if (e.Message["type"].AsString() == "match.invite") {
         if (onMatchInvitation != null) onMatchInvitation(new MatchInviteEvent(Gamer, e.Message));
     }
 }