Esempio n. 1
0
        public static string RequestAchievements(string apiKey, string userID)
        {
            string response = ResponseTool.CheckAPIKey(apiKey, userAPIKey);

            if (response != null)
            {
                return(response);
            }

            using (var conn = DataManager.CreateConnectionObject())
            {
                conn.Open();
                using (var command = conn.CreateCommand())
                {
                    command.CommandText = string.Format("SELECT ID, AchievementID, PercentComplete FROM Achievements WHERE UserID = '{0}'", userID);
                    using (var reader = command.ExecuteReader())
                    {
                        var webResponse = new WebResponse(ResponseTypes.Succeeded);
                        webResponse.Achievements = new List <WebResponse_Achievement>();
                        while (reader.Read())
                        {
                            var a = new WebResponse_Achievement()
                            {
                                ID              = reader["AchievementID"].ToString(),
                                AchievementID   = reader["AchievementID"].ToString(),
                                PercentComplete = float.Parse(reader["PercentComplete"].ToString())
                            };
                            webResponse.Achievements.Add(a);
                        }

                        return(ResponseTool.GenerateXML(webResponse));
                    }
                }
            }
        }
Esempio n. 2
0
        public static string GetGameList(string apiKey, string clientID)
        {
            string response = ResponseTool.CheckAPIKey(apiKey, clientAPIKey);

            if (response != null)
            {
                return(response);
            }

            using (var conn = DataManager.CreateConnectionObject())
            {
                conn.Open();
                using (var command = conn.CreateCommand())
                {
                    var webResponse = new WebResponse(ResponseTypes.Succeeded);
                    webResponse.Games   = new List <WebResponse_Game>();
                    command.CommandText = string.Format("SELECT ID, Name FROM Games WHERE ClientID = '{0}'", clientID);
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var game = new WebResponse_Game()
                            {
                                ID   = reader["ID"].ToString(),
                                Name = reader["Name"].ToString()
                            };
                            webResponse.Games.Add(game);
                        }
                    }

                    return(ResponseTool.GenerateXML(webResponse));
                }
            }
        }
Esempio n. 3
0
        public static string CreateUser(string apiKey, string gameID, string username, string password)
        {
            string response = ResponseTool.CheckAPIKey(apiKey, gameAPIKey);

            if (response != null)
            {
                return(response);
            }

            using (var conn = DataManager.CreateConnectionObject())
            {
                conn.Open();
                using (var command = conn.CreateCommand())
                {
                    // make sure username doesn't already exist
                    command.CommandText = string.Format("SELECT ID FROM Users WHERE GameID = '{0}' and Username = '******'", gameID, username);
                    using (var reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            var webResponse = new WebResponse(ResponseTypes.Error)
                            {
                                ErrorMessage = "Username already exists"
                            };
                            return(ResponseTool.GenerateXML(webResponse));
                        }
                    }

                    // create account
                    string passwordEncrypted = SecurityManager.Hash(password);
                    var    userID            = Guid.NewGuid();
                    string values            = string.Format("('{0}', '{1}', '{2}', '{3}', '{4}')", userID, gameID, username, passwordEncrypted, DateTime.UtcNow);
                    command.CommandText = "INSERT INTO Users (ID, GameID, Username, Password, DateCreated) VALUES " + values;
                    if (command.ExecuteNonQuery() == 1)
                    {
                        var webResponse = new WebResponse(ResponseTypes.Succeeded)
                        {
                            UserID   = userID.ToString(),
                            Username = username
                        };
                        return(ResponseTool.GenerateXML(webResponse));
                    }
                    else
                    {
                        var webResponse = new WebResponse(ResponseTypes.Error)
                        {
                            ErrorMessage = "Failed to properly create user"
                        };
                        return(ResponseTool.GenerateXML(webResponse));
                    }
                }
            }
        }
 /// <summary>
 /// 获取初始化jssdk配置信息
 /// </summary>
 /// <param name="AppId"></param>
 /// <param name="Url"></param>
 /// <returns></returns>
 public JsonResult GetWeChatJsSdk(string AppId, string Url)
 {
     //生成微信sdk的签名参数
     if (!string.IsNullOrEmpty(AppId))
     {
         dynamic WXModel      = new System.Dynamic.ExpandoObject();
         string  timestamp    = ((int)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds).ToString();
         string  nonceStr     = Guid.NewGuid().ToString("N");
         string  jsapi_ticket = WeChatDeploy.GetJSAPITicket(AppId);
         if (!string.IsNullOrEmpty(jsapi_ticket))
         {
             string url = Url;
             //签名
             List <string> Tem = new List <string>();
             Tem.Add("timestamp=" + timestamp);
             Tem.Add("noncestr=" + nonceStr);
             Tem.Add("jsapi_ticket=" + jsapi_ticket);
             Tem.Add("url=" + url);
             Tem.Sort();
             byte[]        StrRes = Encoding.Default.GetBytes(string.Join("&", Tem));
             HashAlgorithm iSHA   = new SHA1CryptoServiceProvider();
             StrRes = iSHA.ComputeHash(StrRes);
             StringBuilder signature = new StringBuilder();
             foreach (byte iByte in StrRes)
             {
                 signature.AppendFormat("{0:x2}", iByte);
             }
             WXModel.appId     = AppId;
             WXModel.timestamp = timestamp;
             WXModel.nonceStr  = nonceStr;
             WXModel.signature = signature.ToString().ToLower();
             WXModel.jsApiList = new List <string>();
             WXModel.jsApiList.Add("updateAppMessageShareData");
             WXModel.jsApiList.Add("updateTimelineShareData");
             WXModel.jsApiList.Add("onMenuShareWeibo");
             WXModel.jsApiList.Add("hideMenuItems");
             WXModel.jsApiList.Add("showMenuItems");
             WXModel.jsApiList.Add("hideAllNonBaseMenuItem");
             WXModel.jsApiList.Add("showAllNonBaseMenuItem");
             WXModel.jsApiList.Add("getLocation");
             WXModel.jsApiList.Add("openLocation");
             return(ResponseTool.Create(WXModel, 200, "ok"));
         }
         else
         {
             return(ResponseTool.Create(201, "初始化失败"));
         }
     }
     else
     {
         return(ResponseTool.Create(201, "初始化失败,请传入AppId"));
     }
 }
