Skip to content
Snippets Groups Projects
Commit b8280176 authored by HoelShare's avatar HoelShare
Browse files

GPN

parent b29346ee
No related branches found
No related tags found
No related merge requests found
// Created by hoelshare on 27.05.17.
//
#ifndef GPN_BADGELASERTAG_CONFIGPAKET_HPP
#define GPN_BADGELASERTAG_CONFIGPAKET_HPP
#include "url-encode.h"
struct ConfigPacket {
int magazineSize[3];
int damage[3];
int magazineReloadTime[3];
int shotTime[3];
int resistance;
int health;
#define TYP "ConfigPacket"
String serial() {
String ret = "";
ret += "typ=" + String(TYP);
ret += "&mag0=" + String(magazineSize[0]);
ret += "&mag1=" + String(magazineSize[1]);
ret += "&mag2=" + String(magazineSize[2]);
ret += "&dmg0=" + String(damage[0]);
ret += "&dmg1=" + String(damage[1]);
ret += "&dmg2=" + String(damage[2]);
ret += "&rlt0=" + String(magazineReloadTime[0]);
ret += "&rlt1=" + String(magazineReloadTime[1]);
ret += "&rlt2=" + String(magazineReloadTime[2]);
ret += "&shotT0=" + String(shotTime[0]);
ret += "&shotT1=" + String(shotTime[1]);
ret += "&shotT2=" + String(shotTime[2]);
ret += "&resistance=" + String(resistance);
ret += "&health=" + String(health);
return ret;
}
static ConfigPacket *read(String value) {
ConfigPacket *config = new ConfigPacket();
UrlDecode decode(value.c_str());
config->magazineSize[0] = int(decode.getKey("mag0"));
config->magazineSize[1] = int(decode.getKey("mag1"));
config->magazineSize[2] = int(decode.getKey("mag2"));
config->damage[0] = int(decode.getKey("dmg0"));
config->damage[1] = int(decode.getKey("dmg1"));
config->damage[2] = int(decode.getKey("dmg2"));
config->magazineReloadTime[0] = int(decode.getKey("rlt0"));
config->magazineReloadTime[1] = int(decode.getKey("rlt1"));
config->magazineReloadTime[2] = int(decode.getKey("rlt2"));
config->shotTime[0] = int(decode.getKey("shotT0"));
config->shotTime[1] = int(decode.getKey("shotT1"));
config->shotTime[2] = int(decode.getKey("shotT2"));
config->resistance = int(decode.getKey("resistance"));
config->health = int(decode.getKey("health"));
return config;
}
};
#endif //GPN_BADGELASERTAG_CONFIGPAKET_HPP
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#define USEIR #define USEIR
#ifdef DEBUG #ifdef DEBUG
#define BADGE_PULL_INTERVAL 6000 #define BADGE_PULL_INTERVAL 10000
#else #else
#define BADGE_PULL_INTERVAL 5*60*1000 #define BADGE_PULL_INTERVAL 5*60*1000
#endif #endif
......
...@@ -4,6 +4,11 @@ ...@@ -4,6 +4,11 @@
#define AUSGABE #define AUSGABE
#include "GameServer.hpp" #include "GameServer.hpp"
#include "ConfigPacket.hpp"
#include "Player.hpp"
#define RESISTANCE 100
#define HEALTH 100
void GameServer::setTeamPlay(char isTeam) { void GameServer::setTeamPlay(char isTeam) {
#ifdef AUSGABE #ifdef AUSGABE
...@@ -41,7 +46,18 @@ void GameServer::update() { ...@@ -41,7 +46,18 @@ void GameServer::update() {
handleWelcome(&(serverClients[numConnections]), numConnections); handleWelcome(&(serverClients[numConnections]), numConnections);
} }
} else { } else {
// todo Normal game functions for (short i = 0; i <= numConnections; i++) { //iterate throu the slots
if (serverClients[i].connected() && serverClients[i].available()) { //skip unconnected slots
String message = serverClients[i].readStringUntil('\n');
UrlDecode decode(message.c_str());
String strTyp = String(decode.getKey("typ"));
if (strTyp == "hit") {
HitPacket* packet = HitPacket::read(message);
sendHit(packet);
delete packet;
}
}
}
} }
} }
...@@ -94,8 +110,29 @@ void GameServer::sendIP() { ...@@ -94,8 +110,29 @@ void GameServer::sendIP() {
} }
void GameServer::startGame() { void GameServer::startGame() {
this->gameStarted = true; if (!gameStarted) {
// todo something more Serial.println("Game started");
ConfigPacket config;
for (int i = 0; i < 3; i++) {
config.magazineSize[i] = Player::magazineSize[i];
config.magazineReloadTime[i] = Player::magazineReloadTime[i];
config.shotTime[i] = Player::shotTime[i];
config.damage[i] = Player::damage[i];
}
config.resistance = RESISTANCE;
config.health = HEALTH;
String value = config.serial() + "\n";
sendAll(value);
this->gameStarted = true;
ui->closeCurrent();
}
}
void GameServer::sendHit(HitPacket* hitPacket) {
int pid = hitPacket->playerId;
serverClients[pid].print(hitPacket->serial());
serverClients[pid].flush();
Serial.printf(String("Send hit: " + hitPacket->serial()).c_str());
} }
String GameServer::buildPlayerList() { String GameServer::buildPlayerList() {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <GPNBadge.hpp> #include <GPNBadge.hpp>
#include "BadgeUI.h" #include "BadgeUI.h"
#include "HitPacket.hpp"
#include "LaserMenuItem.hpp" #include "LaserMenuItem.hpp"
#include "PlayerListMenu.hpp" #include "PlayerListMenu.hpp"
#include "RemotePlayer.hpp" #include "RemotePlayer.hpp"
...@@ -57,12 +58,12 @@ public: ...@@ -57,12 +58,12 @@ public:
Serial.printf("Opened menu\n"); Serial.printf("Opened menu\n");
#endif #endif
playerList = new PlayerListMenu(9); playerList = new PlayerListMenu(9);
LaserMenuItem* item = new LaserMenuItem([]() {}, nullptr); LaserMenuItem *item = new LaserMenuItem([]() {}, nullptr);
item->setText("Playerlist"); item->setText("Playerlist");
playerList->addMenuItem(item); playerList->addMenuItem(item);
playerList->setLeftAction([=]() { this->kick(); }); playerList->setLeftAction([=]() { this->kick(); });
playerList->setRightAction([=]() { this->secureQuestion(); }); playerList->setRightAction([=]() { this->secureQuestion(); });
playerList->setEnterAction([=]() { this->sendIP(); }); playerList->setEnterAction([=]() { this->sendIP(); });
ui->open(playerList); ui->open(playerList);
ui->dispatchInput(badge->getJoystickState()); ui->dispatchInput(badge->getJoystickState());
ui->draw(); ui->draw();
...@@ -92,6 +93,8 @@ protected: ...@@ -92,6 +93,8 @@ protected:
void sendAll(String value); void sendAll(String value);
void sendHit(HitPacket *hitPacket);
private: private:
WindowSystem *ui; WindowSystem *ui;
Badge *badge; Badge *badge;
...@@ -102,8 +105,11 @@ private: ...@@ -102,8 +105,11 @@ private:
WiFiClient *serverClients; // the clients connected to the server WiFiClient *serverClients; // the clients connected to the server
short numConnections = 0; short numConnections = 0;
bool gameStarted = false; bool gameStarted = false;
void sendIP(); void sendIP();
RemotePlayer rPlayers[MAX_SRV_CLIENTS]; RemotePlayer rPlayers[MAX_SRV_CLIENTS];
String buildPlayerList(); String buildPlayerList();
}; };
......
//
// Created by hoelshare on 27.05.17.
//
#ifndef GPN_BADGELASERTAG_HITPACKET_HPP
#define GPN_BADGELASERTAG_HITPACKET_HPP
#include "url-encode.h"
struct HitPacket {
int playerId;
String nickname;
int lastHp;
#define TYP "hit"
String serial(){
String ret = "";
ret += "typ=" + String(TYP);
ret += "&pid=" + String(playerId);
ret += "&nick=" + String(nickname);
ret += "&lastHP=" + String(lastHp);
return ret;
}
static HitPacket* read(String value) {
UrlDecode decode(value.c_str());
HitPacket* ret = new HitPacket();
ret->lastHp = int(decode.getKey("lastHP"));
ret->nickname = String(decode.getKey("nick"));
ret->playerId = int(decode.getKey("pid"));
return ret;
}
};
#endif //GPN_BADGELASERTAG_HITPACKET_HPP
...@@ -6,6 +6,13 @@ ...@@ -6,6 +6,13 @@
#define min(a, b) ((a)<(b)?(a):(b)) #define min(a, b) ((a)<(b)?(a):(b))
#define max(a, b) ((a)>(b)?(a):(b)) #define max(a, b) ((a)>(b)?(a):(b))
// TODO set constants
const int Player::magazineSize[] = {10, 25, 1};
const int Player::shotTime[] = {100, 20, 300};
const int Player::magazineReloadTime[] = {800, 400, 2000};
const int Player::damage[] = {25, 10, 100};
void Player::heal(unsigned short healthPoints) { void Player::heal(unsigned short healthPoints) {
unsigned short calcHP = this->currentHP + healthPoints; unsigned short calcHP = this->currentHP + healthPoints;
this->currentHP = min(this->maxHP, calcHP); this->currentHP = min(this->maxHP, calcHP);
......
...@@ -62,28 +62,28 @@ public: ...@@ -62,28 +62,28 @@ public:
delete healthMenuItem, armorMenuItem, ammoMenuItem; delete healthMenuItem, armorMenuItem, ammoMenuItem;
} }
static const int magazineSize[3];
static const int shotTime[3];
static const int magazineReloadTime[3];
static const int damage[3];
private: private:
unsigned short pID; unsigned int pID;
unsigned short tID; unsigned int tID;
unsigned char teamColor[3]; // 3 Colors RGB unsigned char teamColor[3]; // 3 Colors RGB
char *nickname; char *nickname;
unsigned short maxHP; unsigned int maxHP;
unsigned short currentHP; unsigned int currentHP;
unsigned short shotMagazine[3]; // 3 Weapon categories [pistol, machine gun, explosive] unsigned int shotMagazine[3]; // 3 Weapon categories [pistol, machine gun, explosive]
unsigned short currentShot[3]; unsigned int currentShot[3];
unsigned char weaponIndex; unsigned int weaponIndex;
unsigned short currentArmor; unsigned int currentArmor;
unsigned short maxArmor; unsigned int maxArmor;
float maxArmorPercent; // max protection between 0 and 1 float maxArmorPercent; // max protection between 0 and 1
void die(); void die();
// TODO set constants
const char magazineSize[3] = {10, 25, 1};
const short shotTime[3] = {100, 20, 300};
const short magazineReloadTime[3] = {800, 400, 2000};
const short damage[3] = {25, 10, 100};
Badge *badge; Badge *badge;
protected: protected:
void updateHealthMenuItem(); void updateHealthMenuItem();
...@@ -95,5 +95,4 @@ protected: ...@@ -95,5 +95,4 @@ protected:
LaserMenuItem *armorMenuItem; LaserMenuItem *armorMenuItem;
LaserMenuItem *ammoMenuItem; LaserMenuItem *ammoMenuItem;
}; };
#endif //GPN_LASERTAG_PLAYER_HPP #endif //GPN_LASERTAG_PLAYER_HPP
...@@ -53,3 +53,9 @@ ...@@ -53,3 +53,9 @@
### UID von Server ### UID von Server
- char(4) - char(4)
- char(UID) - char(UID)
### Hit von Client
- Typ: Hit
- From: {playerId}
- who: {nickname}
- lastHP: {verbliebene HP}
\ No newline at end of file
...@@ -11,13 +11,14 @@ struct RemotePlayer { ...@@ -11,13 +11,14 @@ struct RemotePlayer {
String nickname; String nickname;
unsigned short pid; unsigned short pid;
unsigned char tid; unsigned char tid;
#define TYP "RemotePlayer"
String serial() { String serial() {
String ret = ""; String ret = "";
ret += "len=" + String(String(nickname).length()) + ";"; ret += "typ=" + String(TYP);
ret += "&nick=" + String(nickname) + ";"; ret += "&len=" + String(String(nickname).length());
ret += "&pid=" + String(pid) + ";"; ret += "&nick=" + String(nickname);
ret += "&tid=" + String(tid) + ";"; ret += "&pid=" + String(pid);
ret += "&tid=" + String(tid);
return ret; return ret;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment