Added STATS command to pixelnuke
This commit is contained in:
parent
79f3e54f6e
commit
b2b4403b67
1 changed files with 19 additions and 5 deletions
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
unsigned int px_width = 1024;
|
unsigned int px_width = 1024;
|
||||||
unsigned int px_height = 1024;
|
unsigned int px_height = 1024;
|
||||||
|
unsigned int px_pixelcount = 0;
|
||||||
|
unsigned int px_clientcount = 0;
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
|
|
||||||
|
|
@ -21,9 +23,15 @@ static int util_str_starts_with(const char* prefix, const char* str) {
|
||||||
|
|
||||||
// server callbacks
|
// server callbacks
|
||||||
void px_on_connect(NetClient *client) {
|
void px_on_connect(NetClient *client) {
|
||||||
|
px_clientcount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void px_on_close(NetClient *client, int error) {
|
||||||
|
px_clientcount--;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void px_on_read(NetClient *client, char *line) {
|
void px_on_read(NetClient *client, char *line) {
|
||||||
if (util_str_starts_with("PX ", line)) {
|
if (util_str_starts_with("PX ", line)) {
|
||||||
const char * ptr = line + 3;
|
const char * ptr = line + 3;
|
||||||
|
|
@ -76,12 +84,19 @@ void px_on_read(NetClient *client, char *line) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
px_pixelcount++;
|
||||||
canvas_set_px(x, y, c);
|
canvas_set_px(x, y, c);
|
||||||
|
|
||||||
} else if (util_str_starts_with("SIZE", line)) {
|
} else if (util_str_starts_with("SIZE", line)) {
|
||||||
|
|
||||||
char str[64];
|
char str[64];
|
||||||
sprintf(str, "SIZE %d %d", px_width, px_height);
|
snprintf(str, 64, "SIZE %d %d", px_width, px_height);
|
||||||
|
net_send(client, str);
|
||||||
|
|
||||||
|
} else if (util_str_starts_with("STATS", line)) {
|
||||||
|
|
||||||
|
char str[128];
|
||||||
|
snprintf(str, 128, "STATS px:%u conn:%u", px_pixelcount, px_clientcount);
|
||||||
net_send(client, str);
|
net_send(client, str);
|
||||||
|
|
||||||
} else if (util_str_starts_with("HELP", line)) {
|
} else if (util_str_starts_with("HELP", line)) {
|
||||||
|
|
@ -90,7 +105,8 @@ void px_on_read(NetClient *client, char *line) {
|
||||||
"\
|
"\
|
||||||
PX x y: Get color at position (x,y)\n\
|
PX x y: Get color at position (x,y)\n\
|
||||||
PX x y rrggbb(aa): Draw a pixel (with optional alpha channel)\n\
|
PX x y rrggbb(aa): Draw a pixel (with optional alpha channel)\n\
|
||||||
SIZE: Get canvas size");
|
SIZE: Get canvas size\n\
|
||||||
|
STATS: Return statistics");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
@ -99,8 +115,6 @@ SIZE: Get canvas size");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void px_on_close(NetClient *client, int error) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void px_on_key(int key, int scancode, int mods) {
|
void px_on_key(int key, int scancode, int mods) {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue