Exemplo n.º 1
0
 protected override void MessageReceived(string message, bool error, ITCPConnection connection)
 {
     base.MessageReceived(message, error, connection);
     JObject o = JObject.Parse(message);
     if((string)o["action"] == "group") {
         if((string)o["type"] == "ready") {
             JArray playerInfo = (JArray)o["users"];
             JArray gameChoices = (JArray)o["vote"];
             Storage.Set("group_info", playerInfo);
             Storage.Set("game_choices", gameChoices);
             startingGame = true;
             SearchingButtons.Visible = false;
             looking = false;
             multi.Text = "Multiplayer";
             multi.Disabled = false;
         } else if((string)o["type"] == "update") {
             groupSize = ((JArray)o["users"]).Count;
             playersInParty.Text = "Searching for players: " + groupSize + "/4";
         }
     }
 }
Exemplo n.º 2
0
 protected override void MessageReceived(string message, bool error, ITCPConnection connection)
 {
     base.MessageReceived(message, error, connection);
     JObject o = JObject.Parse(message);
     if((string)o["action"] == "game" && (string)o["name"] == "sample_game") {
         JObject data = (JObject)o["data"];
         if((string)data["action"] == "add") {
             // TODO
         }
     }
 }
Exemplo n.º 3
0
 protected override void MessageReceived(string message, bool error, ITCPConnection connection)
 {
     base.MessageReceived(message, error, connection);
 }
 void TCPConnectionClosed(bool error, ITCPConnection connection) {
     offlineScreen.ShowControls(true);
     offlineScreen.GoToNextScreen(typeof(OfflineScreen));
     Helpers.ResetState();
     Storage.Set("error", "Lost connection to server.");
     ResetScreen();
 }
