Skip to content

Commit

Permalink
add cpp-quality workflow + apply fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jakoch committed Jun 20, 2024
1 parent 48e7382 commit 8e0d5d8
Show file tree
Hide file tree
Showing 47 changed files with 750 additions and 359 deletions.
34 changes: 21 additions & 13 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# A complete list of style options can be found at:
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
#
# Google C++ Style Guide
# https://google.github.io/styleguide/cppguide.html
Expand All @@ -13,11 +13,19 @@
# void formatted_code_again;
#

Language: Cpp

# Basic indentation and spacing rules:
IndentWidth: 4
ContinuationIndentWidth: 4
UseCRLF: false
Standard: c++20
UseTab: Never
MaxEmptyLinesToKeep: 1

AccessModifierOffset: -4
ConstructorInitializerIndentWidth: 4
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: true
#AlignConsecutiveBitFields: true
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true
AlignEscapedNewlinesLeft: true
Expand All @@ -26,7 +34,7 @@ AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: Empty
AllowShortBlocksOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortLambdasOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
Expand Down Expand Up @@ -59,19 +67,15 @@ ColumnLimit: 120
CompactNamespaces: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
ExperimentalAutoDetectBinPacking: true
FixNamespaceComments: true
IncludeBlocks: Preserve
IndentCaseLabels: false
IndentGotoLabels: false
IndentPPDirectives: None
IndentFunctionDeclarationAfterType: false
IndentWidth: 4
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 10
Expand All @@ -80,8 +84,6 @@ PenaltyBreakFirstLessLess: 20
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Right
PointerBindsToType: true
SortIncludes: false
SpaceAfterControlStatementKeyword: true
SpaceBeforeParens: ControlStatements
Expand All @@ -97,6 +99,12 @@ SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++20
TabWidth: 4
UseTab: Never

# int* value instead of int *value
DerivePointerAlignment: false
PointerAlignment: Left
PointerBindsToType: true
SpaceAroundPointerQualifiers: After

# Prefer "east const", placing `const` after the type: int const instead of const int
QualifierAlignment: Right
26 changes: 26 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Clang Tidy - Config
---
Checks: '-*
bugprone-*,
-bugprone-easily-swappable-parameters
cert-*,
-cert-err33-c
cppcoreguidelines-*,
-cppcoreguidelines-pro-bounds-pointer-arithmetic
-cppcoreguidelines-pro-type-vararg
-cppcoreguidelines-avoid-c-arrays
-cppcoreguidelines-no-malloc
-cppcoreguidelines-owning-memory
-cppcoreguidelines-pro-bounds-array-to-pointer-decay
misc-*,
-misc-include-cleaner
modernize-*,
-modernize-use-trailing-return-type
performance-*,
readability-*,
-readability-identifier-length
-readability-function-cognitive-complexity
-readability-static-accessed-through-instance
'

WarningsAsErrors: '*'
81 changes: 81 additions & 0 deletions .github/workflows/cpp-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#
# .github/workflows/cpp-quality.yml
#
# Copyright 2024 Jens A. Koch.
# SPDX-License-Identifier: MIT
# This file is part of jakoch/wikifolio_universe_converter.
#

name: "C++ Quality"

on:
- push
- pull_request
# You can manually run this workflow.
- workflow_dispatch

# improve CI concurrency by automatically cancelling outdated jobs
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:

# ---------------------------------------------------------------------------------------

clang-format:

# ---------------------------------------------------------------------------------------

runs-on: ubuntu-latest

steps:

- name: 🤘 Checkout Code
uses: actions/checkout@v4 # https://github.com/actions/checkout

- name: 🔽 Install dos2unix
run: sudo apt-get install -y dos2unix

- name: 🔽 Install clang-format-18
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x ./llvm.sh
sudo ./llvm.sh 18
sudo apt-get install -y clang-format-18
- name: Check formatting
run: ./format.sh && git diff --exit-code
env:
CLANG_FORMAT: clang-format-18

