コード例 #1
0
        public JoinClusterModule()
        {
            this.Post("/api/504", ctx =>
            {
                var args = Serializer.Deserialize <JoinClusterArgs>(this.Request.Body);

                return(PlayerIO.CreateResponse("token", true, new JoinClusterOutput()
                {
                    ActivityLog = "",
                    APIEndpoints = new List <string>()
                    {
                        "http://*****:*****@1234",
                    JoinedClusterName = "Main Cluster",
                    MaxCPUWatchTime = 1000,
                    MaxPlayersPerRoom = 45,
                    MaxRoomCloseAPIRequests = 100000,
                    MaxRoomMB = 10000,
                    ValidEndpoints = null
                }));
            });
        }
コード例 #2
0
        public SaveObjectChangesModule()
        {
            this.Post("/api/88", ctx =>
            {
                var args  = Serializer.Deserialize <SaveObjectChangesArgs>(this.Request.Body);
                var token = this.Request.Headers["playertoken"].FirstOrDefault();
                var game  = GameManager.GetGameFromToken(token);

                var versions = new List <string>();

                foreach (var set in args.Changesets)
                {
                    var dbo = game.BigDB.Load(set.Table, set.Key);

                    if (set.FullOverwrite)
                    {
                    }

                    versions.Add("1");
                }

                return(PlayerIO.CreateResponse(token, true, new SaveObjectChangesOutput()
                {
                    Versions = versions
                }));
            });
        }
コード例 #3
0
        public PayVaultConsumeModule()
        {
            this.Post("/api/166", ctx =>
            {
                var args  = Serializer.Deserialize <PayVaultConsumeArgs>(this.Request.Body);
                var token = this.Request.Headers["playertoken"].FirstOrDefault();
                var game  = GameManager.GetGameFromToken(token);
                var items = game.BigDB.LoadRange("PayVaultItems", "PriceCoins", null, null, 1000);

                // TODO: actually remove the items.

                return(PlayerIO.CreateResponse(token, true, new PayVaultConsumeOutput()
                {
                    VaultContents = new PayVaultContents()
                    {
                        Coins = 1,
                        Version = "22040806-3e9f-438e-97eb-51069207926d",
                        Items = items.Select(x => new PayVaultItem()
                        {
                            Id = "pvi" + x.Key, ItemKey = x.Key, Properties = DatabaseObjectExtensions.FromDatabaseObject(x)
                        }).ToList()
                    }
                }));
            });
        }
コード例 #4
0
        public SimpleRegisterModule()
        {
            this.Post("/api/403", ctx =>
            {
                var args     = Serializer.Deserialize <SimpleRegisterArgs>(this.Request.Body);
                var token    = args.GameId + ":" + args.Username;
                var location = Path.Combine("games", "EverybodyEdits", "accounts", args.GameId);

                if (File.Exists(Path.Combine(location, args.Username + ".tson")))
                {
                    throw new Exception($"An account already exists with the username '{args.Username}' in game '{args.GameId}'");
                }

                File.WriteAllText(Path.Combine(location, args.Username + ".tson"),
                                  new DatabaseObject()
                                  .Set("gameId", args.GameId)
                                  .Set("email", args.Email ?? "")
                                  .Set("username", args.Username)
                                  .Set("password", args.Password)
                                  .ToString());

                return(PlayerIO.CreateResponse(token, true, new SimpleRegisterOutput()
                {
                    UserId = args.Username,
                    Token = token,
                    ShowBranding = true
                }));
            });
        }
コード例 #5
0
 public WebserviceOnlineTestModule()
 {
     this.Post("/api/533", ctx =>
     {
         var args = Serializer.Deserialize <WebserviceOnlineTestArgs>(this.Request.Body);
         return(PlayerIO.CreateResponse("token", true, new WebserviceOnlineTestOutput()
         {
             Message = "success"
         }));
     });
 }
コード例 #6
0
        public UserLeftRoomModule()
        {
            this.Post("/api/40", ctx =>
            {
                var args  = Serializer.Deserialize <UserLeftRoomArgs>(this.Request.Body);
                var token = this.Request.Headers["playertoken"].FirstOrDefault();
                var game  = GameManager.GetGameFromToken(token);

                return(PlayerIO.CreateResponse(token, true, new UserLeftRoomOutput()));
            });
        }
コード例 #7
0
        public WriteErrorModule()
        {
            this.Post("/api/50", ctx =>
            {
                var args  = Serializer.Deserialize <WriteErrorArgs>(this.Request.Body);
                var token = this.Request.Headers["playertoken"].FirstOrDefault();

                Console.WriteLine("WriteError API called: " + string.Join("\n", args.Source, args.Error, args.Details, args.Stacktrace));

                return(PlayerIO.CreateResponse(token, true, new WriteErrorOutput()));
            });
        }
コード例 #8
0
 public ServerHeartbeatModule()
 {
     this.Post("/api/510", ctx =>
     {
         var args = Serializer.Deserialize <ServerHeartbeatArgs>(this.Request.Body);
         return(PlayerIO.CreateResponse("token", true, new ServerHeartbeatOutput()
         {
             State = "success", APIEndpoints = new List <string>()
             {
                 "http://localhost:80/api"
             }
         }));
     });
 }
コード例 #9
0
        public JoinRoomModule()
        {
            this.Post("/api/24", ctx =>
            {
                var args  = Serializer.Deserialize <JoinRoomArgs>(this.Request.Body);
                var token = this.Request.Headers["playertoken"].FirstOrDefault();
                var game  = GameManager.GetGameFromToken(token);

                if (string.IsNullOrEmpty(args.RoomId))
                {
                    args.RoomId = "$service-room$";
                }

                var room = game.Rooms.FirstOrDefault(r => r.Id == args.RoomId);

                string joinKey = null;

                switch (game.GameId)
                {
                default:
                    joinKey = JoinInfo.Create(
                        encryptionKey: GameManager.EncryptionKey,
                        serverId: "serverId",
                        gameId: 128,
                        gameConnectId: game.GameId,
                        gameCodeId: "gameCodeId",
                        serverType: room.RoomType,
                        roomId: args.RoomId,
                        roomData: new byte[] { },
                        extendedRoomId: game.GameId + "/" + room.RoomType + "/" + args.RoomId,
                        connectUserId: token.Split(':')[1],
                        playerIoToken: token,
                        visible: true,
                        roomFlags: 0,
                        partnerId: "",
                        userId: 1234,
                        gameCodeVersion: 1);
                    break;
                }

                return(PlayerIO.CreateResponse(token, true, new JoinRoomOutput()
                {
                    Endpoints = new List <ServerEndpoint>()
                    {
                        GameManager.GameServerEndPoint
                    },
                    JoinKey = joinKey
                }));
            });
        }
コード例 #10
0
        public AchievementsRefreshModule()
        {
            this.Post("/api/271", ctx =>
            {
                var args  = Serializer.Deserialize <AchievementsRefreshArgs>(this.Request.Body);
                var token = this.Request.Headers["playertoken"].FirstOrDefault();

                return(PlayerIO.CreateResponse(token, true, new AchievementsRefreshOutput()
                {
                    Version = "1",
                    Achievements = new List <Achievement>()
                }));
            });
        }
コード例 #11
0
        public PlayerInsightRefreshModule()
        {
            this.Post("/api/301", ctx =>
            {
                var args  = Serializer.Deserialize <PlayerInsightRefreshArgs>(this.Request.Body);
                var token = this.Request.Headers["playertoken"].FirstOrDefault();

                return(PlayerIO.CreateResponse(token, true, new PlayerInsightRefreshOutput()
                {
                    State = new PlayerInsightState()
                    {
                        PlayersOnline = 1, Segments = new System.Collections.Generic.List <KeyValuePair>()
                    }
                }));
            });
        }
コード例 #12
0
        public ListRoomsModule()
        {
            this.Post("/api/30", ctx =>
            {
                var args  = Serializer.Deserialize <ListRoomsArgs>(this.Request.Body);
                var token = this.Request.Headers["playertoken"].FirstOrDefault();
                var game  = GameManager.GetGameFromToken(token);

                return(PlayerIO.CreateResponse(token, true, new ListRoomsOutput()
                {
                    Rooms = game.Rooms.Select(room => new RoomInfo()
                    {
                        Id = room.Id, OnlineUsers = 1, RoomData = new List <KeyValuePair>(), RoomType = room.RoomType
                    }).ToList()
                }));
            });
        }
コード例 #13
0
        public PayVaultGiveModule()
        {
            this.Post("/api/178", ctx =>
            {
                var args  = Serializer.Deserialize <PayVaultGiveArgs>(this.Request.Body);
                var token = this.Request.Headers["playertoken"].FirstOrDefault();

                return(PlayerIO.CreateResponse(token, true, new PayVaultGiveOutput
                {
                    VaultContents = new PayVaultContents
                    {
                        Coins = 0,
                        Items = new List <PayVaultItem>(),
                        Version = "1"
                    }
                }));
            });
        }
コード例 #14
0
        public LoadMatchingObjectsModule()
        {
            this.Post("/api/94", ctx =>
            {
                var args  = Serializer.Deserialize <LoadMatchingObjectsArgs>(this.Request.Body);
                var token = this.Request.Headers["playertoken"].FirstOrDefault();
                var game  = GameManager.GetGameFromToken(token);

                var matches = game.BigDB.LoadMatchingObjects(args.Table, args.Index, args.IndexValue, args.Limit);

                return(PlayerIO.CreateResponse(token, true, new LoadMatchingObjectsOutput()
                {
                    Objects = matches.Select(x => new BigDBObject()
                    {
                        Creator = 0, Key = x.Key, Properties = DatabaseObjectExtensions.FromDatabaseObject(x), Version = "1"
                    }).ToList()
                }));
            });
        }
コード例 #15
0
        public ConnectModule()
        {
            this.Post("/api/10", ctx =>
            {
                var args = Serializer.Deserialize <ConnectArgs>(this.Request.Body);

                return(PlayerIO.CreateResponse("token", true, new ConnectOutput()
                {
                    Token = args.GameId + ":" + args.UserId,
                    UserId = args.UserId,
                    ShowBranding = true,
                    GameFSRedirectMap = "",
                    PartnerId = "",
                    PlayerInsightState = new PlayerInsightState()
                    {
                        PlayersOnline = 1, Segments = new List <KeyValuePair>()
                    }
                }));
            });
        }
コード例 #16
0
        public SimpleConnectModule()
        {
            this.Post("/api/400", ctx =>
            {
                var args  = Serializer.Deserialize <SimpleConnectArgs>(this.Request.Body);
                var token = args.GameId + ":" + args.UsernameOrEmail;

                return(PlayerIO.CreateResponse(token, true, new SimpleConnectOutput()
                {
                    UserId = args.UsernameOrEmail,
                    Token = token,
                    ShowBranding = true,
                    GameFSRedirectMap = "",
                    PartnerId = "",
                    PlayerInsightState = new PlayerInsightState()
                    {
                        PlayersOnline = 0, Segments = new List <KeyValuePair>()
                        {
                        }
                    }
                }));
            });
        }
コード例 #17
0
        public CreateObjectsModule()
        {
            this.Post("/api/82", ctx =>
            {
                var args  = Serializer.Deserialize <CreateObjectsArgs>(this.Request.Body);
                var token = this.Request.Headers["playertoken"].FirstOrDefault();
                var game  = GameManager.GetGameFromToken(token);

                var results = new List <BigDBObject>();

                foreach (var obj in args.Objects)
                {
                    var(exists, dbo) = game.BigDB.FindObjectIfExists(obj.Table, obj.Key);

                    if (exists)
                    {
                        results.Add((new BigDBObject()
                        {
                            Key = obj.Key, Creator = 0, Properties = DatabaseObjectExtensions.FromDatabaseObject(dbo), Version = "1"
                        }));
                    }
                    else
                    {
                        game.BigDB.CreateObject(obj.Table, obj.Key, new DatabaseObject(obj.Table, obj.Key, "1", obj.Properties));
                        results.Add(new BigDBObject()
                        {
                            Key = obj.Key, Creator = 1, Properties = obj.Properties, Version = "1"
                        });
                    }
                }

                return(PlayerIO.CreateResponse(token, true, new CreateObjectsOutput
                {
                    Objects = results
                }));
            });
        }
コード例 #18
0
        public LoadMyPlayerObjectModule()
        {
            this.Post("/api/103", ctx =>
            {
                var args         = Serializer.Deserialize <LoadMyPlayerObjectArgs>(this.Request.Body);
                var token        = this.Request.Headers["playertoken"].FirstOrDefault();
                var game         = GameManager.GetGameFromToken(token);
                var userId       = token.Split(':')[1];
                var(exists, dbo) = game.BigDB.FindObjectIfExists("PlayerObjects", userId);

                return(PlayerIO.CreateResponse(token, true, new LoadMyPlayerObjectOutput()
                {
                    PlayerObject = new BigDBObject()
                    {
                        Creator = 0,
                        Key = userId,
                        Properties = exists ? DatabaseObjectExtensions.FromDatabaseObject(dbo) : new List <ObjectProperty>()
                        {
                        },
                        Version = "1",
                    }
                }));
            });
        }
コード例 #19
0
        public UpdateRoomModule()
        {
            this.Post("/api/53", ctx =>
            {
                var args  = Serializer.Deserialize <UpdateRoomArgs>(this.Request.Body);
                var token = this.Request.Headers["playertoken"].FirstOrDefault();
                var game  = GameManager.GetGameFromToken(token);

                var roomType = args.ExtendedRoomId.Split('/')[1];
                var roomId   = args.ExtendedRoomId.Split('/')[2];

                if (!game.Rooms.Any(x => x.RoomType == roomType && x.Id == roomId))
                {
                    game.Rooms.Add(new RoomInfo()
                    {
                        Id = roomId, OnlineUsers = 1, RoomData = new List <KeyValuePair>(), RoomType = roomType
                    });
                }

                return(PlayerIO.CreateResponse(token, true, new UpdateRoomOutput()
                {
                }));
            });
        }
コード例 #20
0
        public CreateJoinRoomModule()
        {
            this.Post("/api/27", ctx =>
            {
                var args  = Serializer.Deserialize <CreateJoinRoomArgs>(this.Request.Body);
                var token = this.Request.Headers["playertoken"].FirstOrDefault();
                var game  = GameManager.GetGameFromToken(token);

                if (string.IsNullOrEmpty(args.RoomId))
                {
                    args.RoomId = "$service-room$";
                }

                args.RoomId.Replace(" ", "-");
                string joinKey = null;

                // PW01 is the override room.
                if (args.RoomId == "PW01")
                {
                    joinKey = JoinInfo.Create(
                        encryptionKey: GameManager.EncryptionKey,
                        serverId: "serverId",
                        gameId: 128,
                        gameConnectId: game.GameId,
                        gameCodeId: "gameCodeId",
                        serverType: args.RoomType,
                        roomId: GameManager.ForceWorldId ?? args.RoomId,
                        roomData: new byte[] { },
                        extendedRoomId: game.GameId + "/" + args.RoomType + "/" + GameManager.ForceWorldId ?? args.RoomId,
                        connectUserId: token.Split(':')[1],
                        playerIoToken: token,
                        visible: true,
                        roomFlags: 0,
                        partnerId: "",
                        userId: 1234,
                        gameCodeVersion: 1);

                    return(PlayerIO.CreateResponse(token, true, new CreateJoinRoomOutput()
                    {
                        RoomId = GameManager.ForceWorldId ?? args.RoomId,
                        Endpoints = new List <ServerEndpoint>()
                        {
                            GameManager.GameServerEndPoint
                        },
                        JoinKey = joinKey
                    }));
                }
                else
                {
                    joinKey = JoinInfo.Create(
                        encryptionKey: GameManager.EncryptionKey,
                        serverId: "serverId",
                        gameId: 128,
                        gameConnectId: game.GameId,
                        gameCodeId: "gameCodeId",
                        serverType: args.RoomType,
                        roomId: args.RoomId,
                        roomData: new byte[] { },
                        extendedRoomId: game.GameId + "/" + args.RoomType + "/" + args.RoomId,
                        connectUserId: token.Split(':')[1],
                        playerIoToken: token,
                        visible: true,
                        roomFlags: 0,
                        partnerId: "",
                        userId: 1234,
                        gameCodeVersion: 1);

                    return(PlayerIO.CreateResponse(token, true, new CreateJoinRoomOutput()
                    {
                        RoomId = args.RoomId,
                        Endpoints = new List <ServerEndpoint>()
                        {
                            GameManager.GameServerEndPoint
                        },
                        JoinKey = joinKey
                    }));
                }
            });
        }