Exemplo n.º 5
0
 protected virtual void MessageReceived(string message, bool error, ITCPConnection connection)
 {
     JObject o = JObject.Parse(message);
     if((string)o["action"] == "group" && (string)o["type"] == "synced") {
         if(syncAction != null) {
             syncAction((JArray)o["data"], (double)o["rand"]);
             CancelSync();
         }
     }
 }
 protected override void MessageReceived(string message, bool error, ITCPConnection connection)
 {
     base.MessageReceived(message, error, connection);
     JObject o = JObject.Parse(message);
     if((string)o["action"] == "game" && (string)o["name"] == "twilight_tango") {
         JObject data = (JObject)o["data"];
         if((string)data["action"] == "update") {
             // Accept player update packets in both input and timeup phase
             if(phase == Phase.Input || phase == Phase.Timeup) {
                 string source = (string)data["source"];
                 if(players.ContainsKey(source)) {
                     // If the client side commands are more updates, ignore the update
                     JArray commands = (JArray)data["commands"];
                     if(players[source].input.Count() < commands.Count()) {
                         players[source].input.Clear();
                         foreach(JToken command in commands) {
                             players[source].input.Add((Direction)(int)command);
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
 public void RemoveConn()
 {
     if (conn != null) {
         conn.pMessageReceivedEvent -= MessageReceived; // remove the method from the old connection
         conn = null;
     }
 }
Exemplo n.º 8
0
        public void SetConn(ITCPConnection conn)
        {
            RemoveConn(); // remove the old connection first

            if (conn != null) { // set the new conenction
                this.conn = conn;
                conn.pMessageReceivedEvent += MessageReceived;
            }
        }
Exemplo n.º 9
0
        protected void handleLeaders(string message, bool error, ITCPConnection connection)
        {
            JObject o = JObject.Parse(message);
            if((string)o["action"] == "rank" && (string)o["type"] == "leader") {
                doneRetrieving = true;
                connection.pMessageReceivedEvent -= handleLeaders;
                JArray leaderArr = (JArray)o["leaders"];

                PlayerData myData = Storage.Get<PlayerData>("myPlayerData");
                if(retrieving != null)
                    retrieving.Visible = false;
                int index = 1;
                int rank = 0;
                int prevLvl = -1;

                foreach(JObject name in leaderArr) {
                    BorderedView row = playerRows.ElementAt(index - 1);
                    string username = (string)name["username"];
                    int level = (int)name["level"];

                    if(prevLvl != level) {
                        // the levels are different. this player is not a tie. set the rank equal to the current index
                        rank = index;
                        prevLvl = level;
                    } // otherwise display the same rank as before

                    Label rankLabel = new Label(rank.ToString(), new Vector2(startX, startY + index * 70 + 5));
                    Label player = new Label(username, new Vector2(startX + 125, startY + index * 70 + 5));
                    player.CenterX = false;
                    player.Font = "gillsans";
                    player.Scale = 0.85f;
                    player.MaxSize(700);

                    Label levelLabel = new Label(level.ToString(), new Vector2(startX + 850, startY + index * 70 + 5));

                    row.AddElement(rankLabel);
                    row.AddElement(player);
                    row.AddElement(levelLabel);

                    if(myData.username == username) {
                        row.BorderColor = Constants.YellowHighlight;
                    }

                    index++;

                    if(index > 10) {
                        break;
                    }
                }

                int myRank = (int)((JObject)o["rank"])["rank"];

                BorderedView myRow = playerRows.ElementAt(10);

                Label myRankLabel = new Label(myRank.ToString(), new Vector2(startX, startY + 11 * 70 + 5));
                Label myPlayer = new Label(myData.username, new Vector2(startX + 125, startY + 11 * 70 + 5));
                myPlayer.CenterX = false;
                myPlayer.Font = "gillsans";
                myPlayer.Scale = 0.85f;
                myPlayer.MaxSize(700);
                Label myLevel = new Label(myData.level.ToString(), new Vector2(startX + 850, startY + 11 * 70 + 5));

                myRow.AddElement(myRankLabel);
                myRow.AddElement(myPlayer);
                myRow.AddElement(myLevel);
                myRow.BorderColor = Constants.YellowHighlight;
            }
        }
 protected override void MessageReceived(string message, bool error, ITCPConnection connection)
 {
     base.MessageReceived(message, error, connection);
     JObject o = JObject.Parse(message);
     if((string)o["action"] == "game" && (string)o["name"] == "jetpack_jamboree") {
         JObject data = (JObject)o["data"];
         if((string)data["action"] == "add") {
             if(playerName != (string)data["source"] && !exploded) {
                 // Add new pigs flying in
                 for(int i = 0; i < (int)(MAX_PIG_COUNT / (playerData.Count - deadUsers.Count - 1)); i++) {
                     AddFlyingPig((int)data["color"]);
                 }
                 soundList["landing"].Play();
                 avatars[(string)data["source"]].State = true;
             }
         } else if((string)data["action"] == "exploded") {
             string exploded_user = (string)data["source"];
             RemovePlayer(exploded_user);
         } else if((string)data["action"] == "update") {
             if(playerName != (string)data["source"]) {
                 avatars[(string)data["source"]].count = (int)data["count"];
             }
         }
     }
 }
Exemplo n.º 11
0
        protected void handleProfile(string message, bool error, ITCPConnection connection)
        {
            // parse the playerData
            JObject o = JObject.Parse(message);
            if ((string)o["action"] == "profile") {
                dataToDisplay = new PlayerData();
                dataToDisplay.username = (string)o["username"];
                dataToDisplay.profile = (string)o["profile"];
                dataToDisplay.level = (int)o["level"];
                dataToDisplay.rank = (int)o["rank"];
                dataToDisplay.expPercent = (float)o["percent"];

                updateProfileScreen();
            }
        }
        protected override void MessageReceived(string message, bool error, ITCPConnection connection)
        {
            base.MessageReceived(message, error, connection);
            JObject o = JObject.Parse(message);
            if((string)o["action"] == "game" && (string)o["name"] == "fishing_frenzy") {
                JObject data = (JObject)o["data"];
                if((string)data["action"] == "hook") {
                    if((string)data["source"] != playerName) {
                        if(phase == Phase.Fishing) {
                            // Play swoosh
                            soundList["swoosh"].Play();

                            // enforce locks to prevent race conditions
                            lock(hooked) {
                                lock(backupHooked) {
                                    if(!hooked.ContainsKey((string)data["source"])) {
                                        hooked[(string)data["source"]] = new Hook(this, (int)data["pos"], new TimeSpan((long)data["time"]), playerData[(string)data["source"]]);
                                    } else {
                                        backupHooked[(string)data["source"]] = new Hook(this, (int)data["pos"], new TimeSpan((long)data["time"]), playerData[(string)data["source"]]);
                                    }
                                }
                            }
                        } else {
                            backupHooked[(string)data["source"]] = new Hook(this, (int)data["pos"], new TimeSpan((long)data["time"]), playerData[(string)data["source"]]);
                        }
                    }
                }
            }
        }
Exemplo n.º 13
0
 protected override void MessageReceived(string message, bool error, ITCPConnection connection)
 {
     base.MessageReceived(message, error, connection);
     JObject o = JObject.Parse(message);
     if((string)o["action"] == "game" && (string)o["name"] == "color_clash") {
         JObject data = (JObject)o["data"];
         if((string)data["action"] == "paint") {
             string user = (string)data["source"];
             if(user != playerName) {
                 lock(splatters) {
                     Splatter splatter = new Splatter(this, players[user], rand);
                     splatter.Scale = (float)data["scale"];
                     players[user].StartThrow(splatter);
                     players[user].ThrowPaint(new TimeSpan((long)data["time"]), new Vector2((float)data["x_pos"], (float)data["y_pos"]));
                 }
             }
         }
     }
 }