Esempio n. 5
0
        public static string RequestScores(string apiKey, string leaderboardID, string offset, string range, string sortOrder)
        {
            string response = ResponseTool.CheckAPIKey(apiKey, gameAPIKey);

            if (response != null)
            {
                return(response);
            }

            using (var conn = DataManager.CreateConnectionObject())
            {
                conn.Open();
                using (var command = conn.CreateCommand())
                {
                    var webResponse = new WebResponse(ResponseTypes.Succeeded);
                    webResponse.Scores = new List <WebResponse_Score>();

                    // get all leaderboard usersIDs
                    command.CommandText = string.Format("SELECT ID, UserID, Score FROM Scores WHERE LeaderboardID = '{0}' ORDER BY Score {3} OFFSET {1} ROWS FETCH NEXT {2} ROWS ONLY", leaderboardID, offset, range, sortOrder == "Ascending" ? "ASC" : "DESC");
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            webResponse.Scores.Add(new WebResponse_Score()
                            {
                                ID     = reader["ID"].ToString(),
                                UserID = reader["UserID"].ToString(),
                                Score  = long.Parse(reader["Score"].ToString())
                            });
                        }
                    }

                    // get all usernames for IDs
                    foreach (var score in webResponse.Scores)
                    {
                        command.CommandText = string.Format("SELECT Username FROM Users WHERE ID = '{0}'", score.UserID);
                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                score.Username = reader["Username"].ToString();
                            }
                        }
                    }

                    return(ResponseTool.GenerateXML(webResponse));
                }
            }
        }
Esempio n. 6
0
        public static string DeleteGame(string apiKey, string gameID)
        {
            string response = ResponseTool.CheckAPIKey(apiKey, clientAPIKey);

            if (response != null)
            {
                return(response);
            }

            using (var conn = DataManager.CreateConnectionObject())
            {
                conn.Open();
                using (var command = conn.CreateCommand())
                {
                    // get all users
                    command.CommandText = string.Format("SELECT ID FROM Users WHERE GameID = '{0}'", gameID);
                    var userIDs = new List <Guid>();
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            userIDs.Add(new Guid(reader["ID"].ToString()));
                        }
                    }

                    // delete all user scores & achievemetns
                    foreach (var userID in userIDs)
                    {
                        // scores
                        command.CommandText = string.Format("DELETE FROM Scores WHERE UserID = '{0}'", userID);
                        command.ExecuteNonQuery();

                        // achievements
                        command.CommandText = string.Format("DELETE FROM Achievements WHERE UserID = '{0}'", userID);
                        command.ExecuteNonQuery();
                    }

                    // delete users
                    command.CommandText = string.Format("DELETE FROM Users WHERE GameID = '{0}'", gameID);
                    command.ExecuteNonQuery();

                    // delete game
                    command.CommandText = string.Format("DELETE FROM Games WHERE ID = '{0}'", gameID);
                    var webResponse = new WebResponse(command.ExecuteNonQuery() != 0 ? ResponseTypes.Succeeded : ResponseTypes.Error);
                    return(ResponseTool.GenerateXML(webResponse));
                }
            }
        }
