mirror of
https://github.com/fumiama/CMoe-Counter.git
synced 2025-02-17 10:58:36 +01:00
feat: add theme mobius
This commit is contained in:
parent
35126f49c8
commit
02f15b1c59
@ -19,6 +19,9 @@
|
|||||||
##### nixie(nix)
|
##### nixie(nix)
|
||||||
![Nixie Tube](https://counter.seku.su/cmoe?name=demo&theme=nix)
|
![Nixie Tube](https://counter.seku.su/cmoe?name=demo&theme=nix)
|
||||||
|
|
||||||
|
##### mobius(mbs)
|
||||||
|
![Nixie Tube](https://counter.seku.su/cmoe?name=demo&theme=mbs)
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@ -53,7 +56,7 @@ http://yourdomain/cmoe?name=yourname®=token
|
|||||||
```
|
```
|
||||||
### 2. Refer
|
### 2. Refer
|
||||||
```
|
```
|
||||||
http://yourdomain/cmoe?name=yourname(&theme=mb/mbh/gb/gbh/r34/nix)
|
http://yourdomain/cmoe?name=yourname(&theme=mb/mbh/gb/gbh/r34/nix/mbs)
|
||||||
```
|
```
|
||||||
That's all.
|
That's all.
|
||||||
## Credits
|
## Credits
|
||||||
|
@ -43,6 +43,8 @@
|
|||||||
<img src="/cmoe?name=demo&theme=asl" alt="A-SOUL">
|
<img src="/cmoe?name=demo&theme=asl" alt="A-SOUL">
|
||||||
<h5>nixie(nix)</h5>
|
<h5>nixie(nix)</h5>
|
||||||
<img src="/cmoe?name=demo&theme=nix" alt="Nixie-Tube">
|
<img src="/cmoe?name=demo&theme=nix" alt="Nixie-Tube">
|
||||||
|
<h5>mobius(mbs)</h5>
|
||||||
|
<img src="/cmoe?name=demo&theme=mbs" alt="Mobius-Path">
|
||||||
</details>
|
</details>
|
||||||
<h3>Credits</h3>
|
<h3>Credits</h3>
|
||||||
<ul>
|
<ul>
|
||||||
@ -76,6 +78,8 @@
|
|||||||
<option value="gb">gelbooru</option>
|
<option value="gb">gelbooru</option>
|
||||||
<option value="gbh">gelbooru-h</option>
|
<option value="gbh">gelbooru-h</option>
|
||||||
<option value="asl">asoul</option>
|
<option value="asl">asoul</option>
|
||||||
|
<option value="nix">nixie</option>
|
||||||
|
<option value="mbs">mobius</option>
|
||||||
</select>
|
</select>
|
||||||
<button id="get" style="margin: 10px 0;" onclick="_evt_push("click", "normal", "get_counter")">Get</button>
|
<button id="get" style="margin: 10px 0;" onclick="_evt_push("click", "normal", "get_counter")">Get</button>
|
||||||
<img id="result" style="display: block;"/>
|
<img id="result" style="display: block;"/>
|
||||||
|
55
cmoe.c
55
cmoe.c
@ -86,18 +86,20 @@ static inline uint32_t get_content_len(int isbigtiny, uint16_t* len_type, char*
|
|||||||
2|(2<<8)|(1<<16), 2|(2<<8)|(1<<16), 2|(2<<8)|(1<<16), 2|(2<<8)|(1<<16), 2|(2<<8)|(1<<16)
|
2|(2<<8)|(1<<16), 2|(2<<8)|(1<<16), 2|(2<<8)|(1<<16), 2|(2<<8)|(1<<16), 2|(2<<8)|(1<<16)
|
||||||
};
|
};
|
||||||
uint32_t len = sizeof(svg_small) // small & big has the same len
|
uint32_t len = sizeof(svg_small) // small & big has the same len
|
||||||
+ sizeof(svg_tail) - 1;
|
+ sizeof(svg_tail) - 1 + 1; // +1 for no \n
|
||||||
if (isbigtiny&2) len--; // is tiny
|
if (isbigtiny&FLAG_TINY) len--; // is tiny
|
||||||
|
uint32_t frontsz = ((isbigtiny&FLAG_SVG)?sizeof(svg_slot_front):sizeof(img_slot_front)) - 1;
|
||||||
|
uint32_t rearsz = ((isbigtiny&FLAG_SVG)?(sizeof(svg_slot_rear)-3+8):sizeof(img_slot_rear)) - 1 + 1; // +1 for no \n
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; cntstr[i]; i++) {
|
for (; cntstr[i]; i++) {
|
||||||
len += len_type[cntstr[i] - '0'] + (sizeof(img_slot_front) + sizeof(img_slot_rear) - 2);
|
len += (uint32_t)len_type[cntstr[i] - '0'] + frontsz + rearsz;
|
||||||
len += (uint32_t)((int)((int8_t)((lendiff[i]>>(isbigtiny*8))&0xff)));
|
len += (uint32_t)((int)((int8_t)((lendiff[i]>>(isbigtiny*8))&0xff)));
|
||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define cmp_and_set_type(t) if (!strcmp(theme, #t)) { theme_type = (char**)t; len_type = (uint16_t*)t##l; }
|
#define cmp_and_set_type(t) if (!strcmp(theme, #t)) { theme_type = (char**)t; len_type = (uint16_t*)t##l; }
|
||||||
static void draw(int count, char* theme) {
|
static void draw(int count, char* theme, uint32_t color) {
|
||||||
char cntstrbuf[11];
|
char cntstrbuf[11];
|
||||||
sprintf(cntstrbuf, "%010u", count);
|
sprintf(cntstrbuf, "%010u", count);
|
||||||
char* cntstr = cntstrbuf;
|
char* cntstr = cntstrbuf;
|
||||||
@ -106,7 +108,7 @@ static void draw(int count, char* theme) {
|
|||||||
if (i > 2) cntstr = cntstrbuf+i-2;
|
if (i > 2) cntstr = cntstrbuf+i-2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int isbig = 0;
|
int isbigtiny = 0;
|
||||||
char** theme_type = (char**)mb;
|
char** theme_type = (char**)mb;
|
||||||
uint16_t* len_type = (uint16_t*)mbl;
|
uint16_t* len_type = (uint16_t*)mbl;
|
||||||
if (theme) {
|
if (theme) {
|
||||||
@ -115,20 +117,22 @@ static void draw(int count, char* theme) {
|
|||||||
cmp_and_set_type(gb) else
|
cmp_and_set_type(gb) else
|
||||||
cmp_and_set_type(gbh) else
|
cmp_and_set_type(gbh) else
|
||||||
cmp_and_set_type(asl) else
|
cmp_and_set_type(asl) else
|
||||||
cmp_and_set_type(nix)
|
cmp_and_set_type(nix) else
|
||||||
isbig = (
|
cmp_and_set_type(mbs)
|
||||||
|
isbigtiny = (
|
||||||
(theme_type == (char**)gb || theme_type == (char**)gbh) |
|
(theme_type == (char**)gb || theme_type == (char**)gbh) |
|
||||||
((theme_type == (char**)nix) << 1)
|
((theme_type == (char**)nix || theme_type == (char**)mbs) << 1) |
|
||||||
|
((theme_type == (char**)mbs) << 2)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
int w, h;
|
int w, h;
|
||||||
char *head;
|
char *head;
|
||||||
if (isbig&1) {
|
if (isbigtiny&FLAG_BIG) {
|
||||||
w = W_BIG;
|
w = W_BIG;
|
||||||
h = H_BIG;
|
h = H_BIG;
|
||||||
head = (char*)svg_big;
|
head = (char*)svg_big;
|
||||||
}
|
}
|
||||||
else if (isbig&2) {
|
else if (isbigtiny&FLAG_TINY) {
|
||||||
w = W_TINY;
|
w = W_TINY;
|
||||||
h = H_TINY;
|
h = H_TINY;
|
||||||
head = (char*)svg_tiny;
|
head = (char*)svg_tiny;
|
||||||
@ -138,24 +142,33 @@ static void draw(int count, char* theme) {
|
|||||||
h = H_SMALL;
|
h = H_SMALL;
|
||||||
head = (char*)svg_small;
|
head = (char*)svg_small;
|
||||||
}
|
}
|
||||||
if (headers(get_content_len(isbig, len_type, cntstr), "image/svg+xml")) {
|
if (headers(get_content_len(isbigtiny, len_type, cntstr), "image/svg+xml")) {
|
||||||
write(1, "\0\0\0\0", 4);
|
write(1, "\0\0\0\0", 4);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* slot_front = (isbigtiny&FLAG_SVG)?svg_slot_front:img_slot_front;
|
||||||
|
const char* slot_rear;
|
||||||
|
if (isbigtiny&FLAG_SVG) {
|
||||||
|
char rearbuf[sizeof(svg_slot_rear)-3+8];
|
||||||
|
snprintf(rearbuf, sizeof(rearbuf), svg_slot_rear, color?color:SVG_DEFAULT_COLOR);
|
||||||
|
slot_rear = rearbuf;
|
||||||
|
} else slot_rear = img_slot_rear;
|
||||||
|
|
||||||
printf(head, w*(10+cntstrbuf-cntstr));
|
printf(head, w*(10+cntstrbuf-cntstr));
|
||||||
for (i = 0; cntstr[i]; i++) {
|
for (i = 0; cntstr[i]; i++) {
|
||||||
printf(img_slot_front, w * i, w, h);
|
printf(slot_front, w * i, w, h);
|
||||||
int n = cntstr[i] - '0';
|
int n = cntstr[i] - '0';
|
||||||
fwrite(theme_type[n], len_type[n], 1, stdout);
|
fwrite(theme_type[n], len_type[n], 1, stdout);
|
||||||
printf(img_slot_rear);
|
puts(slot_rear); // +1 \n for each turn
|
||||||
}
|
}
|
||||||
printf(svg_tail);
|
puts(svg_tail); // +1 \n
|
||||||
}
|
}
|
||||||
|
|
||||||
#define has_next(fp, ch) ((ch=getc(fp)),(feof(fp)?0:(ungetc(ch,fp),1)))
|
#define has_next(fp, ch) ((ch=getc(fp)),(feof(fp)?0:(ungetc(ch,fp),1)))
|
||||||
static void return_count(FILE* fp, char* name, char* theme) {
|
static void return_count(FILE* fp, char* name, char* theme, uint32_t color) {
|
||||||
if (!strcmp(name, "demo")) {
|
if (!strcmp(name, "demo")) {
|
||||||
draw(123456789, theme);
|
draw(123456789, theme, color);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int ch, exist = 0, user_exist = 0;
|
int ch, exist = 0, user_exist = 0;
|
||||||
@ -172,7 +185,7 @@ static void return_count(FILE* fp, char* name, char* theme) {
|
|||||||
http_error(HTTP500, "Add User Error.");
|
http_error(HTTP500, "Add User Error.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
draw(d->count, theme);
|
draw(d->count, theme, color);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
http_error(HTTP404, "No Such User.");
|
http_error(HTTP404, "No Such User.");
|
||||||
@ -224,6 +237,12 @@ int main(int argc, char **argv) {
|
|||||||
if (theme) {
|
if (theme) {
|
||||||
theme = get_arg(theme + 6);
|
theme = get_arg(theme + 6);
|
||||||
}
|
}
|
||||||
|
char* colors = strstr(QS, "color=");
|
||||||
|
uint32_t color = 0;
|
||||||
|
if (colors) {
|
||||||
|
colors = get_arg(colors + 6);
|
||||||
|
sscanf(colors, "%x", &color);
|
||||||
|
}
|
||||||
char* reg = strstr(QS, "reg=");
|
char* reg = strstr(QS, "reg=");
|
||||||
int fd;
|
int fd;
|
||||||
if (!reg) {
|
if (!reg) {
|
||||||
@ -236,7 +255,7 @@ int main(int argc, char **argv) {
|
|||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
fp = fdopen(fd, "rb+");
|
fp = fdopen(fd, "rb+");
|
||||||
return_count(fp, name, theme);
|
return_count(fp, name, theme, color);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
reg = get_arg(reg + 4);
|
reg = get_arg(reg + 4);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user