# ---------------------------------------------------------------------------------------

cpplint:

# ---------------------------------------------------------------------------------------

runs-on: ubuntu-latest

steps:

- name: 🤘 Checkout Code
uses: actions/checkout@v4 # https://github.com/actions/checkout

- name: Setup Python
run: sudo apt-get -y install python3 python3-pip python3-venv

- name: Setup Python Virtual Env
run: |
export VIRTUAL_ENV=/opt/venv
python3 -m venv $VIRTUAL_ENV
export PATH="$VIRTUAL_ENV/bin:$PATH"
- name: Install cpplint
run: pip install --prefer-binary --no-cache-dir cpplint

- name: Run lint
run: cpplint --recursive src --exclude=src/steamapi/*
47 changes: 33 additions & 14 deletions src/DataObject.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
// SPDX-FileCopyrightText: Copyright © 2018-present Jens A. Koch
// SPDX-License-Identifier: GPL-3.0-or-later

#include "DataObject.h"

std::string DataObject::getPlayerRank(int rank_type_id)
{
int rank_id;
if (rank_type_id == 6) { rank_id = rankings.at(0).id; }
if (rank_type_id == 7) { rank_id = rankings.at(1).id; }
if (rank_type_id == 10) { rank_id = rankings.at(2).id; }
if (rank_type_id == 6) {
rank_id = rankings.at(0).id;
}
if (rank_type_id == 7) {
rank_id = rankings.at(1).id;
}
if (rank_type_id == 10) {
rank_id = rankings.at(2).id;
}

int rank = (rank_id < 0) ? rank_id - 1 : rank_id;

Expand All @@ -19,7 +28,7 @@ std::string DataObject::getPlayerLevel()
return getLevelName(level);
}

const int DataObject::calcPlayerXpBase() const
int const DataObject::calcPlayerXpBase() const
{
return player_cur_xp - 327680000; // xp minus base value, gives normalized player xp
}
Expand All @@ -29,9 +38,9 @@ std::string DataObject::getPlayerXp()
return std::to_string(calcPlayerXpBase());
}

const float DataObject::getPlayerXpPercentage()
float const DataObject::getPlayerXpPercentage()
{
return ((float)calcPlayerXpBase() / 5000) * 100;
return (static_cast<float>(calcPlayerXpBase()) / 5000) * 100;
}

std::string DataObject::getVacStatus()
Expand All @@ -51,9 +60,15 @@ std::string DataObject::getRankName(int i)

std::string DataObject::getRankType(int i)
{
if (i == 6) { return "MatchMaking"; }
if (i == 7) { return "Wingman"; }
if (i == 10) { return "DangerZone"; }
if (i == 6) {
return "MatchMaking";
}
if (i == 7) {
return "Wingman";
}
if (i == 10) {
return "DangerZone";
}
return "Unknown RankType";
}

Expand All @@ -74,11 +89,15 @@ std::string DataObject::getSteamProfileUrl()
std::string DataObject::getCanDoOverwatch()
{
RankingInfo matchmaking_rank = rankings.at(0);
int rank_id = matchmaking_rank.id;
int rank_wins = matchmaking_rank.wins;

if (rank_id < 7) { return "Your rank is too low. " + getRankName(7) + " required."; }
if (rank_wins < 150) { return "You don't have enough wins: 150 required."; }
int rank_id = matchmaking_rank.id;
int rank_wins = matchmaking_rank.wins;

if (rank_id < 7) {
return "Your rank is too low. " + getRankName(7) + " required.";
}
if (rank_wins < 150) {
return "You don't have enough wins: 150 required.";
}
return "Qualified to request replays.";
}
std::string DataObject::getAverageSearchTime()
Expand Down
36 changes: 20 additions & 16 deletions src/DataObject.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
#ifndef DataObject_H
#define DataObject_H
// SPDX-FileCopyrightText: Copyright © 2018-present Jens A. Koch
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef SRC_DATAOBJECT_H_
#define SRC_DATAOBJECT_H_

#include "DateTimeUtils.h"
#include "csgo/CSGOMatchData.h" // for vector<MatchData> matches
#include "cstrike15_gcmessages.pb.h"

#include <ostream>
#include <string>
#include <steam/steamtypes.h>
#include <vector>

class DataObject
{
private:
const std::vector<std::string> ranks = {
std::vector<std::string> const ranks = {
"Not Ranked",
"Silver 1",
"Silver 2",
Expand All @@ -34,7 +38,7 @@ class DataObject
"Global Elite", // big globe
};

const std::vector<std::string> levels = {
std::vector<std::string> const levels = {
"Not Recruited", "Recruit", "Private I", "Private II",
"Private III", "Corporal I", "Corporal II", "Corporal III",
"Corporal IV", "Sergeant I", "Sergeant II", "Sergeant III",
Expand All @@ -47,7 +51,7 @@ class DataObject
"Brigadier General", "Major General", "Lieutenant General", "General",
"Global General"};

const std::vector<std::string> dangerzone_ranks = {
std::vector<std::string> const dangerzone_ranks = {
"Hidden",
"Lab Rat I",
"Lab Rat II",
Expand All @@ -65,7 +69,7 @@ class DataObject
"Wildfire Wolf",
"The Howling Alpha"};

const std::vector<std::string> penalty_reasons_long = {
std::vector<std::string> const penalty_reasons_long = {
"Temporary Matchmaking Cooldown (No reason)",
"You have been kicked from your last matchmaking game.",
"You killed too many teammates.",
Expand All @@ -87,7 +91,7 @@ class DataObject
"Your account is under skill placement calibration.",
"A server using your game server token has been banned."};

const std::vector<std::string> penalty_reasons_short = {
std::vector<std::string> const penalty_reasons_short = {
"CooldownNone"
"Kicked"
"KilledMate"
Expand All @@ -109,20 +113,20 @@ class DataObject
"NewbieCooldown"
"GameServerBanned"};

const std::string steam_profile_url_base = "https://steamcommunity.com/profiles/";
std::string const steam_profile_url_base = "https://steamcommunity.com/profiles/";

// TODO
const std::string tpl_url_wingman_replays = "https://steamcommunity.com/id/{}/gcpd/730/?tab=matchhistorywingman";
// TODO(jakoch): add wingman.
std::string const tpl_url_wingman_replays = "https://steamcommunity.com/id/{}/gcpd/730/?tab=matchhistorywingman";

const int calcPlayerXpBase() const;
int const calcPlayerXpBase() const;

public:
std::string getSteamId();
std::string getSteamProfileUrl();
std::string getPlayerLevel();
std::string getPlayerRank(int rank_type_id);
std::string getPlayerXp();
const float getPlayerXpPercentage();
float const getPlayerXpPercentage();
std::string getVacStatus();
std::string getLevelName(int i);
std::string getRankName(int i);
Expand Down Expand Up @@ -160,9 +164,9 @@ class DataObject
uint32 cmd_leader = 0;

// player level
int32 player_level = 0;
int32 player_cur_xp = 0; // starts at 327680000 (level % = (player_cur_xp - 327680000) / 5000)
int32 player_xp_bonus_flags = 0; // TODO
int32 player_level = 0;
int32 player_cur_xp = 0; // starts at 327680000 (level % = (player_cur_xp - 327680000) / 5000)
int32 player_xp_bonus_flags = 0; // TODO(jakoch): add bonus flag.

// medals
uint32 medals_arms = 0;
Expand Down Expand Up @@ -200,4 +204,4 @@ class DataObject
};
GlobalStats global_stats;
};
#endif
#endif // SRC_DATAOBJECT_H_
Loading

0 comments on commit 8e0d5d8

Please sign in to comment.