Esempio n. 7
0
        public static string CreateGame(string apiKey, string clientID, string name)
        {
            string response = ResponseTool.CheckAPIKey(apiKey, clientAPIKey);

            if (response != null)
            {
                return(response);
            }

            using (var conn = DataManager.CreateConnectionObject())
            {
                conn.Open();
                using (var command = conn.CreateCommand())
                {
                    // make sure name doesn't already exist
                    command.CommandText = string.Format("SELECT ID FROM Games WHERE Name = '{0}'", name);
                    using (var reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            var webResponse = new WebResponse(ResponseTypes.Error)
                            {
                                ErrorMessage = "Game Name already exists"
                            };
                            return(ResponseTool.GenerateXML(webResponse));
                        }
                    }

                    // create account
                    string values = string.Format("(NEWID(), '{0}', '{1}', '{2}')", clientID, name, DateTime.UtcNow);
                    command.CommandText = "INSERT INTO Games (ID, ClientID, Name, DateCreated) VALUES " + values;
                    if (command.ExecuteNonQuery() == 1)
                    {
                        var webResponse = new WebResponse(ResponseTypes.Succeeded);
                        return(ResponseTool.GenerateXML(webResponse));
                    }
                    else
                    {
                        var webResponse = new WebResponse(ResponseTypes.Error)
                        {
                            ErrorMessage = "Failed to properly create game"
                        };
                        return(ResponseTool.GenerateXML(webResponse));
                    }
                }
            }
        }
Esempio n. 8
0
        public static string Login(string apiKey, string username, string email, string password)
        {
            string response = ResponseTool.CheckAPIKey(apiKey, appAPIKey);

            if (response != null)
            {
                return(response);
            }

            using (var conn = DataManager.CreateConnectionObject())
            {
                conn.Open();
                using (var command = conn.CreateCommand())
                {
                    return("TODO");
                }
            }
        }
