Browse Source

Option to list teams

Iñigo Valentin 4 years ago
parent
commit
74ead8fc5a
2 changed files with 73 additions and 2 deletions
  1. 61 2
      src/RuneOptimizer/RuneOptimizer.c
  2. 12 0
      src/RuneOptimizer/RuneOptimizer.h

+ 61 - 2
src/RuneOptimizer/RuneOptimizer.c

@@ -59,6 +59,22 @@ int main(int argc, char *argv[]){
         return SUCCESS;
     }
 
+    // Help command. Call and return
+    else if (strcmp(argv[1], "team") == 0){
+        if (argc < 3){
+            fprintf(stderr, "Command team needs an action\n");
+            return ERROR_INPUT_TEAM_NO_ACTION;
+        }
+        if (strcmp(argv[2], "list") == 0){
+            int result = list_teams(argc, argv);
+            return result;
+        }
+        else{
+            fprintf(stderr, "Invalid action for team command: %s\n", argv[1]);
+            return ERROR_INPUT_TEAM_INVALID_ACTION;
+        }
+    }
+
     // Any other command is an error
     else{
         fprintf(stderr, "Invalid command specified: %s\n", argv[1]);
@@ -68,7 +84,7 @@ int main(int argc, char *argv[]){
 
 int open_database(){
     // The database location and name is hardcoded in the same directory.
-    int db_status = sqlite3_open("data.sqlite", &db);
+    int db_status = sqlite3_open("../data.sqlite", &db);
     if (db_status != SQLITE_OK) {
         fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
         sqlite3_close(db);
@@ -87,10 +103,19 @@ void show_help(){
     printf("\n    Display this help text and exists. It has no options.\n");
     printf("\n\n  Command: update\n");
     printf("\n    Updates the information and builds a database. Currently unimplemented.\n");
+    printf("\n\n  Command: team\n");
+    printf("\n    Manages teams.\n");
+    printf("\n    Usage\n");
+    printf("    RuneOptimizer team [action] [options]\n");
+    printf("\n      Actions: \n\n");
+    printf("        list [team] [options]        List list of all or the selected team.\n");
+    printf("\n        [team] is optional and can can be a team ID or a team name (case sensitive)\n");
+    printf("\n        Options: \n\n");
+    printf("          -u | --units        Include the units in the details.\n");
     printf("\n\n  Command: optimize\n");
     printf("\n    Calculates an optimization for a unit.\n");
     printf("\n    Usage\n");
-    printf("    RuneOptimizer optmize [unit] [options]\n");
+    printf("    RuneOptimizer optimize [unit] [options]\n");
     printf("\n      [unit] can be a unit ID or a unit name (case sensitive)\n");
     printf("\n      Options: \n\n");
     printf("        -h | --min_hp <NUM>         Minumum HP to consider in the optimization.\n");
@@ -1596,3 +1621,37 @@ unsigned short calculate_dmg(unsigned short atk, unsigned short crr, unsigned sh
     dmg = ceil((((float) atk) * (100.0f - crr_capped) / 100.0f) + ((((float) atk) + (((float) atk) * ((float) crd) / 100.0f)) * crr_capped / 100.0f));
     return dmg;
 }
+
+int list_teams(int argc, char *argv[]){
+    printf("A");
+    char id[8] = "\0";
+    char query[300] = "SELECT id, name, priority FROM teams ";
+    char tmp[64];
+    if (argc > 3){
+        strcpy(id, argv[3]);
+        strcpy(tmp, "");
+        sprintf(tmp, "WHERE id = '%s' OR name = '%s' ", id, id);
+        strcat(query, tmp);
+    }
+    printf("LISTING TEAMS %s\n%s\n", id, query);
+    if (SUCCESS != open_database()){
+        return ERROR_DB_CANT_OPEN;
+    }
+    sqlite3_stmt *stmt_teams;
+    db_status = sqlite3_prepare_v2(db, query, -1, &stmt_teams, 0);
+    if (db_status != SQLITE_OK) {
+        fprintf(stderr, "Error getting runes for slot 1: %s\n", sqlite3_errmsg(db));
+        return ERROR_DB_RUNES_SLOT;
+    }
+
+    while (1 == 1){
+        int status = sqlite3_step(stmt_teams);
+        if (status == SQLITE_ROW){
+            printf("OK %s\n", sqlite3_column_text(stmt_teams, 2));
+
+        }
+        else{
+            break;
+        }
+    }
+}

+ 12 - 0
src/RuneOptimizer/RuneOptimizer.h

@@ -151,6 +151,15 @@ char set_names[][24] = {
  */
 void show_help();
 
+/**
+ * Displays teams.
+ *
+ * @param argc Argument count.
+ * @param argv Argument list.
+ * @return 0 on success, other on error.
+ */
+int list_teams(int argc, char *argv[]);
+
 /**
  * Starts the optimization process.
  *
@@ -231,6 +240,9 @@ sqlite3 *db;
 #define ERROR_INPUT_NO_EHP 117
 #define ERROR_INPUT_NO_DMG 118
 #define ERROR_INPUT_INCOMPLETE_SETS 119
+#define ERROR_INPUT_TEAM_NO_ACTION 120
+#define ERROR_INPUT_TEAM_INVALID_ACTION 121
+
 #define ERROR_DB_CANT_OPEN 200
 #define ERROR_DB_UNIT 201
 #define ERROR_DB_UNIT_NOF_FOUND 202