Esempio n. 9
0
        public static string Login(string apiKey, string gameID, string username, string password)
        {
            string response = ResponseTool.CheckAPIKey(apiKey, userAPIKey);

            if (response != null)
            {
                return(response);
            }

            using (var conn = DataManager.CreateConnectionObject())
            {
                conn.Open();
                using (var command = conn.CreateCommand())
                {
                    string passwordEncrypted = SecurityManager.Hash(password);
                    command.CommandText = string.Format("SELECT ID, Username FROM Users WHERE GameID = '{0}' and Username = '******' and Password = '******'", gameID, username, passwordEncrypted);
                    using (var reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            var webResponse = new WebResponse(ResponseTypes.Succeeded)
                            {
                                UserID   = reader["ID"].ToString(),
                                Username = reader["Username"].ToString()
                            };
                            return(ResponseTool.GenerateXML(webResponse));
                        }
                        else
                        {
                            var webResponse = new WebResponse(ResponseTypes.Error)
                            {
                                ErrorMessage = "Failed to find user"
                            };
                            return(ResponseTool.GenerateXML(webResponse));
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        public static string ReportScore(string apiKey, string userID, string leaderboardID, string score)
        {
            string response = ResponseTool.CheckAPIKey(apiKey, userAPIKey);

            if (response != null)
            {
                return(response);
            }

            using (var conn = DataManager.CreateConnectionObject())
            {
                conn.Open();
                using (var command = conn.CreateCommand())
                {
                    // check if score already exists
                    command.CommandText = string.Format("SELECT ID, Score FROM Scores WHERE UserID = '{0}' and LeaderboardID = '{1}'", userID, leaderboardID);
                    string id           = null;
                    long   currentScore = 0;
                    using (var reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            id           = reader["ID"].ToString();
                            currentScore = long.Parse(reader["Score"].ToString());
                        }
                    }

                    if (id == null)
                    {
                        // create score
                        string values = string.Format("(NEWID(), '{0}', '{1}', {2}, '{3}')", userID, leaderboardID, score, DateTime.UtcNow);
                        command.CommandText = "INSERT INTO Scores (ID, UserID, LeaderboardID, Score, Date) VALUES " + values;
                        if (command.ExecuteNonQuery() == 1)
                        {
                            var webResponse = new WebResponse(ResponseTypes.Succeeded);
                            return(ResponseTool.GenerateXML(webResponse));
                        }
                        else
                        {
                            var webResponse = new WebResponse(ResponseTypes.Error)
                            {
                                ErrorMessage = "Failed to properly create score"
                            };
                            return(ResponseTool.GenerateXML(webResponse));
                        }
                    }
                    else if (long.Parse(score) > currentScore)
                    {
                        // update existing score
                        command.CommandText = string.Format("UPDATE Scores SET Date = '{0}', Score = {1} WHERE ID = '{2}'", DateTime.UtcNow, score, id);
                        if (command.ExecuteNonQuery() == 1)
                        {
                            var webResponse = new WebResponse(ResponseTypes.Succeeded);
                            return(ResponseTool.GenerateXML(webResponse));
                        }
                        else
                        {
                            var webResponse = new WebResponse(ResponseTypes.Error)
                            {
                                ErrorMessage = "Failed to properly update score"
                            };
                            return(ResponseTool.GenerateXML(webResponse));
                        }
                    }
                    else
                    {
                        // current score already higher
                        var webResponse = new WebResponse(ResponseTypes.Succeeded);
                        return(ResponseTool.GenerateXML(webResponse));
                    }
                }
            }
        }
Esempio n. 11
0
        public static string ReportAchievement(string apiKey, string userID, string achievementID, string percentComplete)
        {
            string response = ResponseTool.CheckAPIKey(apiKey, userAPIKey);

            if (response != null)
            {
                return(response);
            }

            using (var conn = DataManager.CreateConnectionObject())
            {
                conn.Open();
                using (var command = conn.CreateCommand())
                {
                    // check if achievement already exists
                    command.CommandText = string.Format("SELECT ID, PercentComplete FROM Achievements WHERE UserID = '{0}' and AchievementID = '{1}'", userID, achievementID);
                    string id = null;
                    float  currentPercentComplete = 0;
                    using (var reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            id = reader["ID"].ToString();
                            currentPercentComplete = float.Parse(reader["PercentComplete"].ToString());
                        }
                    }

                    if (id == null)
                    {
                        // create achievement
                        string values = string.Format("(NEWID(), '{0}', '{1}', '{2}', '{3}')", userID, achievementID, percentComplete, DateTime.UtcNow);
                        command.CommandText = "INSERT INTO Achievements (ID, UserID, AchievementID, PercentComplete, Date) VALUES " + values;
                        if (command.ExecuteNonQuery() == 1)
                        {
                            var webResponse = new WebResponse(ResponseTypes.Succeeded);
                            return(ResponseTool.GenerateXML(webResponse));
                        }
                        else
                        {
                            var webResponse = new WebResponse(ResponseTypes.Error)
                            {
                                ErrorMessage = "Failed to properly create achievement"
                            };
                            return(ResponseTool.GenerateXML(webResponse));
                        }
                    }
                    else if (float.Parse(percentComplete) > currentPercentComplete)
                    {
                        // update existing achievement
                        command.CommandText = string.Format("UPDATE Achievements SET Date = '{0}', PercentComplete = {1} WHERE ID = '{2}'", DateTime.UtcNow, percentComplete, id);
                        if (command.ExecuteNonQuery() == 1)
                        {
                            var webResponse = new WebResponse(ResponseTypes.Succeeded);
                            return(ResponseTool.GenerateXML(webResponse));
                        }
                        else
                        {
                            var webResponse = new WebResponse(ResponseTypes.Error)
                            {
                                ErrorMessage = "Failed to properly update achievement"
                            };
                            return(ResponseTool.GenerateXML(webResponse));
                        }
                    }
                    else
                    {
                        // current achievement percent already higher
                        var webResponse = new WebResponse(ResponseTypes.Succeeded);
                        return(ResponseTool.GenerateXML(webResponse));
                    }
                }
            }
        }
 /// <summary>
 /// 获取微信全局JsApiTicket
 /// </summary>
 /// <param name="AppId"></param>
 /// <returns></returns>
 public JsonResult GetWeChatJsApiTicket(string AppId)
 {
     return(ResponseTool.Create(new { AccessToken = WeChatDeploy.GetJSAPITicket(AppId) }, 200, "ok"));
 }
 /// <summary>
 /// 获取微信全局AccessToken
 /// </summary>
 /// <param name="AppId"></param>
 /// <returns></returns>
 public JsonResult GetWeChatAccessToken(string AppId)
 {
     return(ResponseTool.Create(new { AccessToken = WeChatDeploy.GetAccessToken(AppId) }, 200, "ok"));
 }