diff options
Diffstat (limited to 'toj')
116 files changed, 0 insertions, 17174 deletions
diff --git a/toj/center/pro/packpro.sh b/toj/center/pro/packpro.sh deleted file mode 100755 index b53a707..0000000 --- a/toj/center/pro/packpro.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -tar -jcvf ../tmp/propack/$1.tar.bz2 -C $1 . diff --git a/toj/center/src/Makefile b/toj/center/src/Makefile deleted file mode 100755 index 17cbcf3..0000000 --- a/toj/center/src/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -ifneq ($(KERNELRELEASE),) - judgk-objs := judgk_mod.o judgk_proc.o judgk_syscall.o judgk_syscall_asm.o judgk_security.o judgk_security_asm.o judgk_hyperio.o - obj-m := judgk.o -else - KERNEL_SOURCE := /lib/modules/$(shell uname -r)/build - PWD := $(shell pwd) -default: - ${MAKE} -C ${KERNEL_SOURCE} M=${PWD} modules - mv judgk.ko ../judge/ - - g++ -g -rdynamic -fvisibility=hidden -O2 center_server.cpp center_manage.cpp center_judge.cpp tool.cpp /srv/http/toj/php/event_exec.cpp -ldl -lpq -ltar -lbz2 -ljson -lcurl -pthread -o center_server - g++ -g -O2 judge_server.cpp judge_manage.cpp tool.cpp -ldl -lbz2 -ltar -pthread -o judge_server - mv center_server ../ - mv judge_server ../judge/ - - g++ -shared -fPIC -fvisibility=hidden -O2 jmod_test_manage.cpp -ldl -ljson -pthread -o jmod_test_manage.so - g++ -shared -fPIC -fvisibility=hidden -O2 jmod_test_line.cpp -ljson -pthread -o jmod_test_line.so - g++ -shared -fPIC -fvisibility=hidden -O2 jmod_test_check.cpp -o jmod_test_check.so - mv jmod_test_manage.so ../jmod/jmod_test/ - mv jmod_test_line.so ../jmod/jmod_test/ - mv jmod_test_check.so ../jmod/jmod_test/ - tar -jcvf ../tmp/jmodpack/jmod_test.tar.bz2 -C ../jmod/jmod_test . - - g++ -shared -fPIC -fvisibility=hidden -O2 sprout_tar_check.cpp -o ../pro/15/private/check.so -clean: - ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean -endif diff --git a/toj/center/src/center.h b/toj/center/src/center.h deleted file mode 100755 index 2625ab4..0000000 --- a/toj/center/src/center.h +++ /dev/null @@ -1,47 +0,0 @@ -#define CENTER_CACHESTATE_READY 0 -#define CENTER_CACHESTATE_UPDATE 1 - -class center_jmod_info{ -public: - char name[NAME_MAX + 1]; - int cacheid; - void *manage_dll; - void *manage_sub_fn; - void *manage_res_fn; - - int ref_count; - int state; - int update_cacheid; - - center_jmod_info(char *name,int cacheid){ - this->name[0] = '\0'; - strncat(this->name,name,sizeof(this->name)); - this->cacheid = cacheid; - this->manage_dll = NULL; - this->manage_sub_fn = NULL; - this->manage_res_fn = NULL; - } -}; - -class center_pro_info{ -public: - int proid; - int cacheid; - center_jmod_info *jmod_info; - int lang_flag; - - int ref_count; - int state; - int update_cacheid; - - center_pro_info(int proid,int cacheid,center_jmod_info *jmod_info,int lang_flag){ - this->proid = proid; - this->cacheid = cacheid; - this->jmod_info = jmod_info; - this->lang_flag = lang_flag; - - this->ref_count = 0; - this->state = CENTER_CACHESTATE_READY; - this->update_cacheid = 0; - } -}; diff --git a/toj/center/src/center_com.h b/toj/center/src/center_com.h deleted file mode 100755 index 6973eec..0000000 --- a/toj/center/src/center_com.h +++ /dev/null @@ -1,70 +0,0 @@ -#define CENTER_COMCODE_SETID 1 -#define CENTER_COMCODE_SETINFO 2 -#define CENTER_COMCODE_SUBMIT 3 -#define CENTER_COMCODE_RESULT 4 - -#define CENTER_COMCODE_SETPRO 10 -#define CENTER_COMCODE_REQPRO 11 -#define CENTER_COMCODE_SENDPRO 12 -#define CENTER_COMCODE_SETJMOD 13 -#define CENTER_COMCODE_REQJMOD 14 -#define CENTER_COMCODE_SENDJMOD 15 - -#define CENTER_COMCODE_REQCODE 20 -#define CENTER_COMCODE_SENDCODE 21 - -struct center_com_header{ - int code; - int size; -}__attribute__((packed)); -struct center_com_setid{ - int id; //0:new judge -}__attribute__((packed)); -struct center_com_setinfo{ - int avail; -}__attribute__((packed)); -struct center_com_submit{ //judt submit header - int subid; - int proid; - int lang; -}__attribute__((packed)); -struct center_com_result{ //just result header - int subid; -}__attribute__((packed)); - -struct center_com_setpro{ - int proid; - int cacheid; - int type; //0:add problem 1:drop problem -}__attribute__((packed)); -struct center_com_reqpro{ - int proid; - int cacheid; -}__attribute__((packed)); -struct center_com_sendpro{ - int proid; - int cacheid; - size_t filesize; -}__attribute__((packed)); - -struct center_com_setjmod{ - char jmod_name[NAME_MAX + 1]; - int cacheid; - int type; //0:add jmod 1:drop jmod -}__attribute__((packed)); -struct center_com_reqjmod{ - char jmod_name[NAME_MAX + 1]; -}__attribute__((packed)); -struct center_com_sendjmod{ - char jmod_name[NAME_MAX + 1]; - int cacheid; - size_t filesize; -}__attribute__((packed)); - -struct center_com_reqcode{ - int subid; -}__attribute__((packed)); -struct center_com_sendcode{ - int subid; - size_t filesize; -}__attribute__((packed)); diff --git a/toj/center/src/center_judge.cpp b/toj/center/src/center_judge.cpp deleted file mode 100755 index 46600c2..0000000 --- a/toj/center/src/center_judge.cpp +++ /dev/null @@ -1,578 +0,0 @@ -#include<stdio.h> -#include<stdlib.h> -#include<string.h> -#include<unistd.h> -#include<fcntl.h> -#include<limits.h> -#include<errno.h> -#include<sys/stat.h> -#include<sys/types.h> -#include<sys/epoll.h> -#include<sys/sendfile.h> -#include<map> -#include<list> -#include<queue> -#include<string> - -#include"netio.h" -#include"judge_def.h" -#include"judgm_manage.h" -#include"center.h" -#include"center_com.h" -#include"center_judge.h" - -int judge_info::last_id = 0; -judge_info::judge_info(){ - last_id++; - this->id = last_id; - this->avail = 0; - - judge_idmap.insert(std::pair<int,judge_info*>(id,this)); - judge_runlist.push_back(this); - judge_it = judge_runlist.end(); - judge_it--; -} -judge_info::~judge_info(){ - judge_idmap.erase(id); - judge_runlist.erase(judge_it); -} -int judge_info::setavail(int avail){ - int old; - - old = this->avail; - this->avail = avail; - if(this->avail > 0 && old <= 0){ - judge_runlist.erase(judge_it); - judge_runlist.push_front(this); - judge_it = judge_runlist.begin(); - }else if(this->avail <= 0 && old > 0){ - judge_runlist.erase(judge_it); - judge_runlist.push_back(this); - judge_it = judge_runlist.end(); - judge_it--; - } - - return 0; -} -int judge_info::setinfo(int avail){ - setavail(avail); - return 0; -} -int judge_info::submit(judge_submit_info *sub_info){ - setavail(avail - 1); - conn_main->send_submit(sub_info); - return 0; -} -int judge_info::result(int subid,char *res_data){ - setavail(avail + 1); - - printf("submitid:%d\n",subid); - center_manage_result(subid,res_data); - - judge_run_waitqueue(); - return 0; -} -int judge_info::updatepro(std::vector<std::pair<int,int> > &pro_list){ - int i; - - for(i = 0;i < pro_list.size();i++){ - pro_map.erase(pro_list[i].first); - } - conn_main->send_setpro(pro_list,0); - - return 0; -} -int judge_info::updatejmod(std::vector<std::pair<char*,int> > &jmod_list){ - int i; - - for(i = 0;i < jmod_list.size();i++){ - jmod_map.erase(jmod_list[i].first); - } - conn_main->send_setjmod(jmod_list,0); - - return 0; -} - - -judge_conn::judge_conn(int fd):netio(fd){ - this->info = NULL; - this->recv_dispatch_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_dispatch); - this->recv_setid_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_setid); - this->recv_setinfo_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_setinfo); - this->recv_result_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_result); - this->recv_setpro_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_setpro); - this->recv_reqpro_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_reqpro); - this->done_sendpro_fn = new netio_iofn<judge_conn>(this,&judge_conn::done_sendpro); - this->recv_setjmod_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_setjmod); - this->recv_reqjmod_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_reqjmod); - this->recv_reqcode_fn = new netio_iofn<judge_conn>(this,&judge_conn::recv_reqcode); -} -judge_conn::~judge_conn(){ - info->conn_list.erase(conn_it); - if(info->conn_main == this){ - info->conn_main = NULL; - } - if(info->conn_list.empty()){ - delete info; - } - - delete recv_dispatch_fn; - delete recv_setid_fn; - delete recv_setinfo_fn; - delete recv_result_fn; - delete recv_setpro_fn; - delete recv_reqpro_fn; - delete done_sendpro_fn; - delete recv_setjmod_fn; - delete recv_reqjmod_fn; - delete recv_reqcode_fn; -} -char* judge_conn::create_combuf(int code,int size,int &len,void **data){ - char *buf; - center_com_header *header; - - buf = new char[sizeof(center_com_header) + size]; - header = (center_com_header*)buf; - header->code = code; - header->size = size; - len = sizeof(center_com_header) + size; - *data = (void*)(buf + sizeof(center_com_header)); - - return buf; -} -int judge_conn::send_setid(int judgeid){ - char *write_buf; - int write_len; - center_com_setid *setid; - - write_buf = create_combuf(CENTER_COMCODE_SETID,sizeof(center_com_setid),write_len,(void**)&setid); - setid->id = judgeid; - writebytes(write_buf,write_len,NULL,NULL); - - return 0; -} -int judge_conn::send_submit(judge_submit_info *sub_info){ - char *write_buf; - int write_len; - center_com_submit *sub; - - if(sub_info->set_len > JUDGE_SET_DATAMAX){ - delete sub_info; - return -1; - } - - write_buf = create_combuf(CENTER_COMCODE_SUBMIT,sizeof(center_com_submit) + sub_info->set_len,write_len,(void**)&sub); - sub->subid = sub_info->subid; - sub->proid = sub_info->proid; - sub->lang = sub_info->lang; - memcpy((void*)(write_buf + sizeof(center_com_header) + sizeof(center_com_submit)),sub_info->set_data,sub_info->set_len); - writebytes(write_buf,write_len,NULL,NULL); - - delete sub_info; - return 0; -} -int judge_conn::send_setpro(std::vector<std::pair<int,int> > &pro_list,int type){ - int i; - - int count; - char *write_buf; - int write_len; - center_com_setpro *setpro; - - count = pro_list.size(); - write_buf = create_combuf(CENTER_COMCODE_SETPRO,sizeof(center_com_setpro) * count,write_len,(void**)&setpro); - - for(i = 0;i < count;i++){ - setpro[i].proid = pro_list[i].first; - setpro[i].cacheid = pro_list[i].second; - setpro[i].type = type; - } - writebytes(write_buf,write_len,NULL,NULL); - - return 0; -} -int judge_conn::send_setjmod(std::vector<std::pair<char*,int> > &jmod_list,int type){ - int i; - - int count; - char *write_buf; - int write_len; - center_com_setjmod *setjmod; - - count = jmod_list.size(); - write_buf = create_combuf(CENTER_COMCODE_SETJMOD,sizeof(center_com_setjmod) * count,write_len,(void**)&setjmod); - - for(i = 0;i < count;i++){ - setjmod[i].jmod_name[0] = '\0'; - strncat(setjmod[i].jmod_name,jmod_list[i].first,sizeof(setjmod[i].jmod_name)); - setjmod[i].cacheid = jmod_list[i].second; - setjmod[i].type = type; - } - writebytes(write_buf,write_len,NULL,NULL); - - return 0; -} -int judge_conn::readidle(){ - readbytes(new center_com_header,sizeof(center_com_header),recv_dispatch_fn,NULL); - return 0; -} -void judge_conn::recv_dispatch(void *buf,size_t len,void *data){ - center_com_header *header; - char *readbuf; - - header = (center_com_header*)buf; - readbuf = new char[header->size]; - - printf("code:%d size:%d\n",header->code,header->size); - switch(header->code){ - case CENTER_COMCODE_SETID: - readbytes(readbuf,header->size,recv_setid_fn,NULL); - break; - case CENTER_COMCODE_SETINFO: - readbytes(readbuf,header->size,recv_setinfo_fn,NULL); - break; - case CENTER_COMCODE_RESULT: - readbytes(readbuf,header->size,recv_result_fn,NULL); - break; - case CENTER_COMCODE_SETPRO: - readbytes(readbuf,header->size,recv_setpro_fn,NULL); - break; - case CENTER_COMCODE_REQPRO: - readbytes(readbuf,header->size,recv_reqpro_fn,NULL); - break; - case CENTER_COMCODE_SETJMOD: - readbytes(readbuf,header->size,recv_setjmod_fn,NULL); - break; - case CENTER_COMCODE_REQJMOD: - readbytes(readbuf,header->size,recv_reqjmod_fn,NULL); - break; - case CENTER_COMCODE_REQCODE: - readbytes(readbuf,header->size,recv_reqcode_fn,NULL); - break; - } - - delete header; -} -void judge_conn::recv_setid(void *buf,size_t len,void *data){ - center_com_setid *setid; - std::map<int,judge_info*>::iterator it; - - setid = (center_com_setid*)buf; - if(setid->id == 0){ - info = new judge_info(); - - info->conn_list.push_front(this); - conn_it = info->conn_list.begin(); - info->conn_main = this; - - this->send_setid(info->id); - }else{ - if((it = judge_idmap.find(setid->id)) != judge_idmap.end()){ - info = it->second; - info->conn_list.push_front(this); - conn_it = info->conn_list.begin(); - } - } - - delete setid; -} -void judge_conn::recv_setinfo(void *buf,size_t len,void *data){ - int i; - int count; - - center_com_setinfo *setinfo; - std::map<std::string,center_jmod_info*>::iterator jmod_it; - std::vector<std::pair<char*,int> > jmod_list; - std::map<int,center_pro_info*>::iterator pro_it; - std::vector<std::pair<int,int> > pro_list; - - setinfo = (center_com_setinfo*)buf; - info->setinfo(setinfo->avail); - - count = center_manage_jmodmap.size(); - jmod_it = center_manage_jmodmap.begin(); - for(i = 0;i < count;i++,jmod_it++){ - jmod_list.push_back(std::make_pair(jmod_it->second->name,jmod_it->second->cacheid)); - } - send_setjmod(jmod_list,0); - - count = center_manage_promap.size(); - pro_it = center_manage_promap.begin(); - for(i = 0;i < count;i++,pro_it++){ - pro_list.push_back(std::make_pair(pro_it->second->proid,pro_it->second->cacheid)); - } - send_setpro(pro_list,0); - - delete setinfo; -} -void judge_conn::recv_result(void *buf,size_t len,void *data){ - int subid; - char *res_data; - - subid = ((center_com_result*)buf)->subid; - res_data = (char*)((char*)buf + sizeof(center_com_result)); - - info->result(subid,res_data); - - delete (char*)buf; -} -void judge_conn::recv_setpro(void *buf,size_t len,void *data){ - int i; - int count; - - center_com_setpro *setpro; - center_pro_info *pro_info; - std::map<int,center_pro_info*>::iterator pro_it; - - count = len / sizeof(center_com_setpro); - setpro = (center_com_setpro*)buf; - for(i = 0;i < count;i++){ - if(setpro[i].type == 0){ - if((pro_info = center_manage_getprobyid(setpro[i].proid)) == NULL){ - continue; - } - - if(pro_info->cacheid == setpro[i].cacheid){ - info->pro_map.insert(std::pair<int,int>(pro_info->proid,pro_info->cacheid)); - } - center_manage_putpro(pro_info); - - }else if(setpro[i].type == 1){ - info->pro_map.erase(setpro[i].proid); - } - } - - judge_run_waitqueue(); - delete setpro; -} -void judge_conn::recv_reqpro(void *buf,size_t len,void *data){ - center_com_reqpro *reqpro; - std::map<int,center_pro_info*>::iterator pro_it; - center_pro_info *pro_info; - - char tpath[PATH_MAX + 1]; - int fd; - struct stat st; - - char *write_buf; - int write_len; - center_com_sendpro *sendpro; - - reqpro = (center_com_reqpro*)buf; - try{ - if((pro_info = center_manage_getprobyid(reqpro->proid)) == NULL){ - throw -1; - } - if(pro_info->cacheid != reqpro->cacheid){ - throw -1; - } - - snprintf(tpath,sizeof(tpath),"tmp/propack/%d_%d.tar.bz2",pro_info->proid,pro_info->cacheid); - fd = open(tpath,O_RDONLY); - fstat(fd,&st); - write_buf = create_combuf(CENTER_COMCODE_SENDPRO,sizeof(center_com_sendpro),write_len,(void**)&sendpro); - sendpro->proid = pro_info->proid; - sendpro->cacheid = pro_info->cacheid; - sendpro->filesize = st.st_size; - printf("sendpro:%lu\n",sendpro->filesize); - - writebytes(write_buf,write_len,NULL,NULL); - writefile(fd,st.st_size,done_sendpro_fn,pro_info); - }catch(int err){ - if(pro_info != NULL){ - center_manage_putpro(pro_info); - } - } - - delete reqpro; -} -void judge_conn::done_sendpro(void *buf,size_t len,void *data){ - close((int)((long)buf)); - center_manage_putpro((center_pro_info*)data); -} -void judge_conn::recv_setjmod(void *buf,size_t len,void *data){ - int i; - int count; - - center_com_setjmod *setjmod; - std::map<std::string,center_jmod_info*>::iterator jmod_it; - - count = len / sizeof(center_com_setjmod); - setjmod = (center_com_setjmod*)buf; - for(i = 0;i < count;i++){ - if(setjmod[i].type == 0){ - if((jmod_it = center_manage_jmodmap.find(setjmod[i].jmod_name)) == center_manage_jmodmap.end()){ - continue; - } - if(jmod_it->second->cacheid != setjmod[i].cacheid){ - continue; - } - - info->jmod_map.insert(std::pair<std::string,center_jmod_info*>(jmod_it->second->name,jmod_it->second)); - }else if(setjmod[i].type == 1){ - info->jmod_map.erase(setjmod[i].jmod_name); - } - } - - judge_run_waitqueue(); - delete setjmod; -} -void judge_conn::recv_reqjmod(void *buf,size_t len,void *data){ - center_com_reqjmod *reqjmod; - std::map<std::string,center_jmod_info*>::iterator jmod_it; - center_jmod_info *jmod_info; - - char tpath[PATH_MAX + 1]; - int fd; - struct stat st; - - char *write_buf; - int write_len; - center_com_sendjmod *sendjmod; - - reqjmod = (center_com_reqjmod*)buf; - if((jmod_it = center_manage_jmodmap.find(reqjmod->jmod_name)) == center_manage_jmodmap.end()){ - //fix - }else{ - jmod_info = jmod_it->second; - - snprintf(tpath,sizeof(tpath),"tmp/jmodpack/%s.tar.bz2",jmod_info->name); - fd = open(tpath,O_RDONLY); - if(fstat(fd,&st)){ - //fix - }else{ - write_buf = create_combuf(CENTER_COMCODE_SENDJMOD,sizeof(center_com_sendjmod),write_len,(void**)&sendjmod); - sendjmod->jmod_name[0] = '\0'; - strncat(sendjmod->jmod_name,jmod_info->name,sizeof(sendjmod->jmod_name)); - sendjmod->cacheid = jmod_info->cacheid; - sendjmod->filesize = st.st_size; - printf("sendjmod:%lu\n",sendjmod->filesize); - - writebytes(write_buf,write_len,NULL,NULL); - writefile(fd,st.st_size,NULL,NULL); - } - } - - delete reqjmod; -} -void judge_conn::recv_reqcode(void *buf,size_t len,void *data){ - center_com_reqcode *reqcode; - char tpath[PATH_MAX + 1]; - int fd; - struct stat st; - - char *write_buf; - int write_len; - center_com_header *header; - center_com_sendcode *sendcode; - - reqcode = (center_com_reqcode*)buf; - snprintf(tpath,sizeof(tpath),"tmp/codepack/%d.tar.bz2",reqcode->subid); - fd = open(tpath,O_RDONLY); - if(fstat(fd,&st)){ - //fix - }else{ - write_buf = create_combuf(CENTER_COMCODE_SENDCODE,sizeof(center_com_sendcode),write_len,(void**)&sendcode); - sendcode->subid = reqcode->subid; - sendcode->filesize = st.st_size; - printf("sendcode:%lu\n",sendcode->filesize); - - writebytes(write_buf,write_len,NULL,NULL); - writefile(fd,st.st_size,NULL,NULL); - } - - delete reqcode; -} - - -static int judge_run_waitqueue(){ - int count; - judge_submit_info *sub_info; - bool wait_flag; - std::list<judge_info*>::iterator judge_it; - judge_info *info; - std::map<int,center_pro_info*>::iterator pro_it; - center_pro_info *pro_info; - - count = judge_submitqueue.size(); - printf(" remain count %d\n",count); - for(;count > 0;count--){ - sub_info = judge_submitqueue.front(); - judge_submitqueue.pop(); - - if((pro_it = center_manage_promap.find(sub_info->proid)) == center_manage_promap.end()){ - continue; - } - pro_info = pro_it->second; - - wait_flag = true; - for(judge_it = judge_runlist.begin();judge_it != judge_runlist.end();judge_it++){ - info = *judge_it; - if(info->avail <= 0){ - break; - } - if(info->pro_map.find(pro_info->proid) != info->pro_map.end() && info->jmod_map.find(pro_info->jmod_info->name) != info->jmod_map.end()){ - info->submit(sub_info); - wait_flag = false; - break; - } - } - if(wait_flag == true){ - judge_submitqueue.push(sub_info); - } - } - return 0; -} -int center_judge_init(){ - return 0; -} -void* center_judge_addconn(int fd){ - return new judge_conn(fd); -} -int center_judge_dispatch(int evflag,void *data){ - judge_conn *cinfo; - - cinfo = (judge_conn*)data; - if(evflag & EPOLLRDHUP){ - printf("close %d\n",cinfo->fd); - delete cinfo; - }else{ - if(evflag & EPOLLIN){ - cinfo->readio(); - } - if(evflag & EPOLLOUT){ - cinfo->writeio(); - } - } - - return 0; -} -int center_judge_submit(int subid,int proid,int lang,char *set_data,size_t set_len){ - judge_submitqueue.push(new judge_submit_info(subid,proid,lang,set_data,set_len)); - judge_run_waitqueue(); - return 0; -} -int center_judge_updatepro(std::vector<std::pair<int,int> > &pro_list){ - int i; - int j; - std::list<judge_info*>::iterator judge_it; - judge_info *info; - - for(judge_it = judge_runlist.begin();judge_it != judge_runlist.end();judge_it++){ - (*judge_it)->updatepro(pro_list); - } - - return 0; -} -int center_judge_updatejmod(std::vector<std::pair<char*,int> > &jmod_list){ - int i; - int j; - std::list<judge_info*>::iterator judge_it; - judge_info *info; - - for(judge_it = judge_runlist.begin();judge_it != judge_runlist.end();judge_it++){ - (*judge_it)->updatejmod(jmod_list); - } - - return 0; -} diff --git a/toj/center/src/center_judge.h b/toj/center/src/center_judge.h deleted file mode 100755 index a955ce9..0000000 --- a/toj/center/src/center_judge.h +++ /dev/null @@ -1,106 +0,0 @@ -class judge_info; -class judge_conn; -class judge_submit_info; - -class judge_info{ -private: - static int last_id; - -public: - int id; - int avail; - judge_conn *conn_main; - std::list<judge_conn*> conn_list; - std::list<judge_info*>::iterator judge_it; - std::map<int,int> pro_map; - std::map<std::string,center_jmod_info*> jmod_map; - - judge_info(); - ~judge_info(); - int setavail(int value); - int setinfo(int avail); - int submit(judge_submit_info *submit_info); - int result(int subid,char *res_data); - int updatepro(std::vector<std::pair<int,int> > &pro_list); - int updatejmod(std::vector<std::pair<char*,int> > &jmod_list); -}; - -class judge_conn : public netio{ -private: - netio_iofn<judge_conn> *recv_dispatch_fn; - netio_iofn<judge_conn> *recv_setid_fn; - netio_iofn<judge_conn> *recv_setinfo_fn; - netio_iofn<judge_conn> *recv_result_fn; - netio_iofn<judge_conn> *recv_setpro_fn; - netio_iofn<judge_conn> *recv_reqpro_fn; - netio_iofn<judge_conn> *done_sendpro_fn; - netio_iofn<judge_conn> *recv_setjmod_fn; - netio_iofn<judge_conn> *recv_reqjmod_fn; - netio_iofn<judge_conn> *recv_reqcode_fn; - - char* create_combuf(int code,int size,int &len,void **data); - void recv_dispatch(void *buf,size_t len,void *data); - void recv_setid(void *buf,size_t len,void *data); - void recv_setinfo(void *buf,size_t len,void *data); - void recv_result(void *buf,size_t len,void *data); - void recv_setpro(void *buf,size_t len,void *data); - void recv_reqpro(void *buf,size_t len,void *data); - void done_sendpro(void *buf,size_t len,void *data); - void recv_setjmod(void *buf,size_t len,void *data); - void recv_reqjmod(void *buf,size_t len,void *data); - void recv_reqcode(void *buf,size_t len,void *data); - -public: - judge_info *info; - std::list<judge_conn*>::iterator conn_it; - - judge_conn(int fd); - ~judge_conn(); - int send_setid(int judgeid); - int send_submit(judge_submit_info* submit_info); - int send_setpro(std::vector<std::pair<int,int> > &pro_list,int type); - int send_setjmod(std::vector<std::pair<char*,int> > &jmod_list,int type); - virtual int readidle(); -}; - -class judge_submit_info{ -public: - int subid; - int proid; - int lang; - char *set_data; - size_t set_len; - - judge_submit_info(int subid,int proid,int lang,char *set_data,size_t set_len){ - this->subid = subid; - this->proid = proid; - this->lang = lang; - this->set_data = new char[set_len]; - memcpy(this->set_data,set_data,set_len); - this->set_len = set_len; - } - ~judge_submit_info(){ - delete this->set_data; - } -}; - -static int judge_run_waitqueue(); - -static std::map<int,judge_info*> judge_idmap; -static std::list<judge_info*> judge_runlist; -static std::queue<judge_submit_info*> judge_submitqueue; - -int center_judge_init(); -void* center_judge_addconn(int fd); -int center_judge_dispatch(int evflag,void *data); -int center_judge_submit(int subid,int proid,int lang,char *set_data,size_t set_len); -int center_judge_updatepro(std::vector<std::pair<int,int> > &pro_list); -int center_judge_updatejmod(std::vector<std::pair<char*,int> > &jmod_list); - -extern int center_manage_result(int subid,char *res_data); -extern center_pro_info* center_manage_getprobyid(int proid); -extern int center_manage_getpro(center_pro_info *pro_info); -extern int center_manage_putpro(center_pro_info *pro_info); - -extern std::map<std::string,center_jmod_info*> center_manage_jmodmap; -extern std::map<int,center_pro_info*> center_manage_promap; diff --git a/toj/center/src/center_manage.cpp b/toj/center/src/center_manage.cpp deleted file mode 100755 index a6a759c..0000000 --- a/toj/center/src/center_manage.cpp +++ /dev/null @@ -1,640 +0,0 @@ -#include<stdio.h> -#include<stdlib.h> -#include<string.h> -#include<limits.h> -#include<dlfcn.h> -#include<unistd.h> -#include<pthread.h> -#include<semaphore.h> -#include<libpq-fe.h> -#include<sys/eventfd.h> -#include<sys/stat.h> -#include<json/json.h> -#include<vector> -#include<queue> -#include<map> -#include<string> - -#include"tpool.h" -#include"/srv/http/toj/php/event_exec.h" -#include"judge_def.h" -#include"judgm_manage.h" -#include"center.h" -#include"center_manage.h" - -int center_manage_init(tpool **tpinfo){ - manage_tp = new tpool(4); - manage_tp->start(); - *tpinfo = manage_tp; - - manage_updatepro_thfn = new tpool_static_fn(manage_updatepro_th); - manage_updatepro_cbfn = new tpool_static_fn(manage_updatepro_cb); - manage_updatejmod_thfn = new tpool_static_fn(manage_updatejmod_th); - manage_updatejmod_cbfn = new tpool_static_fn(manage_updatejmod_cb); - manage_submit_thfn = new tpool_static_fn(manage_submit_th); - manage_submit_cbfn = new tpool_static_fn(manage_submit_cb); - - //run when startup - center_manage_updatedata(); - center_manage_submitwait(); - return 0; -} -PGconn* center_manage_conndb(){ - return PQconnectdb("host=localhost port=5432 dbname=xxxxx user=xxxxx password=xxxxx"); -} -int center_manage_closedb(PGconn *conn){ - PQfinish(conn); - return 0; -} -int center_manage_updatedata(){ - int i; - - PGconn *db_conn; - PGresult *db_res; - int db_count; - int cacheid; - center_jmod_info *jmod_info; - int proid; - int lang_flag; - std::map<std::string,center_jmod_info*>::iterator jmod_it; - center_pro_info *pro_info; - - std::vector<std::pair<int,int> > pro_list; - - if((db_conn = center_manage_conndb()) == NULL){ - return -1; - } - - db_res = PQexec(db_conn,"SELECT DISTINCT \"jmodname\" FROM \"mod\";"); - if(PQresultStatus(db_res) != PGRES_TUPLES_OK){ - center_manage_closedb(db_conn); - return -1; - } - - db_count = PQntuples(db_res); - for(i = 0;i < db_count;i++){ - jmod_info = new center_jmod_info(PQgetvalue(db_res,i,0),2); - center_manage_jmodmap.insert(std::pair<std::string,center_jmod_info*>(jmod_info->name,jmod_info)); - } - PQclear(db_res); - - db_res = PQexec(db_conn,"SELECT \"proid\",\"cacheid\",\"lang\",\"jmodname\" FROM \"problem\" INNER JOIN \"mod\" ON (\"problem\".\"modid\"=\"mod\".\"modid\");"); - if(PQresultStatus(db_res) != PGRES_TUPLES_OK){ - center_manage_closedb(db_conn); - return -1; - } - - db_count = PQntuples(db_res); - for(i = 0;i < db_count;i++){ - sscanf(PQgetvalue(db_res,i,0),"%d",&proid); - sscanf(PQgetvalue(db_res,i,1),"%d",&cacheid); - sscanf(PQgetvalue(db_res,i,2),"%d",&lang_flag); - if((jmod_it = center_manage_jmodmap.find(PQgetvalue(db_res,i,3))) == center_manage_jmodmap.end()){ - continue; - } - - if(manage_updatepro(proid,cacheid,jmod_it->second,lang_flag) == 1){ - pro_list.push_back(std::make_pair(proid,cacheid)); - - printf("pro update %d %d\n",proid,cacheid); - } - } - PQclear(db_res); - - if(!pro_list.empty()){ - center_judge_updatepro(pro_list); - } - - center_manage_closedb(db_conn); - return 0; -} -int center_manage_submitwait(){ - int i; - - PGconn *db_conn; - PGresult *db_res; - int db_count; - int subid; - - if((db_conn = center_manage_conndb()) == NULL){ - return -1; - } - - db_res = PQexec(db_conn,"SELECT \"subid\" FROM \"submit\" WHERE \"result\"=100;"); - if(PQresultStatus(db_res) != PGRES_TUPLES_OK){ - center_manage_closedb(db_conn); - return -1; - } - - db_count = PQntuples(db_res); - for(i = 0;i < db_count;i++){ - sscanf(PQgetvalue(db_res,i,0),"%d",&subid); - center_manage_submit(subid,"{}"); - } - - PQclear(db_res); - center_manage_closedb(db_conn); - return 0; -} - - -int center_manage_submit(int subid,char *param){ - PGconn *db_conn; - PGresult *db_res; - char *db_param[1]; - char db_subid[64]; - - int uid; - int proid; - int lang; - int result; - bool rejudge_flag; - std::map<int,center_pro_info*>::iterator pro_it; - center_pro_info *pro_info; - center_jmod_info *jmod_info; - manage_submit_info *sub_info; - - if((db_conn = center_manage_conndb()) == NULL){ - return -1; - } - - snprintf(db_subid,sizeof(db_subid),"%d",subid); - db_param[0] = db_subid; - db_res = PQexecParams(db_conn, - "SELECT \"uid\",\"proid\",\"lang\",\"result\" FROM \"submit\" WHERE \"subid\"=$1;", - 1, - NULL, - db_param, - NULL, - NULL, - 0); - if(PQresultStatus(db_res) != PGRES_TUPLES_OK){ - center_manage_closedb(db_conn); - return -1; - } - - sscanf(PQgetvalue(db_res,0,0),"%d",&uid); - sscanf(PQgetvalue(db_res,0,1),"%d",&proid); - sscanf(PQgetvalue(db_res,0,2),"%d",&lang); - sscanf(PQgetvalue(db_res,0,3),"%d",&result); - PQclear(db_res); - center_manage_closedb(db_conn); - - if((pro_it = center_manage_promap.find(proid)) == center_manage_promap.end()){ - return -1; - } - pro_info = pro_it->second; - - if((lang & pro_info->lang_flag) == 0){ - return -1; - } - jmod_info = pro_info->jmod_info; - - if(result == JUDGE_WAIT){ - rejudge_flag = false; - }else{ - rejudge_flag = true; - } - - center_manage_getpro(pro_info); - - sub_info = new manage_submit_info(subid,uid,jmod_info,pro_info,lang,rejudge_flag,param); - manage_submap.insert(std::pair<int,manage_submit_info*>(sub_info->subid,sub_info)); - manage_tp->add(manage_submit_thfn,sub_info,manage_submit_cbfn,sub_info); - - return 0; -} -static void manage_submit_th(void *data){ - manage_submit_info *sub_info; - char dir_path[PATH_MAX + 1]; - char pack_path[PATH_MAX + 1]; - - sub_info = (manage_submit_info*)data; - - snprintf(dir_path,sizeof(dir_path),"submit/%d/%d/data",(sub_info->subid / 1000) * 1000,sub_info->subid); - snprintf(pack_path,sizeof(pack_path),"tmp/codepack/%d.tar.bz2",sub_info->subid); - tool_pack(pack_path,dir_path); -} -static void manage_submit_cb(void *data){ - manage_submit_info *sub_info; - center_jmod_info *jmod_info; - center_pro_info *pro_info; - - char cwd_path[PATH_MAX + 1]; - char tpath[PATH_MAX + 1]; - judgm_manage_info *mg_info; - judgm_manage_submit_fn mg_sub_fn; - FILE *set_file; - char lchr; - char tchr; - - try{ - sub_info = (manage_submit_info*)data; - jmod_info = sub_info->jmod_info; - pro_info = sub_info->pro_info; - - if(jmod_info->manage_dll == NULL){ - getcwd(cwd_path,sizeof(cwd_path)); - snprintf(tpath,sizeof(tpath),"%s/jmod/%s/%s_manage.so",cwd_path,jmod_info->name,jmod_info->name); - - jmod_info->manage_dll = dlopen(tpath,RTLD_NOW); - jmod_info->manage_sub_fn = dlsym(jmod_info->manage_dll,"submit"); - jmod_info->manage_res_fn = dlsym(jmod_info->manage_dll,"result"); - } - mg_sub_fn = (judgm_manage_submit_fn)jmod_info->manage_sub_fn; - - mg_info = sub_info->manage_info; - snprintf(mg_info->pro_path,sizeof(mg_info->pro_path),"tmp/pro/%d_%d",pro_info->proid,pro_info->cacheid); - snprintf(mg_info->res_path,sizeof(mg_info->res_path),"submit/%d/%d/result",(sub_info->subid / 1000) * 1000,sub_info->subid); - - snprintf(tpath,sizeof(tpath),"tmp/pro/%d_%d/setting",pro_info->proid,pro_info->cacheid); - if((set_file = fopen(tpath,"r")) == NULL){ - throw 0; - } - lchr = '\n'; - while((tchr = fgetc(set_file)) != EOF){ - if(lchr == '\n' && tchr == '='){ - while(fgetc(set_file) != '\n'); - break; - } - lchr = tchr; - } - - mg_sub_fn(mg_info,set_file); - - fclose(set_file); - }catch(...){ - manage_finish_result(sub_info->subid, - sub_info->uid, - sub_info->pro_info->proid, - JUDGE_ERR, - 0, - 0, - 0, - sub_info->rejudge_flag); - } -} -DLL_PUBLIC int center_manage_queuesubmit(int subid,int proid,int lang,char *set_data,size_t set_len){ - center_judge_submit(subid,proid,lang,set_data,set_len); - return 0; -} - -int center_manage_result(int subid,char *res_data){ - std::map<int,manage_submit_info*>::iterator sub_it; - manage_submit_info *sub_info; - center_jmod_info *jmod_info; - - char res_path[PATH_MAX + 1]; - judgm_manage_info *mg_info; - judgm_manage_result_fn mg_res_fn; - - if((sub_it = manage_submap.find(subid)) == manage_submap.end()){ - return -1; - } - sub_info = sub_it->second; - jmod_info = sub_info->jmod_info; - mg_info = sub_info->manage_info; - - mg_res_fn = (judgm_manage_result_fn)jmod_info->manage_res_fn; - if(mg_res_fn(mg_info,res_data)){ - manage_submap.erase(sub_it); - - manage_finish_result(subid, - sub_info->uid, - sub_info->pro_info->proid, - mg_info->result, - mg_info->score, - mg_info->runtime, - mg_info->memory, - sub_info->rejudge_flag); - - center_manage_putpro(sub_info->pro_info); - delete sub_info; - }else{ - return -1; - } - - return 0; -} -static int manage_finish_result(int subid,int uid,int proid,int result,double score,int runtime,int memory,bool rejudge_flag){ - PGconn *db_conn; - PGresult *db_res; - char db_result[32]; - char db_score[32]; - char db_runtime[32]; - char db_memory[32]; - char db_subid[32]; - char *db_param[5]; - - if((db_conn = center_manage_conndb()) == NULL){ - return -1; - } - - snprintf(db_result,sizeof(db_result),"%d",result); - snprintf(db_score,sizeof(db_score),"%lf",score); - snprintf(db_runtime,sizeof(db_runtime),"%lu",runtime); - snprintf(db_memory,sizeof(db_memory),"%lu",memory / 1024UL); - snprintf(db_subid,sizeof(db_subid),"%d",subid); - db_param[0] = db_result; - db_param[1] = db_score; - db_param[2] = db_runtime; - db_param[3] = db_memory; - db_param[4] = db_subid; - db_res = PQexecParams(db_conn, - "UPDATE \"submit\" SET \"result\"=$1,\"score\"=$2,\"runtime\"=$3,\"memory\"=$4 WHERE \"subid\"=$5;", - 5, - NULL, - db_param, - NULL, - NULL, - 0); - PQclear(db_res); - center_manage_closedb(db_conn); - - manage_notice(subid, - uid, - proid, - result, - score, - runtime, - memory, - rejudge_flag); - - return 0; -} -static int manage_notice(int subid,int uid,int proid,int result,double score,int runtime,int memory,bool rejudge_flag){ - char msg[4096]; - json_object *jso_msg; - json_object *jso_arg; - - jso_msg = json_object_new_object(); - json_object_object_add(jso_msg,"type",json_object_new_string("result")); - json_object_object_add(jso_msg,"subid",json_object_new_int(subid)); - json_object_object_add(jso_msg,"proid",json_object_new_int(proid)); - json_object_object_add(jso_msg,"result",json_object_new_int(result)); - json_object_object_add(jso_msg,"score",json_object_new_double(score)); - json_object_object_add(jso_msg,"runtime",json_object_new_int(runtime)); - json_object_object_add(jso_msg,"memory",json_object_new_int(memory / 1024UL)); - json_object_object_add(jso_msg,"rejudge_flag",json_object_new_boolean(rejudge_flag)); - - jso_arg = json_object_new_array(); - json_object_array_add(jso_arg,json_object_new_int(uid)); - json_object_array_add(jso_arg,jso_msg); - - event_exec("pzreadtest.php","center_result_event",json_object_get_string(jso_arg)); - json_object_put(jso_arg); - - return 0; -} - - -center_pro_info* center_manage_getprobyid(int proid){ - std::map<int,center_pro_info*>::iterator pro_it; - center_pro_info *pro_info; - - if((pro_it = center_manage_promap.find(proid)) == center_manage_promap.end()){ - return NULL; - } - pro_info = pro_it->second; - - if(center_manage_getpro(pro_info)){ - return NULL; - } - - return pro_info; -} -int center_manage_getpro(center_pro_info *pro_info){ - pro_info->ref_count++; - return 0; -} -int center_manage_putpro(center_pro_info *pro_info){ - char tpath[PATH_MAX + 1]; - - pro_info->ref_count--; - if(pro_info->ref_count == 0){ - snprintf(tpath,sizeof(tpath),"tmp/pro/%d_%d",pro_info->proid,pro_info->cacheid); - tool_cleardir(tpath); - rmdir(tpath); - - snprintf(tpath,sizeof(tpath),"tmp/propack/%d_%d.tar.bz2",pro_info->proid,pro_info->cacheid); - unlink(tpath); - - delete pro_info; - } - return 0; -} -static int manage_updatepro(int proid,int cacheid,center_jmod_info *jmod_info,int lang_flag){ - std::map<int,center_pro_info*>::iterator pro_it; - center_pro_info *old_pro_info; - center_pro_info *update_pro_info; - - char tpath[PATH_MAX + 1]; - struct stat st; - std::pair<std::map<int,center_pro_info*>::iterator,bool> ins_ret; - - if((pro_it = center_manage_promap.find(proid)) == center_manage_promap.end()){ - old_pro_info = NULL; - }else{ - old_pro_info = pro_it->second; - - if(old_pro_info->state == CENTER_CACHESTATE_READY && cacheid == old_pro_info->cacheid){ - return 1; - } - if(old_pro_info->state == CENTER_CACHESTATE_UPDATE && (cacheid <= old_pro_info->cacheid || cacheid <= old_pro_info->update_cacheid)){ - return -1; - } - - old_pro_info->state = CENTER_CACHESTATE_UPDATE; - old_pro_info->update_cacheid = cacheid; - } - - update_pro_info = new center_pro_info(proid,cacheid,jmod_info,lang_flag); //set cacheid 0 to new pro - center_manage_getpro(update_pro_info); - - snprintf(tpath,sizeof(tpath),"tmp/pro/%d_%d",update_pro_info->proid,update_pro_info->cacheid); - if(!stat(tpath,&st)){ - snprintf(tpath,sizeof(tpath),"tmp/propack/%d_%d.tar.bz2",update_pro_info->proid,update_pro_info->cacheid); - if(!stat(tpath,&st)){ - - if(old_pro_info != NULL){ - center_manage_putpro(old_pro_info); - } - - ins_ret = center_manage_promap.insert(std::make_pair(update_pro_info->proid,update_pro_info)); - if(ins_ret.second == false){ - ins_ret.first->second = update_pro_info; - } - - return 1; - } - } - - manage_tp->add(manage_updatepro_thfn,update_pro_info,manage_updatepro_cbfn,update_pro_info); - - return 0; -} -static void manage_updatepro_th(void *data){ - center_pro_info *pro_info; - char src_path[PATH_MAX + 1]; - char dir_path[PATH_MAX + 1]; - char pack_path[PATH_MAX + 1]; - - pro_info = (center_pro_info*)data; - - snprintf(src_path,sizeof(src_path),"pro/%d",pro_info->proid); - snprintf(dir_path,sizeof(dir_path),"tmp/pro/%d_%d",pro_info->proid,pro_info->cacheid); - tool_copydir(src_path,dir_path); - - snprintf(pack_path,sizeof(pack_path),"tmp/propack/%d_%d.tar.bz2",pro_info->proid,pro_info->cacheid); - tool_pack(pack_path,dir_path); -} -static void manage_updatepro_cb(void *data){ - center_pro_info *old_pro_info; - center_pro_info *update_pro_info; - std::pair<std::map<int,center_pro_info*>::iterator,bool> ins_ret; - std::vector<std::pair<int,int> > pro_pair; - - update_pro_info = (center_pro_info*)data; - - ins_ret = center_manage_promap.insert(std::make_pair(update_pro_info->proid,update_pro_info)); - if(ins_ret.second == false){ - old_pro_info = ins_ret.first->second; - - if(update_pro_info->cacheid <= old_pro_info->cacheid){ - center_manage_putpro(update_pro_info); - return; - } - - center_manage_putpro(ins_ret.first->second); - ins_ret.first->second = update_pro_info; - } - - pro_pair.push_back(std::make_pair(update_pro_info->proid,update_pro_info->cacheid)); - center_judge_updatepro(pro_pair); -} - -center_jmod_info* center_manage_getjmodbyname(char *name){ - std::map<std::string,center_jmod_info*>::iterator jmod_it; - center_jmod_info *jmod_info; - - if((jmod_it = center_manage_jmodmap.find(name)) == center_manage_jmodmap.end()){ - return NULL; - } - jmod_info = jmod_it->second; - - if(center_manage_getjmod(jmod_info)){ - return NULL; - } - - return jmod_info; -} -int center_manage_getjmod(center_jmod_info *jmod_info){ - jmod_info->ref_count++; - return 0; -} -int center_manage_putjmod(center_jmod_info *jmod_info){ - char tpath[PATH_MAX + 1]; - - jmod_info->ref_count--; - if(jmod_info->ref_count == 0){ - snprintf(tpath,sizeof(tpath),"tmp/jmod/%s_%d",jmod_info->name,jmod_info->cacheid); - tool_cleardir(tpath); - rmdir(tpath); - - snprintf(tpath,sizeof(tpath),"tmp/jmodpack/%s_%d.tar.bz2",jmod_info->name,jmod_info->cacheid); - unlink(tpath); - - delete jmod_info; - } - return 0; -} -static int manage_updatejmod(char *name,int cacheid){ - std::map<std::string,center_jmod_info*>::iterator jmod_it; - center_jmod_info *old_jmod_info; - center_jmod_info *update_jmod_info; - - char tpath[PATH_MAX + 1]; - struct stat st; - std::pair<std::map<std::string,center_jmod_info*>::iterator,bool> ins_ret; - - if((jmod_it = center_manage_jmodmap.find(name)) == center_manage_jmodmap.end()){ - old_jmod_info = NULL; - }else{ - old_jmod_info = jmod_it->second; - - if(old_jmod_info->state == CENTER_CACHESTATE_READY && cacheid == old_jmod_info->cacheid){ - return -1; - } - if(old_jmod_info->state == CENTER_CACHESTATE_UPDATE && (cacheid <= old_jmod_info->cacheid || cacheid <= old_jmod_info->update_cacheid)){ - return -1; - } - - old_jmod_info->state = CENTER_CACHESTATE_UPDATE; - old_jmod_info->update_cacheid = cacheid; - } - - update_jmod_info = new center_jmod_info(name,cacheid); - center_manage_getjmod(update_jmod_info); - - snprintf(tpath,sizeof(tpath),"tmp/jmod/%s_%d",update_jmod_info->name,update_jmod_info->cacheid); - if(!stat(tpath,&st)){ - snprintf(tpath,sizeof(tpath),"tmp/jmodpack/%s_%d.tar.bz2",update_jmod_info->name,update_jmod_info->cacheid); - if(!stat(tpath,&st)){ - - if(old_jmod_info != NULL){ - center_manage_putjmod(old_jmod_info); - - ins_ret = center_manage_jmodmap.insert(std::make_pair(update_jmod_info->name,update_jmod_info)); - if(ins_ret.second == false){ - ins_ret.first->second = update_jmod_info; - } - - return 1; - } - } - } - - manage_tp->add(manage_updatejmod_thfn,update_jmod_info,manage_updatejmod_cbfn,update_jmod_info); - - return 0; -} -static void manage_updatejmod_th(void *data){ - center_jmod_info *jmod_info; - char src_path[PATH_MAX + 1]; - char dir_path[PATH_MAX + 1]; - char pack_path[PATH_MAX + 1]; - - jmod_info = (center_jmod_info*)data; - - snprintf(src_path,sizeof(src_path),"jmod/%s",jmod_info->name); - snprintf(dir_path,sizeof(dir_path),"tmp/jmod/%s_%d.tar.bz2",jmod_info->name,jmod_info->cacheid); - tool_copydir(src_path,dir_path); - - snprintf(pack_path,sizeof(pack_path),"tmp/jmodpack/%s_%d.tar.bz2",jmod_info->name,jmod_info->cacheid); - tool_pack(pack_path,dir_path); -} -static void manage_updatejmod_cb(void *data){ - center_jmod_info *old_jmod_info; - center_jmod_info *update_jmod_info; - std::pair<std::map<std::string,center_jmod_info*>::iterator,bool> ins_ret; - std::vector<std::pair<std::string,int> > jmod_pair; - - update_jmod_info = (center_jmod_info*)data; - - ins_ret = center_manage_jmodmap.insert(std::make_pair(update_jmod_info->name,update_jmod_info)); - if(ins_ret.second == false){ - old_jmod_info = ins_ret.first->second; - - if(update_jmod_info->cacheid <= old_jmod_info->cacheid){ - center_manage_putjmod(update_jmod_info); - } - - center_manage_putjmod(old_jmod_info); - ins_ret.first->second = update_jmod_info; - } - - jmod_pair.push_back(std::make_pair(update_jmod_info->name,update_jmod_info->cacheid)); - //wait - - // -} diff --git a/toj/center/src/center_manage.h b/toj/center/src/center_manage.h deleted file mode 100755 index b2ee36e..0000000 --- a/toj/center/src/center_manage.h +++ /dev/null @@ -1,75 +0,0 @@ -class manage_submit_info{ -public: - int subid; - int uid; - center_jmod_info *jmod_info; - center_pro_info *pro_info; - int lang; - bool rejudge_flag; - char param[JUDGE_SUB_PARAMMAX]; - judgm_manage_info *manage_info; - - manage_submit_info(int subid,int uid,center_jmod_info *jmod_info,center_pro_info *pro_info,int lang,bool rejudge_flag,char *param){ - this->subid = subid; - this->uid = uid; - this->jmod_info = jmod_info; - this->pro_info = pro_info; - this->lang = lang; - this->rejudge_flag = rejudge_flag; - this->param[0] = '\0'; - strncat(this->param,param,sizeof(this->param)); - - this->manage_info = new judgm_manage_info(this->subid,this->uid,pro_info->proid,this->lang,this->param); - } - ~manage_submit_info(){ - delete this->manage_info; - } -}; - -static void manage_submit_th(void *data); -static void manage_submit_cb(void *data); -static int manage_finish_result(int subid,int uid,int proid,int result,double score,int runtime,int memory,bool rejudge_flag); -static int manage_notice(int subid,int uid,int proid,int result,double score,int runtime,int memory,bool rejudge_flag); - -static int manage_updatepro(int proid,int cacheid,center_jmod_info *jmod_info,int lang_flag); -static void manage_updatepro_th(void *data); -static void manage_updatepro_cb(void *data); -static int manage_updatejmod(char *name,int cacheid); -static void manage_updatejmod_th(void *data); -static void manage_updatejmod_cb(void *data); - -static tpool *manage_tp; -static tpool_static_fn *manage_updatepro_thfn; -static tpool_static_fn *manage_updatepro_cbfn; -static tpool_static_fn *manage_updatejmod_thfn; -static tpool_static_fn *manage_updatejmod_cbfn; -static tpool_static_fn *manage_submit_thfn; -static tpool_static_fn *manage_submit_cbfn; -static std::map<int,manage_submit_info*> manage_submap; - -int center_manage_init(tpool **tpinfo); -PGconn* center_manage_conndb(); -int center_manage_closedb(PGconn *conn); -int center_manage_updatedata(); -int center_manage_submitwait(); -int center_manage_submit(int subid,char *param); -int center_manage_result(int subid,char *res_data); -DLL_PUBLIC int center_manage_queuesubmit(int subid,int proid,int lang,char *set_data,size_t set_len); - -center_pro_info* center_manage_getprobyid(int proid); -int center_manage_getpro(center_pro_info*); -int center_manage_putpro(center_pro_info *pro_info); -center_jmod_info* center_manage_getjmodbyname(char *name); -int center_manage_getjmod(center_jmod_info *jmod_info); -int center_manage_putjmod(center_jmod_info *jmod_info); - -std::map<int,center_pro_info*> center_manage_promap; -std::map<std::string,center_jmod_info*> center_manage_jmodmap; - -extern int tool_pack(char *pack_path,char *dir_path); -extern int tool_unpack(char *pack_path,char *dir_path); -extern int tool_cleardir(char *path); -extern int tool_copydir(char *old_path,char *new_path); - -extern int center_judge_submit(int subid,int proid,int lang,char *set_data,size_t set_len); -extern int center_judge_updatepro(std::vector<std::pair<int,int> > &pro_list); diff --git a/toj/center/src/center_server.cpp b/toj/center/src/center_server.cpp deleted file mode 100755 index 030e273..0000000 --- a/toj/center/src/center_server.cpp +++ /dev/null @@ -1,198 +0,0 @@ -#include<stdio.h> -#include<stdlib.h> -#include<string.h> -#include<unistd.h> -#include<signal.h> -#include<limits.h> -#include<errno.h> -#include<fcntl.h> -#include<pthread.h> -#include<semaphore.h> -#include<libpq-fe.h> -#include<sys/socket.h> -#include<sys/epoll.h> -#include<sys/eventfd.h> -#include<netinet/in.h> -#include<arpa/inet.h> -#include<libpq-fe.h> -#include<vector> -#include<queue> - -#include"tpool.h" -#include"center_server.h" - -server_epevdata::server_epevdata(int fd,int type,void *data){ - this->fd = fd; - this->type = type; - this->data = data; -} - - -server_web_conn::server_web_conn(int fd){ - this->fd = fd; - this->off = 0; - this->count = 0; -} -server_web_conn::~server_web_conn(){ - epoll_ctl(server_epfd,EPOLL_CTL_DEL,fd,NULL); - close(fd); -} -int server_web_conn::readio(){ - int ret; - char c; - int len; - int subid; - char *param; - - while((ret = read(fd,&c,1)) > 0){ - buf[off] = c; - off++; - if(c == '\0'){ - count++; - if(count == 2){ - break; - } - } - } - - if(count == 2){ - off = 0; - count = 0; - - sscanf(buf,"%d",&subid); - param = buf + strlen(buf) + 1; - printf("%d %s\n",subid,param); - - //test - if(subid == -1){ - center_manage_updatedata(); - }else{ - center_manage_submit(subid,param); - } - - //test - - write(fd,"S",2); - } - - return 0; -} - - -static int server_addepev(int fd,unsigned int flag,int type,void *data){ - server_epevdata *epevdata; - epoll_event epev; - - epevdata = new server_epevdata(fd,type,data); - epev.events = flag; - epev.data.ptr = epevdata; - epoll_ctl(server_epfd,EPOLL_CTL_ADD,fd,&epev); - - return 0; -} -static int server_delepev(server_epevdata *epevdata){ - epoll_ctl(server_epfd,EPOLL_CTL_DEL,epevdata->fd,NULL); - delete epevdata; - return 0; -} -int main(){ - int ret; - int i; - - int judge_sfd; - int web_sfd; - int cfd; - sockaddr_in saddr; - sockaddr_in caddr; - epoll_event epev; - epoll_event epevs[SERVER_EPOLL_MAXEVENT]; - int nevs; - - unsigned int ev_flag; - server_epevdata *epevdata; - server_web_conn *winfo; - tpool *tpinfo; - - signal(SIGPIPE,SIG_IGN); - server_epfd = epoll_create1(0); - center_manage_init(&tpinfo); - server_addepev(tpinfo->fd,EPOLLIN | EPOLLET,SERVER_EPEV_TPOOL,tpinfo); - center_judge_init(); - - judge_sfd = socket(AF_INET,SOCK_STREAM | SOCK_NONBLOCK,6); - saddr.sin_family = AF_INET; - saddr.sin_port = htons(SERVER_JUDGE_PORT); - //saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - //saddr.sin_addr.s_addr = htonl(INADDR_ANY); - saddr.sin_addr.s_addr = inet_addr("10.8.0.2"); - setsockopt(judge_sfd,SOL_SOCKET,SO_REUSEADDR,&saddr,sizeof(saddr)); - bind(judge_sfd,(sockaddr*)&saddr,sizeof(saddr)); - - server_addepev(judge_sfd,EPOLLIN | EPOLLET,SERVER_EPEV_JUDGESERVER,NULL); - listen(judge_sfd,4096); - - web_sfd = socket(AF_INET,SOCK_STREAM | SOCK_NONBLOCK,6); - saddr.sin_family = AF_INET; - saddr.sin_port = htons(SERVER_WEB_PORT); - saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - //saddr.sin_addr.s_addr = htonl(INADDR_ANY); - setsockopt(web_sfd,SOL_SOCKET,SO_REUSEADDR,&saddr,sizeof(saddr)); - bind(web_sfd,(sockaddr*)&saddr,sizeof(saddr)); - - server_addepev(web_sfd,EPOLLIN | EPOLLET,SERVER_EPEV_WEBSERVER,NULL); - listen(web_sfd,4096); - - while(true){ - nevs = epoll_wait(server_epfd,epevs,SERVER_EPOLL_MAXEVENT,-1); - for(i = 0;i < nevs;i++){ - ev_flag = epevs[i].events; - epevdata = (server_epevdata*)epevs[i].data.ptr; - - if(epevdata->type == SERVER_EPEV_JUDGESERVER){ - while(true){ - ret = 0; - if((cfd = accept4(epevdata->fd,(sockaddr*)&caddr,(socklen_t*)&ret,SOCK_NONBLOCK)) == -1){ - break; - } - - server_addepev(cfd,EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET,SERVER_EPEV_JUDGECLIENT,center_judge_addconn(cfd)); - } - }else if(epevdata->type == SERVER_EPEV_JUDGECLIENT){ - center_judge_dispatch(ev_flag,epevdata->data); - if(ev_flag & EPOLLRDHUP){ - server_delepev(epevdata); - } - }else if(epevdata->type == SERVER_EPEV_WEBSERVER){ - printf("test\n"); - while(true){ - ret = 0; - if((cfd = accept4(epevdata->fd,(sockaddr*)&caddr,(socklen_t*)&ret,SOCK_NONBLOCK)) == -1){ - break; - } - - server_addepev(cfd,EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET,SERVER_EPEV_WEBCLIENT,new server_web_conn(cfd)); - } - }else if(epevdata->type == SERVER_EPEV_WEBCLIENT){ - winfo = (server_web_conn*)epevdata->data; - if(ev_flag & EPOLLIN){ - winfo->readio(); - } - if(ev_flag & EPOLLRDHUP){ - delete winfo; - delete (server_epevdata*)epev.data.ptr; - } - }else if(epevdata->type == SERVER_EPEV_TPOOL){ - tpinfo = (tpool*)epevdata->data; - if(ev_flag & EPOLLIN){ - tpinfo->done(); - } - } - } - } - - close(judge_sfd); - close(server_epfd); - close(web_sfd); - - return 0; -} diff --git a/toj/center/src/center_server.h b/toj/center/src/center_server.h deleted file mode 100755 index 039e84b..0000000 --- a/toj/center/src/center_server.h +++ /dev/null @@ -1,45 +0,0 @@ -#define SERVER_JUDGE_PORT 2573 -#define SERVER_WEB_PORT 2501 -#define SERVER_EPOLL_MAXEVENT 4096 - -#define SERVER_EPEV_JUDGESERVER 0 -#define SERVER_EPEV_JUDGECLIENT 1 -#define SERVER_EPEV_WEBSERVER 2 -#define SERVER_EPEV_WEBCLIENT 3 -#define SERVER_EPEV_TPOOL 4 -class server_epevdata{ -public: - int fd; - int type; - void *data; - - server_epevdata(int fd,int type,void *data); -}; - -class server_web_conn{ -private: - int fd; - char buf[65536]; - int off; - int count; - -public: - server_web_conn(int fd); - ~server_web_conn(); - int readio(); -}; - -static int server_addepev(int fd,unsigned int flag,int type,void *data); -static int server_delepev(server_epevdata *epevdata); -static int server_epfd; - -extern int center_manage_init(tpool **tpinfo); -extern int center_manage_updatedata(); -extern int center_manage_submit(int subid,char *param); - -extern int center_judge_init(); -extern void* center_judge_addconn(int fd); -extern int center_judge_dispatch(int ev_flag,void *data); - -extern int pack_pack(char *pack_path,char *dir_path); -extern int pack_unpack(char *pack_path,char *target_path); diff --git a/toj/center/src/hyperio/Makefile b/toj/center/src/hyperio/Makefile deleted file mode 100755 index 655e473..0000000 --- a/toj/center/src/hyperio/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -ifneq ($(KERNELRELEASE),) - hyperio-objs := hyperio_mod.o judgk_hyperio.o - obj-m := hyperio.o -else - KERNEL_SOURCE := /usr/lib/modules/$(shell uname -r)/build - PWD := $(shell pwd) -default: - ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules - - g++ -O2 test.cpp -o test -clean: - ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean -endif diff --git a/toj/center/src/hyperio/hyperio_mod.c b/toj/center/src/hyperio/hyperio_mod.c deleted file mode 100755 index a188b14..0000000 --- a/toj/center/src/hyperio/hyperio_mod.c +++ /dev/null @@ -1,58 +0,0 @@ -#include<linux/module.h> -#include<linux/kernel.h> -#include<linux/kdev_t.h> -#include<linux/device.h> -#include<linux/cdev.h> -#include<linux/fs.h> - -#include"../judgk.h" -#include"../judgk_com.h" -#include"hyperio_mod.h" - -static int __init mod_init(){ - alloc_chrdev_region(&mod_dev,0,1,"hyperio"); - mod_class = class_create(THIS_MODULE,"chardev"); - device_create(mod_class,NULL,mod_dev,NULL,"hyperio"); - cdev_init(&mod_cdev,&mod_fops); - cdev_add(&mod_cdev,mod_dev,1); - - judgk_hyperio_init(); - - pr_alert("hyperio:Init\n"); - return 0; -} -static void __exit mod_exit(){ - judgk_hyperio_exit(); - - cdev_del(&mod_cdev); - device_destroy(mod_class,mod_dev); - class_destroy(mod_class); - unregister_chrdev_region(mod_dev,1); - - pr_alert("hyperio:Exit\n"); -} -module_init(mod_init); -module_exit(mod_exit); -MODULE_LICENSE("Dual BSD/GPL"); - -static long mod_ioctl(struct file *filp,unsigned int cmd,unsigned long arg){ - long ret; - - ret = 0; - switch(cmd){ - case IOCTL_HYPERIO_ADD: - ret = judgk_hyperio_add(filp); - break; - case IOCTL_HYPERIO_READ: - ret = judgk_hyperio_read(filp,arg); - break; - case IOCTL_HYPERIO_WRITE: - ret = judgk_hyperio_write(filp,arg); - break; - case IOCTL_HYPERIO_DEL: - ret = judgk_hyperio_del(filp); - break; - } - - return ret; -} diff --git a/toj/center/src/hyperio/hyperio_mod.h b/toj/center/src/hyperio/hyperio_mod.h deleted file mode 100755 index 3d75b68..0000000 --- a/toj/center/src/hyperio/hyperio_mod.h +++ /dev/null @@ -1,21 +0,0 @@ -static int __init mod_init(void); -static void __exit mod_exit(void); - -static long mod_ioctl(struct file *filp,unsigned int cmd,unsigned long arg); - -static dev_t mod_dev; -static struct cdev mod_cdev; -static struct class *mod_class; -extern int judgk_hyperio_mmap(struct file *filp,struct vm_area_struct *vma); -static struct file_operations mod_fops = { - .owner = THIS_MODULE, - .unlocked_ioctl = mod_ioctl, - .mmap = judgk_hyperio_mmap -}; - -extern int judgk_hyperio_init(void); -extern int judgk_hyperio_exit(void); -extern int judgk_hyperio_add(struct file *filp); -extern int judgk_hyperio_read(struct file *filp,size_t len); -extern int judgk_hyperio_write(struct file *filp,size_t len); -extern int judgk_hyperio_del(struct file *filp); diff --git a/toj/center/src/hyperio/test.cpp b/toj/center/src/hyperio/test.cpp deleted file mode 100755 index 18e536b..0000000 --- a/toj/center/src/hyperio/test.cpp +++ /dev/null @@ -1,173 +0,0 @@ -#include<stdio.h> -#include<stdlib.h> -#include<string.h> -#include<unistd.h> -#include<fcntl.h> -#include<time.h> -#include<limits.h> -#include<math.h> -#include<termios.h> -#include<sys/ioctl.h> -#include<sys/types.h> -#include<sys/mman.h> -#include<sys/wait.h> - -#include"../judge_def.h" -#include"../judgm_lib.h" - -int fd; -/*char *rbuf; -off_t roff = 0; - -int judgm_hyperio_compare(char *buf,size_t len){ - int flag; - size_t remain; - off_t off; - size_t data_len; - size_t cmp_len; - - flag = 0; - remain = len; - off = 0; - data_len = 0; - cmp_len = 0; - while(remain > 0 && flag == 0){ - if(data_len == 0){ - if((data_len = ioctl(fd,IOCTL_READ,cmp_len)) <= 0){ - return -1; - } - } - if(remain < data_len){ - cmp_len = remain; - }else{ - cmp_len = data_len; - } - - if((roff + cmp_len) < BUF_SIZE){ - flag |= memcmp(rbuf + roff,buf + off,cmp_len); - roff += cmp_len; - }else{ - flag |= memcmp(rbuf + roff,buf + off,BUF_SIZE - roff); - flag |= memcmp(rbuf,buf + off + (BUF_SIZE - roff),(cmp_len + roff) - BUF_SIZE); - roff = (cmp_len + roff) - BUF_SIZE; - } - remain -= cmp_len; - off += cmp_len; - } - if(cmp_len > 0){ - ioctl(fd,IOCTL_READ,-(long)cmp_len); - } - - if(flag == 0){ - return 0; - }else{ - return -1; - } -}*/ - -int main(){ - int i,j; - char *buf; - int idx; - int pid; - char str[4096]; - int a,b; - int l; - - judgm_hyperio *hyperio; - - fd = open("/dev/judgk",O_RDWR); - hyperio = new judgm_hyperio(fd); - - printf("%d\n",hyperio->tty_idx); - - if((pid = fork()) == 0){ - int outfd; - - outfd = judgm_hyperio::get_ttyfd(0); - - //dup2(fd,0); - dup2(outfd,1); - - printf("Hello World\n"); - char *argv[] = {NULL,NULL}; - char *envp[] = {NULL}; - - execve("/srv/http/toj/center/judge/tmp/run/1/test",argv,envp); - exit(0); - } - - printf("%d\n",hyperio->compare("Hello World\n",12)); - - waitpid(pid,NULL,0); - - getchar(); - delete hyperio; - close(fd); - - /*flag = 0; - roff = 0; - woff = 0; - srand(23); - for(i = 0;i < 1000000;i++){ - a = rand() % 65536; - b = rand() % 65536; - - snprintf(str,sizeof(str),"%d %d\n",a,b); - l = strlen(str); - j = l; - len = 0; - while(j > 0){ - len = ioctl(fd,IOCTL_WRITE,len); - if(j < len){ - len = j; - } - - if((len + woff) < BUF_SIZE){ - memcpy(wbuf + woff,str + (l - j),len); - woff += len; - }else{ - memcpy(wbuf + woff,str + (l - j),BUF_SIZE - woff); - memcpy(wbuf,str + (l - j) + (BUF_SIZE - woff),(len + woff) - BUF_SIZE); - woff = (len + woff) - BUF_SIZE; - } - - j -= len; - } - ioctl(fd,IOCTL_WRITE,-len); - - snprintf(str,sizeof(str),"%d\n",a + b); - l = strlen(str); - j = l; - len = 0; - while(j > 0){ - len = ioctl(fd,IOCTL_READ,len); - if(len <= 0){ - flag = 1; - break; - } - if(j < len){ - len = j; - } - - if((roff + len) < BUF_SIZE){ - flag |= memcmp(rbuf + roff,str + (l - j),len); - roff += len; - }else{ - flag |= memcmp(rbuf + roff,str + (l - j),BUF_SIZE - roff); - flag |= memcmp(rbuf,str + (l - j) + (BUF_SIZE - roff),(len + roff) - BUF_SIZE); - roff = (len + roff) - BUF_SIZE; - } - - j -= len; - } - ioctl(fd,IOCTL_READ,-len); - - if(flag != 0){ - printf("WA\n"); - break; - } - }*/ - - return 0; -} diff --git a/toj/center/src/jmod_test.h b/toj/center/src/jmod_test.h deleted file mode 100755 index 844f5c8..0000000 --- a/toj/center/src/jmod_test.h +++ /dev/null @@ -1,17 +0,0 @@ -#define LINE_ERRMSG_MAXSIZE 4096 - -typedef int (*check_init_fn)(int judgk_modfd,char *data_path,char *run_path); -typedef int (*check_run_fn)(int &status,char *err_msg); -typedef int (*check_stop_fn)(); - -struct line_set_data{ - int id; -}; -struct line_result_data{ - int id; - int status; - double score; - unsigned long runtime; - unsigned long memory; - char err_msg[LINE_ERRMSG_MAXSIZE]; -}; diff --git a/toj/center/src/jmod_test_check.cpp b/toj/center/src/jmod_test_check.cpp deleted file mode 100755 index ae4d060..0000000 --- a/toj/center/src/jmod_test_check.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include<stdio.h> -#include<stdlib.h> -#include<string.h> -#include<limits.h> -#include<unistd.h> -#include<fcntl.h> -#include<errno.h> - -#include"judge_def.h" -#include"judgm_lib.h" -#include"jmod_test.h" -#include"jmod_test_check.h" - -static int ansfd; -static judgm_hyperio *hyperio; -static int tty_idx; - -int p[2]; - -DLL_PUBLIC int init(int judgk_modfd,char *datapath,char *runpath){ - char tpath[PATH_MAX + 1]; - char dstpath[PATH_MAX + 1]; - - pipe(p); - - snprintf(tpath,sizeof(tpath),"%s/in",datapath); - snprintf(dstpath,sizeof(dstpath),"%s/in",runpath); - if(link(tpath,dstpath)){ - return -1; - } - snprintf(tpath,sizeof(tpath),"%s/ans",datapath); - if((ansfd = open(tpath,O_RDONLY)) == -1){ - return -1; - } - - //hyperio = new judgm_hyperio(judgk_modfd); - //tty_idx = hyperio->tty_idx; - - return 0; -} -DLL_PUBLIC int run(int &status,char *err_msg){ - int ret; - - char *inbuf; - char *ansbuf; - - status = JUDGE_AC; - inbuf = new char[65536]; - ansbuf = new char[65536]; - - /*while((ret = read(ansfd,ansbuf,65536)) > 0){ - if(hyperio->compare(ansbuf,ret)){ - status = JUDGE_WA; - break; - } - } - if(status == JUDGE_AC && hyperio->wait() > 0){ - status = JUDGE_WA; - } - - delete inbuf; - delete ansbuf; - close(ansfd); - delete hyperio;*/ - - close(p[1]); - int c_read=-1,pre_status=status; - while((ret = read(p[0],inbuf,65536)) > 0){ - if((c_read=read(ansfd,ansbuf,ret)) != ret){ - status = JUDGE_WA; - break; - } - if(memcmp(ansbuf,inbuf,ret)){ - status = JUDGE_WA; - break; - } - } -// if(c_read - ret == 1 && ansbuf[c_read-1]=='\n'){ -// status = pre_status; -// } - - if(status == JUDGE_AC && ((c_read = read(ansfd,ansbuf,1)) > 1 || c_read == 1 && ansbuf[0]!='\n')){ - status = JUDGE_WA; - } - - return 0; -} -DLL_PUBLIC int proc(){ - int infd; - int outfd; - - if((infd = open("in",O_RDONLY)) == -1){ - return -1; - } - /*if((outfd = judgm_hyperio::get_ttyfd(tty_idx)) == -1){ - return -1; - }*/ - - close(p[0]); - outfd = p[1]; - dup2(infd,0); - dup2(outfd,1); - dup2(outfd,2); - - return 0; -} -DLL_PUBLIC int stop(){ - return 0; -} diff --git a/toj/center/src/jmod_test_check.h b/toj/center/src/jmod_test_check.h deleted file mode 100755 index 20a6286..0000000 --- a/toj/center/src/jmod_test_check.h +++ /dev/null @@ -1,4 +0,0 @@ -DLL_PUBLIC int init(int judgk_modfd,char *datapath,char *runpath); -DLL_PUBLIC int run(int &status,char *err_msg); -DLL_PUBLIC int proc(); -DLL_PUBLIC int stop(); diff --git a/toj/center/src/jmod_test_line.cpp b/toj/center/src/jmod_test_line.cpp deleted file mode 100755 index be1177c..0000000 --- a/toj/center/src/jmod_test_line.cpp +++ /dev/null @@ -1,190 +0,0 @@ -#include<stdio.h> -#include<stdlib.h> -#include<limits.h> -#include<dlfcn.h> -#include<pthread.h> -#include<json/json.h> - -#include"judge_def.h" -#include"judgm_lib.h" -#include"judgm_line.h" -#include"jmod_test.h" -#include"jmod_test_line.h" - -static int line_load_setfile(FILE *set_file,int id,int &timelimit,int &memlimit,double &score){ - int ret; - - json_object *jso; - char buf[JUDGE_SET_FILEMAX]; - - fread(buf,1,sizeof(buf),set_file); - jso = json_tokener_parse(buf); - - timelimit = json_object_get_int(json_object_object_get(jso,"timelimit")); - memlimit = json_object_get_int(json_object_object_get(jso,"memlimit")); - score = json_object_get_double(json_object_array_get_idx(json_object_object_get(jso,"score"),id - 1)); - - json_object_put(jso); - return 0; -} -static void line_sigaction(int sig_num,siginfo_t *sig_info,void *context){ - if(sig_info->si_pid == line_proc->pid && line_proc->status == JUDGE_RUN){ - if(!line_proc->proc_wait(false)){ - line_chk_stop_fn(); - } - } -} -static int line_sig_set(){ - struct sigaction sig; - - sig.sa_sigaction = line_sigaction; - sigemptyset(&sig.sa_mask); - sig.sa_flags = SA_SIGINFO | SA_RESTART; - if(sigaction(SIGCHLD,&sig,NULL)){ - return -1; - } - - return 0; -} -static int line_sig_restore(){ - struct sigaction sig; - - sig.sa_handler = SIG_DFL; - sigemptyset(&sig.sa_mask); - sig.sa_flags = 0; - if(sigaction(SIGCHLD,&sig,NULL)){ - return -1; - } - - return 0; -} -static int line_sig_block(){ - sigset_t mask; - - sigemptyset(&mask); - sigaddset(&mask,SIGCHLD); - if(pthread_sigmask(SIG_BLOCK,&mask,NULL)){ - return -1; - } - - return 0; -} -static int line_sig_unblock(){ - sigset_t mask; - - sigemptyset(&mask); - sigaddset(&mask,SIGCHLD); - if(pthread_sigmask(SIG_UNBLOCK,&mask,NULL)){ - return -1; - } - - return 0; -} -static int line_sig_wait(){ - sigset_t mask; - int num; - - sigfillset(&mask); - sigdelset(&mask,SIGKILL); - sigdelset(&mask,SIGTERM); - sigdelset(&mask,SIGINT); - sigdelset(&mask,SIGCHLD); - sigsuspend(&mask); - - return 0; -} -DLL_PUBLIC int run(judgm_line_info *info){ - int i; - - line_result_data *res_data; - - int set_timelimit; - int set_memlimit; - double set_score; - line_set_data *set_data; - - char main_path[PATH_MAX + 1]; - char exe_path[PATH_MAX + 1]; - - check_init_fn chk_init_fn; - check_run_fn chk_run_fn; - judgm_proc_check_fn chk_proc_fn; - - char data_path[PATH_MAX + 1]; - int chk_status; - - set_data = (line_set_data*)info->set_data; - - res_data = (line_result_data*)info->res_data; - info->res_len = sizeof(line_result_data); - - res_data->id = set_data->id; - res_data->status = JUDGE_ERR; - res_data->score = 0; - res_data->runtime = 0; - res_data->memory = 0; - res_data->err_msg[0] = '\0'; - - if(line_load_setfile(info->set_file,set_data->id,set_timelimit,set_memlimit,set_score)){ - return -1; - } - - snprintf(main_path,sizeof(main_path),"%s/main.cpp",info->code_path); - snprintf(exe_path,sizeof(exe_path),"%s/test",info->run_path); - if(judgm_compile(info->subid,main_path,exe_path,info->lang,false,res_data->err_msg,LINE_ERRMSG_MAXSIZE)){ - res_data->status = JUDGE_CE; - return -1; - } - - chk_init_fn = (check_init_fn)dlsym(info->check_dll,"init"); - chk_run_fn = (check_run_fn)dlsym(info->check_dll,"run"); - chk_proc_fn = (judgm_proc_check_fn)dlsym(info->check_dll,"proc"); - line_chk_stop_fn = (check_stop_fn)dlsym(info->check_dll,"stop"); - line_proc = new judgm_proc(info->judgk_modfd,info->run_path,exe_path,set_timelimit,(set_timelimit * 10 + 5000),set_memlimit,chk_proc_fn); - - snprintf(data_path,sizeof(data_path),"%s/private/%d",info->pro_path,set_data->id); - if(chk_init_fn(info->judgk_modfd,data_path,info->run_path)){ - delete line_proc; - return -1; - } - if(line_sig_set()){ - delete line_proc; - return -1; - } - - if(line_proc->proc_run()){ - delete line_proc; - return -1; - } - chk_run_fn(chk_status,res_data->err_msg); - - line_sig_block(); - if(line_proc->status == JUDGE_RUN){ - line_proc->proc_kill(); - line_sig_wait(); - } - line_sig_unblock(); - - printf("check status %d proc status %d\n",chk_status,line_proc->status); - - if(line_sig_restore()){ - delete line_proc; - return -1; - } - - if(line_proc->status != JUDGE_AC){ - res_data->status = line_proc->status; - }else{ - res_data->status = chk_status; - } - if(res_data->status == JUDGE_AC){ - res_data->score = set_score; - }else{ - res_data->score = 0; - } - res_data->runtime = line_proc->runtime; - res_data->memory = line_proc->memory; - - delete line_proc; - return 0; -} diff --git a/toj/center/src/jmod_test_line.h b/toj/center/src/jmod_test_line.h deleted file mode 100755 index c09a503..0000000 --- a/toj/center/src/jmod_test_line.h +++ /dev/null @@ -1,11 +0,0 @@ -static int line_load_setfile(FILE *set_file,int test_id,int &timelimit,int &memlimit,double &score); -static int line_sig_set(); -static int line_sig_restore(); -static int line_sig_block(); -static int line_sig_unblock(); -static int line_sig_wait(); - -static judgm_proc *line_proc; -static check_stop_fn line_chk_stop_fn; - -DLL_PUBLIC int run(judgm_line_info *info); diff --git a/toj/center/src/jmod_test_manage.cpp b/toj/center/src/jmod_test_manage.cpp deleted file mode 100755 index e77adc9..0000000 --- a/toj/center/src/jmod_test_manage.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include<stdio.h> -#include<stdlib.h> -#include<string.h> -#include<limits.h> -#include<dlfcn.h> -#include<json/json.h> - -#include"judge_def.h" -#include"judgm_lib.h" -#include"judgm_manage.h" -#include"jmod_test.h" -#include"jmod_test_manage.h" - -static void __attribute__ ((constructor)) manage_init(){ - manage_queuesubmit_fn = (judgm_manage_queuesubmit_fn)dlsym(dlopen(NULL,RTLD_NOW),"center_manage_queuesubmit"); -} -static int manage_load_setfile(FILE *set_file,int &count){ - int ret; - - json_object *jso; - char buf[JUDGE_SET_FILEMAX]; - - fread(buf,1,sizeof(buf),set_file); - jso = json_tokener_parse(buf); - - count = json_object_get_int(json_object_object_get(jso,"count")); - - json_object_put(jso); - return 0; -} - -DLL_PUBLIC int submit(judgm_manage_info *info,FILE *set_file){ - int i; - - int count; - manage_result_info *res_info; - line_set_data set_data; - - manage_load_setfile(set_file,count); - - res_info = new manage_result_info(count); - info->private_data = res_info; - - for(i = 0;i < count;i++){ - set_data.id = i + 1; - manage_queuesubmit_fn(info->subid,info->proid,info->lang,(char*)&set_data,sizeof(line_set_data)); - } - - return 0; -} -DLL_PUBLIC int result(judgm_manage_info *info,line_result_data *res_data){ - manage_result_info *res_info; - json_object *jso_item; - char tpath[PATH_MAX + 1]; - - res_info = (manage_result_info*)info->private_data; - res_info->count++; - - if(res_data->status > res_info->result){ - res_info->result = res_data->status; - } - res_info->totalscore += res_data->score; - res_info->totalruntime += res_data->runtime; - if(res_data->memory > res_info->maxmemory){ - res_info->maxmemory = res_data->memory; - } - - jso_item = json_object_new_object(); - json_object_object_add(jso_item,"status",json_object_new_int(res_data->status)); - json_object_object_add(jso_item,"score",json_object_new_double(res_data->score)); - json_object_object_add(jso_item,"runtime",json_object_new_int64(res_data->runtime)); - json_object_object_add(jso_item,"memory",json_object_new_int64(res_data->memory / 1024UL)); - if(strlen(res_data->err_msg) > 0){ - printf(" strlen %d\n",strlen(res_data->err_msg)); - json_object_object_add(jso_item,"errmsg",json_object_new_string(res_data->err_msg)); - } - json_object_array_put_idx(res_info->jso_resarray,res_data->id - 1,jso_item); - - printf("jmod count %d %d\n",res_info->count,res_info->allcount); - - if(res_info->count == res_info->allcount){ - snprintf(tpath,sizeof(tpath),"%s/result",info->res_path); - json_object_to_file_ext(tpath,res_info->jso_res,JSON_C_TO_STRING_PLAIN); - - info->result = res_info->result; - info->score = res_info->totalscore; - info->runtime = res_info->totalruntime; - info->memory = res_info->maxmemory; - - delete res_info; - return 1; - } - return 0; -} - - diff --git a/toj/center/src/jmod_test_manage.h b/toj/center/src/jmod_test_manage.h deleted file mode 100755 index b0244e3..0000000 --- a/toj/center/src/jmod_test_manage.h +++ /dev/null @@ -1,35 +0,0 @@ -class manage_result_info{ -public: - int allcount; - int count; - int result; - double totalscore; - unsigned long totalruntime; - unsigned long maxmemory; - json_object *jso_res; - json_object *jso_resarray; - - manage_result_info(int allcount){ - this->allcount = allcount; - this->count = 0; - this->result = JUDGE_AC; - this->totalscore = 0; - this->totalruntime = 0; - this->maxmemory = 0; - - this->jso_res = json_object_new_object(); - this->jso_resarray = json_object_new_array(); - json_object_object_add(this->jso_res,"result",this->jso_resarray); - } - ~manage_result_info(){ - json_object_put(jso_res); - } -}; - -DLL_PUBLIC int submit(judgm_manage_info *info,FILE *set_file); -DLL_PUBLIC int result(judgm_manage_info *info,line_result_data *res_data); - -static void __attribute__ ((constructor)) manage_init(); -static int manage_load_setfile(FILE *setfile,int &count); - -static judgm_manage_queuesubmit_fn manage_queuesubmit_fn; diff --git a/toj/center/src/judge.h b/toj/center/src/judge.h deleted file mode 100644 index 1b5a885..0000000 --- a/toj/center/src/judge.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef JUDGE_H -#define JUDGE_H - -#define JUDGE_THREAD_MAX 16 -#define JUDGE_THREAD_JUDGEMAX 2 - -#define JUDGE_CACHESTATE_READY 0 -#define JUDGE_CACHESTATE_UPDATE 1 - -class judge_pro_info{ -public: - int proid; - int cacheid; - int ref_count; - - int state; - int update_cacheid; - - judge_pro_info(int proid,int cacheid){ - this->proid = proid; - this->cacheid = cacheid; - this->ref_count = 0; - - this->state = JUDGE_CACHESTATE_READY; - this->update_cacheid = 0; - } -}; - -class judge_submit_info{ -public: - int subid; - judge_pro_info *pro_info; - int lang; - char *set_data; - int set_len; - - judge_submit_info(int subid,judge_pro_info *pro_info,int lang,char *set_data,int set_len){ - this->subid = subid; - this->pro_info = pro_info; - this->lang = lang; - this->set_data = new char[set_len]; - memcpy(this->set_data,set_data,set_len); - this->set_len = set_len; - } - ~judge_submit_info(){ - delete this->set_data; - } -}; - -#endif diff --git a/toj/center/src/judge_def.h b/toj/center/src/judge_def.h deleted file mode 100755 index f0722d0..0000000 --- a/toj/center/src/judge_def.h +++ /dev/null @@ -1,21 +0,0 @@ -#define JUDGE_AC 0 -#define JUDGE_WA 1 -#define JUDGE_TLE 2 -#define JUDGE_MLE 3 -#define JUDGE_RF 4 -#define JUDGE_RE 5 -#define JUDGE_CE 6 -#define JUDGE_ERR 7 -#define JUDGE_WAIT 100 -#define JUDGE_RUN 101 - -#define JUDGE_CPP 0x1 -#define JUDGE_JAVA 0x2 -#define JUDGE_PASCEL 0x4 - -#define JUDGE_SUB_PARAMMAX 4096 -#define JUDGE_SET_FILEMAX 65536 -#define JUDGE_SET_DATAMAX 4096 -#define JUDGE_RES_DATAMAX 65536 - -#define DLL_PUBLIC extern "C" __attribute__ ((visibility ("default"))) diff --git a/toj/center/src/judge_manage.cpp b/toj/center/src/judge_manage.cpp deleted file mode 100644 index 32181bc..0000000 --- a/toj/center/src/judge_manage.cpp +++ /dev/null @@ -1,371 +0,0 @@ -#include<stdio.h> -#include<stdlib.h> -#include<string.h> -#include<unistd.h> -#include<limits.h> -#include<dirent.h> -#include<dlfcn.h> -#include<sys/types.h> -#include<sys/stat.h> -#include<sys/mman.h> -#include<map> - -#include"tpool.h" -#include"judge_def.h" -#include"judge.h" -#include"judgm_line.h" -#include"judgm_lib.h" -#include"judge_manage.h" - -int judge_manage_init(){ - int i; - - manage_tp = new tpool(JUDGE_THREAD_MAX); - judge_server_addtpool(manage_tp); - manage_tp->start(); - - manage_judgk_modfd = open("/dev/judgk",O_RDWR); - for(i = 0;i < JUDGE_THREAD_JUDGEMAX;i++){ - manage_judgepool[i] = new manage_judgeth_info(i); - } - manage_updatepro_thfn = new tpool_static_fn(manage_updatepro_th); - manage_updatepro_cbfn = new tpool_static_fn(manage_updatepro_cb); - manage_unpackcode_thfn = new tpool_static_fn(manage_unpackcode_th); - manage_unpackcode_cbfn = new tpool_static_fn(manage_unpackcode_cb); - manage_judge_thfn = new tpool_static_fn(manage_judge_th); - manage_judge_cbfn = new tpool_static_fn(manage_judge_cb); - - judge_manage_updatedata(); - return 0; -} -int judge_manage_updatedata(){ - DIR *dirp; - char *buf; - dirent *entry; - int proid; - int cacheid; - judge_pro_info *pro_info; - - if((dirp = opendir("tmp/pro")) == NULL){ - return -1; - } - buf = new char[sizeof(dirent) + NAME_MAX + 1]; - - while(true){ - readdir_r(dirp,(dirent*)buf,&entry); - if(entry == NULL){ - break; - } - if(strcmp(entry->d_name,".") == 0 || strcmp(entry->d_name,"..") == 0){ - continue; - } - - if(entry->d_type == DT_DIR){ - sscanf(entry->d_name,"%d_%d",&proid,&cacheid); - pro_info = new judge_pro_info(proid,cacheid); - judge_manage_getpro(pro_info); - judge_manage_promap.insert(std::make_pair(proid,pro_info)); - } - } - - delete(buf); - closedir(dirp); - - return 0; -} - -judge_pro_info* judge_manage_getprobyid(int proid){ - std::map<int,judge_pro_info*>::iterator pro_it; - judge_pro_info *pro_info; - - if((pro_it = judge_manage_promap.find(proid)) == judge_manage_promap.end()){ - return NULL; - } - pro_info = pro_it->second; - - if(judge_manage_getpro(pro_info)){ - return NULL; - } - - return pro_info; -} -int judge_manage_getpro(judge_pro_info *pro_info){ - pro_info->ref_count++; - return 0; -} -int judge_manage_putpro(judge_pro_info *pro_info){ - std::map<int,judge_pro_info*> pro_it; - char tpath[PATH_MAX + 1]; - char src_path[PATH_MAX + 1]; - - pro_info->ref_count--; - if(pro_info->ref_count == 0){ - snprintf(tpath,sizeof(tpath),"tmp/pro/%d_%d",pro_info->proid,pro_info->cacheid); - tool_cleardir(tpath); - rmdir(tpath); - - delete pro_info; - } - return 0; -} -int judge_manage_updatepro(int proid,int cacheid,bool check_flag,judge_pro_info **update_pro_info){ //If check_flag = true, just check - int ret; - - std::map<int,judge_pro_info*>::iterator pro_it; - judge_pro_info *old_pro_info; - - if((pro_it = judge_manage_promap.find(proid)) == judge_manage_promap.end()){ - if(check_flag == true){ - return 0; - } - }else{ - old_pro_info = pro_it->second; - - if(old_pro_info->state == JUDGE_CACHESTATE_READY && cacheid == old_pro_info->cacheid){ - return 1; - } - if(old_pro_info->state == JUDGE_CACHESTATE_UPDATE && (cacheid <= old_pro_info->cacheid || cacheid <= old_pro_info->update_cacheid)){ - return -1; - } - - if(check_flag == true){ - return 0; - } - - old_pro_info->update_cacheid = cacheid; - old_pro_info->state = JUDGE_CACHESTATE_UPDATE; - } - - *update_pro_info = new judge_pro_info(proid,cacheid); - judge_manage_getpro(*update_pro_info); - - return 0; -} -int judge_manage_done_updatepro(judge_pro_info *pro_info){ - manage_tp->add(manage_updatepro_thfn,pro_info,manage_updatepro_cbfn,pro_info); - return 0; -} -static void manage_updatepro_th(void *data){ - judge_pro_info *pro_info; - int proid; - int cacheid; - char pack_path[PATH_MAX + 1]; - char dir_path[PATH_MAX + 1]; - char tpath[PATH_MAX + 1]; - FILE *f; - - pro_info = (judge_pro_info*)data; - - snprintf(pack_path,sizeof(pack_path),"tmp/propack/%d_%d.tar.bz2",pro_info->proid,pro_info->cacheid); - snprintf(dir_path,sizeof(dir_path),"tmp/pro/%d_%d",pro_info->proid,pro_info->cacheid); - mkdir(dir_path,0755); - tool_cleardir(dir_path); - tool_unpack(pack_path,dir_path); - //unlink(pack_path); - - snprintf(tpath,sizeof(tpath),"tmp/pro/%d_%d/cacheinfo",pro_info->proid,pro_info->cacheid); - f = fopen(tpath,"w"); - fprintf(f,"%d",pro_info->cacheid); - fclose(f); -} -static void manage_updatepro_cb(void *data){ - judge_pro_info *old_pro_info; - judge_pro_info *update_pro_info; - std::pair<std::map<int,judge_pro_info*>::iterator,bool> ins_ret; - std::vector<std::pair<int,int> > pro_list; - - update_pro_info = (judge_pro_info*)data; - - ins_ret = judge_manage_promap.insert(std::make_pair(update_pro_info->proid,update_pro_info)); - if(ins_ret.second == false){ - old_pro_info = ins_ret.first->second; - - if(update_pro_info->cacheid < old_pro_info->cacheid){ - judge_manage_putpro(update_pro_info); - return; - } - - judge_manage_putpro(ins_ret.first->second); - ins_ret.first->second = update_pro_info; - } - - pro_list.push_back(std::make_pair(update_pro_info->proid,update_pro_info->cacheid)); - judge_server_setpro(pro_list); -} - - -int judge_manage_submit(int subid,int proid,int lang,char *set_data,int set_len){ - judge_pro_info *pro_info; - judge_submit_info *sub_info; - - char tpath[PATH_MAX + 1]; - struct stat st; - - pro_info = judge_manage_getprobyid(proid); - sub_info = new judge_submit_info(subid,pro_info,lang,set_data,set_len); - - if(manage_submap.find(subid) == manage_submap.end()){ - snprintf(tpath,sizeof(tpath),"tmp/code/%d",subid); - if(!stat(tpath,&st)){ - manage_queuejudge(sub_info); - }else{ - judge_server_reqcode(subid); - manage_submap.insert(std::make_pair(subid,sub_info)); - } - }else{ - manage_submap.insert(std::make_pair(subid,sub_info)); - } - - return 0; -} -int judge_manage_done_code(int subid){ - manage_tp->add(manage_unpackcode_thfn,(void*)((long)subid),manage_unpackcode_cbfn,(void*)((long)subid)); - return 0; -} -static void manage_unpackcode_th(void *data){ - int subid; - char pack_path[PATH_MAX + 1]; - char dir_path[PATH_MAX + 1]; - char tpath[PATH_MAX + 1]; - FILE *f; - - subid = (int)((long)data); - - snprintf(pack_path,sizeof(pack_path),"tmp/codepack/%d.tar.bz2",subid); - snprintf(dir_path,sizeof(dir_path),"tmp/code/%d",subid); - mkdir(dir_path,0755); - tool_cleardir(dir_path); - tool_unpack(pack_path,dir_path); -} -static void manage_unpackcode_cb(void *data){ - int subid; - std::multimap<int,judge_submit_info*>::iterator sub_it; - judge_submit_info *sub_info; - - subid = (int)((long)data); - - while((sub_it = manage_submap.find(subid)) != manage_submap.end()){ - sub_info = sub_it->second; - manage_queuejudge(sub_info); - manage_submap.erase(sub_it); - } -} -static int manage_queuejudge(judge_submit_info *sub_info){ - int i; - - printf("queue judge %d %d\n",sub_info->subid,sub_info->pro_info->proid); - for(i = 0;i < 16;i++){ - if(manage_judgepool[i]->use_flag == false){ - manage_judgepool[i]->use_flag = true; - manage_judgepool[i]->sub_info = sub_info; - manage_tp->add(manage_judge_thfn,manage_judgepool[i],manage_judge_cbfn,manage_judgepool[i]); - break; - } - } - - return 0; -} -static void manage_judge_th(void *data){ - manage_judgeth_info *th_info; - judge_submit_info *sub_info; - judge_pro_info *pro_info; - char pro_path[PATH_MAX + 1]; - char code_path[PATH_MAX + 1]; - char *set_data; - - th_info = (manage_judgeth_info*)data; - sub_info = th_info->sub_info; - pro_info = sub_info->pro_info; - - snprintf(pro_path,sizeof(pro_path),"tmp/pro/%d_%d",pro_info->proid,pro_info->cacheid); - snprintf(code_path,sizeof(code_path),"tmp/code/%d",sub_info->subid); - manage_judge(sub_info->subid,pro_path,code_path,th_info->run_path,sub_info->lang,sub_info->set_data,th_info->res_data,th_info->res_len); -} -static void manage_judge_cb(void *data){ - manage_judgeth_info *th_info; - judge_submit_info *sub_info; - std::vector<std::pair<int,int> > pro_list; - - th_info = (manage_judgeth_info*)data; - sub_info = th_info->sub_info; - - judge_server_result(sub_info->subid,th_info->res_data,th_info->res_len); - judge_manage_putpro(sub_info->pro_info); - - th_info->use_flag = false; - th_info->sub_info = NULL; - delete sub_info; -} -static int manage_judge(int subid,char *pro_path,char *code_path,char *run_path,int lang,char *set_data,char *res_data,size_t &res_len){ - judgm_line_info *line_info; - int pid; - - char tpath[PATH_MAX + 1]; - FILE *set_file; - char cwd_path[PATH_MAX + 1]; - char jmod_name[NAME_MAX + 1]; - char line_path[PATH_MAX + 1]; - char check_name[NAME_MAX + 1]; - char check_path[PATH_MAX + 1]; - char lchr; - char tchr; - - void *line_dll; - void *check_dll; - judgm_line_run_fn run_fn; - - snprintf(tpath,sizeof(tpath),"%s/setting",pro_path); - set_file = fopen(tpath,"r"); - - getcwd(cwd_path,sizeof(cwd_path)); - fscanf(set_file,"%s",jmod_name); - snprintf(line_path,sizeof(line_path),"%s/tmp/jmod/%s/%s_line.so",cwd_path,jmod_name,jmod_name); - fscanf(set_file,"%s",check_name); - if(check_name[0] == '/'){ - snprintf(check_path,sizeof(check_path),"%s/%s/private%s.so",cwd_path,pro_path,check_name); - }else{ - snprintf(check_path,sizeof(check_path),"%s/tmp/jmod/%s/%s.so",cwd_path,jmod_name,check_name); - } - - lchr = '\n'; - while((tchr = fgetc(set_file)) != EOF){ - if(lchr == '\n' && tchr == '='){ - while(fgetc(set_file) != '\n'); - break; - } - lchr = tchr; - } - - line_dll = dlopen(line_path,RTLD_NOW); - check_dll = dlopen(check_path,RTLD_NOW); - - line_info = (judgm_line_info*)mmap(NULL,sizeof(struct judgm_line_info),PROT_READ | PROT_WRITE,MAP_SHARED | MAP_ANONYMOUS,-1,0); - line_info->subid = subid; - line_info->pro_path = pro_path; - line_info->code_path = code_path; - line_info->run_path = run_path; - - line_info->judgk_modfd = manage_judgk_modfd; - line_info->line_dll = line_dll; - line_info->check_dll = check_dll; - - line_info->lang = lang; - line_info->set_file = set_file; - line_info->set_data = set_data; - - tool_cleardir(line_info->run_path); - - run_fn = (judgm_line_run_fn)dlsym(line_dll,"run"); - if((pid = fork()) == 0){ - run_fn(line_info); - exit(0); - } - waitpid(pid,NULL,0); - - memcpy(res_data,line_info->res_data,line_info->res_len); - res_len = line_info->res_len; - - munmap(line_info,sizeof(judgm_line_info)); - fclose(set_file); - return 0; -} diff --git a/toj/center/src/judge_manage.h b/toj/center/src/judge_manage.h deleted file mode 100644 index 594ea71..0000000 --- a/toj/center/src/judge_manage.h +++ /dev/null @@ -1,60 +0,0 @@ -class manage_judgeth_info{ -public: - bool use_flag; - int thid; - char run_path[PATH_MAX + 1]; - judge_submit_info *sub_info; - char res_data[JUDGE_RES_DATAMAX]; - size_t res_len; - - manage_judgeth_info(int thid){ - this->use_flag = false; - this->thid = thid; - snprintf(this->run_path,sizeof(this->run_path),"tmp/run/%d",thid); - mkdir(this->run_path,0775); - this->sub_info = NULL; - this->res_len = 0; - } -}; - -static void manage_updatepro_th(void *data); -static void manage_updatepro_cb(void *data); -static void manage_unpackcode_th(void *data); -static void manage_unpackcode_cb(void *data); -static void manage_judge_th(void *data); -static void manage_judge_cb(void *data); -static int manage_queuejudge(judge_submit_info *sub_info); -static int manage_judge(int subid,char *pro_path,char *code_path,char *run_path,int lang,char *set_data,char *res_data,size_t &res_len); - -static tpool *manage_tp; -static int manage_judgk_modfd; -static manage_judgeth_info *manage_judgepool[16]; -static tpool_static_fn *manage_updatepro_thfn; -static tpool_static_fn *manage_updatepro_cbfn; -static tpool_static_fn *manage_unpackcode_thfn; -static tpool_static_fn *manage_unpackcode_cbfn; -static tpool_static_fn *manage_judge_thfn; -static tpool_static_fn *manage_judge_cbfn; -static std::multimap<int,judge_submit_info*> manage_submap; - -int judge_manage_init(); -int judge_manage_updatedata(); -judge_pro_info* judge_manage_getprobyid(int proid); -int judge_manage_getpro(judge_pro_info *pro_info); -int judge_manage_putpro(judge_pro_info *pro_info); -int judge_manage_updatepro(int proid,int cacheid,bool check_flag,judge_pro_info **update_pro_info); -int judge_manage_done_updatepro(judge_pro_info *pro_info); -int judge_manage_submit(int subid,int proid,int lang,char *set_data,int set_len); -int judge_manage_done_code(int subid); - -std::map<int,judge_pro_info*> judge_manage_promap; - -extern int tool_pack(char *pack_path,char *dir_path); -extern int tool_unpack(char *pack_path,char *dir_path); -extern int tool_cleardir(char *path); - -extern int judge_server_addtpool(tpool *tpinfo); -extern int judge_server_setpro(std::vector<std::pair<int,int> > &pro_list); -extern int judge_server_reqpro(int subid); -extern int judge_server_reqcode(int subid); -extern int judge_server_result(int subid,char *res_data,int res_len); diff --git a/toj/center/src/judge_server.cpp b/toj/center/src/judge_server.cpp deleted file mode 100755 index 66b4d01..0000000 --- a/toj/center/src/judge_server.cpp +++ /dev/null @@ -1,515 +0,0 @@ -#include<stdio.h> -#include<stdlib.h> -#include<string.h> -#include<unistd.h> -#include<fcntl.h> -#include<dlfcn.h> -#include<signal.h> -#include<limits.h> -#include<pthread.h> -#include<semaphore.h> -#include<errno.h> -#include<sys/types.h> -#include<sys/socket.h> -#include<sys/epoll.h> -#include<sys/eventfd.h> -#include<sys/sendfile.h> -#include<sys/mman.h> -#include<netinet/in.h> -#include<arpa/inet.h> -#include<map> -#include<queue> - -#include"netio.h" -#include"tpool.h" -#include"judge_def.h" -#include"judge.h" -#include"center_com.h" -#include"judgm_line.h" -#include"judgm_lib.h" -#include"judge_server.h" - -server_epevdata::server_epevdata(int fd,int type,void *data){ - this->fd = fd; - this->type = type; - this->data = data; -} - - -server_conn::server_conn(int fd):netio(fd){ - this->recv_dispatch_fn = new netio_iofn<server_conn>(this,&server_conn::recv_dispatch); - this->recv_setid_fn = new netio_iofn<server_conn>(this,&server_conn::recv_setid); - this->recv_submit_fn = new netio_iofn<server_conn>(this,&server_conn::recv_submit); - this->recv_setpro_fn = new netio_iofn<server_conn>(this,&server_conn::recv_setpro); - this->recv_sendpro_fn = new netio_iofn<server_conn>(this,&server_conn::recv_sendpro); - this->done_sendpro_fn = new netio_iofn<server_conn>(this,&server_conn::done_sendpro); - this->recv_setjmod_fn = new netio_iofn<server_conn>(this,&server_conn::recv_setjmod); - this->recv_sendjmod_fn = new netio_iofn<server_conn>(this,&server_conn::recv_sendjmod); - this->done_sendjmod_fn = new netio_iofn<server_conn>(this,&server_conn::done_sendjmod); - this->recv_sendcode_fn = new netio_iofn<server_conn>(this,&server_conn::recv_sendcode); - this->done_sendcode_fn = new netio_iofn<server_conn>(this,&server_conn::done_sendcode); - this->tp_unpackjmod_thfn = new tpool_fn<server_conn>(this,&server_conn::tp_unpackjmod_th); - this->tp_unpackjmod_cbfn = new tpool_fn<server_conn>(this,&server_conn::tp_unpackjmod_cb); - - send_setid(); -} -char* server_conn::create_combuf(int code,int size,int &len,void **data){ - char *buf; - center_com_header *header; - - buf = new char[sizeof(center_com_header) + size]; - header = (center_com_header*)buf; - header->code = code; - header->size = size; - len = sizeof(center_com_header) + size; - *data = (void*)(buf + sizeof(center_com_header)); - - return buf; -} -int server_conn::send_setid(){ - char *write_buf; - int write_len; - center_com_setid *setid; - - write_buf = create_combuf(CENTER_COMCODE_SETID,sizeof(center_com_setid),write_len,(void**)&setid); - setid->id = server_id; - writebytes(write_buf,write_len,NULL,NULL); - - return 0; -} -int server_conn::send_setinfo(){ - char *write_buf; - int write_len; - center_com_setinfo *setinfo; - - write_buf = create_combuf(CENTER_COMCODE_SETINFO,sizeof(center_com_setinfo),write_len,(void**)&setinfo); - setinfo->avail = server_avail; - writebytes(write_buf,write_len,NULL,NULL); - - return 0; -} -int server_conn::send_result(int subid,char *res_data,size_t res_len){ - char *write_buf; - int write_len; - center_com_result *result; - - if(res_len > JUDGE_RES_DATAMAX){ - return -1; - } - - write_buf = create_combuf(CENTER_COMCODE_RESULT,sizeof(center_com_result) + res_len,write_len,(void**)&result); - result->subid = subid; - memcpy((void*)(write_buf + sizeof(center_com_header) + sizeof(center_com_result)),res_data,res_len); - writebytes(write_buf,write_len,NULL,NULL); - - return 0; -} -int server_conn::send_reqpro(int proid,int cacheid){ - char *write_buf; - int write_len; - center_com_reqpro *reqpro; - - write_buf = create_combuf(CENTER_COMCODE_REQPRO,sizeof(center_com_reqpro),write_len,(void**)&reqpro); - reqpro->proid = proid; - reqpro->cacheid = cacheid; - writebytes(write_buf,write_len,NULL,NULL); -} -int server_conn::send_setpro(std::vector<std::pair<int,int> > &pro_list,int type){ - int i; - int count; - char *write_buf; - int write_len; - center_com_setpro *setpro; - judge_pro_info *pro_info; - - count = pro_list.size(); - write_buf = create_combuf(CENTER_COMCODE_SETPRO,sizeof(center_com_setpro) * count,write_len,(void**)&setpro); - - for(i = 0;i < count;i++){ - setpro[i].proid = pro_list[i].first; - setpro[i].cacheid = pro_list[i].second; - setpro[i].type = type; - } - writebytes(write_buf,write_len,NULL,NULL); - - return 0; -} -int server_conn::send_setjmod(char **jmod_name,int *cacheid,int type,int count){ - int i; - - char *write_buf; - int write_len; - center_com_setjmod *setjmod; - - write_buf = create_combuf(CENTER_COMCODE_SETJMOD,sizeof(center_com_setjmod) * count,write_len,(void**)&setjmod); - for(i = 0;i < count;i++){ - setjmod[i].jmod_name[0] = '\0'; - strncat(setjmod[i].jmod_name,jmod_name[i],sizeof(setjmod[i].jmod_name)); - setjmod[i].cacheid = cacheid[i]; - setjmod[i].type = type; - } - writebytes(write_buf,write_len,NULL,NULL); - - return 0; -} -int server_conn::send_reqcode(int subid){ - char *write_buf; - int write_len; - center_com_reqcode *reqcode; - - write_buf = create_combuf(CENTER_COMCODE_REQCODE,sizeof(center_com_reqcode),write_len,(void**)&reqcode); - reqcode->subid = subid; - writebytes(write_buf,write_len,NULL,NULL); - - return 0; -} -int server_conn::readidle(){ - readbytes(new center_com_header,sizeof(center_com_header),recv_dispatch_fn,NULL); - return 0; -} -void server_conn::recv_dispatch(void *buf,size_t len,void *data){ - center_com_header *header; - char *readbuf; - - header = (center_com_header*)buf; - readbuf = new char[header->size]; - printf("code:%d size:%d\n",header->code,header->size); - switch(header->code){ - case CENTER_COMCODE_SETID: - readbytes(readbuf,header->size,recv_setid_fn,NULL); - break; - case CENTER_COMCODE_SUBMIT: - readbytes(readbuf,header->size,recv_submit_fn,NULL); - break; - case CENTER_COMCODE_SETPRO: - readbytes(readbuf,header->size,recv_setpro_fn,NULL); - break; - case CENTER_COMCODE_SENDPRO: - readbytes(readbuf,header->size,recv_sendpro_fn,NULL); - break; - case CENTER_COMCODE_SETJMOD: - readbytes(readbuf,header->size,recv_setjmod_fn,NULL); - break; - case CENTER_COMCODE_SENDJMOD: - readbytes(readbuf,header->size,recv_sendjmod_fn,NULL); - break; - case CENTER_COMCODE_SENDCODE: - readbytes(readbuf,header->size,recv_sendcode_fn,NULL); - break; - } - - delete header; -} -void server_conn::recv_setid(void *buf,size_t len,void *data){ - center_com_setid *setid; - - setid = (center_com_setid*)buf; - server_id = setid->id; - printf("server_id:%d\n",server_id); - - //judge server init - send_setinfo(); - - delete setid; -} -void server_conn::recv_submit(void *buf,size_t len,void *data){ - center_com_submit *sub; - - sub = (center_com_submit*)buf; - judge_manage_submit(sub->subid,sub->proid,sub->lang,(char*)((char*)buf + sizeof(center_com_submit)),len - sizeof(center_com_submit)); - - delete sub; -} -void server_conn::recv_setpro(void *buf,size_t len,void *data){ - int ret; - int i; - int count; - center_com_setpro *setpro; - - char tpath[PATH_MAX + 1]; - FILE *f; - int cacheid; - std::vector<std::pair<int,int> > pro_list; - - count = len / sizeof(center_com_setpro); - setpro = (center_com_setpro*)buf; - for(i = 0;i < count;i++){ - if(setpro[i].type == 0){ - ret = judge_manage_updatepro(setpro[i].proid,setpro[i].cacheid,true,NULL); - if(ret == 0){ - if(server_fileconn == NULL){ - server_fileconn = server_connect(); - } - server_fileconn->send_reqpro(setpro[i].proid,setpro[i].cacheid); - }else if(ret == 1){ - pro_list.push_back(std::make_pair(setpro[i].proid,setpro[i].cacheid)); - } - }else if(setpro[i].type == 1){ - - } - } - - if(!pro_list.empty()){ - this->send_setpro(pro_list,0); - } - - delete setpro; -} -void server_conn::recv_sendpro(void *buf,size_t len,void *data){ - center_com_sendpro *sendpro; - judge_pro_info *pro_info; - char tpath[PATH_MAX + 1]; - int fd; - - sendpro = (center_com_sendpro*)buf; - - if(judge_manage_updatepro(sendpro->proid,sendpro->cacheid,false,&pro_info) == 0){ - snprintf(tpath,sizeof(tpath),"tmp/propack/%d_%d.tar.bz2",sendpro->proid,sendpro->cacheid); - fd = open(tpath,O_WRONLY | O_CREAT,0644); - readfile(fd,sendpro->filesize,done_sendpro_fn,pro_info); - } - - delete sendpro; -} -void server_conn::done_sendpro(void *buf,size_t len,void *data){ - judge_pro_info *pro_info; - - close(*(int*)buf); - - pro_info = (judge_pro_info*)data; - judge_manage_done_updatepro(pro_info); -} -void server_conn::recv_setjmod(void *buf,size_t len,void *data){ - int i; - int count; - center_com_setjmod *setjmod; - - char tpath[PATH_MAX + 1]; - FILE *f; - int cacheid; - std::vector<char*> sl_jmod_name; - std::vector<int> sl_cacheid; - - char *write_buf; - int write_len; - center_com_reqjmod *reqjmod; - - count = len / sizeof(center_com_setjmod); - setjmod = (center_com_setjmod*)buf; - for(i = 0;i < count;i++){ - if(setjmod[i].type == 0){ - snprintf(tpath,sizeof(tpath),"tmp/jmod/%s/cacheinfo",setjmod[i].jmod_name); - f = fopen(tpath,"r"); - if(f != NULL){ - fscanf(f,"%d",&cacheid); - fclose(f); - - if(cacheid == setjmod[i].cacheid){ - sl_jmod_name.push_back(setjmod[i].jmod_name); - sl_cacheid.push_back(setjmod[i].cacheid); - continue; - } - } - - if(server_fileconn == NULL){ - server_fileconn = server_connect(); - } - - write_buf = create_combuf(CENTER_COMCODE_REQJMOD,sizeof(center_com_reqjmod),write_len,(void**)&reqjmod); - reqjmod->jmod_name[0] = '\0'; - strncat(reqjmod->jmod_name,setjmod[i].jmod_name,sizeof(reqjmod->jmod_name)); - server_fileconn->writebytes(write_buf,write_len,NULL,NULL); - }else if(setjmod[i].type == 1){ - - } - } - - if(!sl_jmod_name.empty()){ - this->send_setjmod(&sl_jmod_name[0],&sl_cacheid[0],0,sl_jmod_name.size()); - } - - delete setjmod; -} -void server_conn::recv_sendjmod(void *buf,size_t len,void *data){ - center_com_sendjmod *sendjmod; - char tpath[PATH_MAX + 1]; - int fd; - - sendjmod = (center_com_sendjmod*)buf; - snprintf(tpath,sizeof(tpath),"tmp/jmodpack/%s.tar.bz2",sendjmod->jmod_name); - fd = open(tpath,O_WRONLY | O_CREAT,0644); - readfile(fd,sendjmod->filesize,done_sendjmod_fn,sendjmod); -} -void server_conn::done_sendjmod(void *buf,size_t len,void *data){ - center_com_sendjmod *sendjmod; - - close(*(int*)buf); - - sendjmod = (center_com_sendjmod*)data; - server_packtp->add(tp_unpackjmod_thfn,sendjmod,tp_unpackjmod_cbfn,sendjmod); -} -void server_conn::recv_sendcode(void *buf,size_t len,void *data){ - center_com_sendcode *sendcode; - char tpath[PATH_MAX + 1]; - int fd; - - sendcode = (center_com_sendcode*)buf; - snprintf(tpath,sizeof(tpath),"tmp/codepack/%d.tar.bz2",sendcode->subid); - fd = open(tpath,O_WRONLY | O_CREAT,0644); - readfile(fd,sendcode->filesize,done_sendcode_fn,sendcode); -} -void server_conn::done_sendcode(void *buf,size_t len,void *data){ - center_com_sendcode *sendcode; - - close(*(int*)buf); - - sendcode = (center_com_sendcode*)data; - judge_manage_done_code(sendcode->subid); - - delete sendcode; -} -void server_conn::tp_unpackjmod_th(void *data){ - center_com_sendjmod *sendjmod; - char pack_path[PATH_MAX + 1]; - char dir_path[PATH_MAX + 1]; - char tpath[PATH_MAX + 1]; - FILE *f; - - sendjmod = (center_com_sendjmod*)data; - - snprintf(pack_path,sizeof(pack_path),"tmp/jmodpack/%s.tar.bz2",sendjmod->jmod_name); - snprintf(dir_path,sizeof(dir_path),"tmp/jmod/%s",sendjmod->jmod_name); - mkdir(dir_path,0755); - tool_cleardir(dir_path); - tool_unpack(pack_path,dir_path); - - snprintf(tpath,sizeof(tpath),"tmp/jmod/%s/cacheinfo",sendjmod->jmod_name); - f = fopen(tpath,"w"); - fprintf(f,"%d",sendjmod->cacheid); - fclose(f); -} -void server_conn::tp_unpackjmod_cb(void *data){ - center_com_sendjmod *sendjmod; - char *jmod_name; - - sendjmod = (center_com_sendjmod*)data; - jmod_name = sendjmod->jmod_name; - send_setjmod(&jmod_name,&sendjmod->cacheid,0,1); - - delete sendjmod; -} - - - -int judge_server_addtpool(tpool *tpinfo){ - server_addepev(tpinfo->fd,EPOLLIN | EPOLLET,SERVER_EPEV_TPOOL,tpinfo); - return 0; -} -int judge_server_setpro(std::vector<std::pair<int,int> > &pro_list){ - server_mainconn->send_setpro(pro_list,0); - return 0; -} -int judge_server_reqcode(int subid){ - if(server_codeconn == NULL){ - server_codeconn = server_connect(); - } - server_codeconn->send_reqcode(subid); - - return 0; -} -int judge_server_result(int subid,char *res_data,int res_len){ - server_mainconn->send_result(subid,res_data,res_len); - return 0; -} - -static int server_addepev(int fd,unsigned int flag,int type,void *data){ - server_epevdata *epevdata; - epoll_event epev; - - epevdata = new server_epevdata(fd,type,data); - epev.events = flag; - epev.data.ptr = epevdata; - epoll_ctl(server_epfd,EPOLL_CTL_ADD,fd,&epev); - - return 0; -} -static int server_delepev(server_epevdata *epevdata){ - epoll_ctl(server_epfd,EPOLL_CTL_DEL,epevdata->fd,NULL); - delete epevdata; - return 0; -} -static server_conn* server_connect(){ - int cfd; - sockaddr_in caddr; - epoll_event epev; - server_conn *cinfo; - - cfd = socket(AF_INET,SOCK_STREAM | SOCK_NONBLOCK,6); - caddr.sin_family = AF_INET; - caddr.sin_port = htons(SERVER_JUDGE_PORT); - //caddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - caddr.sin_addr.s_addr = inet_addr("10.8.0.2"); - - cinfo = new server_conn(cfd); - server_addepev(cfd,EPOLLIN | EPOLLOUT | EPOLLRDHUP | EPOLLET,SERVER_EPEV_JUDGECLIENT,cinfo); - connect(cfd,(sockaddr*)&caddr,sizeof(caddr)); - - return cinfo; -} -int main(){ - int i; - - epoll_event epev; - epoll_event epevs[SERVER_EPOLL_MAXEVENT]; - int nevs; - - int ev_flag; - server_epevdata *epevdata; - server_conn *cinfo; - tpool *tpinfo; - - signal(SIGPIPE,SIG_IGN); - server_epfd = epoll_create1(0); - - server_id = 0; - server_avail = JUDGE_THREAD_JUDGEMAX; - server_mainconn = server_connect(); - server_fileconn = NULL; - server_codeconn = NULL; - - judge_manage_init(); - - server_packtp = new tpool(4); - judge_server_addtpool(server_packtp); - server_packtp->start(); - - - while(true){ - nevs = epoll_wait(server_epfd,epevs,SERVER_EPOLL_MAXEVENT,-1); - for(i = 0;i < nevs;i++){ - ev_flag = epevs[i].events; - epevdata = (server_epevdata*)epevs[i].data.ptr; - - if(epevdata->type == SERVER_EPEV_JUDGECLIENT){ - cinfo = (server_conn*)epevdata->data; - if(ev_flag & EPOLLIN){ - cinfo->readio(); - } - if(ev_flag & EPOLLOUT){ - cinfo->writeio(); - } - - server_packtp->done(); - }else if(epevdata->type = SERVER_EPEV_TPOOL){ - tpinfo = (tpool*)epevdata->data; - if(ev_flag & EPOLLIN){ - tpinfo->done(); - } - } - } - } - - close(server_epfd); - - return 0; -} diff --git a/toj/center/src/judge_server.h b/toj/center/src/judge_server.h deleted file mode 100755 index 90a4e7c..0000000 --- a/toj/center/src/judge_server.h +++ /dev/null @@ -1,87 +0,0 @@ -#define SERVER_JUDGE_PORT 2573 -#define SERVER_EPOLL_MAXEVENT 4096 - -#define SERVER_EPEV_JUDGECLIENT 0 -#define SERVER_EPEV_TPOOL 1 -class server_epevdata{ -public: - int fd; - int type; - void *data; - - server_epevdata(int fd,int type,void *data); -}; - -class server_conn : public netio{ -private: - netio_iofn<server_conn> *recv_dispatch_fn; - netio_iofn<server_conn> *recv_setid_fn; - netio_iofn<server_conn> *recv_submit_fn; - netio_iofn<server_conn> *recv_setpro_fn; - netio_iofn<server_conn> *recv_sendpro_fn; - netio_iofn<server_conn> *done_sendpro_fn; - netio_iofn<server_conn> *recv_setjmod_fn; - netio_iofn<server_conn> *recv_sendjmod_fn; - netio_iofn<server_conn> *done_sendjmod_fn; - netio_iofn<server_conn> *recv_sendcode_fn; - netio_iofn<server_conn> *done_sendcode_fn; - tpool_fn<server_conn> *tp_unpackjmod_thfn; - tpool_fn<server_conn> *tp_unpackjmod_cbfn; - - char* create_combuf(int code,int size,int &len,void **data); - void recv_dispatch(void *buf,size_t len,void *data); - void recv_setid(void *buf,size_t len,void *data); - void recv_submit(void *buf,size_t len,void *data); - void recv_setpro(void *buf,size_t len,void *data); - void recv_sendpro(void *buf,size_t len,void *data); - void done_sendpro(void *buf,size_t len,void *data); - void recv_setjmod(void *buf,size_t len,void *data); - void recv_sendjmod(void *buf,size_t len,void *data); - void done_sendjmod(void *buf,size_t len,void *data); - void recv_sendcode(void *buf,size_t len,void *data); - void done_sendcode(void *buf,size_t len,void *data); - void tp_unpackjmod_th(void *data); - void tp_unpackjmod_cb(void *data); - -public: - server_conn(int fd); - int send_setid(); - int send_setinfo(); - int send_result(int subid,char *res_data,size_t res_len); - int send_reqpro(int proid,int cacheid); - int send_setpro(std::vector<std::pair<int,int> > &pro_list,int type); - int send_setjmod(char **jmod_name,int *cacheid,int type,int count); - int send_reqcode(int subid); - virtual int readidle(); -}; - -static int server_addepev(int fd,unsigned int flag,int type,void *data); -static int server_delepev(server_epevdata *epevdata); -static server_conn* server_connect(); - -static int server_id; -static int server_avail; -static int server_epfd; -static server_conn *server_mainconn; -static server_conn *server_fileconn; -static server_conn *server_codeconn; -static tpool *server_packtp; - -int judge_server_addtpool(tpool *tpinfo); -int judge_server_setpro(std::vector<std::pair<int,int> > &pro_list); -int judge_server_reqcode(int subid); -int judge_server_result(int subid,char *res_data,int res_len); - -extern int tool_pack(char *pack_path,char *dir_path); -extern int tool_unpack(char *pack_path,char *dir_path); -extern int tool_cleardir(char *path); - -extern int judge_manage_init(); -extern judge_pro_info* judge_manage_getprobyid(int proid); -extern int judge_manage_getpro(judge_pro_info *pro_info); -extern int judge_manage_putpro(judge_pro_info *pro_info); -extern int judge_manage_updatepro(int proid,int cacheid,bool check_flag,judge_pro_info **update_pro_info); -extern int judge_manage_done_updatepro(judge_pro_info *pro_info); -extern int judge_manage_submit(int subid,int proid,int lang,char *set_data,int set_len); -extern int judge_manage_done_code(int subid); - diff --git a/toj/center/src/judgk.h b/toj/center/src/judgk.h deleted file mode 100755 index 18f9a6c..0000000 --- a/toj/center/src/judgk.h +++ /dev/null @@ -1,16 +0,0 @@ -struct judgk_proc_info{ - struct hlist_node node; - struct list_head list; - - struct task_struct *task; - struct file *std_in; - struct file *std_out; - char run_path[PATH_MAX + 1]; - int status; - unsigned long timelimit; - unsigned long jiff_start; - unsigned long jiff_end; - unsigned long memlimit; - unsigned long runtime; - unsigned long memory; -}; diff --git a/toj/center/src/judgk_com.h b/toj/center/src/judgk_com.h deleted file mode 100755 index 842c69c..0000000 --- a/toj/center/src/judgk_com.h +++ /dev/null @@ -1,25 +0,0 @@ -#define IOCTL_PROC_ADD _IOWR('x',0x0,int) -#define IOCTL_PROC_GET _IOWR('x',0x1,int) -#define IOCTL_PROC_DEL _IOR('x',0x3,int) - -#define IOCTL_HYPERIO_ADD _IOWR('x',0x10,int) -#define IOCTL_HYPERIO_READ _IOWR('x',0x11,int) -#define IOCTL_HYPERIO_WRITE _IOWR('x',0x12,int) -#define IOCTL_HYPERIO_DEL _IOWR('x',0x13,int) - -#define JUDGK_COM_HYPERIO_BUFSIZE 4194304 - -struct judgk_com_proc_add{ - char run_path[PATH_MAX + 1]; - pid_t pid; - unsigned long kern_task; - unsigned long timelimit; - unsigned long hardtimelimit; - unsigned long memlimit; -}; -struct judgk_com_proc_get{ - unsigned long kern_task; - int status; - unsigned long runtime; - unsigned long memory; -}; diff --git a/toj/center/src/judgk_hyperio.c b/toj/center/src/judgk_hyperio.c deleted file mode 100755 index b37feb7..0000000 --- a/toj/center/src/judgk_hyperio.c +++ /dev/null @@ -1,413 +0,0 @@ -#include<linux/fs.h> -#include<linux/tty.h> -#include<linux/slab.h> -#include<linux/mm.h> -#include<linux/wait.h> -#include<linux/sched.h> -#include<asm/atomic.h> -#include<asm/mman.h> - -#include"judgk.h" -#include"judgk_com.h" -#include"judgk_hyperio.h" - -int judgk_hyperio_init(){ - int i; - struct hyperio_info *info; - - hyperio_filp_ht = (struct hlist_head*)kmalloc(sizeof(struct hlist_head) * HYPERIO_FILP_HTSIZE,GFP_KERNEL); - for(i = 0;i < HYPERIO_FILP_HTSIZE;i++){ - INIT_HLIST_HEAD(&hyperio_filp_ht[i]); - } - - hyperio_table = (struct hyperio_info*)kmalloc(sizeof(struct hyperio_info) * HYPERIO_MAXNUM,GFP_KERNEL); - for(i = 0;i < HYPERIO_MAXNUM;i++){ - info = &hyperio_table[i]; - - atomic_set(&info->ref_count,0); - info->filp = NULL; - info->create_flag = false; - info->end_flag = false; - info->hook_fops = NULL; - info->old_fops = NULL; - - atomic64_set(&info->read_remain,JUDGK_COM_HYPERIO_BUFSIZE); - info->read_off = 0; - info->read_buf = NULL; - init_completion(&info->read_rwait); - init_completion(&info->read_wwait); - - atomic64_set(&info->write_remain,JUDGK_COM_HYPERIO_BUFSIZE); - info->write_off = 0; - info->write_buf = NULL; - init_completion(&info->write_rwait); - init_completion(&info->write_wwait); - } - - hyperio_tty_drv = tty_alloc_driver(HYPERIO_MAXNUM,TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV); - hyperio_tty_drv->owner = THIS_MODULE; - hyperio_tty_drv->driver_name = "judgk_tty"; - hyperio_tty_drv->name = "jtty"; - hyperio_tty_drv->type = TTY_DRIVER_TYPE_SYSTEM; - hyperio_tty_drv->subtype = SYSTEM_TYPE_TTY; - hyperio_tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; - hyperio_tty_drv->init_termios = tty_std_termios; - hyperio_tty_drv->init_termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); - hyperio_tty_drv->init_termios.c_oflag &= ~OPOST; - hyperio_tty_drv->init_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); - hyperio_tty_drv->init_termios.c_cflag &= ~(CSIZE | PARENB); - hyperio_tty_drv->init_termios.c_cflag |= CS8; - tty_set_operations(hyperio_tty_drv,&hyperio_tops); - - tty_register_driver(hyperio_tty_drv); - - return 0; -} -int judgk_hyperio_exit(){ - int i; - - for(i = 0;i < HYPERIO_MAXNUM;i++){ - if(hyperio_table[i].create_flag == true){ - tty_unregister_device(hyperio_tty_drv,i); - hyperio_table[i].create_flag = false; - } - } - tty_unregister_driver(hyperio_tty_drv); - - return 0; -} -int judgk_hyperio_add(struct file *filp){ - int idx; - struct hyperio_info *info; - - info = NULL; - for(idx = 0;idx < HYPERIO_MAXNUM;idx++){ - if(atomic_cmpxchg(&hyperio_table[idx].ref_count,0,1) == 0){ - info = &hyperio_table[idx]; - break; - } - } - if(info == NULL){ - return -1; - } - - filp->private_data = info; - - info->filp = NULL; - if(info->create_flag == false){ - tty_port_init(&info->port); - tty_port_register_device(&info->port,hyperio_tty_drv,idx,NULL); - info->create_flag = true; - } - info->end_flag = false; - if(info->hook_fops == NULL){ - info->hook_fops = (struct file_operations*)kmalloc(sizeof(struct file_operations),GFP_KERNEL); - } - - atomic64_set(&info->read_remain,JUDGK_COM_HYPERIO_BUFSIZE); - info->read_off = 0; - if(info->read_buf == NULL){ - info->read_buf = kmalloc(JUDGK_COM_HYPERIO_BUFSIZE,GFP_KERNEL); - } - memset(info->read_buf,0,JUDGK_COM_HYPERIO_BUFSIZE); - init_completion(&info->read_rwait); - init_completion(&info->read_wwait); - - atomic64_set(&info->write_remain,JUDGK_COM_HYPERIO_BUFSIZE); - info->write_off = 0; - if(info->write_buf == NULL){ - info->write_buf = kmalloc(JUDGK_COM_HYPERIO_BUFSIZE,GFP_KERNEL); - } - memset(info->write_buf,0,JUDGK_COM_HYPERIO_BUFSIZE); - init_completion(&info->write_rwait); - init_completion(&info->write_wwait); - - return idx; -} -int judgk_hyperio_read(struct file *filp,size_t len){ - struct hyperio_info *info; - bool wait_flag; - size_t remain; - - if((long)len >= 0){ - wait_flag = true; - }else{ - wait_flag = false; - len = -(long)len; - } - - info = (struct hyperio_info*)filp->private_data; - - remain = atomic64_read(&info->write_remain); - if(unlikely(len > (JUDGK_COM_HYPERIO_BUFSIZE - remain))){ - return -EINVAL; - } - - if(unlikely(len > 0 && (remain = atomic64_add_return(len,&info->write_remain)) == len)){ - complete(&info->write_wwait); - } - if(wait_flag == true){ - while(unlikely(remain == JUDGK_COM_HYPERIO_BUFSIZE)){ - if(info->end_flag == true){ - remain = atomic64_read(&info->write_remain); - break; - } - wait_for_completion_interruptible(&info->write_rwait); - remain = atomic64_read(&info->write_remain); - } - } - - return JUDGK_COM_HYPERIO_BUFSIZE - remain; -} -int judgk_hyperio_write(struct file *filp,size_t len){ - struct hyperio_info *info; - bool wait_flag; - size_t remain; - - if((long)len >= 0){ - wait_flag = true; - }else{ - wait_flag = false; - len = -(long)len; - } - - info = (struct hyperio_info*)filp->private_data; - - remain = atomic64_read(&info->read_remain); - if(unlikely(len > remain)){ - return -EINVAL; - } - - if(unlikely(len > 0 && (remain = atomic64_sub_return(len,&info->read_remain)) == (JUDGK_COM_HYPERIO_BUFSIZE - len))){ - complete(&info->read_rwait); - } - if(wait_flag == true){ - while(unlikely(remain == 0)){ - if(info->end_flag == true){ - remain = atomic64_read(&info->read_remain); - break; - } - wait_for_completion_interruptible(&info->read_wwait); - remain = atomic64_read(&info->read_remain); - } - } - - return remain; -} -int judgk_hyperio_del(struct file *filp){ - struct hyperio_info *info; - - info = (struct hyperio_info*)filp->private_data; - info->end_flag = true; - complete(&info->read_rwait); - complete(&info->read_wwait); - complete(&info->write_rwait); - complete(&info->write_wwait); - - atomic_dec(&info->ref_count); - return 0; -} -int judgk_hyperio_mmap(struct file *filp,struct vm_area_struct *vma){ - unsigned long size; - unsigned long off; - void *buf; - - size = vma->vm_end - vma->vm_start; - off = vma->vm_pgoff << PAGE_SHIFT; - if((size + off) > JUDGK_COM_HYPERIO_BUFSIZE){ - return -EINVAL; - } - if((vma->vm_flags & VM_READ) != 0 && (vma->vm_flags & VM_WRITE) != 0){ - return -EINVAL; - } - if((vma->vm_flags & VM_READ) == 0 && (vma->vm_flags & VM_WRITE) == 0){ - return -EINVAL; - } - - if((vma->vm_flags & VM_READ) != 0){ - buf = ((struct hyperio_info*)filp->private_data)->write_buf; - }else{ - buf = ((struct hyperio_info*)filp->private_data)->read_buf; - } - remap_pfn_range(vma, - vma->vm_start, - virt_to_phys(buf + off) >> PAGE_SHIFT, - size, - vma->vm_page_prot); - - return 0; -} - -static inline struct hyperio_info* hyperio_filp_lookup(struct file *filp){ - struct hyperio_info *info; - - rcu_read_lock(); - - info = NULL; - hlist_for_each_entry_rcu(info,&hyperio_filp_ht[(unsigned long)filp % HYPERIO_FILP_HTSIZE],node){ - if((unsigned long)info->filp == (unsigned long)filp){ - break; - } - } - - rcu_read_unlock(); - - return info; -} -static int hyperio_tty_open(struct tty_struct *tty, struct file *filp){ - struct hyperio_info *info; - struct file_operations *hook_fops; - - info = &hyperio_table[tty->index]; - atomic_inc(&info->ref_count); - info->filp = filp; - - hook_fops = info->hook_fops; - info->old_fops = filp->f_op; - memcpy(hook_fops,filp->f_op,sizeof(struct file_operations)); - - hook_fops->read = hyperio_tty_filpread; - hook_fops->write = hyperio_tty_filpwrite; - - filp->f_op = hook_fops; - - spin_lock(&hyperio_filp_htlock); - - hlist_add_head_rcu(&info->node,&hyperio_filp_ht[(unsigned long)info->filp % HYPERIO_FILP_HTSIZE]); - - spin_unlock(&hyperio_filp_htlock); - - return 0; -} -static void hyperio_tty_close(struct tty_struct *tty, struct file *filp){ - struct hyperio_info *info; - - info = &hyperio_table[tty->index]; - - spin_lock(&hyperio_filp_htlock); - - hlist_del_rcu(&info->node); - - spin_unlock(&hyperio_filp_htlock); - - filp->f_op = info->old_fops; - - info->end_flag = true; - complete(&info->read_rwait); - complete(&info->read_wwait); - complete(&info->write_rwait); - complete(&info->write_wwait); - - atomic_dec(&info->ref_count); -} -static int hyperio_tty_write(struct tty_struct *tty,const unsigned char *buf,int count){ - return count; -} -static int hyperio_tty_write_room(struct tty_struct *tty){ - return JUDGK_COM_HYPERIO_BUFSIZE; -} -static ssize_t hyperio_tty_filpread(struct file *filp,char __user *buf,size_t count,loff_t *off){ - struct hyperio_info *info; - size_t buf_len; - off_t buf_off; - size_t remain; - size_t read_len; - off_t read_off; - - if(unlikely(count < 0)){ - return -EINVAL; - } - - info = hyperio_filp_lookup(filp); - if(unlikely(info == NULL)){ - return -EIO; - } - - buf_len = count; - buf_off = 0; - while(likely(buf_len > 0)){ - while(unlikely((remain = atomic64_read(&info->read_remain)) == JUDGK_COM_HYPERIO_BUFSIZE)){ - if(unlikely(info->end_flag == true)){ - return -EIO; - } - if(likely(buf_off > 0)){ - return buf_off; - } - wait_for_completion_interruptible(&info->read_rwait); - } - if(unlikely(buf_len > (JUDGK_COM_HYPERIO_BUFSIZE - remain))){ - read_len = JUDGK_COM_HYPERIO_BUFSIZE - remain; - }else{ - read_len = buf_len; - } - - read_off = info->read_off; - if(likely((read_len + read_off) < JUDGK_COM_HYPERIO_BUFSIZE)){ - copy_to_user(buf + buf_off,info->read_buf + read_off,read_len); - info->read_off = read_len + read_off; - }else{ - copy_to_user(buf + buf_off,info->read_buf + read_off,JUDGK_COM_HYPERIO_BUFSIZE - read_off); - copy_to_user(buf + buf_off + (JUDGK_COM_HYPERIO_BUFSIZE - read_off),info->read_buf,(read_len + read_off) - JUDGK_COM_HYPERIO_BUFSIZE); - info->read_off = (read_len + read_off) - JUDGK_COM_HYPERIO_BUFSIZE; - } - - if(unlikely(atomic64_add_return(read_len,&info->read_remain) == read_len)){ - complete(&info->read_wwait); - } - buf_len -= read_len; - buf_off += read_len; - } - - return count; -} -static ssize_t hyperio_tty_filpwrite(struct file *filp,const char __user *buf,size_t count,loff_t *off){ - struct hyperio_info *info; - size_t buf_len; - off_t buf_off; - size_t remain; - size_t write_len; - off_t write_off; - - if(unlikely(count < 0)){ - return -EINVAL; - } - - info = hyperio_filp_lookup(filp); - if(unlikely(info == NULL)){ - return -EIO; - } - - buf_len = count; - buf_off = 0; - while(likely(buf_len > 0)){ - while(unlikely((remain = atomic64_read(&info->write_remain)) == 0)){ - if(unlikely(info->end_flag == true)){ - return -EIO; - } - wait_for_completion_interruptible(&info->write_wwait); - } - if(unlikely(buf_len > remain)){ - write_len = remain; - }else{ - write_len = buf_len; - } - - write_off = info->write_off; - if(unlikely((write_len + write_off) >= JUDGK_COM_HYPERIO_BUFSIZE)){ - copy_from_user(info->write_buf + write_off,buf + buf_off,JUDGK_COM_HYPERIO_BUFSIZE - write_off); - copy_from_user(info->write_buf,buf + buf_off + (JUDGK_COM_HYPERIO_BUFSIZE - write_off),(write_len + write_off) - JUDGK_COM_HYPERIO_BUFSIZE); - info->write_off = (write_len + write_off) - JUDGK_COM_HYPERIO_BUFSIZE; - }else{ - copy_from_user(info->write_buf + write_off,buf + buf_off,write_len); - info->write_off = write_len + write_off; - } - - if(unlikely(atomic64_sub_return(write_len,&info->write_remain) == (JUDGK_COM_HYPERIO_BUFSIZE - write_len))){ - complete(&info->write_rwait); - } - buf_len -= write_len; - buf_off += write_len; - } - - return count; -} diff --git a/toj/center/src/judgk_hyperio.h b/toj/center/src/judgk_hyperio.h deleted file mode 100755 index ccc1449..0000000 --- a/toj/center/src/judgk_hyperio.h +++ /dev/null @@ -1,53 +0,0 @@ -#define HYPERIO_MAXNUM 256 -#define HYPERIO_FILP_HTSIZE 1009 - -struct hyperio_info{ - atomic_t ref_count; - struct hlist_node node; - struct file *filp; - struct tty_port port; - - bool create_flag; - bool end_flag; - struct file_operations *hook_fops; - const struct file_operations *old_fops; - - atomic64_t read_remain; - off_t read_off; - char *read_buf; - struct completion read_rwait; - struct completion read_wwait; - - atomic64_t write_remain; - off_t write_off; - char *write_buf; - struct completion write_rwait; - struct completion write_wwait; -}; - -static inline struct hyperio_info* hyperio_filp_lookup(struct file *filp); -static int hyperio_tty_open(struct tty_struct * tty, struct file * filp); -static void hyperio_tty_close(struct tty_struct * tty, struct file * filp); -static int hyperio_tty_write(struct tty_struct *tty,const unsigned char *buf,int count); -static int hyperio_tty_write_room(struct tty_struct *tty); -static ssize_t hyperio_tty_filpread(struct file *filp,char __user *buf,size_t count,loff_t *off); -static ssize_t hyperio_tty_filpwrite(struct file *filp,const char __user *buf,size_t count,loff_t *off); - -static struct tty_driver *hyperio_tty_drv; -static struct tty_operations hyperio_tops = { - .open = hyperio_tty_open, - .close = hyperio_tty_close, - .write = hyperio_tty_write, - .write_room = hyperio_tty_write_room -}; -static struct hyperio_info *hyperio_table; -static struct hlist_head *hyperio_filp_ht; -static DEFINE_SPINLOCK(hyperio_filp_htlock); - -int judgk_hyperio_init(void); -int judgk_hyperio_exit(void); -int judgk_hyperio_add(struct file *filp); -int judgk_hyperio_read(struct file *filp,size_t len); -int judgk_hyperio_write(struct file *filp,size_t len); -int judgk_hyperio_del(struct file *filp); -int judgk_hyperio_mmap(struct file *filp,struct vm_area_struct *vma); diff --git a/toj/center/src/judgk_mod.c b/toj/center/src/judgk_mod.c deleted file mode 100755 index ca2f533..0000000 --- a/toj/center/src/judgk_mod.c +++ /dev/null @@ -1,75 +0,0 @@ -#include<linux/module.h> -#include<linux/kernel.h> -#include<linux/kdev_t.h> -#include<linux/device.h> -#include<linux/cdev.h> -#include<linux/fs.h> -#include<linux/sched.h> - -#include"judgk.h" -#include"judgk_com.h" -#include"judgk_mod.h" - -static int __init mod_init(){ - alloc_chrdev_region(&mod_dev,0,1,"judgk"); - mod_class = class_create(THIS_MODULE,"chardev"); - device_create(mod_class,NULL,mod_dev,NULL,"judgk"); - cdev_init(&mod_cdev,&mod_fops); - cdev_add(&mod_cdev,mod_dev,1); - - judgk_proc_init(); - judgk_security_hook(); - judgk_syscall_hook(); - judgk_hyperio_init(); - - pr_alert("judgk:Init\n"); - return 0; -} -static void __exit mod_exit(){ - cdev_del(&mod_cdev); - device_destroy(mod_class,mod_dev); - class_destroy(mod_class); - unregister_chrdev_region(mod_dev,1); - - judgk_proc_exit(); - judgk_syscall_unhook(); - judgk_security_unhook(); - judgk_hyperio_exit(); - - schedule_timeout_interruptible(3 * HZ); - pr_alert("judgk:Exit\n"); -} -module_init(mod_init); -module_exit(mod_exit); -MODULE_LICENSE("Dual MIT/GPL"); - -static long mod_ioctl(struct file *filp,unsigned int cmd,unsigned long arg){ - int ret; - - ret = -1; - switch(cmd){ - case IOCTL_PROC_ADD: - ret = judgk_proc_add(arg); - break; - case IOCTL_PROC_GET: - ret = judgk_proc_get(arg); - break; - case IOCTL_PROC_DEL: - ret = judgk_proc_del(arg); - break; - case IOCTL_HYPERIO_ADD: - ret = judgk_hyperio_add(filp); - break; - case IOCTL_HYPERIO_READ: - ret = judgk_hyperio_read(filp,arg); - break; - case IOCTL_HYPERIO_WRITE: - ret = judgk_hyperio_write(filp,arg); - break; - case IOCTL_HYPERIO_DEL: - ret = judgk_hyperio_del(filp); - break; - } - - return ret; -} diff --git a/toj/center/src/judgk_mod.h b/toj/center/src/judgk_mod.h deleted file mode 100755 index 58bc76b..0000000 --- a/toj/center/src/judgk_mod.h +++ /dev/null @@ -1,31 +0,0 @@ -static int __init mod_init(void); -static void __exit mod_exit(void); -static long mod_ioctl(struct file *filp,unsigned int cmd,unsigned long arg); - -static dev_t mod_dev; -static struct cdev mod_cdev; -static struct class *mod_class; - -extern int judgk_hyperio_mmap(struct file *filp,struct vm_area_struct *vma); -static struct file_operations mod_fops = { - .owner = THIS_MODULE, - .unlocked_ioctl = mod_ioctl, - .mmap = judgk_hyperio_mmap -}; - -extern int judgk_proc_init(void); -extern int judgk_proc_exit(void); -extern int judgk_proc_add(unsigned long arg); -extern int judgk_proc_get(unsigned long arg); -extern int judgk_proc_del(unsigned long arg); -extern int judgk_syscall_hook(void); -extern int judgk_syscall_unhook(void); -extern int judgk_security_hook(void); -extern int judgk_security_unhook(void); - -extern int judgk_hyperio_init(void); -extern int judgk_hyperio_exit(void); -extern int judgk_hyperio_add(struct file *filp); -extern int judgk_hyperio_read(struct file *filp,size_t len); -extern int judgk_hyperio_write(struct file *filp,size_t len); -extern int judgk_hyperio_del(struct file *filp); diff --git a/toj/center/src/judgk_proc.c b/toj/center/src/judgk_proc.c deleted file mode 100755 index f3ed130..0000000 --- a/toj/center/src/judgk_proc.c +++ /dev/null @@ -1,248 +0,0 @@ -#include<linux/fs.h> -#include<linux/slab.h> -#include<linux/fdtable.h> -#include<linux/sched.h> -#include<linux/kthread.h> -#include<asm/uaccess.h> - -#include"judge_def.h" -#include"judgk.h" -#include"judgk_com.h" -#include"judgk_proc.h" - -int judgk_proc_init(){ - int i; - - proc_task_ht = kmalloc(sizeof(struct hlist_head) * PROC_TASK_HTSIZE,GFP_KERNEL); - for(i = 0;i < PROC_TASK_HTSIZE;i++){ - INIT_HLIST_HEAD(&proc_task_ht[i]); - } - proc_info_cachep = kmem_cache_create("proc_info_cachep",sizeof(struct judgk_proc_info),0,0,NULL); - - proc_watcher_task = kthread_run(proc_watcher,NULL,"judgk_proc"); - - return 0; -} -int judgk_proc_exit(){ - kthread_stop(proc_watcher_task); - return 0; -} - -int judgk_proc_add(unsigned long arg){ - int ret; - - struct task_struct *task; - struct judgk_proc_info *info; - struct judgk_com_proc_add *com_proc_add; - - ret = 0; - com_proc_add = kmalloc(sizeof(struct judgk_com_proc_add),GFP_KERNEL); - copy_from_user(com_proc_add,(void* __user)arg,sizeof(struct judgk_com_proc_add)); - - if((task = get_pid_task(find_vpid(com_proc_add->pid),PIDTYPE_PID)) == NULL){ - ret = -1; - goto end; - } - if(judgk_proc_task_lookup(task) != NULL){ - put_task_struct(task); - ret = -1; - goto end; - } - - info = kmem_cache_alloc(proc_info_cachep,GFP_KERNEL); - info->task = task; - info->std_in = fcheck_files(task->files,0); - info->std_out = fcheck_files(task->files,1); - info->status = JUDGE_AC; - info->timelimit = com_proc_add->timelimit; - info->jiff_start = jiffies; - info->jiff_end = info->jiff_start + usecs_to_jiffies(com_proc_add->hardtimelimit); - info->memlimit = com_proc_add->memlimit; - info->runtime = 0L; - info->memory = 0L; - - if(proc_get_path(com_proc_add->run_path,info->run_path)){ - put_task_struct(task); - kmem_cache_free(proc_info_cachep,info); - - ret = -1; - goto end; - } - proc_close_fd(task); - - spin_lock(&proc_task_htlock); - - list_add_rcu(&info->list,&proc_task_list); - hlist_add_head_rcu(&info->node,&proc_task_ht[(unsigned long)info->task % PROC_TASK_HTSIZE]); - - spin_unlock(&proc_task_htlock); - - com_proc_add->kern_task = (unsigned long)task; - copy_to_user((void* __user)arg,com_proc_add,sizeof(struct judgk_com_proc_add)); - -end: - - kfree(com_proc_add); - - return ret; -} -int judgk_proc_get(unsigned long arg){ - struct task_struct *task; - struct judgk_proc_info *info; - struct judgk_com_proc_get *com_proc_get; - - com_proc_get = kmalloc(sizeof(struct judgk_com_proc_get),GFP_KERNEL); - copy_from_user(com_proc_get,(void* __user)arg,sizeof(struct judgk_com_proc_get)); - task = (struct task_struct*)com_proc_get->kern_task; - if((info = judgk_proc_task_lookup(task)) == NULL){ - kfree(com_proc_get); - return -1; - } - - com_proc_get->status = info->status; - if(info->runtime > 0L){ - com_proc_get->runtime = info->runtime; - }else{ - com_proc_get->runtime = cputime_to_usecs(task->utime); - info->runtime = com_proc_get->runtime; - } - com_proc_get->memory = info->memory; - - copy_to_user((void* __user)arg,com_proc_get,sizeof(struct judgk_com_proc_get)); - kfree(com_proc_get); - - spin_lock(&proc_task_htlock); - - list_del_rcu(&info->list); - hlist_del_rcu(&info->node); - - spin_unlock(&proc_task_htlock); - - synchronize_rcu(); - - put_task_struct(info->task); - kmem_cache_free(proc_info_cachep,info); - - return 0; -} -int judgk_proc_del(unsigned long arg){ - struct task_struct *task; - struct judgk_proc_info *info; - - task = (struct task_struct*)arg; - if((info = judgk_proc_task_lookup(task)) == NULL){ - return -1; - } - - spin_lock(&proc_task_htlock); - - list_del_rcu(&info->list); - hlist_del_rcu(&info->node); - - spin_unlock(&proc_task_htlock); - - synchronize_rcu(); - - put_task_struct(info->task); - kmem_cache_free(proc_info_cachep,info); - - return 0; -} -struct judgk_proc_info* judgk_proc_task_lookup(struct task_struct *task){ - struct judgk_proc_info *info; - - rcu_read_lock(); - - info = NULL; - hlist_for_each_entry_rcu(info,&proc_task_ht[(unsigned long)task % PROC_TASK_HTSIZE],node){ - if((unsigned long)info->task == (unsigned long)task){ - break; - } - } - - rcu_read_unlock(); - - return info; -} - -static int proc_watcher(void *data){ - struct judgk_proc_info *info; - - while(!kthread_should_stop()){ - - rcu_read_lock(); - - list_for_each_entry_rcu(info,&proc_task_list,list){ - if(cputime_to_usecs(info->task->utime) > info->timelimit){ - info->status = JUDGE_TLE; - send_sig(SIGKILL,info->task,0); - }else if(time_after(jiffies,info->jiff_end)){ - info->runtime = jiffies_to_usecs((unsigned long)(-((long)info->jiff_start - (long)jiffies))); - info->status = JUDGE_TLE; - send_sig(SIGKILL,info->task,0); - } - } - - rcu_read_unlock(); - - schedule_timeout_interruptible(HZ / 2); - } - - return 0; -} -static int proc_get_path(char *in_path,char *real_path){ - struct file *f; - char *buf_path; - - if(IS_ERR(f = filp_open(in_path,O_RDONLY,0))){ - return -1; - } - - buf_path = kmalloc(sizeof(char) * (PATH_MAX + 1),GFP_KERNEL); - real_path[0] = '\0'; - strncat(real_path,d_path(&f->f_path,buf_path,PATH_MAX + 1),PATH_MAX + 1); - kfree(buf_path); - filp_close(f,NULL); - - return 0; -} -//Watch out kernel update -static int proc_close_fd(struct task_struct *task){ - struct file *f; - struct files_struct *files; - struct fdtable *fdt; - int fd; - - files = task->files; - - spin_lock(&files->file_lock); - - fdt = files_fdtable(files); - for(fd = 3;fd < fdt->max_fds;fd++){ - if((fd = find_next_bit(fdt->open_fds,fdt->max_fds,fd)) >= fdt->max_fds){ - break; - } - f = fdt->fd[fd]; - if(f == NULL){ - continue; - } - - rcu_assign_pointer(fdt->fd[fd],NULL); - __clear_bit(fd,fdt->close_on_exec); - __clear_bit(fd,fdt->open_fds); - if(fd < files->next_fd){ - files->next_fd = fd; - } - - spin_unlock(&files->file_lock); - - filp_close(f,files); - - spin_lock(&files->file_lock); - - } - - spin_unlock(&files->file_lock); - - return 0; -} diff --git a/toj/center/src/judgk_proc.h b/toj/center/src/judgk_proc.h deleted file mode 100755 index fd60d30..0000000 --- a/toj/center/src/judgk_proc.h +++ /dev/null @@ -1,18 +0,0 @@ -#define PROC_TASK_HTSIZE 1009 - -static int proc_watcher(void *data); -static int proc_get_path(char *in_path,char *real_path); -static int proc_close_fd(struct task_struct *task); - -static struct task_struct *proc_watcher_task; -static LIST_HEAD(proc_task_list); -static struct hlist_head *proc_task_ht; -static DEFINE_SPINLOCK(proc_task_htlock); -static struct kmem_cache *proc_info_cachep; - -int judgk_proc_init(void); -int judgk_proc_exit(void); -int judgk_proc_add(unsigned long arg); -int judgk_proc_get(unsigned long arg); -int judgk_proc_del(unsigned long arg); -struct judgk_proc_info* judgk_proc_task_lookup(struct task_struct *task); diff --git a/toj/center/src/judgk_security.c b/toj/center/src/judgk_security.c deleted file mode 100755 index d998223..0000000 --- a/toj/center/src/judgk_security.c +++ /dev/null @@ -1,309 +0,0 @@ -#include<linux/fs.h> -#include<linux/security.h> -#include<linux/sched.h> -#include<linux/hardirq.h> -#include<linux/vmalloc.h> -#include<asm/uaccess.h> - -#include"judge_def.h" -#include"judgk.h" -#include"judgk_security.h" - -int judgk_security_hook(){ - int i; - - int count; - size_t len; - unsigned long *ori_array; - unsigned long *hook_array; - void *addr; - - security_init_hook(); - - ori_sops = (struct security_operations*)*security_hook_addr; - memcpy(&hook_sops,ori_sops,sizeof(struct security_operations)); - - judgk_security_checkaddr = (unsigned long)security_check; - - count = (sizeof(hook_sops) - sizeof(hook_sops.name)) / sizeof(unsigned long); - len = (judgk_security_blockend - judgk_security_block) + sizeof(unsigned long); - security_block_code = __vmalloc(((((len * count - 1) >> PAGE_SHIFT) + 1) << PAGE_SHIFT),GFP_KERNEL | GFP_ATOMIC,PAGE_KERNEL_EXEC); - - ori_array = (unsigned long*)(((char*)ori_sops) + offsetof(struct security_operations,ptrace_access_check)); - hook_array = (unsigned long*)(((char*)&hook_sops) + offsetof(struct security_operations,ptrace_access_check)); - for(i = 0;i < count;i++){ - addr = (((char*)security_block_code) + len * i); - memcpy(addr,&ori_array[i],sizeof(unsigned long)); - memcpy(((char*)addr + sizeof(unsigned long)),judgk_security_block,len - sizeof(unsigned long)); - hook_array[i] = (unsigned long)addr + sizeof(unsigned long); - } - - hook_sops.capable = ori_sops->capable; - hook_sops.bprm_set_creds = ori_sops->bprm_set_creds; - hook_sops.bprm_check_security = ori_sops->bprm_check_security; - hook_sops.bprm_secureexec = ori_sops->bprm_secureexec; - hook_sops.bprm_committing_creds = ori_sops->bprm_committing_creds; - hook_sops.bprm_committed_creds = ori_sops->bprm_committed_creds; - hook_sops.inode_alloc_security = ori_sops->inode_alloc_security; - hook_sops.inode_free_security = ori_sops->inode_free_security; - hook_sops.inode_follow_link = ori_sops->inode_follow_link; - hook_sops.inode_getattr = ori_sops->inode_getattr; - hook_sops.file_alloc_security = ori_sops->file_alloc_security; - hook_sops.file_free_security = ori_sops->file_free_security; - hook_sops.mmap_addr = ori_sops->mmap_addr; - hook_sops.mmap_file = ori_sops->mmap_file; - hook_sops.file_mprotect = ori_sops->file_mprotect; - hook_sops.task_free = ori_sops->task_free; - hook_sops.cred_free = ori_sops->cred_free; - hook_sops.cred_prepare = ori_sops->cred_prepare; - - hook_sops.inode_permission = hook_inode_permission; - hook_sops.file_permission = hook_file_permission; - hook_sops.file_open = hook_file_open; - hook_sops.file_ioctl = hook_file_ioctl; - hook_sops.d_instantiate = hook_d_instantiate; - hook_sops.vm_enough_memory = hook_vm_enough_memory; - - *security_hook_addr = (unsigned long)&hook_sops; - - return 0; -} -int judgk_security_unhook(){ - *security_hook_addr = (unsigned long)ori_sops; - return 0; -} - -static int security_init_hook(){ - ssize_t ret; - int i; - int j; - - struct file *f; - char line[128]; - unsigned char code[3] = {0x48,0xc7,0x05}; - unsigned long addr; - - f = filp_open("/proc/meminfo",O_RDONLY,0); - security_meminfo_ino = f->f_dentry->d_inode->i_ino; - filp_close(f,NULL); - - f = filp_open("/proc/kallsyms",O_RDONLY,0); - set_fs(KERNEL_DS); - - i = 0; - addr = 0; - while(true){ - ret = f->f_op->read(f,&line[i],1,&f->f_pos); - - if(line[i] == '\n' || ret <= 0){ - line[i] = '\0'; - - addr = 0; - for(j = 0;j < i;j++){ - if(line[j] == ' '){ - j++; - break; - } - - addr *= 16UL; - if(line[j] >= '0' && line[j] <= '9'){ - addr += (unsigned long)(line[j] - '0'); - }else{ - addr += (unsigned long)(line[j] - 'a' + 10); - } - } - for(;j < i;j++){ - if(line[j] == ' '){ - j++; - break; - } - } - if(j < i){ - if(strcmp("reset_security_ops",line + j) == 0){ - break; - } - } - - i = 0; - }else{ - i++; - } - - if(ret <= 0){ - break; - } - } - - set_fs(USER_DS); - filp_close(f,NULL); - - i = 0; - while(i < 3){ - if(*(unsigned char*)addr != code[i]){ - i = 0; - }else{ - i++; - } - addr++; - } - - security_hook_addr = (unsigned long*)(addr + (unsigned long)*(unsigned int*)addr + 8UL); - - return 0; -} -static inline void security_kill(void){ - send_sig(SIGKILL,current,0); -} -static long security_check(void){ - struct judgk_proc_info *info; - - info = judgk_proc_task_lookup(current); - if(likely(info == NULL || in_interrupt())){ - return 0; - } - - pr_alert("judgk:PID %d RF\n",current->tgid); - - info->status = JUDGE_RF; - security_kill(); - - return -EACCES; -} - -static int hook_inode_permission(struct inode *inode,int mask){ - struct judgk_proc_info *info; - - info = judgk_proc_task_lookup(current); - if(likely(info == NULL || in_interrupt())){ - return ori_sops->inode_permission(inode,mask); - } - - if((mask & ~(MAY_EXEC | MAY_READ | MAY_OPEN | MAY_CHDIR | MAY_NOT_BLOCK)) != 0){ - pr_alert("judgk:PID %d RF inode_permission %08x\n",current->tgid,mask); - - info->status = JUDGE_RF; - security_kill(); - - return -EACCES; - } - return ori_sops->inode_permission(inode,mask); -} -static int hook_file_permission(struct file *file,int mask){ - struct judgk_proc_info *info; - - info = judgk_proc_task_lookup(current); - if(likely(info == NULL || in_interrupt())){ - return ori_sops->file_permission(file,mask); - } - - if((mask & ~(MAY_READ | MAY_WRITE)) != 0){ - info->status = JUDGE_RF; - security_kill(); - - return -EACCES; - }else if((mask & MAY_WRITE) != 0 && file != info->std_out){ - info->status = JUDGE_RF; - security_kill(); - - return -EACCES; - } - return ori_sops->file_permission(file,mask); -} -static int hook_file_open(struct file *file, const struct cred *cred){ - int ret; - int i; - - struct judgk_proc_info *info; - char *buf_path,*path; - - info = judgk_proc_task_lookup(current); - if(likely(info == NULL || in_interrupt())){ - return ori_sops->file_open(file,cred); - } - - ret = 0; - buf_path = kmalloc(sizeof(char) * (PATH_MAX + 1),GFP_KERNEL); - path = d_path(&file->f_path,buf_path,PATH_MAX + 1); - - if((file->f_mode & !(FMODE_READ | FMODE_LSEEK | FMODE_PREAD | FMODE_EXEC)) != 0){ - ret = -EACCES; - }else if(file->f_dentry->d_inode == NULL || file->f_dentry->d_inode->i_ino != security_meminfo_ino){ - i = 0; - while(info->run_path[i] != '\0'){ - if(path[i] != info->run_path[i]){ - ret = -EACCES; - break; - } - i++; - } - if(path[i] == info->run_path[i]){ - ret = -EACCES; - } - } - - kfree(buf_path); - - if(ret != 0){ - pr_alert("judgk:PID %d RF file_open %s %08x\n",current->tgid,path,file->f_mode); - - info->status = JUDGE_RF; - security_kill(); - - return ret; - } - return ori_sops->file_open(file,cred); -} -static int hook_file_ioctl(struct file *file,unsigned int cmd,unsigned long arg){ - struct judgk_proc_info *info; - - info = judgk_proc_task_lookup(current); - if(likely(info == NULL || in_interrupt())){ - return ori_sops->file_ioctl(file,cmd,arg); - } - - if(file != info->std_in && file != info->std_out){ - pr_alert("judgk:PID %d file_ioctl\n",current->tgid); - - info->status = JUDGE_RF; - security_kill(); - - return -EACCES; - } - return ori_sops->file_ioctl(file,cmd,arg); -} -static void hook_d_instantiate(struct dentry *dentry,struct inode *inode){ - struct judgk_proc_info *info; - - info = judgk_proc_task_lookup(current); - if(likely(info == NULL || in_interrupt())){ - return ori_sops->d_instantiate(dentry,inode); - } - - if(inode == NULL || inode->i_ino != security_meminfo_ino){ - pr_alert("judgk:PID %d d_instantiate\n",current->tgid); - - info->status = JUDGE_RF; - security_kill(); - } - return ori_sops->d_instantiate(dentry,inode); -} -static int hook_vm_enough_memory(struct mm_struct *mm,long pages){ - struct judgk_proc_info *info; - - info = judgk_proc_task_lookup(current); - if(likely(info == NULL)){ - return ori_sops->vm_enough_memory(mm,pages); - } - - info->memory = (mm->total_vm + pages) << PAGE_SHIFT; - - if(info->memory > info->memlimit){ - pr_alert("judgk:PID %d vm_enough_memory %lu\n",current->tgid,info->memory); - - info->status = JUDGE_MLE; - security_kill(); - - return -EACCES; - } - return ori_sops->vm_enough_memory(mm,pages); -} diff --git a/toj/center/src/judgk_security.h b/toj/center/src/judgk_security.h deleted file mode 100755 index 3855d7b..0000000 --- a/toj/center/src/judgk_security.h +++ /dev/null @@ -1,25 +0,0 @@ -static int security_init_hook(void); -static inline void security_kill(void); -static long security_check(void); - -static unsigned long security_meminfo_ino; -static unsigned long* security_hook_addr; -static struct security_operations *ori_sops; -static struct security_operations hook_sops; -static void *security_block_code; - -int judgk_security_hook(void); -int judgk_security_unhook(void); - -unsigned long judgk_security_checkaddr; - -extern struct judgk_proc_info* judgk_proc_task_lookup(struct task_struct *task); -extern void judgk_security_block(void); -extern void judgk_security_blockend(void); - -static int hook_inode_permission(struct inode *inode,int mask); -static int hook_file_permission(struct file *file,int mask); -static int hook_file_open(struct file *file, const struct cred *cred); -static int hook_file_ioctl(struct file *file,unsigned int cmd,unsigned long arg); -static void hook_d_instantiate(struct dentry *dentry,struct inode *inode); -static int hook_vm_enough_memory(struct mm_struct *mm,long pages); diff --git a/toj/center/src/judgk_security_asm.S b/toj/center/src/judgk_security_asm.S deleted file mode 100644 index 80edf37..0000000 --- a/toj/center/src/judgk_security_asm.S +++ /dev/null @@ -1,57 +0,0 @@ -.code64 -.section .data //Don't run these code, just data for copy -.global judgk_security_block -.global judgk_security_blockend -.extern judgk_security_checkaddr - -//First 8 bytes is original function address -judgk_security_block: - push %rbx - push %rcx - push %rdx - push %rsi - push %rdi - push %rbp - push %r8 - push %r9 - push %r10 - push %r11 - push %r12 - push %r13 - push %r14 - push %r15 - pushfq - - callq *(judgk_security_checkaddr) - - popfq - pop %r15 - pop %r14 - pop %r13 - pop %r12 - pop %r11 - pop %r10 - pop %r9 - pop %r8 - pop %rbp - pop %rdi - pop %rsi - pop %rdx - pop %rcx - pop %rbx - - test %rax,%rax - jnz .block - - call .getrip -.offset: - sub $(.offset - judgk_security_block + 8),%rax - jmp *(%rax) - -.block: - ret - -.getrip: - mov (%rsp),%rax - ret -judgk_security_blockend: diff --git a/toj/center/src/judgk_syscall.c b/toj/center/src/judgk_syscall.c deleted file mode 100755 index c876283..0000000 --- a/toj/center/src/judgk_syscall.c +++ /dev/null @@ -1,235 +0,0 @@ -#include<linux/fs.h> -#include<linux/slab.h> -#include<linux/sched.h> -#include<linux/sort.h> -#include<asm/msr.h> -#include<asm/unistd.h> -#include<asm/uaccess.h> - -#include"judge_def.h" -#include"judgk.h" -#include"judgk_com.h" -#include"judgk_syscall.h" - -int judgk_syscall_hook(){ - int i; - int j; - - unsigned int size; - unsigned int restore; - - syscall_init_hook(); - - syscall_addr_write((unsigned long)syscall_table,&size,&restore); - for(i = 0,j = 0;i < syscall_max;i++){ - if(size == 0){ - syscall_addr_restore((unsigned long)(syscall_table + i - 1),restore); - syscall_addr_write((unsigned long)(syscall_table + i),&size,&restore); - } - size -= sizeof(unsigned long); - - if(i == syscall_whitelist[j]){ - j++; - continue; - } - syscall_table[i] = (unsigned long)judgk_syscall_block; - } - syscall_addr_restore((unsigned long)(&syscall_table[i - 1]),restore); - - return 0; -} -int judgk_syscall_unhook(){ - int i; - - unsigned int size; - unsigned int restore; - - syscall_addr_write((unsigned long)syscall_table,&size,&restore); - for(i = 0;i < syscall_max;i++){ - if(size == 0){ - syscall_addr_restore((unsigned long)(&syscall_table[i - 1]),restore); - syscall_addr_write((unsigned long)(&syscall_table[i]),&size,&restore); - } - size -= sizeof(unsigned long); - - syscall_table[i] = (unsigned long)judgk_syscall_ori_table[i]; - } - syscall_addr_restore((unsigned long)(&syscall_table[i - 1]),restore); - - kfree(judgk_syscall_ori_table); - return 0; -} -static int syscall_init_hook(){ - ssize_t ret; - int i; - int j; - - struct file *f; - char line[128]; - unsigned char code[3] = {0xff,0x14,0xc5}; - unsigned long addr; - - f = filp_open("/proc/kallsyms",O_RDONLY,0); - set_fs(KERNEL_DS); - - i = 0; - addr = 0; - while(true){ - ret = f->f_op->read(f,&line[i],1,&f->f_pos); - - if(line[i] == '\n' || ret <= 0){ - line[i] = '\0'; - - addr = 0; - for(j = 0;j < i;j++){ - if(line[j] == ' '){ - j++; - break; - } - - addr *= 16UL; - if(line[j] >= '0' && line[j] <= '9'){ - addr += (unsigned long)(line[j] - '0'); - }else{ - addr += (unsigned long)(line[j] - 'a' + 10); - } - } - for(;j < i;j++){ - if(line[j] == ' '){ - j++; - break; - } - } - if(j < i){ - if(strcmp("system_call",line + j) == 0){ - break; - } - } - - i = 0; - }else{ - i++; - } - - if(ret <= 0){ - break; - } - } - - set_fs(USER_DS); - filp_close(f,NULL); - - while(true){ - for(i = 0;i < 3;i++){ - if(*(unsigned char*)addr != code[i]){ - addr++; - break; - } - addr++; - } - if(i == 3){ - break; - } - } - syscall_table = (unsigned long*)(0xffffffff00000000 + *((unsigned int*)addr)); - - addr -= 4L; - while(true){ - if(*(unsigned char*)addr == 0x3d){ - addr++; - break; - } - addr--; - } - syscall_max = *(unsigned int*)addr; - - judgk_syscall_ori_table = kmalloc(sizeof(unsigned long) * (syscall_max + 1),GFP_KERNEL); - memcpy(judgk_syscall_ori_table,syscall_table,sizeof(unsigned long) * syscall_max); - - sort(syscall_whitelist,SYSCALL_WHITELIST_SIZE,sizeof(unsigned int),syscall_whitelist_cmp,NULL); - - return 0; -} -static int syscall_whitelist_cmp(const void *a,const void *b){ - if(*(unsigned int*)a < *(unsigned int*)b){ - return -1; - }else if(*(unsigned int*)a == *(unsigned int*)b){ - return 0; - }else{ - return 1; - } -} -static int syscall_addr_write(unsigned long addr,unsigned int *size,int *restore){ - unsigned int level; - pte_t *pte; - - pte = lookup_address(addr,&level); - if(pte->pte & _PAGE_RW){ - *restore = 0; - }else{ - pte->pte |= _PAGE_RW; - *restore = 1; - } - - switch(level){ - case PG_LEVEL_4K: - *size = 4096; - break; - case PG_LEVEL_2M: - *size = 2097152; - break; - case PG_LEVEL_1G: - *size = 1073741824; - break; - } - *size -= (((unsigned int)addr) & (*size - 1)); - - return 0; -} -static int syscall_addr_restore(unsigned long addr,int restore){ - unsigned int level; - pte_t *pte; - - if(restore){ - pte = lookup_address(addr,&level); - pte->pte ^= _PAGE_RW; - } - - return 0; -} - -long judgk_syscall_check(){ - struct judgk_proc_info *info; - - if((info = judgk_proc_task_lookup(current)) == NULL){ - return 0; - } - - info->status = JUDGE_RF; - send_sig(SIGKILL,current,0); - - return -EACCES; -} - -/*asmlinkage long hook_sys_nanosleep(struct timespec __user *rqtp,struct timespec __user *rmtp){ - long ret; - - struct judgm_proc_info *info; - - atomic64_inc(&syscall_pending); - - info = judgm_proc_task_lookup(current); - if(info == NULL){ - ret = ori_sys_nanosleep(rqtp,rmtp); - atomic64_dec(&syscall_pending); - return ret; - } - - pr_alert("judgm:PID %d nanosleep\n",current->tgid); - - info->status = JUDGE_RF; - send_sig(SIGKILL,current,0); - - atomic64_dec(&syscall_pending); - return -EACCES; -}*/ diff --git a/toj/center/src/judgk_syscall.h b/toj/center/src/judgk_syscall.h deleted file mode 100755 index 143a2db..0000000 --- a/toj/center/src/judgk_syscall.h +++ /dev/null @@ -1,69 +0,0 @@ -#define SYSCALL_WHITELIST_SIZE 45 - -static int syscall_init_hook(void); -static int syscall_whitelist_cmp(const void *a,const void *b); -static int syscall_addr_write(unsigned long addr,unsigned int *size,int *restore); -static int syscall_addr_restore(unsigned long addr,int restore); - -static unsigned long* syscall_table; -static unsigned int syscall_max; -static unsigned int syscall_whitelist[SYSCALL_WHITELIST_SIZE] = { - __NR_execve, - __NR_open, - __NR_creat, - __NR_unlink, - __NR_access, - __NR_truncate, - __NR_stat, - __NR_lstat, - __NR_readlink, - __NR_exit, - __NR_read, - __NR_write, - __NR_close, - __NR_lseek, - __NR_getpid, - __NR_getuid, - __NR_dup, - __NR_brk, - __NR_getgid, - __NR_geteuid, - __NR_getegid, - __NR_dup2, - __NR_ftruncate, - __NR_fstat, - __NR_personality, - __NR_readv, - __NR_writev, - __NR_getresuid, - __NR_pread64, - __NR_pwrite64, - __NR_fcntl, - __NR_mmap, - __NR_munmap, - __NR_ioctl, - __NR_uname, - __NR_gettid, - __NR_set_thread_area, - __NR_get_thread_area, - __NR_set_tid_address, - __NR_exit_group, - __NR_arch_prctl, - __NR_times, - __NR_time, - __NR_clock_gettime, - __NR_dup3 -}; - -int judgk_syscall_hook(void); -int judgk_syscall_unhook(void); -long judgk_syscall_check(void); - -unsigned long *judgk_syscall_ori_table; - -extern struct judgk_proc_info* judgk_proc_task_lookup(struct task_struct *task); -extern long judgk_syscall_block(void); - -//typedef asmlinkage long (*func_sys_nanosleep)(struct timespec __user *rqtp,struct timespec __user *rmtp); -//func_sys_nanosleep ori_sys_nanosleep; -//asmlinkage long hook_sys_nanosleep(struct timespec __user *rqtp,struct timespec __user *rmtp); diff --git a/toj/center/src/judgk_syscall_asm.S b/toj/center/src/judgk_syscall_asm.S deleted file mode 100755 index 03ff960..0000000 --- a/toj/center/src/judgk_syscall_asm.S +++ /dev/null @@ -1,54 +0,0 @@ -.code64 -.section .text -.global judgk_syscall_block -.extern judgk_syscall_check - -judgk_syscall_block: - push %rax - push %rbx - push %rcx - push %rdx - push %rsi - push %rdi - push %rbp - push %r8 - push %r9 - push %r10 - push %r11 - push %r12 - push %r13 - push %r14 - push %r15 - pushfq - - call judgk_syscall_check - - popfq - pop %r15 - pop %r14 - pop %r13 - pop %r12 - pop %r11 - pop %r10 - pop %r9 - pop %r8 - pop %rbp - pop %rdi - pop %rsi - pop %rdx - pop %rcx - pop %rbx - - test %rax,%rax - pop %rax - jnz .block - - push %rdx //use rdx, because mul rax => rdx:rax, kill two birds with one stone - mov $8,%rdx - mul %rdx - pop %rdx - add judgk_syscall_ori_table,%rax - jmp *(%rax) - -.block: - ret diff --git a/toj/center/src/judgm_lib.h b/toj/center/src/judgm_lib.h deleted file mode 100755 index 2007763..0000000 --- a/toj/center/src/judgm_lib.h +++ /dev/null @@ -1,419 +0,0 @@ -#include<string.h> -#include<limits.h> -#include<unistd.h> -#include<signal.h> -#include<limits.h> -#include<errno.h> -#include<pthread.h> -#include<semaphore.h> -#include<fcntl.h> -#include<sys/ioctl.h> -#include<sys/resource.h> -#include<sys/stat.h> -#include<sys/types.h> -#include<sys/wait.h> -#include<sys/mman.h> -#include<map> -#include<utility> - -#include"judge.h" -#include"judgk_com.h" - -typedef int (*judgm_proc_check_fn)(); - -class judgm_proc{ -private: - int init(){ - int i; - int j; - struct stat st; - - if(stat(exe_path,&st)){ - return -1; - } - if(!S_ISREG(st.st_mode)){ - return -1; - } - - exe_name[NAME_MAX] = '\0'; - for(i = 0,j = 0;exe_path[i] != '\0' && j < NAME_MAX;i++){ - if(exe_path[i] == '/'){ - j = 0; - }else{ - exe_name[j] = exe_path[i]; - j++; - } - } - exe_name[j] = '\0'; - - pid = 0; - kern_task = 0; - status = JUDGE_WAIT; - runtime = 0; - memory = 0; - - return 0; - } - int protect(){ - rlimit limit; - judgk_com_proc_add com_proc_add; - - limit.rlim_cur = 1; - limit.rlim_max = limit.rlim_cur; - prlimit(pid,RLIMIT_NPROC,&limit,NULL); - - limit.rlim_cur = 8L; - limit.rlim_max = limit.rlim_cur; - prlimit(pid,RLIMIT_NOFILE,&limit,NULL); - - limit.rlim_cur = 70368744177664L; - limit.rlim_max = limit.rlim_cur; - prlimit(pid,RLIMIT_STACK,&limit,NULL); - - com_proc_add.run_path[0] = '\0'; - strncat(com_proc_add.run_path,run_path,sizeof(com_proc_add.run_path)); - com_proc_add.pid = pid; - com_proc_add.timelimit = timelimit * 1000L; - com_proc_add.hardtimelimit = hardtimelimit * 1000L; - com_proc_add.memlimit = memlimit * 1024L + 4096L * 128L; - if(ioctl(judgk_modfd,IOCTL_PROC_ADD,&com_proc_add)){ - return -1; - } - kern_task = com_proc_add.kern_task; - - return 0; - } - -public: - int judgk_modfd; - char run_path[PATH_MAX + 1]; - char exe_path[PATH_MAX + 1]; - char exe_name[NAME_MAX + 1]; - unsigned long timelimit; - unsigned long hardtimelimit; - unsigned long memlimit; - judgm_proc_check_fn check_fn; - - pid_t pid; - unsigned long kern_task; - int status; - unsigned long runtime; - unsigned long memory; - - judgm_proc(int judgk_modfd,char *runpath,char *exe_path,unsigned long timelimit,unsigned long hardtimelimit,unsigned long memlimit,judgm_proc_check_fn check_fn){ - this->judgk_modfd = judgk_modfd; - this->run_path[0] = '\0'; - strncat(this->run_path,runpath,sizeof(this->run_path)); - this->exe_path[0] = '\0'; - strncat(this->exe_path,exe_path,sizeof(this->exe_path)); - - this->timelimit = timelimit; - this->hardtimelimit = hardtimelimit; - this->memlimit = memlimit; - this->check_fn = check_fn; - } - - int proc_run(){ - char abspath[PATH_MAX + 1]; - - if(init()){ - return -1; - } - - realpath(exe_path,abspath); - if((pid = fork()) == 0){ - char *argv[] = {NULL,NULL}; - char *envp[] = {NULL}; - - chdir(run_path); - check_fn(); - - setgid(99); - setuid(99); - kill(getpid(),SIGSTOP); - - argv[0] = exe_name; - execve(abspath,argv,envp); - exit(0); - } - - if(pid == -1){ - return -1; - } - waitpid(pid,NULL,WUNTRACED); - - if(protect()){ - kill(pid,SIGKILL); - return -1; - } - status = JUDGE_RUN; - kill(pid,SIGCONT); - - return 0; - } - int proc_wait(bool blockflag){ - int wstatus; - struct judgk_com_proc_get com_proc_get; - - if(blockflag == true){ - if(waitpid(pid,&wstatus,WUNTRACED) == -1){ - return -1; - } - }else{ - if(waitpid(pid,&wstatus,WUNTRACED | WNOHANG) <= 0){ - return -1; - } - } - - com_proc_get.kern_task = kern_task; - if(ioctl(judgk_modfd,IOCTL_PROC_GET,&com_proc_get)){ - return -1; - } - - runtime = com_proc_get.runtime / 1000L; - memory = com_proc_get.memory; - - printf("runtime:%lu memory:%lu\n",runtime,memory); - - if(com_proc_get.status != JUDGE_AC){ - status = com_proc_get.status; - }else if(memory > (memlimit * 1024L)){ - status = JUDGE_MLE; - }else if(runtime > timelimit){ - status = JUDGE_TLE; - }else if(WIFEXITED(wstatus) || (WIFSIGNALED(wstatus) && WTERMSIG(wstatus) == SIGKILL)){ - status = JUDGE_AC; - }else{ - status = JUDGE_RE; - } - - return 0; - } - int proc_kill(){ - if(kill(pid,SIGKILL)){ - return -1; - } - return 0; - } -}; - -class judgm_hyperio{ -private: - int judgk_modfd; - char *read_buf; - off_t read_off; - -public: - int tty_idx; - - judgm_hyperio(int judgk_modfd){ - this->judgk_modfd = judgk_modfd; - this->tty_idx = ioctl(this->judgk_modfd,IOCTL_HYPERIO_ADD,0); - this->read_buf = (char*)mmap(NULL,JUDGK_COM_HYPERIO_BUFSIZE,PROT_READ,MAP_SHARED,judgk_modfd,0); - this->read_off = 0; - } - ~judgm_hyperio(){ - munmap(read_buf,JUDGK_COM_HYPERIO_BUFSIZE); - ioctl(judgk_modfd,IOCTL_HYPERIO_DEL,0); - } - - static int get_ttyfd(int idx){ - char tpath[PATH_MAX + 1]; - - snprintf(tpath,sizeof(tpath),"/dev/jtty%d",idx); - return open(tpath,O_RDWR); - } - size_t wait(){ - return ioctl(judgk_modfd,IOCTL_HYPERIO_READ,0); - } - int compare(char *buf,size_t len){ - int flag; - size_t remain; - off_t off; - size_t data_len; - size_t cmp_len; - - flag = 0; - remain = len; - off = 0; - data_len = 0; - cmp_len = 0; - while(remain > 0 && flag == 0){ - if(data_len == 0){ - if((data_len = ioctl(judgk_modfd,IOCTL_HYPERIO_READ,cmp_len)) <= 0){ - return -1; - } - } - if(remain < data_len){ - cmp_len = remain; - }else{ - cmp_len = data_len; - } - - if((cmp_len + read_off) < JUDGK_COM_HYPERIO_BUFSIZE){ - flag |= memcmp(read_buf + read_off,buf + off,cmp_len); - read_off += cmp_len; - }else{ - flag |= memcmp(read_buf + read_off,buf + off,JUDGK_COM_HYPERIO_BUFSIZE - read_off); - flag |= memcmp(read_buf,buf + off + (JUDGK_COM_HYPERIO_BUFSIZE - read_off),(cmp_len + read_off) - JUDGK_COM_HYPERIO_BUFSIZE); - read_off = (cmp_len + read_off) - JUDGK_COM_HYPERIO_BUFSIZE; - } - remain -= cmp_len; - off += cmp_len; - data_len -= cmp_len; - } - if(cmp_len > 0){ - ioctl(judgk_modfd,IOCTL_HYPERIO_READ,-(long)cmp_len); - } - - if(flag == 0){ - return 0; - }else{ - return -1; - } - } -}; - -static int judgm_compile(int subid,char *code_path,char *exe_path,int lang,bool force_flag,char *err_msg,size_t err_len){ - int ret; - int i; - - char log_path[PATH_MAX + 1]; - char main_path[PATH_MAX + 1]; - char sem_path[PATH_MAX + 1]; - struct stat st; - sem_t *wait_sem; - bool ce_flag; - char dir_path[PATH_MAX + 1]; - char *out_path; - int io[2]; - int pid; - int wstatus; - char buf[64]; - off_t err_off; - FILE *f_log; - - if(force_flag == true){ - force_flag = true; - out_path = exe_path; - }else{ - snprintf(log_path,sizeof(log_path),"tmp/exe/%d/log",subid); - snprintf(main_path,sizeof(main_path),"tmp/exe/%d/main",subid); - snprintf(sem_path,sizeof(sem_path),"/judgm_compile_wait_%d",subid); - if((wait_sem = sem_open(sem_path,0)) == SEM_FAILED){ - if(stat(main_path,&st)){ - if((wait_sem = sem_open(sem_path,O_CREAT | O_EXCL,0644,0)) != SEM_FAILED){ - out_path = main_path; - goto compile; - }else if((wait_sem = sem_open(sem_path,0)) != SEM_FAILED){ - - sem_wait(wait_sem); - - sem_close(wait_sem); - } - } - }else{ - - sem_wait(wait_sem); - - sem_close(wait_sem); - } - - if((f_log = fopen(log_path,"r")) != NULL){ - err_off = fread(err_msg,1,err_len - 1,f_log); - fclose(f_log); - err_msg[err_off] = '\0'; - - if(!link(main_path,exe_path)){ - return 0; - }else{ - return -1; - } - } - } - -compile: - - if(force_flag == false){ - snprintf(dir_path,sizeof(dir_path),"tmp/exe/%d",subid); - mkdir(dir_path,0755); - } - ce_flag = false; - err_off = 0; - - if(lang == JUDGE_CPP){ - pipe(io); - - if((pid = fork()) == 0){ - char arg_compiler[16]; - char arg_static[16]; - char arg_o[16]; - char arg_std[16]; - char arg_output[16]; - char *argv[8]; - - arg_compiler[0] = '\0'; - strncat(arg_compiler,"g++",sizeof(arg_compiler)); - arg_static[0] = '\0'; - strncat(arg_static,"-static",sizeof(arg_static)); - arg_o[0] = '\0'; - strncat(arg_o,"-O2",sizeof(arg_o)); - arg_std[0] = '\0'; - strncat(arg_std,"-std=c++0x",sizeof(arg_std)); - arg_output[0] = '\0'; - strncat(arg_output,"-o",sizeof(arg_output)); - - argv[0] = arg_compiler; - argv[1] = arg_static; - argv[2] = arg_o; - argv[3] = code_path; - argv[4] = arg_std; - argv[5] = arg_output; - argv[6] = out_path; - argv[7] = NULL; - - dup2(io[1],1); - dup2(io[1],2); - execvp("g++",argv); - } - - close(io[1]); - while((ret = read(io[0],err_msg + err_off,err_len - err_off - 1)) > 0){ - err_off += ret; - } - err_msg[err_off] = '\0'; - - while(read(io[0],buf,64) > 0); - close(io[0]); - - if(err_off > (err_len - 4)){ - err_msg[err_len - 4] = '\0'; - strncat(err_msg + err_len - 4,"...",4); - err_off = err_len - 1; - } - - waitpid(pid,&wstatus,0); - if(wstatus != 0){ - ce_flag = true; - } - } - - if(force_flag == false){ - f_log = fopen(log_path,"w"); - fwrite(err_msg,err_off,1,f_log); - fclose(f_log); - - for(i = 0;i < JUDGE_THREAD_MAX;i++){ - sem_post(wait_sem); - } - sem_close(wait_sem); - sem_unlink(sem_path); - } - if(ce_flag == true){ - return -1; - } - - link(main_path,exe_path); - - return 0; -} diff --git a/toj/center/src/judgm_line.h b/toj/center/src/judgm_line.h deleted file mode 100755 index 1b36c74..0000000 --- a/toj/center/src/judgm_line.h +++ /dev/null @@ -1,19 +0,0 @@ -struct judgm_line_info{ - int subid; - - char *pro_path; - char *code_path; - char *run_path; - - int judgk_modfd; - void *line_dll; - void *check_dll; - - int lang; - FILE *set_file; - char *set_data; - - char res_data[JUDGE_RES_DATAMAX]; - size_t res_len; -}; -typedef int (*judgm_line_run_fn)(judgm_line_info *info); diff --git a/toj/center/src/judgm_manage.h b/toj/center/src/judgm_manage.h deleted file mode 100755 index 2795ec7..0000000 --- a/toj/center/src/judgm_manage.h +++ /dev/null @@ -1,29 +0,0 @@ -typedef int (*judgm_manage_queuesubmit_fn)(int subid,int proid,int lang,char *set_data,size_t set_len); - -class judgm_manage_info{ -public: - int subid; - int uid; - int proid; - int lang; - char *param; - char pro_path[PATH_MAX + 1]; - char res_path[PATH_MAX + 1]; - - int result; - double score; - unsigned long runtime; - unsigned long memory; - - void *private_data; - - judgm_manage_info(int subid,int uid,int proid,int lang,char *param){ - this->subid = subid; - this->uid = uid; - this->proid = proid; - this->lang = lang; - this->param = param; - } -}; -typedef int (*judgm_manage_submit_fn)(judgm_manage_info *info,FILE *set_file); -typedef int (*judgm_manage_result_fn)(judgm_manage_info *info,char *res_data); diff --git a/toj/center/src/netio.h b/toj/center/src/netio.h deleted file mode 100755 index db54b23..0000000 --- a/toj/center/src/netio.h +++ /dev/null @@ -1,192 +0,0 @@ -class netio_protoiofn{ -public: - virtual void operator()(void *buf,size_t len,void *data) = 0; -}; - -template<typename C> -class netio_iofn : public netio_protoiofn{ -private: - typedef void (C::*netio_iofn_type)(void *buf,size_t len,void *data); - C *obj; - netio_iofn_type fn; - -public: - netio_iofn(C *obj,netio_iofn_type fn){ - this->obj = obj; - this->fn = fn; - } - void operator()(void *buf,size_t len,void *data){ - (obj->*fn)(buf,len,data); - } -}; - -#define NETIO_IOTYPE_PLAIN 0 -#define NETIO_IOTYPE_FILE 1 -class netio_iocb{ -public: - int type; - - void *buf; - int fd; - off_t off; - size_t len; - netio_protoiofn *cb_fn; - void *cb_data; - - netio_iocb(void *buf,size_t len,netio_protoiofn *cb_fn,void *cb_data){ - this->type = NETIO_IOTYPE_PLAIN; - this->buf = buf; - this->off = 0; - this->len = len; - this->cb_fn = cb_fn; - this->cb_data = cb_data; - } - netio_iocb(int fd,size_t len,netio_protoiofn *cb_fn,void *cb_data){ - this->type = NETIO_IOTYPE_FILE; - this->buf = &this->fd; - this->fd = fd; - this->off = 0; - this->len = len; - this->cb_fn = cb_fn; - this->cb_data = cb_data; - } -}; - -#define NETIO_IOSIZE 65536 -class netio{ -private: - netio_iocb *read_iocb; - std::queue<netio_iocb*> write_queue; - bool readio_reen; - char readio_buf[NETIO_IOSIZE]; - -public: - int fd; - virtual int readidle() = 0; - - netio(int fd){ - this->fd = fd; - this->read_iocb = NULL; - this->readio_reen = false; - } - ~netio(){ - close(this->fd); - } - int readio(){ - int ret; - size_t len; - netio_iocb *iocb; - - if(readio_reen == true){ - return -1; - } - readio_reen = true; - - while(true){ - if(read_iocb == NULL){ - readidle(); - } - - iocb = read_iocb; - if(iocb->type == NETIO_IOTYPE_PLAIN){ - while((ret = read(fd,(char*)iocb->buf + iocb->off,iocb->len - iocb->off)) > 0){ - iocb->off += ret; - } - }else if(iocb->type == NETIO_IOTYPE_FILE){ - while(true){ - len = iocb->len - iocb->off; - if(len >= NETIO_IOSIZE){ - len = NETIO_IOSIZE; - } - if((ret = read(fd,readio_buf,len)) <= 0){ - break; - } - - write(iocb->fd,readio_buf,ret); - iocb->off += ret; - } - } - if(iocb->off == iocb->len){ - read_iocb = NULL; - - if(iocb->cb_fn != NULL){ - (*iocb->cb_fn)(iocb->buf,iocb->len,iocb->cb_data); - }else{ - if(iocb->type == NETIO_IOTYPE_PLAIN){ - delete (char*)iocb->buf; - }else if(iocb->type == NETIO_IOTYPE_FILE){ - close(iocb->fd); - } - } - - delete iocb; - }else{ - break; - } - } - - readio_reen = false; - return 0; - } - int readbytes(void *buf,size_t len,netio_protoiofn *cb_fn,void *cb_data){ - read_iocb = new netio_iocb(buf,len,cb_fn,cb_data); - readio(); - return 0; - } - int readfile(int fd,size_t len,netio_protoiofn *cb_fn,void *cb_data){ - read_iocb = new netio_iocb(fd,len,cb_fn,cb_data); - readio(); - return 0; - } - int writeio(){ - int ret; - size_t len; - netio_iocb *iocb; - - while(!write_queue.empty()){ - iocb = write_queue.front(); - if(iocb->type == NETIO_IOTYPE_PLAIN){ - while((ret = write(fd,(char*)iocb->buf + iocb->off,iocb->len - iocb->off)) > 0){ - iocb->off += ret; - } - }else if(iocb->type == NETIO_IOTYPE_FILE){ - len = iocb->len - iocb->off; - if(len >= NETIO_IOSIZE){ - len = NETIO_IOSIZE; - } - while((ret = sendfile(fd,iocb->fd,NULL,len)) > 0){ - iocb->off += ret; - } - } - if(iocb->off == iocb->len){ - write_queue.pop(); - - if(iocb->cb_fn != NULL){ - (*iocb->cb_fn)(iocb->buf,iocb->len,iocb->cb_data); - }else{ - if(iocb->type == NETIO_IOTYPE_PLAIN){ - delete (char*)iocb->buf; - }else if(iocb->type == NETIO_IOTYPE_FILE){ - close(iocb->fd); - } - } - - delete iocb; - }else{ - break; - } - } - - return 0; - } - int writebytes(void *buf,size_t len,netio_protoiofn *cb_fn,void *cb_data){ - write_queue.push(new netio_iocb(buf,len,cb_fn,cb_data)); - writeio(); - return 0; - } - int writefile(int fd,size_t len,netio_protoiofn *cb_fn,void *cb_data){ - write_queue.push(new netio_iocb(fd,len,cb_fn,cb_data)); - writeio(); - return 0; - } -}; diff --git a/toj/center/src/tool.cpp b/toj/center/src/tool.cpp deleted file mode 100644 index 1502007..0000000 --- a/toj/center/src/tool.cpp +++ /dev/null @@ -1,296 +0,0 @@ -#include<string.h> -#include<dirent.h> -#include<unistd.h> -#include<fcntl.h> -#include<limits.h> -#include<ftw.h> -#include<libtar.h> -#include<bzlib.h> -#include<sys/stat.h> -#include<sys/sendfile.h> -#include<map> -#include<vector> -#include<string> - -#include"tool.h" - -static int pack_copenfn(const char *pathname,int flags,...){ - int fd; - pack_bzinfo *bzinfo; - - if((fd = open(pathname,flags,0644)) == -1){ - return -1; - } - - bzinfo = new pack_bzinfo; - bzinfo->len = 0; - bzinfo->off = 0; - bzinfo->endflag = false; - bzinfo->bzs.bzalloc = NULL; - bzinfo->bzs.bzfree = NULL; - bzinfo->bzs.opaque = NULL; - BZ2_bzCompressInit(&bzinfo->bzs,9,0,0); - - pack_fdmap.insert(std::pair<int,pack_bzinfo*>(fd,bzinfo)); - - return fd; -} -static int pack_cclosefn(long fd){ - int ret; - pack_bzinfo *bzinfo; - - bzinfo = pack_fdmap.find(fd)->second; - pack_fdmap.erase(fd); - - bzinfo->bzs.next_in = NULL; - bzinfo->bzs.avail_in = 0; - while(true){ - bzinfo->bzs.next_out = bzinfo->buf; - bzinfo->bzs.avail_out = PACK_BUFSIZE; - ret = BZ2_bzCompress(&bzinfo->bzs,BZ_FINISH); - - if(bzinfo->bzs.avail_out != PACK_BUFSIZE){ - write(fd,bzinfo->buf,PACK_BUFSIZE - bzinfo->bzs.avail_out); - } - if(ret == BZ_STREAM_END){ - break; - } - } - - BZ2_bzCompressEnd(&bzinfo->bzs); - delete bzinfo; - return close(fd); -} -static ssize_t pack_cwritefn(long fd,const void *buf,size_t count){ - pack_bzinfo *bzinfo; - - bzinfo = pack_fdmap.find(fd)->second; - - bzinfo->bzs.next_in = (char*)buf; - bzinfo->bzs.avail_in = count; - while(bzinfo->bzs.avail_in > 0){ - bzinfo->bzs.next_out = bzinfo->buf; - bzinfo->bzs.avail_out = PACK_BUFSIZE; - BZ2_bzCompress(&bzinfo->bzs,BZ_RUN); - if(bzinfo->bzs.avail_out != PACK_BUFSIZE){ - write(fd,bzinfo->buf,PACK_BUFSIZE - bzinfo->bzs.avail_out); - } - } - - return count; -} -static int pack_xopenfn(const char *pathname,int flags,...){ - int fd; - pack_bzinfo *bzinfo; - - if((fd = open(pathname,flags)) == -1){ - return -1; - } - - bzinfo = new pack_bzinfo; - bzinfo->len = 0; - bzinfo->off = 0; - bzinfo->endflag = false; - bzinfo->bzs.bzalloc = NULL; - bzinfo->bzs.bzfree = NULL; - bzinfo->bzs.opaque = NULL; - BZ2_bzDecompressInit(&bzinfo->bzs,0,0); - - printf(" %d\n",fd); - pack_fdmap.insert(std::pair<int,pack_bzinfo*>(fd,bzinfo)); - - return fd; -} -static int pack_xclosefn(long fd){ - int ret; - pack_bzinfo *bzinfo; - - bzinfo = pack_fdmap.find(fd)->second; - pack_fdmap.erase(fd); - BZ2_bzDecompressEnd(&bzinfo->bzs); - delete bzinfo; - - return close(fd); -} -static ssize_t pack_xreadfn(long fd,void *buf,size_t count){ - int ret; - pack_bzinfo *bzinfo; - - printf(" %d\n",fd); - bzinfo = pack_fdmap.find(fd)->second; - - bzinfo->bzs.next_out = (char*)buf; - bzinfo->bzs.avail_out = count; - while(bzinfo->endflag == false){ - if(bzinfo->len == 0){ - ret = read(fd,bzinfo->buf,PACK_BUFSIZE); - bzinfo->len = ret; - bzinfo->off = 0; - } - if(bzinfo->len == 0){ - break; - } - - bzinfo->bzs.next_in = bzinfo->buf + bzinfo->off; - bzinfo->bzs.avail_in = bzinfo->len; - while(bzinfo->bzs.avail_in > 0 && bzinfo->bzs.avail_out > 0){ - if(BZ2_bzDecompress(&bzinfo->bzs) != BZ_OK){ - bzinfo->endflag = true; - break; - } - } - bzinfo->off += bzinfo->len - bzinfo->bzs.avail_in; - bzinfo->len = bzinfo->bzs.avail_in; - - if(bzinfo->bzs.avail_out == 0){ - break; - } - } - - return count - bzinfo->bzs.avail_out; -} - -int tool_pack(char *pack_path,char *dir_path){ - tartype_t tar_type; - TAR *tarp; - char tpath[2] = {'.','\0'}; - - tar_type.openfunc = pack_copenfn; - tar_type.closefunc = pack_cclosefn; - tar_type.readfunc = (readfunc_t)read; - tar_type.writefunc = pack_cwritefn; - tar_open(&tarp,pack_path,&tar_type,O_WRONLY | O_CREAT,0644,TAR_GNU); - - tar_append_tree(tarp,dir_path,tpath); - tar_close(tarp); - - return 0; -} -int tool_unpack(char *pack_path,char *dir_path){ - tartype_t tar_type; - TAR *tarp; - - tool_cleardir(dir_path); - mkdir(dir_path,0775); - - tar_type.openfunc = pack_xopenfn; - tar_type.closefunc = pack_xclosefn; - tar_type.readfunc = pack_xreadfn; - tar_type.writefunc = (writefunc_t)write; - tar_open(&tarp,pack_path,&tar_type,O_RDONLY,0644,TAR_GNU); - - tar_extract_all(tarp,dir_path); - tar_close(tarp); - - return 0; -} - -static int cleardir_callback(const char *path,const struct stat *st,int flag,struct FTW *ftw_buf){ - if(ftw_buf->level == 0){ - return 0; - } - - if(S_ISDIR(st->st_mode)){ - rmdir(path); - }else{ - unlink(path); - } - return 0; -} -int tool_cleardir(char *path){ - nftw(path,cleardir_callback,64,FTW_DEPTH | FTW_PHYS); - return 0; -} -static int copydir_travel(char *old_path,int old_len,char *new_path,int new_len){ - int i; - int j; - int len; - - DIR *dirp; - char *buf; - dirent *entry; - std::vector<std::string> wait_list; - const char *tname; - - int infd; - int outfd; - struct stat st; - - if((dirp = opendir(old_path)) == NULL){ - return -1; - } - buf = new char[sizeof(dirent) + NAME_MAX + 1]; - - while(true){ - readdir_r(dirp,(dirent*)buf,&entry); - if(entry == NULL){ - break; - } - if(strcmp(entry->d_name,".") == 0 || strcmp(entry->d_name,"..") == 0){ - continue; - } - - if(entry->d_type == DT_DIR){ - wait_list.push_back(entry->d_name); - }else{ - old_path[old_len] = '/'; - new_path[new_len] = '/'; - len = strlen(entry->d_name); - for(i = 0;i <= len;i++){ - old_path[old_len + i + 1] = entry->d_name[i]; - new_path[new_len + i + 1] = entry->d_name[i]; - } - - infd = open(old_path,O_RDONLY); - outfd = open(new_path,O_WRONLY | O_CREAT,0644); - fstat(infd,&st); - sendfile(outfd,infd,NULL,st.st_size); - close(infd); - close(outfd); - - old_path[old_len] = '\0'; - new_path[new_len] = '\0'; - } - } - - delete buf; - closedir(dirp); - - while(!wait_list.empty()){ - tname = wait_list.back().c_str(); - wait_list.pop_back(); - - old_path[old_len] = '/'; - new_path[new_len] = '/'; - len = strlen(tname); - for(i = 0;i <= len;i++){ - old_path[old_len + i + 1] = tname[i]; - new_path[new_len + i + 1] = tname[i]; - } - - mkdir(new_path,0775); - - copydir_travel(old_path,old_len + len + 1,new_path,new_len + len + 1); - - old_path[old_len] = '\0'; - new_path[new_len] = '\0'; - } - - return 0; -} -int tool_copydir(char *old_path,char *new_path){ - char old_buf[PATH_MAX + 1]; - char new_buf[PATH_MAX + 1]; - - tool_cleardir(new_path); - mkdir(new_path,0775); - - old_buf[0] = '\0'; - strncat(old_buf,old_path,sizeof(old_buf)); - new_buf[0] = '\0'; - strncat(new_buf,new_path,sizeof(new_buf)); - - copydir_travel(old_buf,strlen(old_buf),new_buf,strlen(new_buf)); - - return 0; -} diff --git a/toj/center/src/tool.h b/toj/center/src/tool.h deleted file mode 100644 index f876c29..0000000 --- a/toj/center/src/tool.h +++ /dev/null @@ -1,26 +0,0 @@ -#define PACK_BUFSIZE 65536 -struct pack_bzinfo{ - bz_stream bzs; - char buf[PACK_BUFSIZE]; - int len; - int off; - bool endflag; -}; - -static int pack_copenfn(const char *pathname,int flags,...); -static int pack_cclosefn(long fd); -static ssize_t cpack_writefn(long fd,const void *buf,size_t count); -static int pack_xopenfn(const char *pathname,int flags,...); -static int pack_xclosefn(long fd); -static ssize_t pack_xreadfn(long fd,void *buf,size_t count); - -static std::map<int,pack_bzinfo*> pack_fdmap; - -int tool_pack(char *pack_path,char *dir_path); -int tool_unpack(char *pack_path,char *dir_path); - -static int cleardir_callback(const char *path,const struct stat *st,int flag,struct FTW *ftw_buf); -static int copydir_travel(char *old_path,int old_len,char *new_path,int new_len); - -int tool_cleardir(char *path); -int tool_copydir(char *old_path,char *new_path); diff --git a/toj/center/src/tpool.h b/toj/center/src/tpool.h deleted file mode 100755 index c06efc1..0000000 --- a/toj/center/src/tpool.h +++ /dev/null @@ -1,175 +0,0 @@ -#include<pthread.h> -#include<semaphore.h> -#include<sys/eventfd.h> -#include<queue> -#include<vector> - -class tpool_protofn{ -public: - virtual void operator()(void *data) = 0; -}; - -template<typename C> -class tpool_fn : public tpool_protofn{ -private: - typedef void (C::*tpool_fn_type)(void *data); - C *obj; - tpool_fn_type fn; - -public: - tpool_fn(C *obj,tpool_fn_type fn){ - this->obj = obj; - this->fn = fn; - } - void operator()(void *data){ - (obj->*fn)(data); - } -}; -class tpool_static_fn : public tpool_protofn{ -private: - typedef void (*tpool_static_fn_type)(void *data); - tpool_static_fn_type fn; - -public: - tpool_static_fn(tpool_static_fn_type fn){ - this->fn = fn; - } - void operator()(void *data){ - fn(data); - } -}; - -class tpool_thcb{ -public: - tpool_protofn *th_fn; - void *th_data; - tpool_protofn *cb_fn; - void *cb_data; - - tpool_thcb(tpool_protofn *th_fn,void *th_data,tpool_protofn *cb_fn,void *cb_data){ - this->th_fn = th_fn; - this->th_data = th_data; - this->cb_fn = cb_fn; - this->cb_data = cb_data; - } - int run(){ - (*th_fn)(th_data); - return 0; - } - int done(){ - if(cb_fn != NULL){ - (*cb_fn)(cb_data); - } - return 0; - } -}; - -#define TPOOL_THREAD_MAXNUM 64 -class tpool{ -private: - std::queue<tpool_thcb*> wait_queue; - std::vector<tpool_thcb*> done_list; - pthread_t pt[TPOOL_THREAD_MAXNUM]; - int pt_num; - sem_t pt_sem; - pthread_mutex_t pt_mutex; - - static void* pt_runfn(void *arg){ - tpool *that; - tpool_thcb *thcb; - long long int sig; - - that = (tpool*)arg; - - while(true){ - - sem_wait(&that->pt_sem); - - pthread_mutex_lock(&that->pt_mutex); - - if(!that->wait_queue.empty()){ - thcb = that->wait_queue.front(); - that->wait_queue.pop(); - }else{ - thcb = NULL; - } - - pthread_mutex_unlock(&that->pt_mutex); - - if(thcb == NULL){ - continue; - } - - thcb->run(); - - pthread_mutex_lock(&that->pt_mutex); - - that->done_list.push_back(thcb); - - pthread_mutex_unlock(&that->pt_mutex); - - sig = 1; - write(that->fd,&sig,sizeof(sig)),that->done_list.size(); - } - return NULL; - } - -public: - int fd; - - tpool(int pt_num){ - if((this->pt_num = pt_num) > TPOOL_THREAD_MAXNUM){ - this->pt_num = TPOOL_THREAD_MAXNUM; - } - fd = eventfd(0,EFD_NONBLOCK); - sem_init(&pt_sem,0,0); - pthread_mutex_init(&pt_mutex,NULL); - } - ~tpool(){ - close(fd); - sem_destroy(&pt_sem); - pthread_mutex_destroy(&pt_mutex); - } - int start(){ - int i; - - for(i = 0;i < pt_num;i++){ - pthread_create(&pt[pt_num],NULL,pt_runfn,this); - } - - return 0; - } - int done(){ - int i; - std::vector<tpool_thcb*> l; - long long int sig; - - pthread_mutex_lock(&pt_mutex); - - l.swap(done_list); - - pthread_mutex_unlock(&pt_mutex); - - for(i = l.size() - 1;i >= 0;i--){ - l[i]->done(); - delete l[i]; - } - - read(fd,&sig,sizeof(sig)); - } - int add(tpool_protofn *th_fn,void *th_data,tpool_protofn *cb_fn,void *cb_data){ - tpool_thcb *thcb; - - thcb = new tpool_thcb(th_fn,th_data,cb_fn,cb_data); - - pthread_mutex_lock(&pt_mutex); - - wait_queue.push(thcb); - - pthread_mutex_unlock(&pt_mutex); - - sem_post(&pt_sem); - - return 0; - } -}; diff --git a/toj/index.html b/toj/index.html deleted file mode 100755 index a96b73a..0000000 --- a/toj/index.html +++ /dev/null @@ -1,473 +0,0 @@ -<!DOCTYPE HTML> -<html> -<head> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<title>Taiwan Online Judge</title> - -<link href='http://fonts.googleapis.com/css?family=Droid+Sans' rel='stylesheet' type='text/css'> - -<link rel="stylesheet" type="text/css" href="/codemirror.css"> -<link rel="stylesheet" type="text/css" href="/lesser-dark.css"> - -<link rel="stylesheet" type="text/css" href="/toj/jcs/ui.css"> -<link rel="stylesheet" type="text/css" href="/toj/jcs/common.css"> -<link rel="stylesheet" type="text/css" href="/toj/jcs/index.css"> -<link rel="stylesheet" type="text/css" href="/toj/jcs/notice.css"> -<link rel="stylesheet" type="text/css" href="/toj/jcs/home.css"> -<link rel="stylesheet" type="text/css" href="/toj/jcs/stat.css"> -<link rel="stylesheet" type="text/css" href="/toj/jcs/user.css"> -<link rel="stylesheet" type="text/css" href="/toj/jcs/sq.css"> -<link rel="stylesheet" type="text/css" href="/toj/jcs/pro.css"> - -<script type="text/javascript" src="/jquery-1.9.1.min.js"></script> -<script type="text/javascript" src="/jquery.easing.1.3.js"></script> -<script type="text/javascript" src="https://www.google.com/jsapi"></script> -<script type="text/javascript" src="/codemirror.js"></script> -<script type="text/javascript" src="/clike.js"></script> -<script type="text/javascript" src="/xml.js"></script> -<script type="text/javascript" src="/javascript.js"></script> -<script type="text/javascript" src="/css.js"></script> -<script type="text/javascript" src="/htmlmixed.js"></script> -<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> -<script type="text/x-mathjax-config"> - MathJax.Hub.Config({ - tex2jax:{inlineMath:[['$','$'],['\\(','\\)']]} - }); -</script> - -<script src="/toj/jcs/common.js"></script> -<script src="/toj/jcs/index.js"></script> -<script src="/toj/jcs/notice.js"></script> -<script src="/toj/jcs/home.js"></script> -<script src="/toj/jcs/stat.js"></script> -<script src="/toj/jcs/user.js"></script> -<script src="/toj/jcs/sq.js"></script> -<script src="/toj/jcs/pro.js"></script> - -<link href='http://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'> -<link href='http://fonts.googleapis.com/css?family=Droid+Sans+Mono' rel='stylesheet' type='text/css'> -<style type="text/css"> -/*@font-face{ - font-family:Droid Sans Mono; - src:url('/DroidSansMono.ttf'); -}*/ - -/*::-webkit-scrollbar{ - width:12px; -} -::-webkit-scrollbar-track{ - background-color:#E9E9E9; -} -::-webkit-scrollbar-thumb { - background-color:rgba(0,0,0,0.4); -} -::-webkit-scrollbar-thumb:window-inactive { - background-color:rgba(0,0,0,0.1); -}*/ - -body{ - color:#E9E9E9; - background-color:#373C38; - font-family:'Roboto','LiHei Pro','微軟正黑體'; - overflow-y:scroll; -} -button{ - height:32px; - margin:0px 0px; - padding:0px 16px 0px 16px; - font-size:16px; - font-family:'Roboto','LiHei Pro','微軟正黑體'; - color:#E9E9E9; - background-color:#00896C; - border:none; - cursor:pointer; -} -button:hover{ - background-color:#24936E; -} -a{ - color:#E9E9E9; - text-decoration:none; -} -a:hover{ - color:#E9E9E9; - text-decoration:underline; -} -input{ - height:32px; - font-size:16px; - font-family:'Roboto','LiHei Pro','微軟正黑體'; - padding:0px 6px 0px 6px; - border-width:0px; - display:block; -} -select{ - height:32px; - font-size:16px; - font-family:'Roboto','LiHei Pro','微軟正黑體'; - border-width:0px; - display:block; -} - -</style> -<script type="text/javascript"> - google.load("visualization","1",{packages:["corechart"]}); - $(document).ready(function(){ - com.init(); - user.init(); - index.init(); - notice.init(); - home.init(); - stat.init(); - sq.init(); - pro.init(); - - com.exheight(); - $(window).resize(function(e){com.exheight();}); - $(window).on('popstate',function(e){ - if(location.href != com.url_curr){ - com.url_prev = com.url_curr; - com.url_curr = location.href; - com.url_chg(); - } - }); - - com.url_chg(); - }); -</script> -</head> -<body> - -<div class="index_head_box"> - <div id="index_head" class="index_head"> - <div class="title">Taiwan Online Judge</div> - <div class="tab_box"></div> - <div class="content_box"></div> - </div> - <div id="index_head_panel" class="panel">開始</div> - <div id="index_head_notice" class="notice" style="display:none">[0]</div> - <div id="index_head_nickname" class="nickname"><a class="nickname"></a></div> -</div> - -<div id="index_panel_box" exminheight=true class="index_panel_box"><ul id="index_panel" class="index_panel"> - <li class="button home"><a href="/toj/home/" class="button">首頁</a></li> - <li class="button stat"><a href="/toj/stat/sub/" class="button">狀態</a></li> - <li class="button user" style="display:none;"><a class="button">個人</a></li> - <li class="button square" style="display:none;"><a class="button">方塊</a></li> - <ul class="square_box"> - <li class="button mgsq"><a class="button"><strong>管理方塊</strong></a></li> - <li class="title"><span class="title">進行中</span></li> - <ul class="run"></ul> - <li class="title"><span class="title">已結束</span></li> - <ul class="past"></ul> - </ul> - - <li class="button login" style="margin:64px 0px 0px 0px; display:none;"><a href="/toj/login/" class="button">登入</a></li> - <li class="button register" style="display:none;"><a href="/toj/register/" class="button">註冊</a></li> - <li class="button logout" style="margin:64px 0px 0px 0px; display:none;"><a href="/toj/logout/" class="button">登出</a></li> -</ul></div> - -<div id="notice_list_box" exminheight=true class="notice_list_box"><ul id="notice_list" class="notice_list"></ul></div> - -<div id="index_page" class="index_page"> - - <div exheight=true extop=32 class="com_pbox home_pbox"> - <audio id="tmpload_audio" src="/tmpload.ogg" preload></audio> - <audio id="tmp_audio" src="/tmp.ogg" preload></audio> - <div id="tmpani" style="width:100%; height:100%; background-color:#0C0C0C;"> - <canvas id="tmpcanv" width=1280 height=720 style="margin:0px auto 0px auto; display:block;"></canvas> - </div> - </div> - - <div class="com_pbox none_pbox"> - <div style="margin:192px 0px 0px 246px;"> - <h1>Oops! 此頁不存在或權限不足</h1> - <a href="/toj/home/" style="margin-left:6px; color:#E9E9E9;">回首頁</a> - </div> - </div> - - <div class="stat_page"> - <div class="com_pbox sub_pbox"> - <div class="subset"> - <table class="filter"> - <tr class="head"> - <th class="key"><strong>過濾器</strong></th> - <th class="value"><button class="clear">清除</button></th> - </tr> - <tr class="item uid"> - <td class="key">UID</td> - <td class="value">None</td> - </tr> - <tr class="item proid"> - <td class="key">ProID</td> - <td class="value"><input type="textbox" value="None"></td> - </tr> - <tr class="item result"> - <td class="key">Result</td> - <td class="value"> - <select> - <option value=null>None</option> - <option value=0>AC</option> - <option value=1>WA</option> - <option value=2>TLE</option> - <option value=3>MLE</option> - <option value=4>RF</option> - <option value=5>RE</option> - <option value=6>CE</option> - </select> - </td> - </tr> - </table> - </div> - <table class="sublist"> - <tr class="head"> - <th class="subid">SubID</th> - <th class="proid" >ProID</th> - <th class="nickname">暱稱</th> - <th class="runtime">執行時間</th> - <th class="memory">記憶體</th> - <th class="result">結果</th> - <th class="score">分數</th> - <th class="time">時間</th> - <th class="lang">語言</th> - </tr> - </table> - </div> - </div> - - <div class="user_page"> - <div class="com_pbox main_pbox"> - <div class="info_box"> - <div class="name"></div> - <img class="avatar"></img> - <div class="aboutme"></div> - </div> - <div class="data_box"> - <button class="looksub">查看動態</button> - <h2>統計</h2> - <div class="statis"> - <div class="subpie chart_box"> - <div class="title">上傳次數</div> - <div class="chart"></div> - </div> - <div class="trypie chart_box"> - <div class="title">嘗試題目</div> - <div class="chart"></div> - </div> - <div class="timecombo chart_box"> - <div class="title">時間</div> - <div class="chart"></div> - </div> - <div style="clear:both"></div> - </div> - <h2>已嘗試題目</h2> - <div class="trylist"></div> - </div> - </div> - <div class="com_pbox edit_pbox"> - <div class="edit_box"> - <h2>個人資料</h2> - <label>暱稱</label> - <input name="nickname" type="textbox"> - <label>照片</label> - <input name="avatar" type="textbox" placeholder="http://example.png"> - <img class="avatar"></img> - <label>關於我</label> - <input name="aboutme" type="textbox"> - <label>電子郵件</label> - <input name="email" type="textbox"><br> - - <h2>重設密碼</h2> - <label>舊使用者密碼</label> - <input name="password_old" type="password"> - <label>新使用者密碼</label> - <input name="password_new" type="password"> - <label>重復新密碼</label> - <input name="password_repeat" type="password"><br> - - <div class="error"></div> - <button class="submit">確定</button> - <button class="cancel">取消</button> - </div> - </div> - <div class="com_pbox mgsq_pbox"> - <div class="in_box"> - <h2>已加入方塊</h2> - <h3>等待中</h3> - <div class="wait"></div><br> - <h3>進行中</h3> - <div class="run"></div><br> - <h3>已結束</h3> - <div class="past"></div> - </div> - <div class="out_box"> - <h2>未加入方塊</h2> - <h3>等待中</h3> - <div class="wait"></div><br> - <h3>進行中</h3> - <div class="run"></div><br> - <h3>已結束</h3> - <div class="past"></div> - </div> - </div> - <div class="com_pbox mg_pbox"> - <div class="left_box"> - <h2>方塊</h2> - <button class="newsq">建立方塊</button> - <h2>題目</h2> - <button class="newpro">建立題目</button> - <table class="prolist"> - <tr class="head"> - <th class="proid">ProID</th> - <th class="name">題目名稱</th> - <th class="cacheid">CacheID</th> - <th></th> - </tr> - </table> - </div> - </div> - </div> - - <div class="sq_page"></div> - - <div class="pro_page"></div> - - <div class="com_pbox login_pbox"> - <div class="info_box"> - <h1>登入TOJ, 開始你的解題</h1> - <strong>沒有帳號?</strong><a href="/toj/register/" style="margin-left:6px; color:#E9E9E9;">註冊</a> - </div> - <div class="login_box"> - <h1>登入</h1> - <div class="error"></div> - <input name="username" type="textbox" placeholder="使用者名稱"> - <input name="password" type="password" placeholder="使用者密碼"> - <button>登入</button> - </div> - </div> - - <div class="com_pbox register_pbox"> - <div class="info_box"> - <h1>註冊TOJ, 開始你的解題</h1> - <strong>有帳號?</strong><a href="/toj/login/" style="margin-left:6px; color:#E9E9E9;">登入</a> - </div> - <div class="register_box"> - <h1>註冊</h1> - <div class="error"></div> - <input name="username" type="textbox" placeholder="使用者名稱"> - <input name="password" type="password" placeholder="使用者密碼"> - <input name="password_repeat" type="password" placeholder="重復密碼"> - <input name="nickname" type="textbox" placeholder="暱稱"> - <input name="email" type="textbox" placeholder="電子郵件"> - <button>註冊</button> - </div> - </div> - -</div> - -<div id="index_mask" class="index_mask_nopbox"> - <button class="close">關閉</button> - - <div class="user_mask"> - <div class="com_mbox editsq_mbox"> - <div class="edit_box"> - <h2>基本資料</h2> - <label>方塊名稱</label> - <input name="sqname" type="textbox" size="16" placeholder="foo"> - <label>模組名稱</label> - <input name="sqmodname" type="textbox" size="16" placeholder="sqmod_foo"> - <label>隱私</label> - <select name="publicity"> - <option value=3>公開</option> - <option value=2>可申請</option> - <option value=1>秘密</option> - </select> - <label>時間限制</label> - <select name="infinite"> - <option value=1>無時限</option> - <option value=2>有時限</option> - </select> - <div class="time" style="display:none;"> - <label>開始時間</label><br> - <input name="s_year" type="textbox" size="1" placeholder="2501" style="display:inline-block"> - <input name="s_month" type="textbox" size="1" placeholder="1" style="display:inline-block"> - <input name="s_day" type="textbox" size="1" placeholder="1" style="display:inline-block"> - <input name="s_hr" type="textbox" size="1" placeholder="18" style="margin:0px 0px 0px 6px; display:inline-block"> - <input name="s_min" type="textbox" size="1" placeholder="30" style="display:inline-block"><br> - <label>結束時間</label><br> - <input name="e_year" type="textbox" size="1" placeholder="2501" style="display:inline-block"> - <input name="e_month" type="textbox" size="1" placeholder="1" style="display:inline-block"> - <input name="e_day" type="textbox" size="1" placeholder="1" style="display:inline-block"> - <input name="e_hr" type="textbox" size="1" placeholder="18" style="margin:0px 0px 0px 6px; display:inline-block"> - <input name="e_min" type="textbox" size="1" placeholder="30" style="display:inline-block"> - </div> - - <div class="error"></div> - <button class="submit">確定</button> - <button class="cancel">取消</button> - <button class="delete" style="display:none;">刪除</button> - </div> - <div class="pro_box"> - <h2>已加入題目</h2> - <div class="prolist_box"> - <table class="prolist prolist_in"></table> - </div> - <h2>未加入題目</h2> - <div class="prolist_box"> - <table class="prolist prolist_out"></table> - </div> - </div> - <div style="width:100%; clear:both;"></div> - </div> - <div class="com_mbox editpro_mbox"> - <div class="edit_box"> - <h2>基本資料</h2> - <label>題目名稱</label> - <input name="name" type="textbox" size="16" placeholder="foo"> - <label>模組ID</label> - <input name="modid" type="textbox" size="16" placeholder="1"> - <label>隱私</label> - <select name="hidden"> - <option value=1>公開</option> - <option value=2>隱藏</option> - </select> - <div class="update" style="display:none;"> - <h2>更新題目</h2> - <span class="cacheid"></span><br><br> - <button class="update">更新</button> - <button class="rejudge">重測</button> - </div> - - <div class="error"></div> - <button class="submit">確定</button> - <button class="cancel">取消</button> - <button class="delete" style="">刪除</button> - </div> - </div> - </div> - <div class="pro_mask"> - <div exheight=true extop=32 exbottom=32 class="com_mbox sub_mbox"> - <div class="head"> - <div class="title"></div> - <div class="error"></div> - <div class="oper"> - <select name="lang" style="display:inline-block;"> - <option value="1">C++</option> - </select> - <button class="submit">確定</button> - </div> - </div> - <div exheight=true extop=76 exbottom=38 class="codebox"></div> - </div> - </div> - <div class="stat_mask"> - <div class="com_mbox subres_mbox"></div> - <div class="com_mbox subfile_mbox"> - <button class="result" style="margin:6px 0px 0px 0px; float:right;">結果</button> - <h2 class="subid"></h2> - </div> - </div> -</div> - -</body> -</html> diff --git a/toj/jcs/common.css b/toj/jcs/common.css deleted file mode 100755 index f05adea..0000000 --- a/toj/jcs/common.css +++ /dev/null @@ -1,14 +0,0 @@ -div.com_pbox{ - width:1224px; - margin:0px auto 0px auto; - position:relative; - display:none; -} -div.com_mbox{ - width:978px; - margin:32px auto 32px auto; - padding:0px 6px 0px 6px; - background-color:#373C38; - position:relative; - display:none; -} diff --git a/toj/jcs/common.js b/toj/jcs/common.js deleted file mode 100755 index 6d4f0d3..0000000 --- a/toj/jcs/common.js +++ /dev/null @@ -1,496 +0,0 @@ -var RESULTMAP = {0:'AC',1:'WA',2:'TLE',3:'MLE',4:'RF',5:'RE',6:'CE',7:'ERR',100:'WAIT'}; -var RESULTCOLOR = {0:'#00FF00',1:'#FF0000',2:'#FFFFFF',3:'#FFFFFF',4:'#FFFFFF',5:'#FFFFFF',6:'#FFFFFF',7:'#FFFFFF',100:'#FFFFFF'}; - -var USER_PER_USER = 0x00000001; -var USER_PER_PROCREATOR = 0x00000002; -var USER_PER_PROADMIN = 0x00000004; - -var USER_LEVEL_USER = 0x00000001; -var USER_LEVEL_PROCREATOR = 0x00000003; -var USER_LEVEL_PROADMIN = 0x00000007; -var USER_LEVEL_ADMIN = 0x0000ffff; -var USER_LEVEL_SUPERADMIN = -1; - -var __extend = function(child,parent){ - child.prototype.__super = parent; -}; - -var vus = new function(){ - var that = this; - - that.node = function(name){ - var that = this; - that.name = name; - that.parent = null; - that.ref_count = 1; - that.child = new Object; - that.delay_child = new Object; - - that.url_chg = function(direct,url_upart,url_dpart){ - return 'cont'; - }; - that.get = function(){ - that.ref_count++; - }; - that.child_set = function(node){ - var delay_obj; - - node.parent = that; - that.child[node.name] = node; - - if(node.name in that.delay_child){ - delay_obj = that.delay_child[node.name]; - delete that.delay_child[node.name]; - delay_obj.defer.resolve(); - } - }; - that.child_delayset = function(name){ - that.delay_child[name] = { - 'defer':$.Deferred() - }; - }; - that.child_del = function(node){ - node.parent = null; - delete that.child[node.name]; - }; - that.lookup = function(url,close_flag){ - var i; - var url_part; - var node_curr; - var node_prev; - - url_part = url.match(/\/toj\/(.*)/)[1].split('/'); - url_part.pop(); - node_prev = null; - node_curr = that; - for(i = 0;i < url_part.length;i++){ - node_prev = node_curr; - if((node_curr = node_curr.child[url_part[i]]) == undefined){ - if(close_flag == true){ - return node_prev; - }else{ - return null; - } - } - } - return node_curr; - } - }; -}; -var com = new function(){ - var that = this; - - var check_mbox_url = function(url){ - if(url.search(/toj\/m\/.*/) != -1){ - return true; - }else{ - return false; - } - } - - that.url_curr = null; - that.url_prev = null; - that.url_back = null; - that.url_pbox = null; - - that.init = function(){ - var i; - var url; - var urlpart; - - that.vus_root = new vus.node(null); - that.vus_mbox = new vus.node('m'); - - that.vus_mbox.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - index.mask_show(); - }else if(direct == 'out'){ - index.mask_hide(); - } - - return 'cont'; - }; - that.vus_root.child_set(that.vus_mbox); - - urlpart = location.href.split('?'); - if(urlpart[0].search(/\/$/) == -1){ - url = urlpart[0] + '/'; - if(urlpart.length > 1){ - url = url + '?'; - for(i = 1;i < urlpart.length;i++){ - url = url + urlpart[i]; - } - } - window.history.replaceState(null,document.title,url); - } - - $(document).on('click','a',function(e){ - that.url_push($(this).attr('href')); - return false; - }); - }; - - that.url_push = function(url){ - if(url == location.href){ - return; - } - - that.url_prev = location.href; - that.url_back = that.url_prev; - window.history.pushState(null,document.title,url); - that.url_chg(); - }; - that.url_push_back = function(block_regexp){ - if(that.url_back == null || that.url_back.search(block_regexp) != -1){ - that.url_push('/toj/home/'); - }else{ - that.url_push(that.url_back); - } - }; - that.url_update = function(url){ - if(url == location.href){ - return; - } - - that.url_prev = location.href; - window.history.replaceState(null,document.title,url); - that.url_chg(); - }; - that.url_pull_pbox = function(){ - that.url_update(that.url_pbox); - //window.history.back(); - }; - that.url_chg = function(){ - var i; - var ret; - var stop_flag; - - var url_old; - var url_new; - var url_cpart; - var url_ppart; - var is_mbox_old; - var is_mbox_new; - - var url_upart; - var url_dpart; - var node_curr; - var node_parent; - var node_bottom; - - var _chg_out = function(url_ppart,url_cpart){ - var i; - var len; - - var url_upart; - var url_dpart; - var node_curr; - var node_parent; - var node_bottom; - - len = Math.min(url_ppart.length,url_cpart.length); - node_bottom = that.vus_root; - node_curr = node_bottom; - for(i = 0;i < len;i++){ - if(url_ppart[i] != url_cpart[i]){ - break; - } - if((node_curr = node_curr.child[url_ppart[i]]) == undefined){ - break; - } - node_bottom = node_curr; - } - if(node_curr != undefined){ - for(;i < url_ppart.length;i++){ - if(node_curr.child[url_ppart[i]] == undefined){ - break; - } - node_curr = node_curr.child[url_ppart[i]]; - } - - url_upart = url_ppart.slice(0); - url_dpart = new Array; - while(node_curr != node_bottom){ - node_parent = node_curr.parent; - node_curr.url_chg('out',url_upart,url_dpart); - url_dpart = url_dpart.splice(0,0,url_upart.pop()); - node_curr = node_parent; - } - } - - return node_bottom; - }; - var _chg_in = function(url_cpart,idx,node_curr,url_upart,url_dpart){ - var node_parent; - var delay_obj; - - for(;idx < url_cpart.length;idx++){ - node_parent = node_curr; - if((node_curr = node_parent.child[url_cpart[idx]]) == undefined){ - if((delay_obj = node_parent.delay_child[url_cpart[idx]]) == undefined){ - that.url_update('/toj/none/'); - }else{ - delay_obj.url_curr = url_new; - delay_obj.defer.done(function(){ - if(url_new == delay_obj.url_curr){ - _chg_in(url_cpart,idx,node_parent,url_upart,url_dpart); - } - }); - } - break; - } - url_upart.push(url_dpart.shift()); - - ret = node_curr.url_chg('in',url_upart,url_dpart); - if(ret == 'stop'){ - break; - } - } - }; - - that.url_curr = location.href; - console.log(that.url_curr); - - if(arguments.callee.reentrant == true){ - arguments.callee.hasnext = true; - return; - }else{ - arguments.callee.reentrant = true; - arguments.callee.hasnext = true; - } - - while(arguments.callee.hasnext){ - arguments.callee.hasnext = false; - - url_old = that.url_prev; - url_new = that.url_curr; - - url_cpart = url_new.match(/toj\/(.*)/)[1].split('/'); - url_cpart.pop(); - if(url_cpart.length == 0){ - that.url_update('/toj/home/'); - continue; - } - - if(url_old == null){ - is_mbox_old = false; - }else{ - is_mbox_old = check_mbox_url(url_old); - } - is_mbox_new = check_mbox_url(url_new); - - if(url_old == null || (is_mbox_old == false && is_mbox_new == true)){ - node_bottom = that.vus_root; - }else if(that.url_pbox != null && is_mbox_old == true && is_mbox_new == false){ - url_ppart = that.url_pbox.match(/toj\/(.*)/)[1].split('/'); - url_ppart.pop(); - node_bottom = _chg_out(url_ppart,url_cpart); - }else{ - url_ppart = url_old.match(/toj\/(.*)/)[1].split('/'); - url_ppart.pop(); - node_bottom = _chg_out(url_ppart,url_cpart); - } - - if(url_old != null && is_mbox_old == false && is_mbox_new == false){ - index.page_scroll_reset(); - } - - if(url_new != that.url_pbox){ - i = 0; - node_curr = that.vus_root; - url_upart = new Array; - url_dpart = url_cpart.slice(0); - stop_flag = false; - while(node_curr != node_bottom){ - if((node_curr = node_curr.child[url_cpart[i]]) == undefined){ - break; - } - url_upart.push(url_dpart.shift()); - ret = node_curr.url_chg('same',url_upart,url_dpart); - if(ret == 'stop'){ - stop_flag = true; - break; - } - i++; - } - if(stop_flag == false){ - _chg_in(url_cpart,i,node_curr,url_upart,url_dpart); - } - } - - if(that.url_pbox != null && is_mbox_old == true && is_mbox_new == false){ - url_ppart = url_old.match(/toj\/(.*)/)[1].split('/'); - url_ppart.pop(); - _chg_out(url_ppart,url_cpart); - } - - if(is_mbox_new == false){ - if(that.url_pbox == null){ - $('#index_mask').removeClass('index_mask_nopbox'); - $('#index_mask').addClass('index_mask'); - } - that.url_pbox = url_new; - } - } - - arguments.callee.reentrant = false; - }; - - that.exheight = function(){ - var _ex = function(es,css){ - var i; - var extop; - var exbottom; - var j_e; - var j_parent; - - for(i = 0;i < es.length;i++){ - j_e = $(es[i]); - if((extop = j_e.attr('extop')) == undefined){ - extop = j_e.css('top').match(/(.+)px/)[1]; - } - if((exbottom = j_e.attr('exbottom')) == undefined){ - exbottom = 0; - } - extop = parseInt(extop); - exbottom = parseInt(exbottom); - - j_e.css(css,($(window).height() - (extop + exbottom) + 'px')); - } - }; - - _ex($('[exheight=true]'),'height'); - _ex($('[exminheight=true]'),'min-height'); - }; - that.get_cookie = function(){ - var ret; - var i; - var part; - var subpart; - - ret = new Array(); - part = document.cookie.split(';'); - for(i = 0;i < part.length;i++){ - part[i] = part[i].replace(/\+/g,' '); - subpart = part[i].split('='); - ret[decodeURIComponent(subpart[0])] = decodeURIComponent(subpart[1]); - } - - return ret; - }; - that.get_date = function(str){ - var part; - part = str.match(/(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/); - return new Date(part[1],parseInt(part[2]) - 1,part[3],part[4],part[5],part[6],0); - }; - that.get_datestring = function(date,secflag){ - var month; - var day; - var hr; - var min; - var sec; - - month = date.getMonth() + 1; - if(month < 10){ - month = '0' + month; - } - day = date.getDate(); - if(day < 10){ - day = '0' + day; - } - hr = date.getHours(); - if(hr < 10){ - hr = '0' + hr; - } - min = date.getMinutes(); - if(min < 10){ - min = '0' + min; - } - if(secflag == true){ - sec = date.getSeconds(); - if(sec < 10){ - sec = '0' + sec; - } - - return date.getFullYear() + '-' + month + '-' + day + ' ' + hr + ':' + min + ':' + sec; - }else{ - return date.getFullYear() + '-' + month + '-' + day + ' ' + hr + ':' + min; - } - }; - that.get_durstring = function(duration,secflag){ - var sec; - var min; - var hr; - var day; - - duration = Math.floor(duration / 1000); - - sec = duration % 60; - duration = Math.floor(duration / 60); - if(sec < 10){ - sec = '0' + sec; - } - - min = duration % 60; - duration = Math.floor(duration / 60); - if(min < 10){ - min = '0' + min; - } - - hr = duration % 24; - duration = Math.floor(duration / 24); - if(hr < 10){ - hr = '0' + hr; - } - - day = duration; - if(day == 0){ - day = ''; - }else{ - day = day + ':'; - } - - if(secflag == true){ - return day + hr + ':' + min + ':' + sec; - }else{ - return day + hr + ':' + min; - } - }; - that.get_lang = function(value){ - var i; - var ret; - var langlist = ['C++','JAVA','Pascal']; - - ret = new Array; - i = 0; - while(value > 0){ - if((value & 1) == 1){ - ret.push(langlist[i]); - } - value = value >> 1; - } - - return ret; - }; -}; - -var class_com_pbox = function(){ - var that = this; - - that.fadein = function(j_e){ - j_e.stop().fadeIn('fast'); - }; - that.fadeout = function(j_e){ - j_e.stop().hide(); - }; -}; -var class_com_mbox = function(){ - var that = this; - - that.fadein = function(j_e){ - j_e.stop().show(); - }; - that.fadeout = function(j_e){ - j_e.stop().hide(); - }; -}; diff --git a/toj/jcs/home.css b/toj/jcs/home.css deleted file mode 100755 index e69de29..0000000 --- a/toj/jcs/home.css +++ /dev/null diff --git a/toj/jcs/home.js b/toj/jcs/home.js deleted file mode 100755 index d84d7ec..0000000 --- a/toj/jcs/home.js +++ /dev/null @@ -1,473 +0,0 @@ -var home = new function(){ - var that = this; - - that.init = function(){ - home.home_pbox = new class_home_pbox; - home.none_pbox = new class_none_pbox; - } -}; - -var class_home_pbox = function(){ - var that = this; - var j_pbox = $('#index_page > div.home_pbox'); - - that.node = new vus.node('home'); - - that.__super(); - - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - that.fadein(j_pbox); - index.title_set('Taiwan Online Judge (for sprout)'); - tmp(); - }else if(direct == 'out'){ - that.fadeout(j_pbox); - tmp_stop = true; - } - - return 'cont'; - } - com.vus_root.child_set(that.node); - - var tmp_stop = true; - var tmp_first = true; - - var load; - var prog = 0; - var bd = Math.PI / 180; - - var co_table = [ - '255,255,0', - '255,0,255', - '255,255,0', - '255,255,255', - '17,50,133', - '203,27,69', - '233,139,42', - '186,145,50', - '123,162,63', - '27,129,62', - '0,170,144', - '0,137,167', - '0,92,175', - '203,64,66', - '233,205,76', - '232,48,21', - '255,196,8' - ]; - - var st; - var et; - var pa_off = 0; - var pa_c = 6; - var pa_co = 0; - var pb_off = 0; - var pb_c = 6; - var pb_co = 0; - - function tmp(){ - var e_ani; - var e_canvas; - var ctx; - var e_audio; - - function drawTextAlongArc(context,str,centerX,centerY,radius,angle,offangle) { - var len = str.length, s; - context.save(); - context.translate(centerX,centerY); - context.rotate(-1 * offangle); - context.rotate(-1 * angle / 2); - context.rotate(-1 * (angle / len) / 2); - for(var n = 0; n < len; n++) { - context.rotate(angle / len); - context.save(); - context.translate(0, -1 * radius); - s = str[n]; - context.fillText(s,0,0); - context.restore(); - } - context.restore(); - } - function drawRect(ctx,x,y,w,h){ - ctx.beginPath(); - ctx.rect(x,y,w,h); - ctx.fill(); - } - function drawCircle(ctx,x,y,r,a,off){ - ctx.beginPath(); - ctx.arc(x,y,r,off,a + off,false); - ctx.stroke(); - } - function drawLine(ctx,ax,ay,bx,by){ - ctx.beginPath(); - ctx.moveTo(ax,ay); - ctx.lineTo(bx,by); - ctx.stroke(); - } - function drawPoly(ctx,x,y,r,c,offangle){ - var i; - - ctx.save(); - ctx.beginPath(); - ctx.translate(x,y); - ctx.rotate(-1 * offangle); - ctx.moveTo(0,-r); - for(i = 1;i <= c;i++){ - ctx.rotate(bd * 360 / c); - ctx.lineTo(0,-r); - } - ctx.stroke(); - ctx.restore(); - } - - var ani = function(){ - var i; - var u,v; - - if(tmp_stop == true){ - return; - } - - et = new Date().getTime(); - if((et - st) < 20){ - window.requestAnimationFrame(ani); - return; - } - ctx.clearRect(0,0,1920,1080); - - ctx.fillStyle = 'rgba(128,128,128,1)'; - ctx.shadowBlur = 0; - - ctx.strokeStyle = 'rgba(30,30,30,1)'; - ctx.lineWidth = 2; - u = 3000 - (prog % 240) / 240 * 3000; - for(i = 0;i < 12;i++){ - v = (u + i * 250) % 3000; - drawLine(ctx,v - 540,-5,v - 1040,1085); - } - ctx.strokeStyle = 'rgba(30,30,30,1)'; - ctx.lineWidth = 2; - u = 2500 - (prog % 240) / 240 * 2500; - for(i = 0;i < 10;i++){ - v = (u + i * 250) % 2500; - drawLine(ctx,-5,v - 1250,1925,v - 540); - } - - ctx.strokeStyle = 'rgba(128,128,128,1)'; - - ctx.lineWidth = 12; - drawCircle(ctx,700,500,550,bd * 30,-bd * (prog % 360)); - drawCircle(ctx,700,500,550,bd * 30,-bd * (prog % 360 + 120)); - drawCircle(ctx,700,500,550,bd * 30,-bd * (prog % 360 + 240)); - - ctx.lineWidth = 8; - drawCircle(ctx,700,500,450,bd * 360,0); - - ctx.lineWidth = 16; - drawCircle(ctx,700,500,440,bd * 60,-bd * ((prog * 2) % 360)); - drawCircle(ctx,700,500,440,bd * 60,-bd * ((prog * 2) % 360 + 120)); - drawCircle(ctx,700,500,440,bd * 60,-bd * ((prog * 2) % 360 + 240)); - - ctx.lineWidth = 10; - drawCircle(ctx,700,500,390,bd * 60,bd * ((prog * 7) % 360 + 160)); - ctx.lineWidth = 8; - drawCircle(ctx,700,500,370,bd * 30,-bd * ((prog * 8) % 360 + 290)); - - ctx.lineWidth = 8; - drawCircle(ctx,700,500,350,bd * 60,bd * ((prog * 3) % 360)); - ctx.lineWidth = 38; - drawCircle(ctx,700,500,335,bd * 20,bd * ((prog * 3) % 360 + 59)); - ctx.lineWidth = 8; - drawCircle(ctx,700,500,320,bd * 80,bd * ((prog * 3) % 360 + 60)); - - ctx.lineWidth = 8; - drawCircle(ctx,700,500,350,bd * 50,bd * ((prog * 3) % 360 + 200)); - ctx.lineWidth = 28; - drawCircle(ctx,700,500,340,bd * 40,bd * ((prog * 3) % 360 + 249)); - ctx.lineWidth = 8; - drawCircle(ctx,700,500,330,bd * 60,bd * ((prog * 3) % 360 + 260)); - - if(prog % 6 < 4 || prog < 456 || prog > 912){ - ctx.lineWidth = 4; - drawCircle(ctx,700,500,300,bd * 360,0); - ctx.lineWidth = 16; - drawCircle(ctx,700,500,295,bd * 80,-bd * ((prog * 4) % 360 + 90)); - } - - ctx.lineWidth = 8; - drawCircle(ctx,700,500,260,bd * 90,bd * ((prog * 6) % 360 + 120)); - drawCircle(ctx,700,500,210,bd * 160,bd * ((prog * 3) % 360 + 270)); - drawCircle(ctx,700,500,230,bd * 120,-bd * ((prog * 5) % 360 + 120)); - - ctx.strokeStyle = 'rgba(128,128,128,' + (1 - (prog % 24)/24) + ')'; - ctx.lineWidth = 8; - drawCircle(ctx,700,500,80 + (prog % 24) * 4,bd * 360,0); - ctx.lineWidth = 4; - drawCircle(ctx,700,500,70 + (prog % 24) * 4,bd * 360,0); - - ctx.font = 'bold 16px tahoma'; - drawTextAlongArc(ctx,"Hello TOJ [sprout]",700,500,460,bd * 60,bd * (prog % 360 + 115) * 2); - drawTextAlongArc(ctx,"Are You Happy?",700,500,460,bd * 50,bd * (prog % 360 + 30) * 2); - - if(prog < 456 || prog > 912){ - ctx.strokeStyle = 'rgba(255,255,255,1)'; - ctx.lineWidth = 6; - drawCircle(ctx,700,500,60,bd * 60,bd * ((prog * 4) % 360)); - drawCircle(ctx,700,500,60,bd * 60,bd * ((prog * 4) % 360 + 180)); - }else{ - u = prog % 48; - if(u == 0){ - pa_off = bd * (prog % 373); - pa_c = prog % 5 + 3; - pa_co = Math.round(Math.random() * co_table.length); - } - ctx.strokeStyle = 'rgba(' + co_table[pa_co] + ',' + (1 - u / 48) + ')'; - drawPoly(ctx,700,500,u * 20,pa_c,pa_off); - u = (prog + 24) % 48; - if(u == 0){ - pb_off = bd * (prog % 173); - pb_c = prog % 5 + 3; - pb_co = Math.round(Math.random() * co_table.length); - } - ctx.strokeStyle = 'rgba(' + co_table[pb_co] + ',' + (1 - u / 48) + ')'; - drawPoly(ctx,700,500,u * 20,pb_c,pb_off); - - ctx.strokeStyle = 'rgba(255,255,255,1)'; - ctx.lineWidth = 6; - drawCircle(ctx,700,500,40,bd * 60,-bd * ((prog * 15) % 360)); - drawCircle(ctx,700,500,40,bd * 60,-bd * ((prog * 15) % 360 + 180)); - } - - v = prog % 96; - if((v >= 24 && v < 26)|| (v >= 28 && v < 30)){ - ctx.shadowBlur = 8; - }else{ - ctx.shadowBlur = 0; - } - - ctx.font = 'bold 64px tahoma'; - u = 0; - ctx.fillStyle = 'rgba(255,255,0,1)'; - ctx.shadowColor = 'rgba(255,255,0,1)'; - ctx.fillText('T',1000 + u,600); - ctx.fillStyle = 'rgba(255,255,255,1)'; - ctx.shadowColor = 'rgba(255,255,255,1)'; - u += ctx.measureText('T').width; - ctx.fillText('aiwan',1000 + u,600); - u += ctx.measureText('aiwan').width; - - if((v >= 32 && v < 34)|| (v >= 36 && v < 38)){ - ctx.shadowBlur = 8; - }else{ - ctx.shadowBlur = 0; - } - - ctx.fillStyle = 'rgba(255,0,255,1)'; - ctx.shadowColor = 'rgba(255,0,255,1)'; - ctx.fillText(' O',1000 + u,600); - ctx.fillStyle = 'rgba(255,255,255,1)'; - ctx.shadowColor = 'rgba(255,255,255,1)'; - u += ctx.measureText(' O').width; - ctx.fillText('nline',1000 + u,600); - u += ctx.measureText('nline').width; - - if((v >= 40 && v < 42)|| (v >= 44 && v < 46)){ - ctx.shadowBlur = 8; - }else{ - ctx.shadowBlur = 0; - } - - ctx.fillStyle = 'rgba(0,255,255,1)'; - ctx.shadowColor = 'rgba(0,255,255,1)'; - ctx.fillText(' J',1000 + u,600); - ctx.fillStyle = 'rgba(255,255,255,1)'; - ctx.shadowColor = 'rgba(255,255,255,1)'; - u += ctx.measureText(' J').width; - ctx.fillText('udge',1000 + u,600); - - ctx.shadowBlur = 0; - - ctx.fillStyle = 'rgba(255,196,8,0.9)'; - drawRect(ctx,0,930,1920,70); - - ctx.font = 'bold 50px 微軟正黑體'; - ctx.fillStyle = 'rgba(255,255,255,1)'; - ctx.fillText('Taiwan Online Judge (for sprout) システムテスト',1920 - (prog % 720) / 720 * 3000,980); - ctx.fillText('Taiwan Online Judge (for sprout) システムテスト',1920 - ((prog + 360) % 720) / 720 * 3000,980); - - ctx.font = 'bold 36px 微軟正黑體'; - u = ctx.measureText('Parallel Judge 使用可能').width + 64; - ctx.fillText('Parallel Judge 使用可能',1920 - u,64); - - if(prog % 24 < 12){ - ctx.font = 'bold 36px 微軟正黑體'; - u = ctx.measureText('INSERT COIN[S]').width + 64; - ctx.fillText('INSERT COIN[S]',1920 - u,1045); - } - - if(prog <= 45){ - ctx.fillStyle = 'rgba(8,8,8,1)'; - drawRect(ctx,0,0,1920,1080); - }else if(prog < 50){ - ctx.fillStyle = 'rgba(8,8,8,' + (1 - (prog / 50)) + ')'; - drawRect(ctx,0,0,1920,1080); - } - - if(prog > 25){ - if(prog <= 45){ - ctx.fillStyle = 'rgba(255,255,0,1)'; - drawRect(ctx,1000 * ((prog - 25) / 20) * 4 - 3000,500,200,128); - ctx.fillStyle = 'rgba(255,0,255,1)'; - drawRect(ctx,1200 * ((prog - 25) / 20) * 4 - 3600,500,200,128); - ctx.fillStyle = 'rgba(0,255,255,1)'; - drawRect(ctx,1400 * ((prog - 25) / 20) * 4 - 4200,500,200,128); - }else if(prog < 50){ - ctx.fillStyle = 'rgba(255,255,0,' + (1 - (prog / 50)) + ')'; - drawRect(ctx,1000,500,200,128); - ctx.fillStyle = 'rgba(255,0,255,' + (1 - (prog / 50)) + ')'; - drawRect(ctx,1200,500,200,128); - ctx.fillStyle = 'rgba(0,255,255,' + (1 - (prog / 50)) + ')'; - drawRect(ctx,1400,500,200,128); - } - } - - st = et; - prog++; - if(prog == 1080){ - prog = 360; - } - window.requestAnimationFrame(ani); - }; - - var loadani = function(){ - var u; - var v; - - ctx.clearRect(0,0,1920,1080); - - if(tmp_stop == true){ - return; - } - - if(prog < 50){ - u = 0; - }else if(prog < 100){ - u = (prog - 50) / 50; - }else if(prog < 250){ - u = 1; - }else if(prog < 300){ - u = (300 - prog) / 50; - }else{ - u = 0; - } - - ctx.fillStyle = 'rgba(8,8,8,1)'; - drawRect(ctx,0,0,320,1080); - - //v = ctx.measureText('TF ∪ CK').width; - //ctx.fillStyle = 'rgba(128,0,0,' + u + ')'; - //ctx.fillRect(960 - v / 2 - 10,380,v + 20,200); - - //var canvas = document.createElement('sproutcanvas'); - //var context = canvas.getContext('2d'); - //var img = document.getElementById('myimg'); - //context.drawImage(img, 0, 0 ); - //var myData = context.getImageData(0, 0, img.width, img.height); - //ctx.fillStyle = 'rgba(255,255,255,' + u + ')'; - //ctx.font = 'bold 36px tahoma';//v - //ctx.fillText('TF ∪ CK',1560 - v / 2,850); - - - var imageObjSprout = new Image(); - imageObjSprout.src = '/toj/jcs/sprout2.png'; - ctx.drawImage(imageObjSprout, 690,260,500,500); - //var imgdSprout = ctx.getImageData(0, 0, 300, 300); - //var Sproutpix_alpha = imgdSprout.data; - //for(var spj = 3, spn = Sproutpix_alpha.length; spj < spn; spj += 4) { - // Sproutpix_alpha[spj] = Sproutpix_alpha[spj] * 0.2; - //} - //ctx.drawImage(Sproutpix_alpha, 2, 2); - //ctx.putImageData(imgdSprout, 0, 0, 300, 300); - var spu = 1.0-u; - //alert(pu); - var spuint=parseInt(8); - //if(spuint<1)spuint=1; - ctx.fillStyle = 'rgba(' + spuint + ',' + spuint + ',' + spuint + ',' + spu + ')'; - - ctx.fillRect(690-1+23,260-1+23,500+2-46+2,500+2-46+3); - - //ctx.fillStyle = 'rgba(255,255,255,' + u + ')'; - //ctx.font = 'bold 32px tahoma';//v - //ctx.fillText('TF∪CK ',1560 - v / 2,850); - - - prog++; - if(prog == 400){ - prog = 0; - st = 0; - document.getElementById('tmp_audio').volume = 0.5; - document.getElementById('tmp_audio').play(); - ani(); - }else{ - setTimeout(loadani,10); - } - } - - e_ani = document.getElementById('tmpani'); - e_canvas = document.getElementById('tmpcanv'); - - if(e_ani.clientWidth * 9 > e_ani.clientHeight * 16){ - e_canvas.width = e_ani.clientHeight / 9 * 16; - e_canvas.height = e_ani.clientHeight; - }else{ - e_canvas.width = e_ani.clientWidth; - e_canvas.height = e_ani.clientWidth / 16 * 9; - } - - var waitaudio = function(){ - if(document.getElementById('tmpload_audio').readyState != 4 || document.getElementById('tmp_audio').readyState != 4){ - setTimeout(waitaudio,100); - }else{ - e_audio = document.getElementById('tmpload_audio'); - e_audio.volume = 0.5; - e_audio.play(); - loadani(); - } - } - - ctx = e_canvas.getContext('2d'); - ctx.scale(e_canvas.width / 1920,e_canvas.height / 1080); - - tmp_stop = false; - if(tmp_first == true){ - load = true; - waitaudio(); - }else{ - load = false; - ani(); - } - - tmp_first = false; - } -}; __extend(class_home_pbox,class_com_pbox); - -var class_none_pbox = function(){ - var that = this; - var j_pbox = $('#index_page > div.none_pbox'); - - that.node = new vus.node('none'); - - that.__super(); - - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - that.fadein(j_pbox); - index.title_set('Taiwan Online Judge'); - }else if(direct == 'out'){ - that.fadeout(j_pbox); - } - - return 'cont'; - } - com.vus_root.child_set(that.node); -}; __extend(class_none_pbox,class_com_pbox); diff --git a/toj/jcs/index.css b/toj/jcs/index.css deleted file mode 100755 index 62de39e..0000000 --- a/toj/jcs/index.css +++ /dev/null @@ -1,235 +0,0 @@ -div.index_head_box{ - width:100%; - height:32px; - font-size:16px; - line-height:32px; - background-color:#1C1C1C; - color:#E9E9E9; - position:fixed; - top:0px; - left:0px; - z-index:100; -} -div.index_head{ - width:1224px; - height:100%; - margin:0px auto 0px auto; -} -div.index_head > div.title{ - width:240px; - height:100%; - float:left; -} -div.index_head > div.tab_box{ - height:100%; - margin:0px 0px 0px 6px; - float:left; -} -div.index_head > div.tab_box > div.button{ - height:100%; - width:117px; - margin:0px 6px 0px 0px; - float:left; -} -div.index_head > div.tab_box > div.button_s{ - background-color:#3A8FB7; -} -div.index_head > div.tab_box > div.button > a.button{ - height:100%; - padding:0px 16px 0px 16px; - color:#E9E9E9; - text-decoration:none; - display:block; -} -div.index_head > div.tab_box > div.button > a:hover.button{ - color:#FFFFFF; -} -div.index_head > div.content_box{ - width:auto; - height:100%; - float:left; -} -div.index_head_box > div.panel{ - width:96px; - height:100%; - text-align:center; - cursor:pointer; - position:absolute; - top:0px; - right:0px; -} -div.index_head_box > div.panel_m{ - color:#FFFFFF; -} -div.index_head_box > div.notice{ - width:96px; - height:100%; - text-align:center; - font-family:Droid Sans Mono; - font-weight:400; - cursor:pointer; - position:absolute; - top:0px; - right:96px; -} -div.index_head_box > div:hover.notice{ - color:#FFFFFF; -} -div.index_head_box > div.notice_s{ - color:#FFFFFF; -} -div.index_head_box > div.notice_h{ - background-color:#E83015; - color:#FFFFFF; -} -div.index_head_box > div.nickname{ - height:100%; - padding:0px 16px 0px 16px; - position:absolute; - top:0px; - right:192px; -} -div.index_head_box > div.nickname > a.nickname{ - height:100%; - color:#E9E9E9; - text-align:center; - text-decoration:none; -} -div.index_head_box > div.nickname > a:hover.nickname{ - color:#FFFFFF; -} - -div.index_panel_box{ - width:0px; - background-color:#1C1C1C; - opacity:0; - position:absolute; - left:auto; - right:0px; - top:32px; - overflow-x:hidden; - z-index:100; -} -ul.index_panel{ - width:240px; - margin:0px 0px; - padding:0px 0px 64px 0px; - position:relative; - left:auto; - right:0px; - top:0px; - overflow-x:hidden; - list-style:none; -} -ul.index_panel > li.button{ - width:auto; - height:64px; - padding:0px 0px 0px 38px; - font-size:20px; - line-height:64px; -} -ul.index_panel > li:hover.button{ - color:#FFFFFF; - background-color:rgba(255,255,255,0.2); -} -ul.index_panel > ul.square_box{ - width:100%; - margin:0px 0px; - padding:0px 0px; - list-style:none; - overflow:hidden; - display:none; -} -ul.index_panel > ul.square_box ul{ - width:100%; - margin:0px 0px; - padding:0px 0px; - list-style:none; - overflow:hidden; -} -ul.index_panel > ul.square_box li.title{ - width:auto; - height:32px; - margin:6px 0px 0px 0px; - padding:0px 0px 0px 32px; - line-height:32px; - border-bottom:#BDC0BA 1px solid; -} -ul.index_panel > ul.square_box li.button{ - width:auto; - height:32px; - padding:0px 0px 0px 32px; - font-size:16px; - line-height:32px; -} -ul.index_panel > ul.square_box li:hover.button{ - color:#FFFFFF; - background-color:rgba(255,255,255,0.2); -} -ul.index_panel span.title{ - width:100%; - height:100%; - color:#BDC0BA; - font-size:16px; - font-weight:bold; - position:relative; - top:0px; - left:50%; - display:block; -} -ul.index_panel a.button{ - width:100%; - height:100%; - color:#E9E9E9; - text-decoration:none; - position:relative; - top:0px; - left:50%; - cursor:pointer; - display:block; -} -ul.index_panel a.button_m{ - color:#FFFFFF; -} - -div.index_page{ - width:100%; - position:absolute; - left:0px; - top:32px; - z-index:0; -} - -div.index_mask{ - width:100%; - min-height:100%; - background-color:rgba(0,0,0,0.9); - position:absolute; - top:0px; - left:0px; - z-index:1000; - display:none; -} -div.index_mask_nopbox{ - width:100%; - position:absolute; - top:32px; - left:0px; - z-index:0; - display:none; -} -div.index_mask > button.close{ - height:32px; - line-height:32px; - position:absolute; - top:0px; - right:96px; -} -div.index_mask_nopbox > button.close{ - height:32px; - line-height:32px; - position:absolute; - top:0px; - right:96px; - display:none; -} diff --git a/toj/jcs/index.js b/toj/jcs/index.js deleted file mode 100755 index 262b5fa..0000000 --- a/toj/jcs/index.js +++ /dev/null @@ -1,193 +0,0 @@ -var index = new function(){ - var that = this; - var page_scroll_ref = 0; - var page_scroll_top = 0; - - that.init = function(){ - $(window).on('mouseover',function(e){ - var j_panel; - - if(e.target == null || e.target.id == 'index_panel_box' || $(e.target).parents('#index_panel_box').length > 0){ - return; - } - - j_panel = $('#index_head_panel'); - if(e.target.id == 'index_head_panel'){ - - if($('#index_head_notice').hasClass('notice_s')){ - notice.hide(); - } - - if(!j_panel.hasClass('panel_m')){ - that.page_scroll_lock(); - - j_panel.addClass('panel_m'); - $('#index_panel_box').stop().css('opacity','1').animate({width:240},'slow','easeOutExpo'); - $('#index_panel span.title').stop().animate({left:0},'slow','easeOutQuart'); - $('#index_panel a.button').stop().animate({left:0},'slow','easeOutQuart'); - } - }else{ - if(j_panel.hasClass('panel_m')){ - j_panel.removeClass('panel_m'); - $('#index_panel_box').stop().animate({opacity:0},'fast','easeOutQuad', - function(){ - $('#index_panel_box').css('width','0px'); - $('#index_panel span.title').css('left','50%'); - $('#index_panel a.button').css('left','50%'); - - that.page_scroll_unlock(); - } - ); - } - } - }); - $('#index_head_panel').on('mousedown',function(e){ - return false; - }); - - $('#index_panel > li').on('mousedown',function(e){ - return false; - }); - - $('#index_panel > li.square > a.button').off('click').on('click',function(e){ - var j_ul; - - j_ul = $('#index_panel > ul.square_box'); - if(j_ul.is(':visible')){ - j_ul.stop().slideUp('slow','easeOutExpo'); - }else{ - j_ul.stop().slideDown('slow','easeOutExpo'); - } - - return false; - }); - - $('#index_mask').on('click',function(e){ - if((e.target == this || e.target.parentNode == this) && $(this).hasClass('index_mask')){ - com.url_pull_pbox(); - } - }); - $('#index_mask > button.close').on('click',function(e){ - com.url_pull_pbox(); - }); - }; - - that.panel_show = function(name){ - $('#index_panel > .' + name).show(); - }; - that.panel_hide = function(name){ - $('#index_panel > .' + name).hide(); - }; - that.panel_set = function(name,panellink,paneltext){ - var j_a; - - j_a = $('#index_panel > .' + name + ' > a.button'); - j_a.attr('href',panellink); - j_a.text(paneltext); - }; - - that.title_set = function(titletext){ - $('#index_head > div.title').text(titletext); - }; - - that.tab_add = function(tabname,tablink,tabtext){ - var j_div; - var j_a; - - j_div = $('<div class="button"></div>'); - j_div.attr('tab',tabname); - - j_a = $('<a class="button"></a>'); - j_a.attr('href',tablink); - j_a.text(tabtext); - - j_div.append(j_a); - $('#index_head > div.tab_box').append(j_div); - - return j_div; - }; - that.tab_set = function(tabname,tablink,tabtext){ - var j_a; - - j_a = $('#index_head > div.tab_box [tab="' + tabname + '"] > a.button'); - j_a.attr('href',tablink); - j_a.text(tabtext); - }; - that.tab_empty = function(){ - $('#index_head > div.tab_box').empty(); - }; - that.tab_hl = function(tabname){ - $('#index_head > div.tab_box > [tab="' + tabname + '"]').addClass('button_s'); - }; - that.tab_ll = function(tabname){ - $('#index_head > div.tab_box > [tab="' + tabname + '"]').removeClass('button_s'); - }; - - that.content_set = function(j_content){ - $('#index_head > div.content_box').append(j_content); - }; - that.content_empty = function(){ - $('#index_head > div.content_box').empty(); - }; - - that.page_scroll_lock = function(){ - var j_index; - - console.log('lock'); - if(page_scroll_ref == 0){ - j_index = $('#index_page'); - - page_scroll_top = $(window).scrollTop(); - off = -page_scroll_top + 32; - j_index.css('position','fixed'); - j_index.css('top',off + 'px'); - } - page_scroll_ref++; - }; - that.page_scroll_unlock = function(){ - var j_index; - - console.log('unlock'); - page_scroll_ref--; - if(page_scroll_ref == 0){ - j_index = $('#index_page'); - - j_index.css('position','absolute'); - j_index.css('top','32px'); - $(window).scrollTop(page_scroll_top); - } - }; - that.page_scroll_reset = function(){ - var j_index; - - console.log('reset'); - if(page_scroll_ref > 0){ - j_index = $('#index_page'); - if(j_index.css('position') == 'fixed'){ - page_scroll_top = 0; - j_index.css('top','32px'); - } - } - }; - - that.mask_show = function(){ - var j_mask; - var off; - - j_mask = $('#index_mask'); - j_mask.stop().fadeIn('fast'); - if(j_mask.hasClass('index_mask')){ - that.page_scroll_lock(); - } - }; - that.mask_hide = function(){ - var j_mask; - var j_index; - - j_mask = $('#index_mask'); - j_mask.stop().hide(); - if(j_mask.hasClass('index_mask')){ - that.page_scroll_unlock(); - } - }; -}; diff --git a/toj/jcs/notice.css b/toj/jcs/notice.css deleted file mode 100755 index 2d9e8b8..0000000 --- a/toj/jcs/notice.css +++ /dev/null @@ -1,55 +0,0 @@ -div.notice_list_box{ - width:0px; - background-color:#1C1C1C; - opacity:0; - position:absolute; - left:auto; - right:0px; - top:32px; - overflow-x:hidden; - z-index:50; -} -ul.notice_list{ - width:322px; - margin:0px 0px; - padding:0px 0px 64px 0px; - position:relative; - left:auto; - right:0px; - top:0px; - overflow-x:hidden; - list-style:none; -} -ul.notice_list > li.item{ - width:auto; - height:96px; - padding:0px 0px 0px 38px; -} -ul.notice_list > li:hover.item{ - color:#FFFFFF; - background-color:rgba(255,255,255,0.2); -} -ul.notice_list > li.item div.head{ - padding:16px 0px 6px 0px; - font-weight:bold; - font-size:20px; -} -ul.notice_list > li.item div.content{ - font-size:16px; - word-break:break-all; - overflow:hidden; -} -ul.notice_list a.item{ - width:100%; - height:100%; - color:#91989F; - text-decoration:none; - position:relative; - top:0px; - left:50%; - cursor:pointer; - display:block; -} -ul.notice_list a.item_h{ - color:#E9E9E9; -} diff --git a/toj/jcs/notice.js b/toj/jcs/notice.js deleted file mode 100755 index 0f027fd..0000000 --- a/toj/jcs/notice.js +++ /dev/null @@ -1,174 +0,0 @@ -var notice = new function(){ - var that = this; - var j_ajax = null; - var enid = null; - - var listnew = function(noticeo){ - j_item = $('<li class="item"><a class="item"><div class="head"></div><div class="content"></div></a></li>') - j_a = j_item.find('a.item'); - j_a.on('click',function(e){ - that.hide(); - }); - - j_head = j_item.find('div.head'); - j_content = j_item.find('div.content'); - - switch(noticeo.type){ - case 'result': - j_a.attr('href','/toj/m/sub/' + noticeo.subid + '/res/'); - if(noticeo.rejudge_flag == false){ - j_head.text('Submit ' + noticeo.subid); - }else{ - j_head.text('Rejudge ' + noticeo.subid); - } - j_content.html('ProID ' + noticeo.proid + ' 結果: ' + RESULTMAP[noticeo.result] + ' 分數: ' + noticeo.score + '<br>' + - noticeo.runtime+ 'ms / ' + noticeo.memory + 'KB'); - break; - } - - return j_item; - }; - var updatenew = function(){ - var j_list; - - if(j_ajax != null){ - j_ajax.abort(); - } - - j_list = $('#notice_list'); - j_ajax = $.post('/toj/php/notice.php',{'action':'get','data':JSON.stringify({'nid':0,'count':10})}, - function(res){ - var i; - - var reto; - var noticeo; - var j_item; - var j_a; - - if(res[0] != 'E'){ - reto = JSON.parse(res); - for(i = 0;i < reto.length;i++){ - noticeo = JSON.parse(reto[i].txt); - j_item = listnew(noticeo); - j_list.prepend(j_item); - j_a = j_item.find('a.item'); - j_a.addClass('item_h'); - j_a.stop().animate({left:0},'slow','easeOutQuart'); - } - - if(enid == null){ - if(reto.length == 0){ - enid = 2147483647; - }else{ - enid = reto[0].nid; - } - updateprev(); - } - } - - j_ajax = null; - } - ); - }; - var updateprev = function(){ - var j_list; - - j_list = $('#notice_list'); - $.post('/toj/php/notice.php',{'action':'get','data':JSON.stringify({'nid':enid,'count':10})}, - function(res){ - var i; - - var reto; - var noticeo; - var j_item; - - if(res[0] != 'E'){ - reto = JSON.parse(res); - for(i = reto.length - 1;i >= 0;i--){ - noticeo = JSON.parse(reto[i].txt); - j_item = listnew(noticeo); - j_list.append(j_item); - j_item.find('a.item').stop().animate({left:0},'slow','easeOutQuart'); - } - - enid = 0; - } - } - ); - }; - var refresh = function(){ - $.post('/toj/php/notice.php',{'action':'count','data':JSON.stringify({})}, - function(res){ - var count; - var j_notice; - - if(res[0] != 'E'){ - count = JSON.parse(res); - j_notice = $('#index_head_notice'); - if(count == 0){ - j_notice.removeClass('notice_h'); - j_notice.text('[' + count + ']'); - }else{ - if($('#notice_list_box').css('opacity') == 1){ - updatenew(); - }else{ - j_notice.addClass('notice_h'); - j_notice.text('[' + count + ']'); - } - } - - setTimeout(refresh,2000); - } - } - ); - }; - - that.init = function(){ - $(window).on('click',function(e){ - var j_notice; - - if(e.target == null || ($(e.target).parents('a.item').length == 0 && $(e.target).parents('#notice_list_box').length > 0)){ - return; - } - - j_notice = $('#index_head_notice'); - if(e.target.id == 'index_head_notice' && !j_notice.hasClass('notice_s')){ - that.show(); - }else if(j_notice.hasClass('notice_s')){ - that.hide(); - } - }); - $('#index_head_notice').on('click',function(e){ - var j_list; - - j_list = $('#notice_list'); - if($('#notice_list_box').css('opacity') == 0){ - j_list.empty(); - enid = null; - updatenew(); - } - }).on('mousedown',function(e){ - return false; - }); - - refresh(); - }; - that.show = function(){ - index.page_scroll_lock(); - - $('#index_head_notice').addClass('notice_s'); - $('#notice_list_box').stop().css('opacity','1').animate({width:322},'slow','easeOutExpo'); - $('#notice_list a.item').stop().animate({left:0},'slow','easeOutQuart'); - }; - that.hide = function(){ - $('#index_head_notice').removeClass('notice_s'); - $('#notice_list_box').stop().animate({opacity:0},'fast','easeOutQuad', - function(){ - $('#notice_list_box').css('width','0px'); - $('#notice_list a.item').css('left','50%'); - - index.page_scroll_unlock(); - } - ); - }; -}; diff --git a/toj/jcs/pro.css b/toj/jcs/pro.css deleted file mode 100755 index 0629ee1..0000000 --- a/toj/jcs/pro.css +++ /dev/null @@ -1,28 +0,0 @@ -div.pro_mask > div.sub_mbox{ - width:62%; -} -div.pro_mask > div.sub_mbox > div.head{ - width:100%; - height:32px; - padding:6px 0px 6px 0px; -} -div.pro_mask > div.sub_mbox > div.head > div.title{ - font-size:20px; - line-height:32px; - float:left; -} -div.pro_mask > div.sub_mbox > div.head > div.error{ - margin:0px 0px 0px 16px; - color:#FFA0A0; - font-size:16px; - line-height:32px; - float:left; -} -div.pro_mask > div.sub_mbox > div.head > div.oper{ - float:right; -} -div.pro_mask > div.sub_mbox > div.head > div.oper > select{ - height:32px; - border-width:0px; - font-size:16px; -} diff --git a/toj/jcs/pro.js b/toj/jcs/pro.js deleted file mode 100755 index b922be0..0000000 --- a/toj/jcs/pro.js +++ /dev/null @@ -1,164 +0,0 @@ -var pro = new function(){ - var that = this; - var j_page = null; - var pro_page = null; - var pro_proid = null; - var pro_pmodname = null; - - that.init = function(){ - j_page = $('#index_page > div.pro_page'); - - that.sub_mbox = new class_pro_sub_mbox(); - - that.node = new vus.node('pro'); - that.node.url_chg = function(direct,url_upart,url_dpart){ - var proid; - - var _clean = function(){ - if(pro_page != null){ - that.node.child_del(pro_page.node); - } - j_page.empty(); - j_page.removeClass(pro_pmodname); - index.tab_empty(); - index.content_empty(); - - pro_page = null; - pro_proid = null; - pro_pmodname = null; - }; - - if(direct == 'in' || direct == 'same'){ - index.title_set('TOJ-題目'); - - proid = url_dpart[0]; - if(proid == ''){ - com.url_update('/toj/none/'); - return 'stop'; - } - proid = parseInt(proid); - if(proid == pro_proid){ - return 'cont'; - } - - _clean(); - that.node.child_delayset(proid.toString()); - - $.post('/toj/php/problem.php',{'action':'get_pro','data':JSON.stringify({'proid':proid})},function(res){ - var css; - var reto; - - if(res[0] != 'E'){ - pro_proid = proid; - reto = JSON.parse(res); - pro_pmodname = reto.pmodname; - - css = $('<link rel="stylesheet" type="text/css" href="/toj/pmod/' + pro_pmodname + '/' + pro_pmodname + '.css">'); - $('head').append(css); - css.ready(function(){ - j_page.addClass(pro_pmodname); - - $.get('/toj/pmod/' + pro_pmodname + '/' + pro_pmodname + '.html',{},function(res){ - j_page.html(res); - $.getScript('/toj/pmod/' + pro_pmodname + '/' + pro_pmodname + '.js',function(script,stat,res){ - pro_page = new class_pro_page(pro_proid,reto.proname); - eval('new ' + pro_pmodname + '(pro_page,j_page)'); - that.node.child_set(pro_page.node); - }); - }); - }); - }else{ - com.url_update('/toj/none/'); - } - }); - }else if(direct == 'out'){ - _clean(); - } - - return 'cont'; - }; - com.vus_root.child_set(that.node); - }; -}; - -var class_pro_page = function(proid,proname){ - var that = this; - var j_page = $('#index_page > div.pro_page'); - - that.proid = proid; - that.proname = proname; - that.node = new vus.node(proid.toString()); - - that.__super(); - - that.submit = function(proid){ - if(proid == undefined){ - proid = that.proid - } - pro.sub_mbox.init(proid); - com.url_push('/toj/m/pro_sub/'); - }; -}; __extend(class_pro_page,class_com_pbox); - -var class_pro_sub_mbox = function(){ - var that = this; - var j_mbox = $('#index_mask > div.pro_mask > div.sub_mbox'); - var j_error = j_mbox.find('div.head > div.error'); - var codebox = CodeMirror(j_mbox.find('div.codebox')[0],{ - mode:'text/x-c++src', - theme:'lesser-dark', - lineNumbers:true, - matchBrackets:true, - indentUnit:4 - }); - var proid = null; - - that.node = new vus.node('pro_sub'); - - that.__super(); - - that.init = function(id){ - proid = id; - j_mbox.find('div.head > div.title').text('上傳ProID:' + proid); - j_error.text(''); - $(j_mbox.find('[name="lang"] > option')[0]).attr('selected',true); - codebox.setValue(''); - - com.vus_mbox.child_set(that.node); - }; - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - that.fadein(j_mbox); - codebox.refresh(); - }else if(direct == 'out'){ - that.fadeout(j_mbox); - proid = null; - com.vus_mbox.child_del(that.node); - } - - return 'cont'; - }; - - j_mbox.find('div.head > div.oper > button.submit').on('click',function(e){ - $.post('/toj/php/problem.php',{'action':'submit_code','data':JSON.stringify({'proid':proid,'lang':1,'code':codebox.getValue()})},function(res){ - if(res[0] == 'E'){ - if(res == 'Enot_login'){ - j_error.text('未登入'); - }else if(res == 'Ewrong_language'){ - j_error.text('語言錯誤'); - }else if(res == 'Ecode_too_long'){ - j_error.text('程式碼過長'); - }else{ - j_error.text('其他錯誤'); - } - }else{ - com.url_pull_pbox(); - } - }); - }); - - codebox.getWrapperElement().style.width = '100%'; - codebox.getWrapperElement().style.height = '100%'; - codebox.getScrollerElement().style.width = '100%'; - codebox.getScrollerElement().style.height = '100%'; -}; __extend(class_pro_sub_mbox,class_com_mbox); diff --git a/toj/jcs/sq.css b/toj/jcs/sq.css deleted file mode 100755 index e69de29..0000000 --- a/toj/jcs/sq.css +++ /dev/null diff --git a/toj/jcs/sq.js b/toj/jcs/sq.js deleted file mode 100755 index 17c07c0..0000000 --- a/toj/jcs/sq.js +++ /dev/null @@ -1,88 +0,0 @@ -var sq = new function(){ - var that = this; - var j_page = null; - var sq_page = null; - var sq_sqid = null; - var sq_sqmodname = null; - - that.init = function(){ - j_page = $('#index_page > div.sq_page'); - - that.node = new vus.node('sq'); - that.node.url_chg = function(direct,url_upart,url_dpart){ - var sqid; - - var _clean = function(){ - if(sq_page != null){ - that.node.child_del(sq_page.node); - } - - j_page.empty(); - j_page.removeClass(sq_sqmodname); - index.content_empty(); - index.tab_empty(); - - sq_page = null; - sq_sqid = null; - sq_sqmodname = null; - }; - - if(direct == 'in' || direct == 'same'){ - sqid = url_dpart[0]; - if(sqid == ''){ - com.url_update('/toj/none/'); - return 'stop'; - } - sqid = parseInt(sqid); - if(sqid == sq_sqid){ - return 'cont'; - } - - _clean(); - that.node.child_delayset(sqid.toString()); - - $.post('/toj/php/square.php',{'action':'get_sq','data':JSON.stringify({'sqid':sqid})},function(res){ - var css; - var reto; - - if(res[0] != 'E'){ - sq_sqid = sqid; - reto = JSON.parse(res); - sq_sqmodname = reto.sqmodname; - - css = $('<link rel="stylesheet" type="text/css" href="/toj/sqmod/' + sq_sqmodname + '/' + sq_sqmodname + '.css">'); - $('head').append(css); - css.ready(function(){ - j_page.addClass(sq_sqmodname); - - $.get('/toj/sqmod/' + sq_sqmodname + '/' + sq_sqmodname + '.html',{},function(res){ - j_page.html(res); - $.getScript('/toj/sqmod/' + sq_sqmodname + '/' + sq_sqmodname + '.js',function(script,stat,res){ - sq_page = new class_sq_page(sq_sqid,reto.sqname); - eval('new ' + sq_sqmodname + '(sq_page,j_page)'); - that.node.child_set(sq_page.node); - }); - }); - }); - }else{ - com.url_update('/toj/none/'); - } - }); - - }else if(direct == 'out'){ - _clean(); - } - - return 'cont'; - }; - com.vus_root.child_set(that.node); - }; -}; - -var class_sq_page = function(sqid,sqname){ - var that = this; - - that.sqid = sqid; - that.sqname = sqname; - that.node = new vus.node(sqid.toString()); -}; diff --git a/toj/jcs/stat.css b/toj/jcs/stat.css deleted file mode 100755 index 88a465c..0000000 --- a/toj/jcs/stat.css +++ /dev/null @@ -1,71 +0,0 @@ -div.stat_page > div.sub_pbox > div.subset{ - width:240px; - margin:0px 0px 6px 0px; - float:left; -} -div.stat_page > div.sub_pbox > div.subset > table.filter{ - width:100%; - border-collapse:collapse; - text-align:left; -} -div.stat_page > div.sub_pbox > div.subset > table.filter tr.head{ - height:64px; -} -div.stat_page > div.sub_pbox > div.subset > table.filter tr.item{ - height:38px; -} -div.stat_page > div.sub_pbox > div.subset > table.filter th.key,div.stat_page > div.sub_pbox > div.subset > table.filter td.key{ - width:76px; -} -div.stat_page > div.sub_pbox > div.subset > table.filter th.value,div.stat_page > div.sub_pbox > div.subset > table.filter td.value{ - width:158px; - padding:0px 0px 0px 6px; -} -div.stat_page > div.sub_pbox > table.sublist{ - width:978px; - margin:0px 0px 6px 6px; - border-collapse:collapse; - text-align:left; - float:left; -} -div.stat_page > div.sub_pbox > table.sublist tr.head{ - height:64px; -} -div.stat_page > div.sub_pbox > table.sublist tr.item{ - height:32px; - display:none; -} -div.stat_page > div.sub_pbox > table.sublist tr:hover.item{ - background-color:rgba(255,255,255,0.2); -} -div.stat_page > div.sub_pbox > table.sublist th,div.stat_page > div.sub_pbox > table.sublist td{ - width:76px; - padding:0px 0px 0px 6px; -} -div.stat_page > div.sub_pbox > table.sublist th.nickname,div.stat_page > div.sub_pbox > table.sublist td.nickname{ - width:auto; -} -div.stat_page > div.sub_pbox > table.sublist th.time{ - width:158px; -} -div.stat_page > div.sub_pbox > table.sublist td.time{ - width:158px; - color:#BDC0BA; - font-size:12px; -} -div.stat_page > div.sub_pbox > table.sublist th.lang,div.stat_page > div.sub_pbox > table.sublist td.lang{ - width:76px; -} - -div.stat_mask > div.subfile_mbox > h2.subid{ - width:50%; - padding:6px 0px 0px 82px; -} -div.stat_mask > div.subfile_mbox > label{ - padding:6px 0px 32px 82px; -} -div.stat_mask > div.subfile_mbox > div.filebox{ - width:814px; - height:384px; - padding:6px 0px 32px 82px; -} diff --git a/toj/jcs/stat.js b/toj/jcs/stat.js deleted file mode 100755 index 95ec06a..0000000 --- a/toj/jcs/stat.js +++ /dev/null @@ -1,577 +0,0 @@ -var stat = new function(){ - var that = this; - var stat_sub_pbox = null; - - - var sub_node = null; - var subid_node = null; - - - var j_subres_mbox = null; - var subres_mbox = null; - var subfile_mbox = null; - - - that.sub_subid = null; - - that.init = function(){ - stat_sub_pbox = new class_stat_sub_pbox('sub'); - subfile_mbox = new class_stat_subfile_mbox; - j_subres_mbox = $('#index_mask > div.stat_mask > div.subres_mbox'); - - that.stat_node = new vus.node('stat'); - that.stat_node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - index.title_set('TOJ-狀態'); - - index.tab_add('sub','/toj/stat/sub/','全部動態'); - if(url_dpart[0] != 'sub'){ - com.url_update('/toj/stat/sub/'); - return 'stop'; - } - }else if(direct == 'out'){ - index.tab_empty(); - } - - return 'cont'; - }; - that.stat_node.child_set(stat_sub_pbox.node); - com.vus_root.child_set(that.stat_node); - - - - - sub_node = new vus.node('sub'); - subid_node = new vus.node(''); - - sub_node.url_chg = function(direct,url_upart,url_dpart){ - var subid; - - if(direct == 'in' || direct == 'same'){ - if((subid = url_dpart[0]) == ''){ - com.url_update('/toj/none/'); - return 'stop'; - } - subid = parseInt(url_dpart[0]); - if(subid == that.sub_subid){ - return 'cont'; - } - - if(that.sub_subid != null){ - sub_node.child_del(subid_node); - } - that.sub_subid = subid; - - subid_node.name = that.sub_subid.toString(); - sub_node.child_set(subid_node); - }else if(direct == 'out'){ - if(that.sub_subid != null){ - sub_node.child_del(subid_node); - } - that.sub_subid = null; - } - - return 'cont'; - }; - com.vus_mbox.child_set(sub_node); - - - - - subid_node.mbox_name = null; - subid_node.smodname = null; - subid_node.url_chg = function(direct,url_upart,url_dpart){ - var mbox_name; - - var _clean = function(){ - if(subres_mbox != null){ - subid_node.child_del(subres_mbox.node); - - j_subres_mbox.empty(); - j_subres_mbox.removeClass(subid_node.smodname); - - subres_mbox = null; - subid_node.smodname = null; - } - }; - - if(direct == 'in' || direct == 'same'){ - mbox_name = url_dpart[0]; - if(mbox_name == subid_node.mbox_name){ - return 'cont'; - } - - _clean(); - - subid_node.mbox_name = mbox_name; - if(mbox_name == 'res'){ - subid_node.child_delayset('res'); - - $.post('/toj/php/status.php',{'action':'get_by_subid','data':JSON.stringify({'subid':that.sub_subid})},function(res){ - var reto; - - if(res[0] == 'E'){ - com.url_update('/toj/none/'); - }else{ - reto = JSON.parse(res); - subid_node.smodname = reto.smodname; - reto.submit_time = com.get_date(reto.submit_time); - delete reto.smodname; - - css = $('<link rel="stylesheet" type="text/css" href="/toj/smod/' + subid_node.smodname + '/' + subid_node.smodname + '.css">'); - $('head').append(css); - css.ready(function(){ - j_subres_mbox.addClass(subid_node.smodname); - - $.get('/toj/smod/' + subid_node.smodname + '/' + subid_node.smodname + '.html',{},function(res){ - var j_h; - var j_button; - - j_subres_mbox.html(res); - - j_h = $('<h2 style="padding:6px 0px 0px 82px;"></h2>'); - j_h.text('SubID: ' + that.sub_subid); - j_subres_mbox.prepend(j_h); - - if(reto.uid == user.uid || user.level == -1){ - j_button = $('<button style="margin:6px 0px 0px 0px; float:right;">檔案</button>'); - j_button.on('click',function(e){ - com.url_update('/toj/m/sub/' + that.sub_subid + '/file/'); - }); - j_subres_mbox.prepend(j_button); - } - if(user.level == -1){ - j_button = $('<button style="margin:6px 0px 0px 6px; float:right;">重測</button>'); - j_button.on('click',function(e){ - $.post('/toj/php/status.php',{'action':'rejudge_submit','data':JSON.stringify({'subid':that.sub_subid})}); - com.url_pull_pbox(); - }); - j_subres_mbox.prepend(j_button); - } - - $.getScript('/toj/smod/' + subid_node.smodname + '/' + subid_node.smodname + '.js',function(script,stat,res){ - subres_mbox = new class_stat_subres_mbox(that.sub_subid,reto); - eval('new ' + subid_node.smodname + '(subres_mbox,j_subres_mbox)'); - subid_node.child_set(subres_mbox.node); - }); - }); - }); - } - }); - } - }else if(direct == 'out'){ - _clean(); - subid_node.mbox_name = null; - } - - return 'cont'; - }; - subid_node.child_set(subfile_mbox.node); - }; -}; - -var class_stat_sub_pbox = function(pbox_name){ - var that = this; - var j_pbox = $('#index_page > div.stat_page > div.' + pbox_name + '_pbox'); - var j_filter = j_pbox.find('div.subset > table.filter'); - var j_table = j_pbox.find('table.sublist'); - - var refresh_flag = false; - var j_ajax = null; - var ssubid = 0; - var esubid = 2147483647; - var last_update = null; - var top_flag = true; - var top_queue = new Array; - var down_block = false; - - var filter = new Object; - - var sub_listset = function(j_item,subo){ - var j_a; - - j_item.attr('subid',subo.subid); - - j_item.find('td.subid').text(subo.subid); - - j_a = j_item.find('td.proid > a'); - j_a.attr('href','/toj/pro/' + subo.proid+ '/'); - j_a.text(subo.proid); - - j_a = j_item.find('td.nickname > a'); - j_a.attr('href','/toj/user/' + subo.uid+ '/'); - j_a.text(subo.nickname); - - j_item.find('td.runtime').text(subo.runtime); - j_item.find('td.memory').text(subo.memory); - j_item.find('td.result').text(RESULTMAP[subo.result]); - j_item.find('td.score').text(subo.score); - j_item.find('td.time').text(com.get_datestring(subo.submit_time,true)); - j_item.find('td.lang').text(com.get_lang(subo.lang)[0]); - - j_item.off('click').on('click',function(e){ - if(e.target.tagName != 'A'){ - com.url_push('/toj/m/sub/' + subo.subid + '/res/'); - } - }); - }; - var sub_listnew = function(subo){ - var j_item; - - j_item = $('<tr class="item"><td class="subid"></td><td class="proid"><a></a></td><td class="nickname"><a></a></td><td class="runtime"></td><td class="memory"></td><td class="result"></td><td class="score"></td><td class="time"></td><td class="lang"></td></tr>'); - sub_listset(j_item,subo); - - return j_item; - }; - var sub_refresh = function(){ - if(refresh_flag == false){ - return; - } - if(j_ajax != null){ - j_ajax.abort(); - } - j_ajax = $.post('/toj/php/status.php',{'action':'get_submit', - 'data':JSON.stringify({ - 'filter':{'uid':filter.uid,'result':filter.result,'proid':filter.proid,'lang':null}, - 'sort':{'score':null,'runtime':null,'memory':null,'subid':[1,0]}, - 'wait':10, - 'count':100, - 'last_update':last_update - })} - ,function(res){ - var i; - - var reto; - var j_item; - var masubid; - - if(res[0] != 'E'){ - reto = JSON.parse(res); - - masubid = ssubid; - for(i = 0;i < reto.length;i++){ - reto[i].submit_time = com.get_date(reto[i].submit_time); - - j_item = j_table.find('[subid="' + reto[i].subid + '"]') - if(j_item.length > 0){ - sub_listset(j_item,reto[i]); - }else if(reto[i].subid > ssubid){ - if(top_flag == true){ - j_item = sub_listnew(reto[i]); - j_item.insertAfter(j_table.find('tr.head')); - j_item.css('opacity',0).slideDown('fast').fadeTo(100,1); - }else{ - j_item = sub_listnew(reto[i]); - j_item.insertAfter(j_table.find('tr.head')); - topqueue.push(reto[i].subid); - } - } - - if(reto[i].subid > masubid){ - masubid = reto[i].subid; - } - if(reto[i].last_update > last_update){ - last_update = reto[i].last_update; - } - } - ssubid = masubid; - } - - j_ajax = null; - sub_refresh(); - } - ); - }; - var sub_update = function(type){ - if(type == 0){ - while(top_queue.length > 0){ - j_table.find('[subid="' + top_queue.pop() + '"]').css('opacity',0).slideDown('fast').fadeTo(100,1); - } - }else if(type == 1 && down_block == false){ - down_block = true; - $.post('/toj/php/status.php',{'action':'get_submit', - 'data':JSON.stringify({ - 'filter':{'uid':filter.uid,'result':filter.result,'proid':filter.proid,'lang':null}, - 'sort':{'score':null,'runtime':null,'memory':null,'subid':[0,esubid]}, - 'wait':0, - 'count':50, - 'last_update':null - })} - ,function(res){ - var i; - var reto; - - if(res[0] == 'E'){ - if(res != 'Eno_result'){ - down_block = false; - } - }else{ - reto = JSON.parse(res); - for(i = 0;i < reto.length;i++){ - reto[i].submit_time = com.get_date(reto[i].submit_time); - - j_item = sub_listnew(reto[i]); - j_table.append(j_item); - j_item.css('opacity',0).slideDown('fast').fadeTo(100,1); - } - - if(last_update == null){ - for(i = 0;i < reto.length;i++){ - if(ssubid < reto[i].subid){ - ssubid = reto[i].subid; - } - } - - last_update = reto[0].last_update; - for(i = 1;i < reto.length;i++){ - if(last_update < reto[i].last_update){ - last_update = reto[i].last_update; - } - } - - sub_refresh(); - - $(window).off('scroll').on('scroll',function(e){ - var j_window; - - j_window = $(window); - if(Math.floor(j_window.scrollTop() / 32) < 10){ - if(top_flag == false){ - top_flag = true; - sub_update(0); - } - }else{ - top_flag = false; - } - - if(Math.floor((j_table.height() - j_window.scrollTop()) / 32) < 50){ - sub_update(1); - } - }); - } - - esubid = reto[reto.length - 1].subid; - down_block = false; - } - } - ); - } - }; - var filter_getparam = function(){ - var ret; - - ret = ''; - if(filter.uid != null){ - ret += 'uid:' + filter.uid + ':'; - } - if(filter.proid != null){ - ret += 'proid:' + filter.proid + ':'; - } - if(filter.result != null){ - ret += 'result:' + filter.result + ':'; - } - ret = ret.slice(0,-1); - - return ret; - }; - - that.node = new vus.node(pbox_name); - - that.__super(); - - that.node.url_chg = function(direct,url_upart,url_dpart){ - var i; - var filter_part; - var key; - var value; - - var _clear = function(){ - $(window).off('scorll'); - j_filter.find('tr.uid > td.value').text('None'); - j_filter.find('tr.proid input').val('None'); - j_filter.find('tr.result select').val('null'); - j_table.find('tr.item').remove(); - - if(j_ajax != null){ - j_ajax.abort(); - j_ajax = null; - } - - refresh_flag = false; - j_ajax = null; - esubid = 2147483647; - last_update = null; - top_flag = true; - top_queue = new Array; - down_block = false; - subid_curr = null; - - filter = new Object; - } - - if(direct == 'in' || direct == 'same'){ - if(direct == 'same'){ - _clear(); - }else{ - index.tab_hl(pbox_name); - that.fadein(j_pbox); - } - refresh_flag = true; - - filter.uid = null; - filter.proid = null; - filter.result = null; - if(url_dpart[0] != undefined){ - filter_part = url_dpart[0].split(':'); - for(i = 0;i < filter_part.length;i += 2){ - key = filter_part[i]; - value = filter_part[i + 1]; - - if(key == 'uid'){ - filter.uid = parseInt(value); - }else if(key == 'proid'){ - filter.proid = parseInt(value); - }else if(key == 'result'){ - filter.result = parseInt(value); - } - } - } - - if(filter.uid != null){ - j_filter.find('tr.uid > td.value').text(filter.uid); - } - if(filter.proid != null){ - j_filter.find('tr.proid input').val(filter.proid); - } - if(filter.result != null){ - j_filter.find('tr.result select').val(filter.result); - } - - sub_update(1); - }else if(direct == 'out'){ - index.tab_ll(pbox_name); - that.fadeout(j_pbox); - _clear(); - } - - return 'stop'; - }; - - j_pbox.find('div.subset > table.filter tr.proid input').on('focusin',function(e){ - if($(this).val() == 'None'){ - $(this).val(''); - } - }).on('focusout',function(e){ - if($(this).val() == ''){ - $(this).val('None'); - } - }).on('keypress',function(e){ - var param; - - if(e.which != 13){ - return; - } - - if((filter.proid = $(this).val()) == 'None'){ - filter.proid = null; - } - console.log(filter.proid); - if((param = filter_getparam()) != ''){ - com.url_push('/toj/stat/sub/' + param + '/'); - }else{ - com.url_push('/toj/stat/sub/'); - } - }); - j_pbox.find('div.subset > table.filter tr.result select').on('change',function(e){ - var param; - - if((filter.result = $(this).val()) == 'null'){ - filter.result = null; - } - if((param = filter_getparam()) != ''){ - com.url_push('/toj/stat/sub/' + param + '/'); - }else{ - com.url_push('/toj/stat/sub/'); - } - }); - j_pbox.find('div.subset > table.filter button.clear').on('click',function(e){ - com.url_push('/toj/stat/sub/'); - }); - j_table.on('mousedown',function(e){ - return false; - }); -}; __extend(class_stat_sub_pbox,class_com_pbox); - -var class_stat_subres_mbox = function(subid,subo){ - var that = this; - - that.subid = subid; - that.subo = subo; - that.node = new vus.node('res'); - - that.__super(); -}; __extend(class_stat_subres_mbox,class_com_mbox); -var class_stat_subfile_mbox = function(){ - var that = this; - var j_mbox = $('#index_mask > div.stat_mask > div.subfile_mbox'); - - var filebox_add = function(filename,content){ - var j_name; - var j_box; - var filebox; - - j_name = $('<label></label>'); - j_name.text(filename); - j_box = $('<div class="filebox"></div>'); - filebox = CodeMirror(j_box[0],{ - mode:'text/x-c++src', - theme:'lesser-dark', - lineNumbers:true, - matchBrackets:true, - indentUnit:4, - readOnly:true - }); - filebox.getWrapperElement().style.width = '100%'; - filebox.getWrapperElement().style.height = '100%'; - filebox.getScrollerElement().style.width = '100%'; - filebox.getScrollerElement().style.height = '100%'; - filebox.setValue(content); - - j_mbox.append(j_name); - j_mbox.append(j_box); - filebox.refresh(); - } - - that.node = new vus.node('file'); - - that.__super(); - - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - that.fadein(j_mbox); - j_mbox.find('h2.subid').text('SubID: ' + stat.sub_subid); - - $.post('/toj/php/status.php',{'action':'get_submit_data','data':JSON.stringify({'subid':stat.sub_subid})},function(res){ - var i; - var reto; - - if(res[0] != 'E'){ - reto = JSON.parse(res); - for(i = 0;i < reto.length;i++){ - filebox_add(reto[i].filename,reto[i].content); - } - } - }); - }else if(direct == 'out'){ - that.fadeout(j_mbox); - j_mbox.find('label').remove(); - j_mbox.find('div.filebox').remove(); - } - - return 'cont'; - }; - - j_mbox.find('button.result').on('click',function(e){ - com.url_update('/toj/m/sub/' + stat.sub_subid + '/res/'); - }); -}; __extend(class_stat_subfile_mbox,class_com_mbox); diff --git a/toj/jcs/user.css b/toj/jcs/user.css deleted file mode 100755 index a99f8c9..0000000 --- a/toj/jcs/user.css +++ /dev/null @@ -1,268 +0,0 @@ -div.user_page > div.main_pbox > div.info_box{ - width:240px; - padding:32px 0px 32px 0px; - float:left; -} -div.user_page > div.main_pbox > div.info_box > div.name{ - width:100%; - height:32px; - padding:0px 0px 6px 0px; - font-weight:bold; - line-height:32px; - word-break:break-all; -} -div.user_page > div.main_pbox > div.info_box > img.avatar{ - width:100%; - display:block; -} -div.user_page > div.main_pbox > div.info_box > div.aboutme{ - width:100%; - padding:6px 0px 6px 0px; - word-break:break-all; -} -div.user_page > div.main_pbox > div.data_box{ - width:978px; - margin:0px 0px 0px 6px; - padding:32px 0px 32px 0px; - float:left; -} -div.user_page > div.main_pbox > div.data_box > div.statis > div.chart_box{ - width:322px; - height:240px; - margin:0px 6px 6px 0px; - background-color:#1C1C1C; - float:left; - position:relative; -} -div.user_page > div.main_pbox > div.data_box > div.statis > div.chart_box > div.title{ - position:absolute; - top:6px; - left:6px; - z-index:1 -} -div.user_page > div.main_pbox > div.data_box > div.statis > div.chart_box > div.chart{ - width:100%; - height:100%; - position:absolute; - top:0px; - left:0px; - z-index:0 -} -div.user_page > div.main_pbox > div.data_box > div.statis > div.timecombo{ - width:978px; - height:240px; -} -div.user_page > div.main_pbox > div.data_box > div.trylist > span.item{ - width:35px; - height:24px; - margin:0px 6px 6px 0px; - line-height:24px; - background-color:#1C1C1C; - display:inline-block; -} -div.user_page > div.main_pbox > div.data_box > div.trylist > span.item > a{ - padding:0px 0px 0px 3px; - font-size:12px; -} -div.user_page > div.edit_pbox > div.edit_box{ - width:240px; - margin:0px 0px 0px 246px; - padding:0px 0px 32px 0px; -} -div.user_page > div.edit_pbox > div.edit_box > img.avatar{ - width:100%; - margin:0px 0px 16px 0px; - display:block; -} -div.user_page > div.edit_pbox > div.edit_box > div.error{ - margin:0px 0px 16px 0px; - color:#FFA0A0; -} -div.user_page > div.edit_pbox > div.edit_box input{ - width:228px; - margin:0px 0px 16px 0px; -} -div.user_page > div.mgsq_pbox > div.in_box{ - width:486px; - margin:0px 0px 0px 246px; - padding:0px 0px 32px 0px; - float:left; -} -div.user_page > div.mgsq_pbox > div.out_box{ - width:486px; - margin:0px 0px 0px 6px; - padding:0px 0px 32px 0px; - float:left; -} -div.user_page > div.mgsq_pbox div.item{ - width:auto; - margin:6px 0px 6px 0px; - padding:6px 0px 6px 6px; - cursor:pointer; -} -div.user_page > div.mgsq_pbox div.item_s{ - background-color:rgba(255,255,255,0.2); -} -div.user_page > div.mgsq_pbox div:hover.item{ - background-color:rgba(255,255,255,0.2); -} -div.user_page > div.mgsq_pbox div.item > div.info{ - width:100%; - height:32px; - line-height:32px; -} -div.user_page > div.mgsq_pbox div.item > div.info > span.time{ - width:237px; - height:32px; - color:#BDC0BA; - font-size:12px; - line-height:32px; - float:right; -} -div.user_page > div.mgsq_pbox div.item > div.data{ - width:100%; - height:32px; - margin:6px 0px 0px 0px; - display:none; -} -div.user_page > div.mg_pbox > div.left_box{ - margin:0px 0px 0px 246px; - padding:0px 0px 32px 0px; - float:left; -} -div.user_page > div.mg_pbox table.prolist{ - width:486px; - border-collapse:collapse; - text-align:left; -} -div.user_page > div.mg_pbox table.prolist tr.head{ - height:64px; -} -div.user_page > div.mg_pbox table.prolist tr.item{ - height:44px; -} -div.user_page > div.mg_pbox table.prolist tr:hover.item{ - background-color:rgba(255,255,255,0.2); -} -div.user_page > div.mg_pbox table.prolist th,div.user_page > div.mg_pbox table.prolist td{ - width:76px; - padding:0px 0px 0px 6px; -} -div.user_page > div.mg_pbox table.prolist th.name,div.user_page > div.mg_pbox table.prolist td.name{ - width:auto; -} - -div.user_mask > div.editsq_mbox > div.edit_box{ - width:322px; - margin:0px 0px 0px 164px; - padding:6px 0px 32px 0px; - float:left; -} -div.user_mask > div.editsq_mbox > div.edit_box > div.error{ - margin:0px 0px 16px 0px; - color:#FFA0A0; -} -div.user_mask > div.editsq_mbox > div.edit_box input{ - width:146px; - margin:0px 0px 16px 0px; -} -div.user_mask > div.editsq_mbox > div.edit_box > div.time > input{ - width:35px; -} -div.user_mask > div.editsq_mbox > div.edit_box select{ - width:76px; - height:32px; - margin:0px 0px 16px 0px; -} -div.user_mask > div.editsq_mbox > div.pro_box{ - width:404px; - margin:0px 0px 0px 6px; - padding:6px 0px 32px 0px; - float:left; -} -div.user_mask > div.editsq_mbox > div.pro_box > div.prolist_box{ - width:100%; - max-height:256px; - overflow-y:scroll; -} -div.user_mask > div.editsq_mbox > div.pro_box table.prolist{ - width:100%; - border-collapse:collapse; - text-align:left; -} -div.user_mask > div.editsq_mbox > div.pro_box table.prolist tr.item{ - height:44px; -} -div.user_mask > div.editsq_mbox > div.pro_box table.prolist tr:hover.item{ - background-color:rgba(255,255,255,0.2); -} -div.user_mask > div.editsq_mbox > div.pro_box table.prolist td{ - width:76px; - padding:0px 0px 0px 6px; -} -div.user_mask > div.editsq_mbox > div.pro_box table.prolist td.name{ - width:auto; -} - -div.user_mask > div.editpro_mbox > div.edit_box{ - margin:0px 0px 0px 246px; - padding:6px 0px 32px 0px; -} -div.user_mask > div.editpro_mbox > div.edit_box > div.error{ - margin:0px 0px 16px 0px; - color:#FFA0A0; -} -div.user_mask > div.editpro_mbox > div.edit_box input{ - width:146px; - height:32px; - margin:0px 0px 16px 0px; -} -div.user_mask > div.editpro_mbox > div.edit_box select{ - width:76px; - height:32px; - margin:0px 0px 16px 0px; - border-width:0px; - display:block; -} - -div.login_pbox > div.info_box{ - width:486px; - margin:128px 0px 0px 246px; - float:left; -} -div.login_pbox > div.login_box{ - width:240px; - margin:128px 0px 0px 0px; - padding:0px 6px 0px 0px; - float:left; -} -div.login_pbox > div.login_box > div.error{ - margin:0px 0px 16px 0px; - color:#FFA0A0; -} -div.login_pbox > div.login_box > input{ - width:228px; - height:32px; - margin:0px 0px 16px 0px; -} - -div.register_pbox > div.info_box{ - width:486px; - margin:128px 0px 0px 246px; - float:left; -} -div.register_pbox > div.register_box{ - width:240px; - margin:128px 0px 0px 0px; - padding:0px 6px 0px 0px; - float:left; -} -div.register_pbox > div.register_box > div.error{ - margin:0px 0px 16px 0px; - color:#FFA0A0; -} -div.register_pbox > div.register_box > input{ - width:228px; - height:32px; - margin:0px 0px 16px 0px; -} diff --git a/toj/jcs/user.js b/toj/jcs/user.js deleted file mode 100755 index 81e30ca..0000000 --- a/toj/jcs/user.js +++ /dev/null @@ -1,1540 +0,0 @@ -/* -square state -0 => wait -1 => run -2 => past -*/ - -var user = new function(){ - var that = this; - var main_pbox = null; - var edit_pbox = null; - var mgsq_pbox = null; - var mg_pbox = null; - var uid_node = null; - - that.login_chg = $.Callbacks(); - that.data_chg = $.Callbacks(); - - that.uid = null; - that.level = null; - that.username = null; - that.nickname = null; - that.avatar = null; - that.aboutme = null; - that.email = null; - that.sq_inlist = null; - - that.view_uid = null; - - that.init = function(){ - that.login_pbox = new class_login_pbox; - that.register_pbox = new class_register_pbox; - - main_pbox = new class_user_main_pbox; - edit_pbox = new class_user_edit_pbox; - mgsq_pbox = new class_user_mgsq_pbox; - mg_pbox = new class_user_mg_pbox; - that.editsq_mbox = new class_user_editsq_mbox; - that.editpro_mbox = new class_user_editpro_mbox; - - that.user_node = new vus.node('user'); - - uid_node = new vus.node(''); - uid_node.child_set(main_pbox.node); - uid_node.child_set(edit_pbox.node); - uid_node.child_set(mgsq_pbox.node); - uid_node.child_set(mg_pbox.node); - - that.user_node.url_chg = function(direct,url_upart,url_dpart){ - var uid; - - if(direct == 'in' || direct == 'same'){ - index.title_set('TOJ-使用者'); - - if((uid = url_dpart[0]) == ''){ - com.url_update('/toj/none/'); - return 'stop'; - } - uid = parseInt(uid); - if(uid == that.view_uid){ - return 'cont'; - } - - if(uid != null){ - that.user_node.child_del(uid_node); - index.tab_empty(); - } - - uid_node.name = uid.toString(); - that.user_node.child_set(uid_node); - - if(url_dpart[1] == undefined){ - com.url_update('/toj/user/' + uid + '/main/'); - return 'stop'; - } - - that.view_uid = uid; - - index.tab_add('main','/toj/user/' + that.view_uid + '/main/','個人'); - if(that.view_uid == that.uid){ - index.tab_add('edit','/toj/user/' + that.uid + '/edit/','設定'); - index.tab_add('mgsq','/toj/user/' + that.uid + '/mgsq/','方塊'); - if((user.level & USER_LEVEL_SUPERADMIN) == USER_LEVEL_SUPERADMIN){ - index.tab_add('mg','/toj/user/' + that.uid + '/mg/','管理'); - } - } - }else if(direct == 'out'){ - if(that.view_uid != null){ - that.user_node.child_del(uid_node); - } - that.view_uid = null; - - index.tab_empty(); - } - - return 'cont'; - }; - com.vus_root.child_set(that.user_node); - - $('#index_panel > li.logout > a.button').off('click').on('click',function(e){ - var cookie; - var key; - - cookie = com.get_cookie(); - for(key in cookie){ - document.cookie = key + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/toj/'; - } - - location.href = '/toj/home/'; - return false; - }); - that.login_chg.add(function(login){ - var j_notice; - var j_nickname; - - j_notice = $('#index_head_notice'); - j_nickname = $('#index_head_nickname > a.nickname'); - - if(login){ - j_notice.show(); - j_nickname.attr('href','/toj/user/' + that.uid + '/main/'); - j_nickname.text(that.nickname); - - index.panel_hide('login'); - index.panel_hide('register'); - index.panel_show('logout'); - index.panel_set('user','/toj/user/' + that.uid + '/main/','個人'); - index.panel_show('user'); - index.panel_show('square'); - - $('#index_panel > ul.square_box > li.mgsq > a.button').attr('href','/toj/user/' + that.uid + '/mgsq/'); - }else{ - j_notice.hide(); - j_nickname.attr('href',''); - j_nickname.text(''); - - index.panel_show('login'); - index.panel_show('register'); - index.panel_hide('logout'); - index.panel_set('user',null,'個人'); - index.panel_hide('user'); - index.panel_hide('square'); - - $('#index_panel > ul.square_box > li.mgsq > a.button').attr('href',null); - } - }); - that.data_chg.add(function(){ - var i; - var j_ul_run; - var j_ul_past; - var sqo; - var idx_run; - var idx_past; - - var panelsq_listadd = function(j_ul,idx,sqid,sqname){ - var j_li; - var j_a; - - j_li = $(j_ul.find('li.square')[idx]); - if(j_li.length == 0){ - j_li = $('<li class="button square"><a class="button"></a></li>'); - j_li.hide(); - j_ul.append(j_li); - } - - j_a = j_li.find('a.button'); - j_a.attr('href','/toj/sq/' + sqid + '/pro/'); - j_a.text(sqname); - - j_li.show(); - }; - - $('#index_head_nickname > a.nickname').text(that.nickname); - - j_ul_run = $('#index_panel > ul.square_box > ul.run'); - j_ul_run.find('li.square').hide(); - idx_run = 0; - j_ul_past = $('#index_panel > ul.square_box > ul.past'); - j_ul_past.find('li.square').hide(); - idx_past = 0; - for(i = 0;i < user.sq_inlist.length;i++){ - sqo = user.sq_inlist[i]; - if(sqo.relationship != 1){ - if(sqo.state == 1){ - panelsq_listadd(j_ul_run,idx_run,sqo.sqid,sqo.sqname); - idx_run++; - }else if(sqo.state == 2){ - panelsq_listadd(j_ul_past,idx_past,sqo.sqid,sqo.sqname); - idx_past++; - } - } - } - }); - - user.update(true); - }; - that.update = function(sync){ - $.ajax({'url':'/toj/php/user.php', - 'type':'POST', - 'data':{'action':'view','data':JSON.stringify({'uid':null})}, - 'async':!sync, - 'success':function(res){ - var usero; - var old_uid; - - old_uid = that.uid; - if(res[0] == 'E'){ - that.uid = null; - that.level = null; - that.username = null; - that.nickname = null; - that.avatar = null; - that.aboutme = null; - that.email = null; - that.sq_inlist = null; - - that.login_chg.fire(false); - }else{ - usero = JSON.parse(res).user; - that.uid = usero.uid; - that.level = usero.level; - that.username = usero.username; - that.nickname = usero.nickname; - that.avatar = usero.avatar; - that.aboutme = usero.aboutme; - that.email = usero.email; - - if(old_uid != that.uid){ - that.login_chg.fire(true); - } - - $.post('/toj/php/square.php',{'action':'get_entered_sq','data':JSON.stringify({'uid':that.uid})},function(res){ - var i; - var reto; - var ts; - var sqlist; - var sqo; - - if(res[0] == 'E'){ - return; - } - - reto = JSON.parse(res); - ts = com.get_date(reto.timestamp); - sqlist = reto.list; - for(i = 0;i < sqlist.length;i++){ - sqo = sqlist[i]; - sqo.state = 1; - if(sqo.start_time != null){ - sqo.start_time = com.get_date(sqo.start_time); - if(ts < sqo.start_time){ - sqo.state = 0; - } - } - if(sqo.end_time != null){ - sqo.end_time = com.get_date(sqo.end_time); - if(sqo.end_time < ts){ - sqo.state = 2; - } - } - } - user.sq_inlist = sqlist; - - user.data_chg.fire(true); - }); - } - } - }); - }; -}; - -var class_user_main_pbox = function(){ - var that = this; - var j_pbox = $('#index_page > div.user_page > div.main_pbox'); - - that.node = new vus.node('main'); - - that.__super(); - - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - index.tab_hl('main'); - that.fadein(j_pbox); - - $.post('/toj/php/user.php',{'action':'view','data':JSON.stringify({'uid':user.view_uid})},function(res){ - var i; - - var reto; - var usero; - var statiso; - var trylist; - var substatis; - var actry; - var series; - var total; - - var j_div; - var j_span; - var j_a; - - var pie_add = function(j_div,series){ - var draw = function(){ - var data = google.visualization.arrayToDataTable(series); - var chart = new google.visualization.PieChart(j_div[0]); - - chart.draw(data,{ - 'chartArea':{'width':'90%','height':'85%','top':'15%','left':'10%'}, - 'backgroundColor':'#1C1C1C', - 'legend':{ - 'textStyle':{'color':'#E9E9E9'} - }, - 'pieSliceBorderColor':'#E9E9E9', - 'pieSliceText':'value', - 'titleTextStyle':{'color':'#E9E9E9','fontSize':'16'} - }); - } - if(typeof google === 'object'){ - draw(); - }else{ - google.setOnLoadCallback(draw); - } - }; - var combo_add = function(j_div,series){ - var draw = function(){ - var data = google.visualization.arrayToDataTable(series); - var chart = new google.visualization.ComboChart(j_div[0]); - - chart.draw(data,{ - 'backgroundColor':'#1C1C1C', - 'legend':{ - 'textStyle':{'color':'#E9E9E9'} - }, - 'titleTextStyle':{'color':'#E9E9E9','fontSize':'16'}, - 'hAxis':{'textStyle':{'color':'#E9E9E9'},'slantedText':false}, - 'vAxis':{'textStyle':{'color':'#E9E9E9'}}, - 'series':{'0':{'type':'bars','targetAxisIndex':0}} - }); - } - if(typeof google === 'object'){ - draw(); - }else{ - google.setOnLoadCallback(draw); - } - }; - var draw_timeline = function(timesub){ - var i; - var j; - var series; - var part; - var last_time; - var curr_time; - - if(timesub.length == 0){ - return; - } - series = new Array(); - series.push(['Time','上傳次數']); - - part = timesub[0].time.split('-'); - last_time = parseInt(part[0]) * 12 + parseInt(part[1]) + 1; - - series.push([timesub[0].time,timesub[0].count]); - - for(i = 1;i < timesub.length;i++){ - part = timesub[i].time.split('-'); - curr_time = parseInt(part[0]) * 12 + parseInt(part[1]); - - for(;last_time < curr_time;last_time++){ - if((last_time % 6) == 1){ - series.push([Math.floor(last_time / 12) + '-' + last_time % 12,0]); - }else{ - series.push(['',0]); - } - } - - if((last_time % 6) == 1){ - series.push([Math.floor(last_time / 12) + '-' + last_time % 12,timesub[i].count]); - }else{ - series.push(['',timesub[i].count]); - } - - last_time = curr_time + 1; - } - - combo_add(j_pbox.find('div.data_box > div.statis > div.timecombo > div.chart'),series); - }; - - if(res[0] == 'E'){ - com.url_update('/toj/none/'); - }else{ - reto = JSON.parse(res); - usero = reto.user; - statiso = reto.statis; - - j_pbox.find('div.info_box > div.name').text(usero.nickname + ' (' + usero.username + ')'); - if(usero.avatar == ''){ - j_pbox.find('div.info_box > img.avatar').attr('src','http://i.imgur.com/ykkQD.png'); - }else{ - j_pbox.find('div.info_box > img.avatar').attr('src',usero.avatar); - } - j_pbox.find('div.info_box > div.aboutme').text(usero.aboutme); - - j_div = j_pbox.find('div.data_box > div.trylist'); - trylist = statiso.trylist; - actry = 0; - for(i = 0;i < trylist.length;i++){ - j_span = $('<span class="item"><a></a></span>'); - - j_a = j_span.find('a'); - j_a.css('color',RESULTCOLOR[trylist[i].result]); - j_a.text(trylist[i].proid); - j_a.attr('href','/toj/pro/' + trylist[i].proid + '/'); - - j_div.append(j_span); - - if(trylist[i].result == 0){ - actry++; - } - } - - substatis = statiso.substatis; - series = new Array(); - series[0] = ['Result','Count']; - total = 0; - for(i = 0;i < substatis.length;i++){ - series[i + 1] = [RESULTMAP[substatis[i].result],substatis[i].count]; - } - - pie_add(j_pbox.find('div.data_box > div.statis > div.subpie > div.chart'),series); - - pie_add(j_pbox.find('div.data_box > div.statis > div.trypie > div.chart'), - [['Result','Count'], - ['AC',actry], - ['Failed',statiso.trylist.length - actry] - ]); - - draw_timeline(statiso.timesub); - } - }); - }else if(direct == 'out'){ - index.tab_ll('main'); - that.fadeout(j_pbox); - - j_pbox.find('div.info_box > div.name').text(''); - j_pbox.find('div.info_box > img.avatar').attr('src',''); - j_pbox.find('div.data_box > div.trylist').empty(); - } - }; - - j_pbox.find('div.data_box > button.looksub').on('click',function(e){ - com.url_push('/toj/stat/sub/uid:' + user.view_uid + '/'); - }); -}; __extend(class_user_main_pbox,class_com_pbox); - -var class_user_edit_pbox = function(){ - var that = this; - var j_pbox = $('#index_page > div.user_page > div.edit_pbox'); - - that.node = new vus.node('edit'); - - that.__super(); - - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - index.tab_hl('edit'); - that.fadein(j_pbox); - - j_pbox.find('div.edit_box > [name="nickname"]').val(user.nickname); - j_pbox.find('div.edit_box > [name="avatar"]').val(user.avatar); - if(user.avatar == ''){ - j_pbox.find('div.edit_box > img.avatar').attr('src','http://i.imgur.com/ykkQD.png'); - }else{ - j_pbox.find('div.edit_box > img.avatar').attr('src',user.avatar); - } - j_pbox.find('div.edit_box > [name="aboutme"]').val(user.aboutme); - j_pbox.find('div.edit_box > [name="email"]').val(user.email); - }else if(direct == 'out'){ - index.tab_ll('edit'); - that.fadeout(j_pbox); - - j_pbox.find('div.edit_box > input').val(''); - j_pbox.find('div.edit_box > img.avatar').attr('src',null); - j_pbox.find('div.edit_box > div.error').text(''); - } - }; - - j_pbox.find('div.edit_box > [name="avatar"]').change(function(e){ - var avatar; - - avatar = $(this).val(); - if(avatar == ''){ - j_pbox.find('div.edit_box > img.avatar').attr('src','http://i.imgur.com/ykkQD.png'); - }else{ - j_pbox.find('div.edit_box > img.avatar').attr('src',avatar); - }('test') - }); - j_pbox.find('div.edit_box > button.submit').click(function(e){ - var j_error; - var nickname; - var avatar; - var aboutme; - var email; - var password_old; - var password_new; - var password_repeat; - var data; - - j_error = j_pbox.find('div.edit_box > div.error'); - nickname = j_pbox.find('div.edit_box > [name="nickname"]').val(); - avatar = j_pbox.find('div.edit_box > [name="avatar"]').val(); - aboutme = j_pbox.find('div.edit_box > [name="aboutme"]').val(); - email = j_pbox.find('div.edit_box > [name="email"]').val(); - password_old = j_pbox.find('div.edit_box > [name="password_old"]').val(); - password_new = j_pbox.find('div.edit_box > [name="password_new"]').val(); - password_repeat = j_pbox.find('div.edit_box > [name="password_repeat"]').val(); - - data = {'nickname':nickname,'avatar':avatar,'aboutme':aboutme,'email':email}; - if(password_old != '' || password_new != '' || password_repeat != ''){ - if(password_new != password_repeat){ - j_error.text('使用者密碼不相同'); - return; - } - data.oldpw = password_old; - data.password = password_new; - } - - $.post('/toj/php/user.php',{'action':'update','data':JSON.stringify(data)},function(res){ - if(res[0] == 'E'){ - switch(res){ - case 'Epassword_too_short': - j_error.text('使用者密碼太短'); - break; - case 'Epassword_too_long': - j_error.text('使用者密碼太長'); - break; - case 'Enickname_too_short': - j_error.text('暱稱太短'); - break; - case 'Enickname_too_long': - j_error.text('暱稱太長'); - break; - case 'Eold_password_not_match': - j_error.text('舊使用者密碼錯誤'); - break; - case 'Eempty_email': - j_error.text('電子郵件不能爲空'); - break; - case 'Eemail_too_long': - j_error.text('電子郵件太長'); - break; - default: - j_error.text('更新錯誤'); - break; - } - }else{ - user.update(true); - com.url_push('/toj/user/' + user.uid + '/main/'); - } - }); - }); - j_pbox.find('div.edit_box > button.cancel').click(function(e){ - com.url_push('/toj/user/' + user.uid + '/main/'); - }); -}; __extend(class_user_edit_pbox,class_com_pbox); - -var class_user_mgsq_pbox = function(){ - var that = this; - var j_pbox = $('#index_page > div.user_page > div.mgsq_pbox'); - - var sq_join = function(sqid){ - $.post('/toj/php/square.php',{'action':'add_user','data':JSON.stringify({'uid':user.uid,'sqid':sqid})},function(res){ - if(res[0] != 'E'){ - sq_update(); - } - }); - }; - var sq_quit = function(sqid){ - $.post('/toj/php/square.php',{'action':'delete_user','data':JSON.stringify({'uid':user.uid,'sqid':sqid})},function(res){ - if(res[0] != 'E'){ - sq_update(); - } - }); - }; - var sq_listset = function(j_item,sqo){ - var j_info; - var j_data; - var j_button; - - j_info = j_item.find('div.info'); - j_data = j_item.find('div.data'); - j_data.empty(); - - j_item.attr('sqid',sqo.sqid); - - j_info.find('span.name').text(sqo.sqname); - - if(sqo.end_time == null){ - j_info.find('span.time').text(''); - }else{ - j_info.find('span.time').text(com.get_datestring(sqo.start_time,false) + ' > ' + com.get_datestring(sqo.end_time,false)); - } - - if(sqo.relationship == 3 || (user.level & USER_LEVEL_SUPERADMIN) == USER_LEVEL_SUPERADMIN){ - j_button = $('<button style="margin:0px 6px 0px 0px;">管理</button>'); - j_button.on('click',function(e){ - user.editsq_mbox.init('edit',sqo).done(sq_update); - com.url_push('/toj/m/user_editsq/'); - return false; - }); - j_data.append(j_button); - } - - j_button = $('<button style="margin:0px 6px 0px 0px;"></button>'); - if(sqo.relationship == 0){ - if(sqo.publicity == 2 && (user.level & USER_LEVEL_SUPERADMIN) != USER_LEVEL_SUPERADMIN){ - j_button.text('申請'); - }else{ - j_button.text('加入'); - } - j_button.off('click').on('click',function(e){ - sq_join(sqo.sqid); - return false; - }); - }else{ - if(sqo.relationship == 1){ - j_button.text('取消申請'); - }else{ - j_button.text('退出'); - } - j_button.on('click',function(e){ - sq_quit(sqo.sqid); - return false; - }); - } - j_data.append(j_button); - - if(sqo.relationship >= 2){ - j_button = $('<button>開啟</button>'); - j_button.on('click',function(e){ - com.url_push('/toj/sq/' + sqo.sqid + '/pro/'); - return false; - }); - j_data.append(j_button); - } - - j_item.off('click').on('click',function(e){ - if(j_data.is(':visible')){ - j_item.removeClass('item_s'); - j_data.stop().fadeTo(100,0).slideUp('fast'); - }else{ - j_item.addClass('item_s'); - j_data.stop().css('opacity',1).slideDown('fast'); - } - }); - }; - var sq_listnew = function(sqo){ - var j_item; - var j_info; - var j_data; - - j_item = $('<div class="item"></div>'); - j_info = $('<div class="info"><span class="name"></span><span class="time"></span></div>'); - j_item.append(j_info); - j_data = $('<div class="data"></div>'); - j_item.append(j_data); - - sq_listset(j_item,sqo); - - return j_item; - }; - var sq_update = function(){ - var _updatelist = function(j_list,sqlist){ - var i; - var j; - - var divs; - var j_last; - var j_item; - var oldhash; - var sqo; - - divs = j_list.children('div.item'); - oldhash = new Array(); - for(i = 0;i < divs.length;i++){ - oldhash[$(divs[i]).attr('sqid')] = i; - } - - j = 0; - j_last = null; - for(i = 0;i < sqlist.length;i++){ - sqo = sqlist[i]; - if(sqo.sqid in oldhash){ - for(;j < oldhash[sqo.sqid];j++){ - j_item = $(divs[j]); - j_item.stop().fadeTo(100,0).slideUp('fast',function(){$(this).remove();}); - } - j_item = $(divs[j]); - j++; - - sq_listset(j_item,sqo); - j_last = j_item; - }else{ - j_item = sq_listnew(sqo); - j_item.hide(); - if(j_last == null){ - j_list.prepend(j_item); - }else{ - j_item.insertAfter(j_last); - } - j_item.css('opacity',0).slideDown('fast').fadeTo(100,1); - j_last = j_item; - } - } - for(;j < divs.length;j++){ - j_item = $(divs[j]); - j_item.stop().fadeTo(100,0).slideUp('fast',function(){$(this).remove();}); - } - }; - - user.data_chg.add(function(){ - var i; - var sqo; - var sqwait; - var sqrun; - var sqpast; - - var j_wait; - var j_run; - var j_past; - - user.data_chg.remove(arguments.callee); - - sqwait = new Array(); - sqrun = new Array(); - sqpast = new Array(); - for(i = 0;i < user.sq_inlist.length;i++){ - sqo = user.sq_inlist[i]; - switch(sqo.state){ - case 0: - sqwait.push(sqo); - break; - case 1: - sqrun.push(sqo); - break; - case 2: - sqpast.push(sqo); - break; - }; - } - - j_wait = j_pbox.find('div.in_box > div.wait'); - j_run = j_pbox.find('div.in_box > div.run'); - j_past = j_pbox.find('div.in_box > div.past'); - - _updatelist(j_wait,sqwait); - _updatelist(j_run,sqrun); - _updatelist(j_past,sqpast); - }); - user.update(false); - - $.post('/toj/php/square.php',{'action':'get_available_sq','data':null},function(res){ - var i; - var reto; - var ts; - var sqlist; - var sqo; - var sqwait; - var sqrun; - var sqpast; - - var j_wait; - var j_run; - var j_past; - - if(res[0] == 'E'){ - return; - } - - reto = JSON.parse(res); - ts = com.get_date(reto.timestamp); - sqlist = reto.list; - sqwait = new Array(); - sqrun = new Array(); - sqpast = new Array(); - for(i = 0;i < sqlist.length;i++){ - sqo = sqlist[i]; - sqo.relationship = 0; - sqo.state = 1; - if(sqo.start_time != null){ - sqo.start_time = com.get_date(sqo.start_time); - if(ts < sqo.start_time){ - sqo.state = 0; - } - } - if(sqo.end_time != null){ - sqo.end_time = com.get_date(sqo.end_time); - if(sqo.end_time < ts){ - sqo.state = 2; - } - } - - switch(sqo.state){ - case 0: - sqwait.push(sqo); - break; - case 1: - sqrun.push(sqo); - break; - case 2: - sqpast.push(sqo); - break; - } - } - - j_wait = j_pbox.find('div.out_box > div.wait'); - j_run = j_pbox.find('div.out_box > div.run'); - j_past = j_pbox.find('div.out_box > div.past'); - - _updatelist(j_wait,sqwait); - _updatelist(j_run,sqrun); - _updatelist(j_past,sqpast); - }); - } - - that.node = new vus.node('mgsq'); - - that.__super(); - - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - index.tab_hl('mgsq'); - that.fadein(j_pbox); - sq_update(); - }else if(direct == 'out'){ - index.tab_ll('mgsq'); - that.fadeout(j_pbox); - j_pbox.find('div.in_box > div > div').remove(); - j_pbox.find('div.out_box > div > div').remove(); - } - - return 'cont'; - }; -}; __extend(class_user_mgsq_pbox,class_com_pbox); - -var class_user_mg_pbox = function(){ - var that = this; - var j_pbox = $('#index_page > div.user_page > div.mg_pbox'); - - var pro_listset = function(j_item,proo){ - j_item.find('td.proid').text(proo.proid); - j_item.find('td.name').text(proo.proname); - j_item.find('td.cacheid').text(proo.cacheid); - }; - var pro_listnew = function(proo){ - var j_item; - - j_item = $('<tr class="item"><td class="proid"></td><td class="name"></td><td class="cacheid"></td><td><button class="setting" style="display:none;">設置</button></td></tr>'); - j_item.hover( - function(){ - $(this).find('button.setting').show(); - }, - function(){ - $(this).find('button.setting').hide(); - } - ); - j_item.find('button.setting').on('click',function(e){ - user.editpro_mbox.init('edit',proo).done(function(){ - pro_update(); - }); - com.url_push('/toj/m/user_editpro/'); - }); - - pro_listset(j_item,proo); - - return j_item; - }; - var pro_update = function(){ - $.post('/toj/php/problem.php',{'action':'get_pro_list','data':null},function(res){ - var i; - - var reto; - var j_table; - var j_item; - - if(res[0] == 'E'){ - return; - } - - reto = JSON.parse(res); - j_table = j_pbox.find('table.prolist'); - j_table.find('tr.item').remove(); - for(i = 0;i < reto.length;i++){ - j_item = pro_listnew(reto[i]); - j_table.append(j_item); - } - }); - }; - - that.node = new vus.node('mg'); - - that.__super(); - - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - index.tab_hl('mg'); - that.fadein(j_pbox); - - pro_update(); - }else if(direct == 'out'){ - index.tab_ll('mg'); - that.fadeout(j_pbox); - } - - return 'cont'; - }; - - j_pbox.find('button.newsq').on('click',function(e){ - user.editsq_mbox.init('new'); - com.url_push('/toj/m/user_editsq/'); - }); - j_pbox.find('button.newpro').on('click',function(e){ - user.editpro_mbox.init('new').done(function(){ - pro_update(); - }); - com.url_push('/toj/m/user_editpro/'); - }); -}; __extend(class_user_mg_pbox,class_com_pbox); - -var class_user_editsq_mbox = function(){ - var that = this; - var j_mbox = $('#index_mask > div.user_mask > div.editsq_mbox'); - var action = null; - var sqid = null; - var defer = null; - - var pro_listset = function(j_item,proo,type){ - j_item.attr('proid',proo.proid); - j_item.find('td.id').text(proo.proid); - j_item.find('td.name').text(proo.proname); - - j_button = j_item.find('button.oper'); - if(type == 'in'){ - j_button.text('移除'); - j_button.off('click').on('click',function(e){ - $.post('/toj/php/square.php',{'action':'delete_pro_from_sq','data':JSON.stringify({'sqid':sqid,'proid':proo.proid})},function(res){ - if(res == 'S'){ - pro_update(); - } - }); - }); - }else{ - j_button.text('加入'); - j_button.off('click').on('click',function(e){ - $.post('/toj/php/square.php',{'action':'add_pro_into_sq','data':JSON.stringify({'sqid':sqid,'proid':proo.proid})},function(res){ - if(res == 'S'){ - pro_update(); - } - }); - }); - } - }; - var pro_listnew = function(proo,type){ - var j_item; - - j_item = $('<tr class="item"><td class="id"></td><td class="name"></td><td><button class="oper" style="display:none;"></button></td></tr>'); - pro_listset(j_item,proo,type); - - j_item.hover( - function(){ - $(this).find('button.oper').show(); - }, - function(){ - $(this).find('button.oper').hide(); - } - ); - - return j_item; - }; - var pro_update = function(){ - _updatelist = function(j_table,prolist,type){ - var i; - var j; - - var trs; - var j_last; - var j_item; - var oldhash; - var proo; - - trs = j_table.find('tr.item'); - oldhash = new Array(); - for(i = 0;i < trs.length;i++){ - oldhash[$(trs[i]).attr('proid')] = i; - } - - j = 0; - j_last = null; - for(i = 0;i < prolist.length;i++){ - proo = prolist[i]; - - if(proo.proid in oldhash){ - for(;j < oldhash[proo.proid];j++){ - j_item = $(trs[j]); - j_item.stop().fadeTo(100,0).slideUp('fast',function(){$(this).remove()}); - } - j_item = $(trs[j]); - j++; - - pro_listset(j_item,proo,type); - }else{ - j_item = pro_listnew(proo,type); - j_item.hide(); - - if(j_last == null){ - j_table.prepend(j_item); - }else{ - j_item.insertAfter(j_last); - } - j_item.css('opacity',0).slideDown('fast').fadeTo(100,1); - } - - j_last = j_item; - } - for(;j < trs.length;j++){ - j_item = $(trs[j]); - j_item.stop().fadeTo(100,0).slideUp('fast',function(){$(this).remove()}); - } - }; - - $.post('/toj/php/square.php',{'action':'get_sq_pro_list','data':JSON.stringify({'sqid':sqid})},function(res){ - var i; - - var inlist; - - if(res[0] != 'E'){ - inlist = JSON.parse(res); - _updatelist(j_mbox.find('table.prolist_in'),inlist,'in'); - } - - $.post('/toj/php/problem.php',{'action':'get_pro_list','data':null},function(res){ - var i; - var j; - - var reto; - var outlist; - - if(res[0] != 'E'){ - reto = JSON.parse(res); - outlist = new Array(); - for(i = 0,j = 0;i < reto.length;i++){ - if(j < inlist.length && reto[i].proid == inlist[j].proid){ - j++; - }else{ - outlist.push(reto[i]); - } - } - _updatelist(j_mbox.find('table.prolist_out'),outlist,'out'); - } - }); - }); - }; - - that.node = new vus.node('user_editsq'); - - that.__super(); - - that.init = function(act,sqo){ - action = act; - if(action == 'edit'){ - sqid = sqo.sqid; - - j_mbox.find('[name="sqname"]').val(sqo.sqname); - j_mbox.find('[name="sqmodname"]').val(sqo.sqmodname); - j_mbox.find('[name="publicity"]').val(sqo.publicity); - if(sqo.end_time == null){ - j_mbox.find('[name="infinite"]').val(1); - }else{ - j_mbox.find('[name="infinite"]').val(2); - j_mbox.find('div.time').show(); - j_mbox.find('[name="s_year"]').val(sqo.start_time.getFullYear()); - j_mbox.find('[name="s_month"]').val(sqo.start_time.getMonth() + 1); - j_mbox.find('[name="s_day"]').val(sqo.start_time.getDate()); - j_mbox.find('[name="s_hr"]').val(sqo.start_time.getHours()); - j_mbox.find('[name="s_min"]').val(sqo.start_time.getMinutes()); - j_mbox.find('[name="e_year"]').val(sqo.end_time.getFullYear()); - j_mbox.find('[name="e_month"]').val(sqo.end_time.getMonth() + 1); - j_mbox.find('[name="e_day"]').val(sqo.end_time.getDate()); - j_mbox.find('[name="e_hr"]').val(sqo.end_time.getHours()); - j_mbox.find('[name="e_min"]').val(sqo.end_time.getMinutes()); - } - j_mbox.find('button.delete').show(); - - pro_update(); - } - - com.vus_mbox.child_set(that.node); - - defer = $.Deferred(); - return defer.promise(); - }; - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - that.fadein(j_mbox); - }else if(direct == 'out'){ - that.fadeout(j_mbox); - - sqid = null; - - j_mbox.find('input').val(''); - j_mbox.find('[name="publicity"]').val(3); - j_mbox.find('[name="infinite"]').val(1); - j_mbox.find('div.time').hide(); - j_mbox.find('button.delete').hide(); - j_mbox.find('div.error').text(''); - - j_mbox.find('table.prolist_in').empty(); - j_mbox.find('table.prolist_out').empty(); - - if(defer.state() == 'pending'){ - defer.reject(); - } - - com.vus_mbox.child_del(that.node); - } - - return 'cont'; - }; - - j_mbox.find('[name="infinite"]').on('change',function(e){ - if($(this).val() == 1){ - j_mbox.find('div.time').hide(); - }else{ - j_mbox.find('div.time').show(); - } - }); - j_mbox.find('button.delete').on('click',function(e){ - if(confirm('確定刪除方塊?')){ - $.post('/toj/php/square.php',{'action':'delete_sq','data':JSON.stringify({'sqid':sqid})},function(res){ - var j_error; - - if(res[0] == 'E'){ - j_error = j_mbox.find('div.error'); - switch(res){ - case 'Eno_login': - j_error.text('未登入'); - case 'Epermission_denied': - j_error.text('權限不足'); - break; - default: - j_error.text('其他錯誤'); - break; - } - }else{ - defer.resolve(); - com.url_pull_pbox(); - } - }); - } - }); - j_mbox.find('button.submit').on('click',function(e){ - var sqname; - var sqmodname; - var publicity; - var start_time; - var end_time; - var j_error; - - sqname = j_mbox.find('[name="sqname"]').val(); - sqmodname = j_mbox.find('[name="sqmodname"]').val(); - publicity = parseInt(j_mbox.find('[name="publicity"]').val()); - if(j_mbox.find('[name="infinite"]').val() == 1){ - start_time = null; - end_time = null; - }else{ - start_time = j_mbox.find('[name="s_year"]').val() + '-' + - j_mbox.find('[name="s_month"]').val() + '-' + - j_mbox.find('[name="s_day"]').val() + ' ' + - j_mbox.find('[name="s_hr"]').val() + ':' + - j_mbox.find('[name="s_min"]').val(); - end_time = j_mbox.find('[name="e_year"]').val() + '-' + - j_mbox.find('[name="e_month"]').val() + '-' + - j_mbox.find('[name="e_day"]').val() + ' ' + - j_mbox.find('[name="e_hr"]').val() + ':' + - j_mbox.find('[name="e_min"]').val(); - } - - j_error = j_mbox.find('div.error'); - if(action == 'new'){ - $.post('/toj/php/square.php',{'action':'add_sq','data':JSON.stringify({'sqname':sqname,'sqmodname':sqmodname,'publicity':publicity,'start_time':start_time,'end_time':end_time})},function(res){ - if(res[0] == 'E'){ - switch(res){ - case 'Eno_login': - j_error.text('未登入'); - case 'Epermission_denied': - j_error.text('權限不足'); - break; - case 'Esqname_too_short': - j_error.text('方塊名稱太短'); - break; - case 'Esqname_too_long': - j_error.text('方塊名稱太長'); - break; - case 'Esqmodname_empty': - j_error.text('模組名稱不能爲空'); - break; - default: - j_error.text('其他錯誤'); - break; - } - }else{ - defer.resolve(); - com.url_pull_pbox(); - } - }); - }else if(action == 'edit'){ - $.post('/toj/php/square.php',{'action':'edit_sq','data':JSON.stringify({'sqid':sqid,'sqname':sqname,'sqmodname':sqmodname,'publicity':publicity,'start_time':start_time,'end_time':end_time})},function(res){ - if(res[0] == 'E'){ - switch(res){ - case 'Eno_login': - j_error.text('未登入'); - case 'Epermission_denied': - j_error.text('權限不足'); - break; - case 'Esqname_too_short': - j_error.text('方塊名稱太短'); - break; - case 'Esqname_too_long': - j_error.text('方塊名稱太長'); - break; - default: - j_error.text('其他錯誤'); - break; - } - }else{ - user.update(false); - defer.resolve(); - com.url_pull_pbox(); - } - }); - } - }); - j_mbox.find('button.cancel').on('click',function(e){ - com.url_pull_pbox(); - }); -}; __extend(class_user_editsq_mbox,class_com_mbox); -var class_user_editpro_mbox = function(){ - var that = this; - var j_mbox = $('#index_mask > div.user_mask > div.editpro_mbox'); - var action; - var proid; - var defer; - - that.node = new vus.node('user_editpro'); - - that.__super(); - - that.init = function(act,proo){ - action = act; - if(action == 'edit'){ - proid = proo.proid; - - j_mbox.find('[name="proid"]').val(proo.proid); - j_mbox.find('[name="name"]').val(proo.proname); - j_mbox.find('[name="modid"]').val(proo.modid); - j_mbox.find('span.cacheid').text('當前CacheID:' + proo.cacheid); - if(proo.hidden == true){ - j_mbox.find('[name="hidden"]').val(2); - }else{ - j_mbox.find('[name="hidden"]').val(1); - } - j_mbox.find('div.update').show(); - j_mbox.find('button.delete').show(); - } - - com.vus_mbox.child_set(that.node); - - defer = $.Deferred(); - return defer.promise(); - }; - that.node.url_chg = function(direct,url_dpart,url_upart){ - if(direct == 'in'){ - that.fadein(j_mbox); - }else if(direct == 'out'){ - that.fadeout(j_mbox); - - j_mbox.find('input').val(''); - j_mbox.find('[name="hidden"]').val(1); - j_mbox.find('div.update').hide(); - j_mbox.find('button.delete').hide(); - j_mbox.find('div.error').text(''); - - if(defer.state() == 'pending'){ - defer.reject(); - } - - com.vus_mbox.child_del(that.node); - } - }; - - j_mbox.find('button.update').on('click',function(e){ - $.post('/toj/php/problem.php',{'action':'update_pro_cache','data':JSON.stringify({'proid':proid})},function(res){ - defer.resolve(); - com.url_pull_pbox(); - }); - }); - j_mbox.find('button.rejudge').on('click',function(e){ - $.post('/toj/php/problem.php',{'action':'rejudge_pro','data':JSON.stringify({'proid':proid})},function(res){ - defer.resolve(); - com.url_pull_pbox(); - }); - }); - j_mbox.find('button.submit').on('click',function(e){ - var proname; - var modid; - var hidden; - var j_error; - - proname = j_mbox.find('[name="name"]').val(); - modid = j_mbox.find('[name="modid"]').val(); - if(parseInt(j_mbox.find('[name="hidden"]').val()) == 1){ - hidden = false; - }else{ - hidden = true; - } - - j_error = j_mbox.find('div.error'); - if(action == 'new'){ - $.post('/toj/php/problem.php',{'action':'add_pro','data':JSON.stringify({'proname':proname,'modid':modid,'hidden':hidden})},function(res){ - if(res[0] == 'E'){ - switch(res){ - case 'Eno_login': - j_error.text('未登入'); - case 'Epermission_denied': - j_error.text('權限不足'); - break; - case 'Eproname_too_short': - j_error.text('題目名稱太短'); - break; - case 'Eproname_too_long': - j_error.text('題目名稱太長'); - break; - case 'Ewrong_modid': - j_error.text('模組ID錯誤'); - break; - default: - j_error.text('其他錯誤'); - break; - } - }else{ - defer.resolve(); - com.url_pull_pbox(); - } - }); - }else if(action == 'edit'){ - $.post('/toj/php/problem.php',{'action':'edit_pro','data':JSON.stringify({'proid':proid,'proname':proname,'modid':modid,'hidden':hidden})},function(res){ - if(res[0] == 'E'){ - switch(res){ - case 'Eno_login': - j_error.text('未登入'); - case 'Epermission_denied': - j_error.text('權限不足'); - break; - case 'Eproname_too_short': - j_error.text('題目名稱太短'); - break; - case 'Eproname_too_long': - j_error.text('題目名稱太長'); - break; - case 'Ewrong_modid': - j_error.text('模組ID錯誤'); - break; - default: - j_error.text('其他錯誤'); - break; - } - }else{ - defer.resolve(); - com.url_pull_pbox(); - } - }); - } - }); - j_mbox.find('button.cancel').on('click',function(e){ - com.url_pull_pbox(); - }); -}; __extend(class_user_editpro_mbox,class_com_mbox); - -var class_login_pbox = function(){ - var that = this; - var j_page = $('#index_page > div.login_pbox'); - - that.node = new vus.node('login'); - - that.__super(); - - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - that.fadein(j_page); - index.title_set('TOJ-登入'); - j_page.find('div.login_box [name="username"]').focus(); - }else if(direct == 'out'){ - that.fadeout(j_page); - j_page.find('div.login_box > div.error').text(''); - j_page.find('div.login_box > input').val(''); - } - - return 'cont'; - }; - com.vus_root.child_set(that.node); - - j_page.find('div.login_box > input').keypress(function(e){ - if(e.which == 13){ - j_page.find('div.login_box > button').click(); - } - }); - - j_page.find('div.login_box > button').click(function(e){ - var j_error; - var username; - var password; - var data; - - j_error = j_page.find('div.login_box > div.error'); - username = j_page.find('div.login_box [name="username"]').val(); - password = j_page.find('div.login_box [name="password"]').val(); - - if(username == '' || password == ''){ - j_error.text('欄位不可為空'); - return; - } - - data = {'username':username,'password':password}; - $.post('/toj/php/user.php',{'action':'login','data':JSON.stringify(data)},function(res){ - if(res[0] == 'E'){ - j_error.text('登入錯誤'); - }else{ - user.update(true); - com.url_push_back('/toj\/register/'); - } - }); - }); -}; __extend(class_login_pbox,class_com_pbox); - -var class_register_pbox = function(){ - var that = this; - var j_page = $('#index_page > div.register_pbox'); - - that.node = new vus.node('register'); - - that.__super(); - - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - that.fadein(j_page); - index.title_set('TOJ-註冊'); - j_page.find('div.register_box [name="username"]').focus(); - }else if(direct == 'out'){ - that.fadeout(j_page); - j_page.find('div.register_box > div.error').text(''); - j_page.find('div.register_box > div.register_box > input').val(''); - j_page.find('div.register_box > div.register_box > div.cover').show(); - } - - return 'cont'; - }; - com.vus_root.child_set(that.node); - - j_page.find('div.register_box > input').keypress(function(e){ - if(e.which == 13){ - j_page.find('div.register_box > button').click(); - } - }); - - j_page.find('div.register_box > button').click(function(e){ - var j_error; - var username; - var password; - var password_repeat; - var nickname; - var email; - var data; - - j_error = j_page.find('div.register_box > div.error'); - username = j_page.find('div.register_box [name="username"]').val(); - password = j_page.find('div.register_box [name="password"]').val(); - password_repeat = j_page.find('div.register_box [name="password_repeat"]').val(); - nickname = j_page.find('div.register_box [name="nickname"]').val(); - email = j_page.find('div.register_box [name="email"]').val(); - - if(username == '' || password == '' || password_repeat == '' || nickname == '' || email == ''){ - j_error.text('欄位不可為空'); - return; - } - if(password != password_repeat){ - j_error.text('使用者密碼不相同'); - return; - } - - data = {'username':username,'password':password,'nickname':nickname,'email':email}; - $.post('/toj/php/user.php',{'action':'register','data':JSON.stringify(data)},function(res){ - if(res[0] == 'E'){ - switch(res){ - case 'Eusername_too_short': - j_error.text('使用者名稱太短'); - break; - case 'Eusername_too_long': - j_error.text('使用者名稱太長'); - break; - case 'Epassword_too_short': - j_error.text('使用者密碼太短'); - break; - case 'Epassword_too_long': - j_error.text('使用者密碼太長'); - break; - case 'Enickname_too_short': - j_error.text('暱稱太短'); - break; - case 'Enickname_too_long': - j_error.text('暱稱太長'); - break; - case 'Eusername_exists': - j_error.text('使用者名稱已存在'); - break; - case 'Eempty_email': - j_error.text('電子郵件不能爲空'); - break; - case 'Eemail_too_long': - j_error.text('電子郵件太長'); - break; - default: - j_error.text('註冊錯誤'); - break; - } - }else{ - user.update(true); - com.url_push_back('/toj\/login/'); - } - }); - }); -}; __extend(class_register_pbox,class_com_pbox); diff --git a/toj/php/_json.php b/toj/php/_json.php deleted file mode 100755 index b3c443e..0000000 --- a/toj/php/_json.php +++ /dev/null @@ -1,3 +0,0 @@ -<?php -echo json_encode("#include <stdio.h>\nint main(){while(scanf(\"%d%d\", &a, &b)==2)printf(\"%d\n\", a+b); return 0;}\n"); -?> diff --git a/toj/php/_pzread_update.php b/toj/php/_pzread_update.php deleted file mode 100644 index 674f15b..0000000 --- a/toj/php/_pzread_update.php +++ /dev/null @@ -1,21 +0,0 @@ -<?php -require_once('common.inc.php'); - -$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); -$sconn = socket_connect($socket, '127.0.0.1',CENTER_SOCKET_PORT); - -if(!$sconn) - exit('error'); - -$wret = socket_write($socket,'-1'.chr(0).'{}'.chr(0)); -if($wret === false) - exit('error'); - -$cret = socket_read($socket, 1024); -if($cret === false) - exit('error'); -if($cret[0] != 'S') - exit('error'); - -exit('ok'); -?> diff --git a/toj/php/_test.php b/toj/php/_test.php deleted file mode 100755 index 5ce8271..0000000 --- a/toj/php/_test.php +++ /dev/null @@ -1,20 +0,0 @@ -<form action="notice.php" method=post> - <input type='hidden' value='{"uid":111}' name='data'> - <input type='hidden' value='count' name='action'> - <input type='submit' value='ti jiao count'> -</form> -<form action="notice.php" method=post> - <input type='text' value='{"uid":111}' name='data'> - <input type='hidden' value='get' name='action'> - <input type='submit' value='ti jiao get'> -</form> -<form action="notice.php" method=post> - <input type='hidden' value='{"uid":111}' name='data'> - <input type='hidden' value='clear' name='action'> - <input type='submit' value='ti jiao clear'> -</form> -<form action="notice.php" method=post> - <input type='text' value='{"uid":111,"type":1,"value":111,"context":"aaaaaa"}' name='data'> - <input type='hidden' value='add' name='action'> - <input type='submit' value='ti jiao add'> -</form> diff --git a/toj/php/common.inc.php b/toj/php/common.inc.php deleted file mode 100755 index 18786e9..0000000 --- a/toj/php/common.inc.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php - -date_default_timezone_set('Asia/Taipei'); -//error_reporting(E_ALL ^ E_NOTICE); -//ini_set("display_errors", "On"); - -//error_reporting(0); -// - -require('connect.inc.php'); - -?> diff --git a/toj/php/connect.inc.php b/toj/php/connect.inc.php deleted file mode 100755 index 3eebe89..0000000 --- a/toj/php/connect.inc.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php - -define('DB_NAME','xxxxx'); -define('DB_USER','xxxxx'); -define('DB_PASSWORD','xxxxx'); -define('SEC_SALT','xxxxx'); - -define('SMTP_HOST','xxxxx'); -define('SMTP_USER','xxxxx'); -define('SMTP_PASS','xxxxx'); - -const CENTER_SOCKET_PORT = 2501; - -function sec_is_login() -{ - if(!isset($_COOKIE['uid']) || !isset($_COOKIE['usec'])){ - return false; - } - - $userid = $_COOKIE['uid']; - $usersec = $_COOKIE['usec']; - - if($userid == '' || $usersec == '' || strval(intval($userid)) != $userid || hash('sha512',$userid.SEC_SALT) != $usersec){ - return false; - } - - return true; -} - -function db_connect($dbn = DB_NAME) -{ - return pg_connect('host=localhost port=5432 dbname='.$dbn.' user='.DB_USER.' password='.DB_PASSWORD); -} - -function db_close($sqlcx) -{ - pg_close($sqlcx); -} - -?> diff --git a/toj/php/event.inc.php b/toj/php/event.inc.php deleted file mode 100755 index acc2f14..0000000 --- a/toj/php/event.inc.php +++ /dev/null @@ -1,71 +0,0 @@ -<?php -class event -{ - private static $white_list; - - private static function init() - { - event::$white_list = array('127.0.0.1'); - } - - // execute function $name in file $fname - // if want to call a function of a class, have 2 choice: - // 1. pass an array as $name, put every level of class in it, like: - // A::B::C() should be passed like array("A", "B", "C"). - // 2. pass a string with :: directly, it will be automatically - // translated. - // return value will be FALSE on failure, return value of target - // function otherwise. NULL when no return value. - public static function exec_func($fname, $name, $arg) - { - if(!file_exists($fname)) - { - return false; - } - require_once($fname); - if(is_string($name) && strpos($name, ":") !== FALSE) - { - $name = preg_split("/::/", $name); - } - if(is_string($name) && !is_callable($name)) - { - return false; - } - if(is_array($name) && !is_callable(join($name, "::"))) - { - return false; - } - if($arg == NULL) - { - $res = call_user_func($name); - } - else - { - $res = call_user_func_array($name, $arg); - } - if($res === false) - { - return false; - } - return $res; - } - - public static function validate_ip() - { - event::init(); - if (!empty($_SERVER['HTTP_CLIENT_IP'])) - { - $ip=$_SERVER['HTTP_CLIENT_IP']; - } - else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) - { - $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; - } - else - { - $ip=$_SERVER['REMOTE_ADDR']; - } - return in_array($ip, event::$white_list); - } -} -?> diff --git a/toj/php/event.php b/toj/php/event.php deleted file mode 100755 index e121287..0000000 --- a/toj/php/event.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - require_once('event.inc.php'); - if (!empty($_SERVER['HTTP_CLIENT_IP'])) - $ip=$_SERVER['HTTP_CLIENT_IP']; - else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) - $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; - else - $ip=$_SERVER['REMOTE_ADDR']; - if(!event::validate_ip()) - { - exit; - } - $fname = $_POST['fname']; - $name = $_POST['name']; - $arg = json_decode($_POST['arg']); - if(event::exec_func($fname, $name, $arg) === false) - { - echo "false"; - } - else - { - echo "true"; - } -?> diff --git a/toj/php/event_exec.cpp b/toj/php/event_exec.cpp deleted file mode 100755 index af258c0..0000000 --- a/toj/php/event_exec.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "event_exec.h" - -#define EVENT_BUFLEN 1005 -#define EVENT_URL "http://localhost/toj/php/event.php" - -struct event_handle -{ - int init, plen, blen; - char *post, *buf; - pthread_mutex_t mutex; - CURL *handle; -}; - -static struct event_handle conn; - -size_t event_write_cb(void *in, size_t siz, size_t nb, void *buf) -{ - int len; - len = siz*nb+1; - if(len > conn.blen) - { - len = conn.blen-1; - } - memcpy(buf, in, len); - ((char*)buf)[len] = 0; - return siz*nb; -} - -int event_init() -{ - if(conn.init) - { - return 0; - } - conn.plen = conn.blen = EVENT_BUFLEN; - conn.post = (char*)malloc(EVENT_BUFLEN); - conn.buf = (char*)malloc(EVENT_BUFLEN); - curl_global_init(CURL_GLOBAL_ALL); - conn.handle = curl_easy_init(); - curl_easy_setopt(conn.handle, CURLOPT_URL, EVENT_URL); - curl_easy_setopt(conn.handle, CURLOPT_WRITEFUNCTION, event_write_cb); - curl_easy_setopt(conn.handle, CURLOPT_WRITEDATA, conn.buf); - pthread_mutex_init(&conn.mutex, NULL); - conn.init = 1; - return 1; -} - -int event_exec(const char *fname, const char *name, const char *arg) -{ - int res, len; - char *t; - event_init(); - if(pthread_mutex_lock(&conn.mutex) == 0) - { - len = 0; - len += strlen(fname)+6; - len += strlen(name)+6; - len += strlen(arg)+6; - if(len > conn.plen) - { - t = (char*)malloc(len); - if(!t) - { - pthread_mutex_unlock(&conn.mutex); - return 0; - } - free(conn.post); - conn.post = t; - conn.plen = len; - } - sprintf(conn.post, "fname=%s&name=%s&arg=%s", fname, name, arg); - curl_easy_setopt(conn.handle, CURLOPT_POSTFIELDS, conn.post); - res = curl_easy_perform(conn.handle); - if(res) - { - pthread_mutex_unlock(&conn.mutex); - return 0; - } - fprintf(stderr, "%s\n", conn.buf); - if(!strcmp(conn.buf, "true")) - { - pthread_mutex_unlock(&conn.mutex); - return 1; - } - - pthread_mutex_unlock(&conn.mutex); - } - return 0; -} diff --git a/toj/php/event_exec.h b/toj/php/event_exec.h deleted file mode 100755 index aec1acb..0000000 --- a/toj/php/event_exec.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef EVENT_EXEC -#define EVENT_EXEC - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <curl/curl.h> -#include <pthread.h> - -int event_exec(const char *fname, const char *name, const char *arg); - -#endif diff --git a/toj/php/notice.inc.php b/toj/php/notice.inc.php deleted file mode 100755 index dbf47cc..0000000 --- a/toj/php/notice.inc.php +++ /dev/null @@ -1,244 +0,0 @@ -<?php -require_once('common.inc.php'); -require_once('user.inc.php'); - -const NOTICE_DEF_LIM = 5; -const NOTICE_MAX_LIM = 30; - -const NOTICE_ACT_CNT = 1; -const NOTICE_ACT_NEW = 2; -const NOTICE_ACT_OLD = 4; - -const NOTICE_TYP_USR = 1; -const NOTICE_TYP_PRO = 2; -const NOTICE_TYP_SQR = 3; -const NOTICE_TYP_ALL = 255; - -class notice -{ - private static function ins_uid($sqlc, $uid) - { - $sqlstr = 'INSERT INTO "notice_cache" ("uid", "tim", "cnt", "tmp", "rsv") VALUES ($1, $2, $3, $4, $5) RETURNING *;'; - $sqlarr = array($uid, date("Y-m-d H:i:s"), 0, "0", "0"); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $ret = pg_fetch_object($sqlr); - pg_free_result($sqlr); - return $ret; - } - - public static function is_match($sqlc, $uid, &$not) - { - if($not->typ == NOTICE_TYP_ALL) - { - return true; - } - if($not->typ == NOTICE_TYP_USR) - { - return $uid == intval($not->val); - } - require_once('event.inc.php'); - if($not->typ == NOTICE_TYP_PRO) - { - if(!event::exec_func('problem.inc.php', 'problem::is_available', array($sqlc, $not->val, $uid))) - { - return false; - } - return true; - } - else if($not->typ == NOTICE_TYP_SQR) - { - $ret = event::exec_func('square.inc.php', 'square::get_user_relationship', array($sqlc, $uid, $not->val)); - if($ret >= SQUARE_USER_ACTIVE) - { - return true; - } - return false; - } - return false; - } - - private static function update($sqlc, $uid, &$tar, &$arr) - { - if(count($arr) <= 0) - { - return false; - } - $sqlstr = 'UPDATE "notice_cache" SET "tmp"=$1, "cnt"=$2, "tim"=$4 WHERE "uid"=$3 RETURNING *;'; - $sqlarr = array($arr[0], intval($tar->cnt)+count($arr), $uid, date('Y-m-d H:i:s')); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $ret = pg_fetch_object($sqlr); - pg_free_result($sqlr); - foreach($arr as $it) - { - $sqlstr = 'INSERT INTO "user_notice" ("uid", "nid") VALUES ($1, $2);'; - $sqlarr = array(intval($uid), intval($it)); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - pg_free_result($sqlr); - } - return $ret; - } - - private static function check_new($sqlc, $uid) - { - $sqlstr = 'SELECT * FROM "notice_cache" WHERE "uid"=$1;'; - $sqlarr = array($uid); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $ret = pg_fetch_object($sqlr); - if($ret === false) - { - $ret = notice::ins_uid($sqlc, $uid); - } - pg_free_result($sqlr); - $sqlstr = 'SELECT * FROM "notice" WHERE "nid" > $1 ORDER BY "tim";'; - $sqlarr = array(intval($ret->tmp)); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $buf = array(); - while($row = pg_fetch_object($sqlr)) - { - if(self::is_match($sqlc, $uid, $row)) - { - array_unshift($buf, $row->nid); - } - } - pg_free_result($sqlr); - if(count($buf) > 0) - { - return self::update($sqlc, $uid, $ret, $buf); - } - return $ret; - } - - // **warning**: this function will clear notice count of uid!! - public static function get($sqlc, $uid, $typ, $arg1, $arg2) - { - $uid = intval($uid); - if(!$uid || !$sqlc) - { - return false; - } - $ret = self::check_new($sqlc, $uid); - if($typ == NOTICE_ACT_CNT) - { - return intval($ret->cnt); - } - else if($typ == NOTICE_ACT_NEW) - { - if($ret->cnt == 0) - { - return array(); - } - $sqlstr = 'SELECT "nid" FROM "user_notice" WHERE "uid"=$1 AND "nid">$2 ORDER BY "nid" DESC'; - $sqlarr = array($uid, intval($ret->rsv)); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $nids = array(); - while($it=pg_fetch_array($sqlr)) - { - $nids[] = $it[0]; - } - $sqlstr = 'SELECT * FROM "notice" WHERE "nid" IN ('.join($nids, ",").') ORDER BY "tim";'; - $sqlr = pg_query($sqlc, $sqlstr); - $buf = array(); - while($it = pg_fetch_object($sqlr)) - { - $it->nid = intval($it->nid); - $it->typ = intval($it->typ); - $buf[] = $it; - } - pg_free_result($sqlr); - $sqlstr = 'UPDATE "notice_cache" SET "cnt"=0, "rsv"=$2 WHERE "uid"=$1;'; - $sqlarr = array($uid, $nids[0]); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - return $buf; - } - else if($typ == NOTICE_ACT_OLD) - { - if($arg2 <= 0) - { - $arg2 = 1; - } - if($arg2 > NOTICE_MAX_LIM) - { - $arg2 = NOTICE_MAX_LIM; - } - $sqlstr = 'SELECT "nid" FROM "user_notice" WHERE "uid"=$1 AND "nid"<$2 ORDER BY "nid" DESC LIMIT $3'; - $sqlarr = array($uid, $arg1, $arg2); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $nids = array(); - while($it=pg_fetch_array($sqlr)) - { - $nids[] = $it[0]; - } - $sqlstr = 'SELECT * FROM "notice" WHERE "nid" IN ('.join($nids, ",").') ORDER BY "tim";'; - $sqlr = pg_query($sqlc, $sqlstr); - $buf = array(); - while($it = pg_fetch_object($sqlr)) - { - $it->nid = intval($it->nid); - $it->typ = intval($it->typ); - $buf[] = $it; - } - pg_free_result($sqlr); - return $buf; - } - return false; - } - - public static function clr($sqlc, $uid, $lim=NOTICE_DEF_LIM) - { - return false; - if($lim < 0) - { - $lim = 0; - } - $ret = self::check_new($sqlc, $uid); - $buf = preg_split("/[,]/", $ret->tmp); - $buf = array_slice($buf, 0, $ret->cnt+$lim); - $sqlstr = 'UPDATE "notice_cache" SET "tmp"=$1 WHERE "uid"=$2;'; - $sqlarr = array(join($buf, ","), $uid); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - if($sqlr) - { - return count($buf); - } - return false; - } - - // you can add notice by calling it. - public static function add($sqlc, $typ, $val, $txt) - { - if(!is_string($val)) - { - $val = json_encode($val); - } - $sqlstr = 'INSERT INTO "notice" ("typ", "val", "txt", "tim") VALUES ($1, $2, $3, $4) RETURNING *;'; - $sqlarr = array($typ, $val, $txt, date('Y-m-d H:i:s')); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $ret = pg_fetch_object($sqlr); - if($ret === false) - { - return false; - } - return json_encode($ret); - } - - public static function del($sqlc, $cond) - { - $sqlstr = 'DELETE FROM "notice" WHERE 0'; - if(isset($cond['nid'])) - { - $sqlstr .= ' OR "nid"=$1'; - } - if(isset($cond['tim'])) - { - $sqlstr .= ' OR "tim" >= $2'; - } - $sqlarr = array($cond['nid'], $cond['tim']); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - if(!$sqlr) - { - return false; - } - return true; - } -} -?> diff --git a/toj/php/notice.php b/toj/php/notice.php deleted file mode 100755 index a0f984a..0000000 --- a/toj/php/notice.php +++ /dev/null @@ -1,110 +0,0 @@ -<?php -//ini_set("display_errors", "On"); -//error_reporting(E_ALL & ~E_NOTICE); - -require_once('notice.inc.php'); - -/* usage: - * action count(uid): update notice count of uid, return value: integer - * action get(uid): update notice of uid, return notice data limited to notice count, - * and clear notice count. format: object array, see table "notice" - * action clear(uid, [limit]): clear cache number to notice_count+limit, - * does not affect notice, only user cache. return remain number as int. - * action add(type, value, context): add a notice, need admin permission now. - * **attention**: this is only for web, use notice::add with your own code, - * that function does not require any user permission. - * type is an integer, see "notice.inc.php" NOTICE_TYP_*. - * value are paired with type, like proid, sqid, uid, .., meaning nothing - * with NOTICE_TYP_ALL, but cannot be NULL. - * context is what you want. treat as string data so its format - * depends on your own. - * return 'S' when success. - */ - -$sqlc = db_connect(); -$action = $_POST['action']; -$data = json_decode($_POST['data']); - -if(strlen($action) == 0) -{ - die('Eno_action'); -} -if(!sec_is_login()) -{ - die('Eno_login'); -} -$uid = intval($_COOKIE['uid']); -$usr = user::get_from_uid($sqlc, $uid); -if(!$usr) -{ - die('Eno_such_user'); -} - -if($action == 'count') -{ - $cnt = notice::get($sqlc, $uid, NOTICE_ACT_CNT); - echo $cnt; -} -else if($action == 'get') -{ - $nid = intval($data->nid); - if($nid > 0) - { - $cnt = intval($data->count); - $res = notice::get($sqlc, $uid, NOTICE_ACT_OLD, $nid, $cnt); - if($res === false) - { - die('Eno_such_nid'); - } - echo json_encode($res); - } - else - { - $res = notice::get($sqlc, $uid, NOTICE_ACT_NEW); - echo json_encode($res); - } -} -else if($action == 'clear') -{ - $lim = NOTICE_DEF_LIM; - if(isset($data->limit)) - { - $lim = intval($data->limit); - } - if($lim > NOTICE_MAX_LIM) - { - $lim = NOTICE_MAX_LIM; - } - $ret = notice::clr($sqlc, $uid, $lim); - echo $ret; -} -else if($action == 'add') -{ - if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN) && $uid != 111) - //if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN)) - { - die('Epermission_denied'); - } - if(!isset($data->type)) - { - die('Etype_is_empty'); - } - if(!isset($data->value)) - { - die('Evalue_is_empty'); - } - if(!isset($data->context)) - { - die('Econtext_is_empty'); - } - $res = notice::add($sqlc, $data->type, $data->value, $data->context); - if(!$res) - { - die('Efail'); - } - echo 'S'; -} - -db_close($sqlc); - -?> diff --git a/toj/php/problem.inc.php b/toj/php/problem.inc.php deleted file mode 100755 index d4c8e45..0000000 --- a/toj/php/problem.inc.php +++ /dev/null @@ -1,354 +0,0 @@ -<?php -require_once('common.inc.php'); -require_once('user.inc.php'); -require_once('square.inc.php'); - -const PRONAME_LEN_MAX = 100; - -const CODE_LEN_MIN = 1; -const CODE_LEN_MAX = 102400; - -const SUBMIT_MIN_INTERVAL = 10; - -$LANGUAGE = array(0x1=>'C/C++', 0x2=>'JAVA', 0x4=>'Pascal'); -$EXTENSION = array(0x1=>'cpp', 0x2=>'java', 0x4=>'pas'); - -class problem -{ - public $proid; - public $modid; - public $proname; - public $hidden; - - public static function getmod($sqlc, $modid) - { - //return pmodname, smodname, jmodname for specified $modid. - //False if not found. - $result = pg_query_params($sqlc, 'SELECT * FROM "mod" WHERE "modid"=$1 LIMIT 1;', array($modid)); - $mret = pg_fetch_object($result); - pg_free_result($result); - if(!$mret) - return false; - return $mret; - } - public static function get($sqlc, $proid) - { - //return problem data: proid, modid, proname, pmodname, smodname, jmodname - //False if not found. - $result = pg_query_params($sqlc, 'SELECT * FROM "problem" WHERE "proid"=$1 LIMIT 1;', array(intval($proid))) or die ("Eerror_get_problem"); - $ret = pg_fetch_object($result, null, 'problem'); - pg_free_result($result); - if(!$ret) - return false; - - $ret->proid = intval($ret->proid); - $ret->modid = intval($ret->modid); - $ret->admin_uid = intval($ret->admin_uid); - - $mret = problem::getmod($sqlc, $ret->modid); - if(!$mret) - return false; - - $ret->pmodname = $mret->pmodname; - $ret->smodname = $mret->smodname; - $ret->jmodname = $mret->jmodname; - - return $ret; - } - - public static function is_available($sqlc, $proid, $uid = null) - { - //return whether the problem is available for user $_COOKIE['uid'] or not. - //USER_PER_PROADMIN always OK - //admin of problem always OK - //if HIDDEN , then NOT OK except admins - //in sqid=1 always OK , even if not login - //otherwise must exist at least one common square with relationship >= SQUARE_USER_ACTIVE - $uidnull = false; - if($uid == null) - { - $uid = intval($_COOKIE['uid']); - $uidnull = true; - } - $sqlr = pg_query_params('SELECT "hidden", "admin_uid" FROM "problem" WHERE "proid"=$1;', array($proid)); - $obj = pg_fetch_object($sqlr); - $hdn = $obj->hidden; - if($hdn == null) - return false; // no such problem - - if(sec_check_level($sqlc, USER_PER_PROADMIN, $uidnull?null:$uid)) - return true; - - if((!$uidnull || sec_is_login()) && $uid == intval($obj->admin_uid)) - return true; - - if($hdn == "t") - return false; - - $sqlstr = 'SELECT COUNT(*) FROM "pro_sq" WHERE "proid"=$1 AND "sqid"=$2;'; - $sqlarr = array($proid, 1); - $sqlr = pg_query_params($sqlstr, $sqlarr); - $ret = intval(pg_fetch_result($sqlr, 0)); - if($ret > 0) - return true; - - if($uidnull && !sec_is_login()) - return false; - - $sqlstr = 'SELECT COUNT("pro_sq"."sqid") FROM "pro_sq" INNER JOIN "us_sq" ON "pro_sq"."sqid"="us_sq"."sqid" WHERE "pro_sq"."proid"=$1 AND "us_sq"."uid"=$2 AND "us_sq"."relationship">=$3;'; - $sqlarr = array($proid, $uid, SQUARE_USER_ACTIVE); - $sqlr = pg_query_params($sqlstr, $sqlarr); - $ret = intval(pg_fetch_result($sqlr, 0)); - if($ret > 0) - return true; - - return false; - } - - public static function submit($sqlc, $proid, $uid, $lang, $code) - { - //Submit code(or data) : $proid, $uid, $lang, $code - //Return subid. False if failed. - - ////$submit_time = date('Y-m-d H:i:s'); - ////$last_update = $submit_time; - $sqlstr = 'INSERT INTO "submit" ("proid", "uid", "lang") VALUES ($1, $2, $3) RETURNING subid;'; - $sqlarr = array($proid, $uid, $lang); - $sqlr = pg_query_params($sqlstr, $sqlarr); - $subid = intval(pg_fetch_result($sqlr, 0)); - if(!$subid) - return false; - - global $EXTENSION; - $ext = $EXTENSION[intval($lang)]; - if($ext == null) - die('Ewrong_extension'); - - $parnum = $subid - ($subid%1000); - $pardir = '../center/submit/'.$parnum.'/'; - if(!is_dir($pardir)) - mkdir($pardir, 0755) or die('Ecannot_mkdir'); - mkdir($pardir.$subid, 0755) or die('Ecannot_mkdir'); - mkdir($pardir.$subid.'/data', 0755) or die('Ecannot_mkdir'); - mkdir($pardir.$subid.'/result', 0755) or die('Ecannot_mkdir'); - chmod($pardir.$subid.'/result', 0775) or die('Ecannot_chmod'); - - $file = fopen($pardir.$subid.'/data/main.'.$ext,'w'); - if(!$file) - die('Ewrite_file_failed'); - fwrite($file, $code); - fclose($file); - - return $subid; - } - - public static function add($sqlc, $pro) - { - //Add a new problem $pro into problem table. - //Return the inserted object. False if failed. - - if($pro->hidden == true){ - $hidden = 't'; - }else{ - $hidden = 'f'; - } - - $sqlstr = 'INSERT INTO "problem" ("modid", "proname", "hidden", "admin_uid") VALUES ($1, $2, $3, $4) RETURNING *;'; - $sqlarr = array($pro->modid, $pro->proname, $hidden, $pro->admin_uid); - $sqlr = pg_query_params($sqlstr, $sqlarr); - if(!$sqlr) - return false; - $obj = pg_fetch_object($sqlr, null, 'problem'); - pg_free_result($sqlr); - if(!$obj) - return false; - - $obj->proid = intval($obj->proid); - $obj->modid = intval($obj->modid); - $obj->cacheid = intval($obj->cacheid); - $obj->admin_uid = intval($obj->admin_uid); - $obj->hidden = ($obj->hidden=='t'); - - return $obj; - } - - public static function edit($sqlc, $pro) - { - if($pro->hidden == true){ - $hidden = 't'; - }else{ - $hidden = 'f'; - } - - $sqlstr = 'UPDATE "problem" SET "modid"=$1, "proname"=$2, "hidden"=$3, "admin_uid"=$4 WHERE "proid"=$5 RETURNING *;'; - $sqlarr = array($pro->modid, $pro->proname, $hidden, $pro->admin_uid,$pro->proid); - $sqlr = pg_query_params($sqlstr, $sqlarr); - if(!$sqlr) - return false; - $obj = pg_fetch_object($sqlr, null, 'problem'); - pg_free_result($sqlr); - if(!$obj) - return false; - - $obj->proid = intval($obj->proid); - $obj->modid = intval($obj->modid); - $obj->cacheid = intval($obj->cacheid); - $obj->admin_uid = intval($obj->admin_uid); - $obj->hidden = ($obj->hidden=='t'); - - return $obj; - } - - public static function mod_get_lang($sqlc, $modid) - { - //get available language code (OR) format - //return language code - - $sqlstr = 'SELECT "lang" FROM "mod" WHERE "modid"=$1;'; - $sqlarr = array($modid); - $sqlr = pg_query_params($sqlstr, $sqlarr); - $ret = pg_fetch_result($sqlr, 0); - pg_free_result($sqlr); - if(!$ret) - return false; - return intval($ret); - } - - public static function recent_submit($sqlc, $uid, $time) - { - //return submission number in recent $time seconds. - $lasttime = date('Y-m-d H:i:s', time()-$time); - $sqlstr = 'SELECT COUNT(*) FROM "submit" WHERE "uid"=$1 AND "submit_time" >= $2;'; - $sqlarr = array($uid, $lasttime); - $sqlr = pg_query_params($sqlstr, $sqlarr); - $ret = pg_fetch_result($sqlr, 0); - if(!$ret) - return false; - return intval($ret); - } - - public static function send_socket($subid) - { - ///send socket to center. - //Return true if success, false if failed. - - $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); - $sconn = socket_connect($socket, '127.0.0.1', CENTER_SOCKET_PORT); - - if(!$sconn) - return false; - - $wret = socket_write($socket, $subid.chr(0).'{}'.chr(0)); - if($wret === false) - return false; - - - $cret = socket_read($socket, 1024); - if($cret === false) - return false; - if($cret[0] != 'S') - return false; - return true; - } - - public static function get_pro_stat($sqlc, $proid, $uid) - { - //get $uid 's score and is_ac of problem $proid. - - $ret = new stdClass(); - - $sqlstr = 'SELECT COUNT(*) FROM "submit" WHERE "proid"=$1 AND "uid"=$2 AND "result"=0;'; - $sqlarr = array($proid, $uid); - $res = pg_query_params($sqlc, $sqlstr, $sqlarr); - $acct = pg_fetch_result($res, 0); - $ret->is_ac = ($acct > 0); - - $sqlstr = 'SELECT "score" FROM "submit" WHERE "proid"=$1 AND "uid"=$2 ORDER BY "score" DESC LIMIT 1;'; - $sqlarr = array($proid, $uid); - $res = pg_query_params($sqlc, $sqlstr, $sqlarr); - $score = pg_fetch_result($res, 0); - if($score === false) - { - $ret->tried = false; - $ret->score = 0; - } - else - { - $ret->tried = true; - $ret->score = $score; - } - - return $ret; - } - - public static function get_pro_list($sqlc){ - $sqlstr = 'SELECT * FROM "problem" ORDER BY "proid" ASC;'; - $sqlr = pg_query($sqlc,$sqlstr); - - $ret = array(); - while($obj = pg_fetch_object($sqlr)) - { - $obj->proid = intval($obj->proid); - $obj->modid = intval($obj->modid); - $obj->cacheid = intval($obj->cacheid); - $obj->admin_uid = intval($obj->admin_uid); - $obj->hidden = ($obj->hidden=='t'); - array_push($ret, $obj); - } - - pg_free_result($sqlr); - return $ret; - } - - public static function update_pro_cache($sqlc,$proid){ - $sqlstr = 'UPDATE "problem" SET "cacheid"="cacheid" + 1 WHERE "proid"=$1;'; - $sqlarr = array($proid); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - if(!$sqlr)return false; - pg_free_result($sqlr); - - if(!problem::send_socket(-1))return false; - else return true; - } - - public static function rejudge_pro($sqlc, $proid) - { - $sqlstr = 'SELECT "subid" FROM "submit" WHERE "proid"=$1 ORDER BY "subid";'; - $sqlarr = array($proid); - $res = pg_query_params($sqlc, $sqlstr, $sqlarr); - $ok = true; - $sublist = pg_fetch_all_columns($res, 0); - if(!$sublist)return false; - - $sqlstr = 'UPDATE "submit" SET "result"=100,"runtime"=0,"memory"=0,"score"=0 WHERE "proid"=$1;'; - $sqlarr = array($proid); - $res = pg_query_params($sqlc, $sqlstr, $sqlarr); - pg_free_result($res); - - foreach($sublist as $sub) - { - $subid = intval($sub); - if(!problem::send_socket($subid))$ok = false; - } - return $ok; - } - - public static function rejudge_sub($sqlc, $subid) - { - $sqlstr = 'SELECT "proid" FROM "submit" WHERE "subid"=$1;'; - $sqlarr = array($subid); - $res = pg_query_params($sqlc, $sqlstr, $sqlarr); - $proid = intval(pg_fetch_result($res, 0)); - if(!$proid)return false; - - $sqlstr = 'UPDATE "submit" SET "result"=100,"runtime"=0,"memory"=0,"score"=0 WHERE "subid"=$1;'; - $sqlarr = array($subid); - $res = pg_query_params($sqlc, $sqlstr, $sqlarr); - pg_free_result($res); - - return problem::send_socket($subid); - } -} - - -?> diff --git a/toj/php/problem.php b/toj/php/problem.php deleted file mode 100755 index 4ef43f3..0000000 --- a/toj/php/problem.php +++ /dev/null @@ -1,219 +0,0 @@ -<?php -//ini_set("display_errors", "On"); -//error_reporting(E_ALL & ~E_NOTICE); - -require_once('problem.inc.php'); -require_once('user.inc.php'); -require_once('event.inc.php'); - -$sqlc = db_connect(); - -$action = $_POST['action']; -$data = $_POST['data']; - -if(strlen($action)==0) - die('Eno_action'); -if($action == 'get_pro') -{ - //get problem data: proid, modid, name, pmodname, smodname, jmodname - //only USER_LEVEL_SUPERADMIN or is_available - //data : proid - - $dt = json_decode($data); - - $proid = intval($dt->proid); - - $ret = problem::get($sqlc, $proid); - if(!$ret) - die('Eget_problem'); - - if(!problem::is_available($sqlc, $proid)) - die('Epermission_denied'); - - unset($ret->proid); - //unset($ret->hidden); - - echo(json_encode($ret)); -} -if($action == 'add_pro') -{ - //Add problem - //need SUPERADMIN - //data: modid, proname, [hidden] - if(!sec_is_login()) - die('Enot_login'); - if(!sec_check_level($sqlc, USER_PER_PROCREATOR)) - die('Epermission_denied'); - - $dt = json_decode($data); - - if(strlen($dt->proname) == 0) - die('Eproname_too_short'); - if(strlen($dt->proname) > PRONAME_LEN_MAX) - die('Eproname_too_long'); - - $mod = problem::getmod($sqlc, $dt->modid); - if(!$mod) - die('Ewrong_modid'); - - if($dt->hidden !== true && $dt->hidden !== false) - die('Ewrong_hidden_value'); - - /*CHECK OTHER DATA, TESTDATA ETC*/ - - $dt->admin_uid = intval($_COOKIE['uid']); - - $pro = problem::add($sqlc, $dt); - if(!$pro) - die('Eadd_problem'); - - if(event::exec_func('../pmod/'.$mod->pmodname.'/'.$mod->pmodname.'.inc.php','event_create',[$pro->proid]) === false) - die('Eevent_error'); - - echo(json_encode($pro)); -} -if($action == 'edit_pro') -{ - //Edit problem - //need SUPERADMIN - //data: modid, proname, [hidden] - if(!sec_is_login()) - die('Enot_login'); - if(!sec_check_level($sqlc, USER_PER_PROCREATOR)) - die('Epermission_denied'); - - $dt = json_decode($data); - - if(strlen($dt->proname) == 0) - die('Eproname_too_short'); - if(strlen($dt->proname) > PRONAME_LEN_MAX) - die('Eproname_too_long'); - - if(!problem::getmod($sqlc, $dt->modid)) - die('Ewrong_modid'); - - if($dt->hidden !== true && $dt->hidden !== false) - die('Ewrong_hidden_value'); - - /*CHECK OTHER DATA, TESTDATA ETC*/ - - $dt->admin_uid = intval($_COOKIE['uid']); - - $pro = problem::edit($sqlc, $dt); - if(!$pro) - die('Eedit_problem'); - - echo(json_encode($pro)); -} -if($action == 'submit_code') -{ - //Submit code - //Need problem available - //data: proid, lang, code - if(!sec_is_login()) - die('Enot_login'); - - $uid = intval($_COOKIE['uid']); - $dt = json_decode($data); - - $proid = intval($dt->proid); - - if(!problem::is_available($sqlc, $proid)){ - die('Epermission_denied'); - } - - $obj = problem::get($sqlc, $proid); - $lang = intval($dt->lang); - $oklang = problem::mod_get_lang($sqlc, $obj->modid); - if($LANGUAGE[$lang] == null || (($lang & $oklang) == 0)) - die('Ewrong_language'); - - if(strlen($dt->code) < CODE_LEN_MIN) - die('Ecode_too_short'); - if(strlen($dt->code) > CODE_LEN_MAX) - die('Ecode_too_long'); - - //if(problem::recent_submit($sqlc, $uid, SUBMIT_MIN_INTERVAL) > 0) - // die('Esubmit_too_frequently'); - - $subid = problem::submit($sqlc, $proid, $uid, $lang, $dt->code); - if(!$subid) - die('Esubmit_code_failed'); - - /*ASSOCIATED SQUARE : CALL SQUARE MODULE TO GET EXTRA JUDGE OPTION*/ - - if(!problem::send_socket($subid, $proid)) - die('Esend_socket_failed'); - - echo(json_encode($subid)); -} -if($action == 'get_pro_stat') -{ - //Get score and is_ac for specified proid. - //Need login and problem available. - //data : proid - - if(!sec_is_login()) - die('Enot_login'); - - $uid = intval($_COOKIE['uid']); - $dt = json_decode($data); - - $proid = intval($dt->proid); - - if(!problem::is_available($sqlc, $proid)){ - die('Epermission_denied'); - } - - $ret = problem::get_pro_stat($sqlc, $proid, $uid); - if(!$ret) - die('Eerror_get_pro_stat'); - - echo(json_encode($ret)); -} -if($action == 'get_pro_list') -{ - if(!sec_is_login()) - die('Enot_login'); - if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN)) - die('Epermission_denied'); - - $ret = problem::get_pro_list($sqlc); - if(!$ret) - die('Error_get_pro_list'); - - echo(json_encode($ret)); -} -if($action == 'update_pro_cache') -{ - if(!sec_is_login()) - die('Enot_login'); - if(!sec_check_level($sqlc, USER_PER_PROCREATOR)) - die('Epermission_denied'); - - $dt = json_decode($data); - $proid = intval($dt->proid); - if(!problem::update_pro_cache($sqlc,$proid)) - die('Eupdate_problem_cache'); - - echo('S'); -} -if($action == 'rejudge_pro') -{ - if(!sec_is_login()) - die('Enot_login'); - if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN)) - die('Epermission_denied'); - - $dt = json_decode($data); - $proid = intval($dt->proid); - if(!problem::rejudge_pro($sqlc, $proid)) - die('Erejudge_pro'); - - echo('S'); -} - -db_close($sqlc); - - -?> diff --git a/toj/php/pzreadtest.php b/toj/php/pzreadtest.php deleted file mode 100755 index b67ae9e..0000000 --- a/toj/php/pzreadtest.php +++ /dev/null @@ -1,9 +0,0 @@ -<?php - require_once('notice.inc.php'); - - function center_result_event($uid,$msg){ - $db = db_connect(); - notice::add($db,NOTICE_TYP_USR,$uid,json_encode($msg)); - db_close($db); - } -?> diff --git a/toj/php/sqlib.inc.php b/toj/php/sqlib.inc.php deleted file mode 100755 index 154bcbd..0000000 --- a/toj/php/sqlib.inc.php +++ /dev/null @@ -1,5 +0,0 @@ -<?php - - require_once('sqlib_scoreboard.inc.php'); - -?> diff --git a/toj/php/sqlib_scoreboard.inc.php b/toj/php/sqlib_scoreboard.inc.php deleted file mode 100755 index 32bec44..0000000 --- a/toj/php/sqlib_scoreboard.inc.php +++ /dev/null @@ -1,247 +0,0 @@ -<?php - - /* - Square mod library : Scoreboard - 2013/02/10 By TOJTeam - - Get scoreboard by rank : - sqlib_scoreboard::get_scoreboard($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time, $end_time, $start_rank, $number) - - Get scoreboard of specific user : - sqlib_scoreboard::get_scoreboard_uid($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time, $end_time, $uid) - - $sqlc : sql connection to database 'toj' - $msqlc : sql connection to database 'toj_mod' - $sqid : square id number - $sboard_id : scoreboard id number (of square) - $score_func : function to determine rank_score - $start_time : start timestamp - $end_time : end timestamp - $start_rank : display from which rank - $number : number to display - $uid : user id number - - Parameter format of $score_func: - func($sqid, $proid, $best_score, $best_time, $is_ac, $ac_time, $tries_before_ac, $last_score, $last_status, $tries); - - */ - - require_once('common.inc.php'); - - class sqlib_scoreboard - { - public static function def_func($sqid, $proid, $best_score, $best_time, $is_ac, $ac_time, $tries_before_ac, $last_score, $last_status, $tries) - { - return $best_score; - } - - public static function get_last_update($msqlc, $sqid, $sboard_id) - { - $sqlstr = 'SELECT "last_update" FROM "sqlib_scoreboard_last_update" WHERE "sqid"=$1 AND "sboard_id"=$2;'; - $sqlarr = array($sqid, $sboard_id); - $res = pg_query_params($msqlc, $sqlstr, $sqlarr); - $ret = pg_fetch_result($res, 0); - return $ret; - } - - public static function set_last_update($msqlc, $sqid, $sboard_id, $new) - { - $now = date('Y-m-d H:i:s+08'); - $sqlstr = 'UPDATE "sqlib_scoreboard_last_update" SET "last_update"=$3 WHERE "sqid"=$1 AND "sboard_id"=$2;'; - if($new) - { - $sqlstr = 'INSERT INTO "sqlib_scoreboard_last_update" ("sqid", "sboard_id", "last_update") VALUES ($1, $2, $3);'; - sqlib_scoreboard::clear_scoreboard($msqlc, $sqid, $sboard_id); - } - $sqlarr = array($sqid, $sboard_id, $now); - $res = pg_query_params($msqlc, $sqlstr, $sqlarr); - } - - public static function clear_scoreboard($msqlc, $sqid, $sboard_id) - { - $sqlstr = 'DELETE FROM "sqlib_scoreboard_main" WHERE "sqid"=$1 AND "sboard_id"=$2;'; - $sqlarr = array($sqid, $sboard_id); - $res = pg_query_params($msqlc, $sqlstr, $sqlarr); - } - - public static function get_scoreboard($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time = null, $end_time = null, $start_offset, $number, $uid = null) - { - if(!$start_time)$start_time = '1900-01-01 01:01:01+08'; - if(!$end_time)$end_time = '2222-01-01- 01:01:01+08'; - sqlib_scoreboard::update($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time, $end_time); - - //display - $sqlstr = 'SELECT "a1"."uid", "a1"."rank_score", COUNT(*) AS "rank" FROM "sqlib_scoreboard_main" "a1", "sqlib_scoreboard_main" "a2" WHERE "a1"."sqid"=$1 AND "a1"."sboard_id"=$2 AND "a2"."sqid"=$1 AND "a2"."sboard_id"=$2 AND ("a2"."rank_score">"a1"."rank_score" OR "a2"."uid"="a1"."uid") GROUP BY "a1"."uid", "a1"."rank_score" ORDER BY "a1"."rank_score" DESC, "a1"."uid" LIMIT $4 OFFSET $3;'; - $sqlarr = array($sqid, $sboard_id, $start_offset, $number); - if($uid) - { - $sqlstr = 'SELECT "a1"."uid", "a1"."rank_score", COUNT(*) AS "rank" FROM "sqlib_scoreboard_main" "a1", "sqlib_scoreboard_main" "a2" WHERE "a1"."sqid"=$1 AND "a1"."sboard_id"=$2 AND "a1"."uid"=$3 AND "a2"."sqid"=$1 AND "a2"."sboard_id"=$2 AND ("a2"."rank_score">"a1"."rank_score" OR "a2"."uid"="a1"."uid") GROUP BY "a1"."uid", "a1"."rank_score";'; - $sqlarr = array($sqid, $sboard_id, $uid); - } - - $res = pg_query_params($msqlc, $sqlstr, $sqlarr); - $arr = pg_fetch_all($res); - - $ret_obj = array(); - foreach($arr as $item) - { - $obj = new stdClass(); - $obj->uid = intval($item['uid']); - $obj->rank_score = doubleval($item['rank_score']); - $obj->rank = intval($item['rank']); - $obj->problem = array(); - - $sqlstr = 'SELECT "proid", "best_score", "best_time", "is_ac", "ac_time", "tries_before_ac", "last_score", "last_status", "last_time", "tries", "rank_score" FROM "sqlib_scoreboard_pro" WHERE "sqid"=$1 AND "sboard_id"=$2 AND "uid"=$3 ORDER BY "proid";'; - $sqlarr = array($sqid, $sboard_id, $obj->uid); - $res = pg_query_params($msqlc, $sqlstr, $sqlarr); - $data = pg_fetch_all($res); - foreach($data as $pro) - { - $pobj = new stdClass(); - $pobj->proid = intval($pro['proid']); /// - $pobj->best_score = doubleval($pro['best_score']); - $pobj->best_time = $pro['best_time']; - $pobj->is_ac = ($pro['is_ac']=='t'); - $pobj->ac_time = $pro['ac_time']; - $pobj->tries_before_ac = intval($pro['tries_before_ac']); - $pobj->last_score = doubleval($pro['last_score']); - $pobj->last_status = intval($pro['last_status']); - $pobj->last_time = $pro['last_time']; - $pobj->tries = intval($pro['tries']); - $pobj->rank_score = doubleval($pro['rank_score']); - - $proid = intval($pro['proid']); - $obj->problem[$proid] = $pobj; - } - array_push($ret_obj, $obj); - } - return $ret_obj; - } - - public static function get_scoreboard_uid($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time = null, $end_time = null, $uid) - { - return sqlib_scoreboard::get_scoreboard($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time, $end_time, null, null, $uid); - } - - public static function update($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time, $end_time) - { - $last_update = sqlib_scoreboard::get_last_update($msqlc, $sqid, $sboard_id); - $last_update_time = strtotime($last_update); - if(!$last_update)$last_update_time = 0; - if($last_update_time <= time()-2) - { - sqlib_scoreboard::set_last_update($msqlc, $sqid, $sboard_id, !$last_update); - } - else return; - $last_update = date('Y-m-d H:i:s+08', $last_update_time); - - //echo ('update!!'.$last_update.'<br>'); - $sqlstr = 'SELECT DISTINCT "uid" FROM "submit" WHERE "last_update">=$4 AND "proid" IN (SELECT "proid" FROM "pro_sq" WHERE "sqid"=$1) AND "submit_time">=$2 AND "submit_time"<=$3;'; - $sqlarr = array($sqid, $start_time, $end_time, $last_update); - $res = pg_query_params($sqlc, $sqlstr, $sqlarr); - $uid_list = pg_fetch_all_columns($res); - foreach($uid_list as $item) - { - //echo($item.', '); - $uid = intval($item); - sqlib_scoreboard::update_user($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time, $end_time, $uid); - } - } - - public static function update_user($sqlc, $msqlc, $sqid, $sboard_id, $score_func, $start_time, $end_time, $uid) - { - $sqlstr = 'SELECT "proid" FROM "pro_sq" WHERE "sqid"=$1;'; - $sqlarr = array($sqid); - $res = pg_query_params($sqlc, $sqlstr, $sqlarr); - $proid_list = pg_fetch_all_columns($res, 0); - - $total_rank_score = 0.0; - foreach($proid_list as $item) - { - $proid = intval($item); - $sqlstr = 'SELECT "result", "score", "submit_time" FROM "submit" WHERE "uid"=$1 AND "proid"=$2 AND "submit_time">=$3 AND "submit_time"<=$4 ORDER BY "submit_time";'; - $sqlarr = array($uid, $proid, $start_time, $end_time); - $res = pg_query_params($sqlc, $sqlstr, $sqlarr); - $sub_list = pg_fetch_all($res); - - $best_score = -1.0; - $best_time = '1900-01-01 01:01:01+08'; - - $is_ac = false; - $ac_time = null; - $tries_before_ac = 0; - - $tries = count($sub_list); - $last_score = null; - $last_status = null; - $last_time = null; - if($sub_list) - { - $last_score = doubleval($sub_list[$tries-1]['score']); - $last_status = intval($sub_list[$tries-1]['result']); - $last_time = $sub_list[$tries-1]['submit_time']; - - foreach($sub_list as $obj) - { - $score = doubleval($obj['score']); - $status = intval($obj['result']); - $stime = $obj['submit_time']; - if($score > $best_score) - { - $best_score = $score; - $best_time = $stime; - } - if(!$is_ac) - { - if($status == 0) // JUDGE_AC - { - $is_ac = true; - $ac_time = $stime; - } - else - { - $tries_before_ac += 1; - } - } - } - } - else - { - $tries = 0; - $best_score = null; - $best_time = null; - } - - if($score_func == null)$score_func = array('sqlib_scoreboard', 'def_func'); - $rank_score = $score_func($sqid, $proid, $best_score, $best_time, $is_ac, $ac_time, $tries_before_ac, $last_score, $last_status, $last_time, $tries); - $sqlstr = 'SELECT COUNT(*) FROM "sqlib_scoreboard_pro" WHERE "sqid"=$1 AND "sboard_id"=$3 AND "proid"=$2 AND "uid"=$4;'; - $sqlarr = array($sqid, $proid, $sboard_id, $uid); - $res = pg_query_params($msqlc, $sqlstr, $sqlarr); - $cnt = intval(pg_fetch_result($res, 0)); - - $sqlstr = 'UPDATE "sqlib_scoreboard_pro" SET "best_score"=$5, "best_time"=$6, "is_ac"=$7, "ac_time"=$8, "tries_before_ac"=$9, "last_score"=$10, "last_status"=$11, "last_time"=$12, "tries"=$13, "rank_score"=$14 WHERE "sqid"=$1 AND "sboard_id"=$2 AND "proid"=$3 AND "uid"=$4;'; - if($cnt==0) - { - $sqlstr = 'INSERT INTO "sqlib_scoreboard_pro" ("sqid", "sboard_id", "proid", "uid", "best_score", "best_time", "is_ac", "ac_time", "tries_before_ac", "last_score", "last_status", "last_time", "tries", "rank_score") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14);'; - } - $sqlarr = array($sqid, $sboard_id, $proid, $uid, $best_score, $best_time, $is_ac?'t':'f', $ac_time, $tries_before_ac, $last_score, $last_status, $last_time, $tries, $rank_score); - $res = pg_query_params($msqlc, $sqlstr, $sqlarr); - //var_dump($sqlarr); - $total_rank_score += $rank_score; - } - - $sqlstr = 'SELECT COUNT(*) FROM "sqlib_scoreboard_main" WHERE "sqid"=$1 AND "sboard_id"=$2 AND "uid"=$3;'; - $sqlarr = array($sqid, $sboard_id, $uid); - $res = pg_query_params($msqlc, $sqlstr, $sqlarr); - $cnt = intval(pg_fetch_result($res, 0)); - - $sqlstr = 'UPDATE "sqlib_scoreboard_main" SET "rank_score"=$4 WHERE "sqid"=$1 AND "sboard_id"=$2 AND "uid"=$3;'; - if($cnt == 0) - { - $sqlstr = 'INSERT INTO "sqlib_scoreboard_main" ("sqid", "sboard_id", "uid", "rank_score") VALUES ($1, $2, $3, $4);'; - } - $sqlarr = array($sqid, $sboard_id, $uid, $total_rank_score); - $res = pg_query_params($msqlc, $sqlstr, $sqlarr); - } - } -?> diff --git a/toj/php/square.inc.php b/toj/php/square.inc.php deleted file mode 100755 index 99f0d2e..0000000 --- a/toj/php/square.inc.php +++ /dev/null @@ -1,245 +0,0 @@ -<?php - -require_once('common.inc.php'); -require_once('user.inc.php'); -require_once('problem.inc.php'); - -const SQUARE_USER_PENDING = 1; -const SQUARE_USER_ACTIVE = 2; -const SQUARE_USER_ADMIN = 3; - -const SQUARE_PUBLIC = 3; -const SQUARE_AUTH = 2; -const SQUARE_PRIVATE = 1; - -const SQUARE_NAME_LEN_MAX = 100; - -class square -{ - public $sqid; - public $publicity; - public $start_time; - public $end_time; - public $sqname; - public $sqmodname; - - public static function get($sqlc, $sqid) - { - //get square object from sqid - //return the object found. False if no such record - $sqlr = pg_query_params($sqlc, 'SELECT * FROM "square" WHERE "sqid"=$1 LIMIT 1;', array($sqid)); - $ret = pg_fetch_object($sqlr, null, 'square'); - pg_free_result($sqlr); - if($ret)$ret->sqid = intval($ret->sqid); - return $ret; - } - - public static function add($sqlc, $sq) - { - //add a square object - //required member of sq : publicity, start_time, end_time, sqname, sqmodname - //publicity : SQUARE_PUBLIC, SQUARE_AUTH, SQUARE_PRIVATE - //return the object . False if failed. - $sqlstr = 'INSERT INTO "square" ("publicity", "start_time", "end_time", "sqname", "sqmodname") VALUES ($1, $2, $3, $4, $5) RETURNING *;'; - $sqlarr = array($sq->publicity, $sq->start_time, $sq->end_time, $sq->sqname, $sq->sqmodname); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $ret = pg_fetch_object($sqlr, null, 'square'); - pg_free_result($sqlr); - if($ret)$ret->sqid = intval($ret->sqid); - return $ret; - } - - public static function edit($sqlc, $sqid, $sq) - { - //edit exist square data - //required member of sq : publicity, start_time, end_time, sqname, sqmodname - //publicity : SQUARE_PUBLIC, SQUARE_AUTH, SQUARE_PRIVATE - //return edited object . False if failed. - // - //if puhlicity change SQUARE_AUTH => SQUARE_PUBLIC, - //set all SQUARE_USER_PENDING users to SQUARE_USER_ACTIVE. - $oldsq = square::get($sqlc, $sqid); - if($oldsq->publicity==SQUARE_AUTH && $sq->publicity==SQUARE_PUBLIC) - { - $sqlstr = 'UPDATE "us_sq" SET "relationship"=$1 WHERE "sqid"=$2 AND "relationship"=$3;'; - $sqlarr = array(SQUARE_USER_ACTIVE, $sqid, SQUARE_USER_PENDING); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - } - $sqlstr = 'UPDATE "square" SET "publicity"=$1, "start_time"=$2, "end_time"=$3, "sqname"=$4, "sqmodname"=$5 WHERE "sqid"=$6 RETURNING *;'; - $sqlarr = array($sq->publicity, $sq->start_time, $sq->end_time, $sq->sqname, $sq->sqmodname, $sqid); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $ret = pg_fetch_object($sqlr, null, 'square'); - pg_free_result($sqlr); - if($ret)$ret->sqid = intval($ret->sqid); - return $ret; - } - - public static function del($sqlc, $sqid) - { - //Delete the square $sqid. Also delete the user-square relation involves this square. - //return false if failed. - $sqlstr = 'DELETE FROM "square" WHERE "sqid"=$1;'; - $sqlstr2 = 'DELETE FROM "us_sq" WHERE "sqid"=$1;'; - $sqlr = pg_query_params($sqlc, $sqlstr, array($sqid)); - if(!$sqlr)return false; - $sqlr = pg_query_params($sqlc, $sqlstr2, array($sqid)); - if(!$sqlr)return false; - else return true; - } - - public static function add_user($sqlc, $uid, $sqid, $relationship) - { - //add user into user-square relation. - //return false if failed. - $sqlstr = 'INSERT INTO "us_sq" ("uid", "sqid", "relationship") VALUES ($1, $2, $3) RETURNING *;'; - $sqlarr = array($uid, $sqid, $relationship); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $ret = pg_fetch_object($sqlr); - pg_free_result($sqlr); - if(!$ret)return false; - else return true; - } - - public static function del_user($sqlc, $uid, $sqid) - { - //delete user from user-square relation. - //return false if failed. - $sqlstr = 'DELETE FROM "us_sq" WHERE "uid"=$1 AND "sqid"=$2;'; - $sqlarr = array($uid, $sqid); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - if(!$sqlr)return false; - else return true; - } - - public static function set_user_relationship($sqlc, $uid, $sqid, $relationship) - { - //update user relationship. - //relationship: SQUARE_USER_PENDING, SQUARE_USER_ACTIVE, SQUARE_USER_ADMIN - //return false if failed. - $sqlr = pg_query_params($sqlc, 'UPDATE "us_sq" SET "relationship"=$3 WHERE "uid"=$1 AND "sqid"=$2;', array($uid, $sqid, $relationship)); - if(!$sqlr)return false; - else return true; - } - - public static function get_user_relationship($sqlc, $uid, $sqid) - { - //get the relationship of uid,sqid from user-square relation. - //Return the relationship. SQUARE_USER_PENDING, SQUARE_USER_ACTIVE, SQUARE_USER_ADMIN - //return false if no record in the table; - $sqlr = pg_query_params($sqlc, 'SELECT "relationship" FROM "us_sq" WHERE "uid"=$1 AND "sqid"=$2;', array($uid, $sqid)); - $ret = pg_fetch_result($sqlr, 0); - if(!$ret)return false; - else return intval($ret); - } - - public static function get_available_sq($sqlc, $uid, $minpub) - { - //get all available square for given uid and publicity at least minpub. (not includes entered ones) - //Return array of object, which contains each sqid, start_time, end_time, publicity, sqname, sqmodname - //return empty array if no record in the table; - $sqlstr = 'SELECT "sqid", "start_time", "end_time", "publicity", "sqname", "sqmodname" FROM "square" WHERE "sqid" NOT IN (SELECT "sqid" FROM "us_sq" WHERE "uid"=$1) AND "publicity" >= $2 ORDER BY (CASE WHEN "square"."end_time" IS NULL THEN "square"."sqid" ELSE 0 END), "square"."start_time", "square"."sqid";'; - $sqlarr = array($uid, $minpub); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $ret = array(); - while($row = pg_fetch_object($sqlr)) - { - $row->sqid = intval($row->sqid); - array_push($ret, $row); - } - return $ret; - } - - public static function get_entered_sq($sqlc, $uid) - { - //gel all entered square for given uid. - //Return array of object, which contains each sqid, start_time, end_time, publicity, sqname, sqmodname, relationship - //return empty array if no record in the table; - $sqlstr = 'SELECT "square"."sqid", "square"."start_time", "square"."end_time", "square"."publicity", "square"."sqname", "square"."sqmodname", "us_sq"."relationship" FROM "us_sq" INNER JOIN "square" ON "us_sq"."sqid"="square"."sqid" WHERE "us_sq"."uid"=$1 ORDER BY (CASE WHEN "square"."end_time" IS NULL THEN "square"."sqid" ELSE 0 END), "square"."start_time", "square"."sqid";'; - $sqlarr = array($uid); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $ret = array(); - while($row = pg_fetch_object($sqlr)) - { - $row->sqid = intval($row->sqid); - array_push($ret, $row); - } - return $ret; - } - - public static function del_pro($sqlc, $proid, $sqid) - { - //Delete $proid from square $sqid. - //Return true if success, false if failed. - $sqlstr = 'DELETE FROM "pro_sq" WHERE "proid"=$1 AND "sqid"=$2;'; - $sqlarr = array($proid, $sqid); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - if(!$sqlr) - return false; - return true; - } - - public static function add_pro($sqlc, $proid, $sqid) - { - //Add problem $proid into square $sqid. - //Return true if success, false if failed. - $sqlstr = 'INSERT INTO "pro_sq" ("proid", "sqid") VALUES ($1, $2) RETURNING *;'; - $sqlarr = array($proid, $sqid); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $ret = pg_fetch_result($sqlr, 0); - if(!$ret) - return false; - return true; - } - - public static function is_pro_in_sq($sqlc, $proid, $sqid) - { - //Return whether problem $proid is in square $sqid or not. - $sqlstr = 'SELECT COUNT(*) FROM "pro_sq" WHERE "proid"=$1 AND "sqid"=$2;'; - $sqlarr = array($proid, $sqid); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $ret = intval(pg_fetch_result($sqlr, 0)); - return $ret > 0; - } - - public static function get_sqmod($sqlc, $sqid) - { - //Return the sqmodname of square $sqid. - $sqlstr = 'SELECT "sqmodname" FROM "square" WHERE "sqid"=$1;'; - $sqlarr = array($sqid); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $ret = pg_fetch_result($sqlr, 0); - return $ret; - } - - public static function get_pro_list($sqlc, $sqid) - { - //get problem list of square $sqid. - $sqlstr = 'SELECT "problem"."proid", "problem"."proname", "problem"."hidden" FROM "problem" INNER JOIN "pro_sq" ON "problem"."proid"="pro_sq"."proid" WHERE "pro_sq"."sqid"=$1 ORDER BY "problem"."proid";'; - $sqlarr = array($sqid); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $ret = array(); - while($obj = pg_fetch_object($sqlr)) - { - $obj->proid = intval($obj->proid); - $obj->hidden = ($obj->hidden=='t'); - array_push($ret, $obj); - } - return $ret; - } - public static function get_user_list($sqlc, $sqid) - { - //get problem list of square $sqid. - $sqlstr = 'SELECT "user"."uid", "user"."nickname" FROM "user" INNER JOIN "us_sq" ON "user"."uid"="us_sq"."uid" WHERE "us_sq"."sqid"=$1 ORDER BY "user"."uid";'; - $sqlarr = array($sqid); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $ret = array(); - while($obj = pg_fetch_object($sqlr)) - { - $obj->uid = intval($obj->uid); - array_push($ret, $obj); - } - return $ret; - } -} - -?> diff --git a/toj/php/square.php b/toj/php/square.php deleted file mode 100755 index fb87741..0000000 --- a/toj/php/square.php +++ /dev/null @@ -1,382 +0,0 @@ -<?php -//ini_set("display_errors", "On"); - -require_once('square.inc.php'); -require_once('event.inc.php'); - -$sqlc = db_connect(); - -$action = $_POST['action']; -$data = $_POST['data']; - -if(strlen($action)==0) - die('Eno_action'); -if($action == 'add_sq') -{ - //Add new square. level USER_LEVEL_SUPERADMIN or above required. - //data: sqname, publicity, [start_time, end_time], sqmodname - - $sq = json_decode($data); - - if(!sec_is_login()) - die('Eno_login'); - if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN)) - die('Epermission_denied'); - - if($sq->publicity != SQUARE_PUBLIC && $sq->publicity != SQUARE_AUTH && $sq->publicity != SQUARE_PRIVATE) - die('Ewrong_publicity'); - - if(!($sq->start_time)) - $sq->start_time = date('Y-m-d H:i:s'); - if(!($sq->end_time)) - $sq->start_time = null; - if(strlen($sq->sqname)==0) - die('Esqname_too_short'); - if(strlen($sq->sqname)>SQUARE_NAME_LEN_MAX) - die('Esqname_too_long'); - if(strlen($sq->sqmodname)==0) - die('Esqmodname_empty'); - - $res = square::add($sqlc, $sq); - if(!$res) - die('Eadd_sq_failed'); - - $res2 = square::add_user($sqlc, $_COOKIE['uid'], $res->sqid, SQUARE_USER_ADMIN); - if(!$res2) - die('Eadd_admin_failed'); - - if(event::exec_func('../sqmod/'.$sq->sqmodname.'/'.$sq->sqmodname.'.inc.php','event_create',[$res->sqid]) === false) - die('Eevent_error'); - - echo('S'); -} -if($action == 'delete_sq') -{ - //Delete exist square. level USER_LEVEL_SUPERADMIN or above required. - //data : sqid - - $sq = json_decode($data); - - if(!sec_is_login()) - die('Eno_login'); - if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN)) - die('Epermission_denied'); - - $sqid = intval($sq->sqid); - $sq = square::get($sqlc, $sqid); - if(!$sq) - die('Ewrong_sqid'); - - $res = square::del($sqlc, $sqid); - if(!$res) - die('Edelete_failed'); - - if(event::exec_func('../sqmod/'.$sq->sqmodname.'/'.$sq->sqmodname.'.inc.php','event_destroy',[$sq->sqid]) === false) - die('Eevent_error'); - - echo('S'); -} -if($action == 'edit_sq') -{ - //edit exist square. level USER_LEVEL_SUPERADMIN / SQUARE_USER_ADMIN or above required. - //data: sqid, sqname, publicity, [start_time, end_time], sqmodname - - $sq = json_decode($data); - - if(!sec_is_login()) - die('Eno_login'); - - $sqid = intval($sq->sqid); - if(!square::get($sqlc, $sqid)) - die('Eno_such_sq'); - - if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN) && !(square::get_user_relationship($sqlc, $_COOKIE['uid'], $sqid)>=SQUARE_USER_ADMIN)) - die('Epermission_denied'); - - if($sq->publicity != SQUARE_PUBLIC && $sq->publicity != SQUARE_AUTH && $sq->publicity != SQUARE_PRIVATE) - die('Ewrong_publicity'); - - if(!($sq->start_time) && $sq->end_time) - $sq->start_time = date('Y-m-d H:i:s'); - if(strlen($sq->sqname)==0) - die('Esqname_too_short'); - if(strlen($sq->sqname)>SQUARE_NAME_LEN_MAX) - die('Esqname_too_long'); - if(strlen($sq->sqmodname)==0) - die('Esqmodname_empty'); - - $res = square::edit($sqlc, $sqid, $sq); - if(!$res) - die('Eedit_failed'); - - echo('S'); -} -if($action == 'get_sq') -{ - //get exist square data - //data: sqid - $sq = json_decode($data); - - $sqid = intval($sq->sqid); - - $ret = square::get($sqlc, $sqid); - if(!$ret) - die('Eno_such_sq'); - - echo(json_encode($ret)); -} -if($action == 'add_user') -{ - //add user to exist square - //data: uid, sqid - $dt = json_decode($data); - - if(!sec_is_login()) - die('Eno_login'); - - $uid = intval($dt->uid); - $sqid = intval($dt->sqid); - - $usr = user::get_from_uid($sqlc, $uid); - if(!$usr) - die('Eno_such_user'); - - $sq = square::get($sqlc, $sqid); - if(!$sq) - die('Eno_such_sq'); - - $adm = sec_check_level($sqlc, USER_LEVEL_SUPERADMIN) || (square::get_user_relationship($sqlc, $_COOKIE['uid'], $sqid)>=SQUARE_USER_ADMIN); - - if($uid != intval($_COOKIE['uid']) && !$adm) - die('Epermission_denied'); - - $rela = SQUARE_USER_ACTIVE; - if(!$adm) - { - if($sq->publicity == SQUARE_AUTH) - $rela = SQUARE_USER_PENDING; - if($sq->publicity == SQUARE_PRIVATE) - die('Eprivate_square'); - } - - if(square::get_user_relationship($sqlc, $uid, $sqid)) - die('Ealready_entered'); - - $ret = square::add_user($sqlc, $uid, $sqid, $rela); - if(!$ret) - die('Eadd_user_failed'); - - echo('S'); -} -if($action == 'delete_user') -{ - //delete user from user-square relation - //data : uid, sqid - $dt = json_decode($data); - - if(!sec_is_login()) - die('Eno_login'); - - $uid = intval($dt->uid); - $sqid = intval($dt->sqid); - - $usr = user::get_from_uid($sqlc, $uid); - if(!$usr) - die('Eno_such_user'); - - $sq = square::get($sqlc, $sqid); - if(!$sq) - die('Eno_such_sq'); - - $adm = sec_check_level($sqlc, USER_LEVEL_SUPERADMIN) || (square::get_user_relationship($sqlc, $_COOKIE['uid'], $sqid)>=SQUARE_USER_ADMIN); - - if($uid != intval($_COOKIE['uid']) && !$adm) - die('Epermission_denied'); - - if(!square::get_user_relationship($sqlc, $uid, $sqid)) - die('Enot_entered'); - - $ret = square::del_user($sqlc, $uid, $sqid); - if(!$ret) - die('Edelete_user_failed'); - - echo('S'); -} -if($action == 'edit_user_relationship') -{ - //edit user relationship. - //data: uid, sqid, relationship - $dt = json_decode($data); - - if(!sec_is_login()) - die('Eno_login'); - - $uid = intval($dt->uid); - $sqid = intval($dt->sqid); - $rel = intval($dt->relationship); - - $usr = user::get_from_uid($sqlc, $uid); - if(!$usr) - die('Eno_such_user'); - - $sq = square::get($sqlc, $sqid); - if(!$sq) - die('Eno_such_sq'); - - $adm = sec_check_level($sqlc, USER_LEVEL_SUPERADMIN) || (square::get_user_relationship($sqlc, $_COOKIE['uid'], $sqid)>=SQUARE_USER_ADMIN); - - if(!$adm) - die('Epermission_denied'); - - if(!square::get_user_relationship($sqlc, $uid, $sqid)) - die('Enot_entered'); - - if($rel!=SQUARE_USER_PENDING && $rel!=SQUARE_USER_ACTIVE && $rel!=SQUARE_USER_ADMIN) -die('Ewrong_relationship'); - - $ret = square::set_user_relationship($sqlc, $uid, $sqid, $rel); - if(!$ret) - die('Eedit_user_relationship_failed'); - - echo('S'); -} -if($action == 'get_available_sq') -{ - //get all available square data: sqid, start_time, end_time, publicity, sqname for given uid. - //only USER_LEVEL_SUPERADMIN can see SQUARE_PRIVATE squares. - //data: (no) - - if(!sec_is_login()) - die('Eno_login'); - - $uid = intval($_COOKIE['uid']); - - $usr = user::get_from_uid($sqlc, $uid); - if(!$usr) - die('Eno_such_user'); - - $adm = sec_check_level($sqlc, USER_LEVEL_SUPERADMIN); - - $pub = 2; - if($adm) - $pub = 1; - - $list = square::get_available_sq($sqlc, $uid, $pub); - - $ret = new stdClass; - $ret->list = $list; - $ret->timestamp = date('Y-m-d H:i:s'); - - echo(json_encode($ret)); -} -if($action == 'get_entered_sq') -{ - - //get all entered square data: sqid, start_time, end_time, publicity, sqname, relationship for given uid. - //data: (no) - - if(!sec_is_login()) - die('Eno_login'); - - $uid = intval($_COOKIE['uid']); - - $usr = user::get_from_uid($sqlc, $uid); - if(!$usr) - die('Eno_such_user'); - - $list = square::get_entered_sq($sqlc, $uid); - - $ret = new stdClass; - $ret->list = $list; - $ret->timestamp = date('Y-m-d H:i:s'); - - echo(json_encode($ret)); -} -if($action == 'get_sq_pro_list') -{ - if(!sec_is_login()) - die('Enot_login'); - if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN)) - die('Epermission_denied'); - - $dt = json_decode($data); - if(!square::get($sqlc, $dt->sqid)) - die('Ewrong_sqid'); - - $ret = square::get_pro_list($sqlc, $dt->sqid); - echo(json_encode($ret)); -} -if($action == 'add_pro_into_sq') -{ - if(!sec_is_login()) - die('Eno_login'); - - $uid = intval($_COOKIE['uid']); - - $usr = user::get_from_uid($sqlc, $uid); - if(!$usr) - die('Eno_such_user'); - - $dt = json_decode($data); - if(!problem::is_available($sqlc, $dt->proid)) - die('Ewrong_proid'); - - $sq = square::get($sqlc, $dt->sqid); - if(!$sq) - die('Ewrong_sqid'); - - $adm = sec_check_level($sqlc, USER_LEVEL_SUPERADMIN) || square::get_user_relationship($sqlc, $uid, $dt->sqid) >= SQUARE_USER_ADMIN; - - if(!$adm) - die('Enot_square_admin'); - - if(square::is_pro_in_sq($sqlc, $dt->proid, $dt->sqid)) - die('Ealready_in_square'); - - $ret = square::add_pro($sqlc, $dt->proid, $dt->sqid); - if(!$ret) - die('Eadd_problem_into_square_failed'); - - if(event::exec_func('../sqmod/'.$sq->sqmodname.'/'.$sq->sqmodname.'.inc.php','event_add_pro',[$sq->sqid, $dt->proid]) === false) - die('Eevent_error'); - - echo('S'); -} -if($action == 'delete_pro_from_sq') -{ - if(!sec_is_login()) - die('Eno_login'); - - $uid = intval($_COOKIE['uid']); - - $usr = user::get_from_uid($sqlc, $uid); - if(!$usr) - die('Eno_such_user'); - - $dt = json_decode($data); - - $sq = square::get($sqlc, $dt->sqid); - if(!$sq) - die('Ewrong_sqid'); - - $adm = sec_check_level($sqlc, USER_LEVEL_SUPERADMIN) || square::get_user_relationship($sqlc, $uid, $dt->sqid) >= SQUARE_USER_ADMIN; - - if(!$adm) - die('Enot_square_admin'); - - if(!square::is_pro_in_sq($sqlc, $dt->proid, $dt->sqid)) - die('Enot_in_square'); - - $ret = square::del_pro($sqlc, $dt->proid, $dt->sqid); - if(!$ret) - die('Edelete_problem_from_square_failed'); - - if(event::exec_func('../sqmod/'.$sq->sqmodname.'/'.$sq->sqmodname.'.inc.php','event_del_pro',[$sq->sqid, $dt->proid]) === false) - die('Eevent_error'); - - echo('S'); -} - -db_close($sqlc); - -?> diff --git a/toj/php/status.inc.php b/toj/php/status.inc.php deleted file mode 100755 index f0ad3da..0000000 --- a/toj/php/status.inc.php +++ /dev/null @@ -1,162 +0,0 @@ -<?php -require_once('common.inc.php'); -require_once('user.inc.php'); -require_once('problem.inc.php'); - -const SUBMIT_COUNT_MAX = 100; -const SUBMIT_SLEEP_TIME = 2; -const SUBMIT_WAIT_MAX = 10; - -class status -{ - public static function get_submit($sqlc, $filter, $sort, $count, $last_update, $admin) - { - //get submit from submit table. - //return an array with every entry an object of submission. - $condstr = ''; - $ordstr = ''; - - if($admin != true) - { - $uid = $_COOKIE['uid']; - if(!sec_is_login()) - $uid = 0; - $condstr = $condstr.'("problem"."admin_uid"='.intval($uid).' OR "problem"."hidden"=\'f\') AND '; - } - - if($last_update != null) - { - $condstr = $condstr.'"last_update">\''.pg_escape_string($last_update).'\' AND '; - } - - if($filter->uid != null) - { - $condstr = $condstr.'"submit"."uid"='.pg_escape_string($filter->uid).' AND '; - } - if($filter->result !== null) - { - $condstr = $condstr.'"result"='.pg_escape_string($filter->result).' AND '; - } - if($filter->proid != null) - { - $condstr = $condstr.'"submit"."proid"='.pg_escape_string($filter->proid).' AND '; - } - if($filter->lang != null) - { - $condstr = $condstr.'"lang"='.pg_escape_string($filter->lang).' AND '; - } - if($sort->score !== null) - { - $relstr = $sort->score[0]==0 ? '<=' : '>='; - $condstr = $condstr.'"score"'.$relstr.pg_escape_string($sort->score[1]).' AND '; - $ordstr = $ordstr.'"score" '.($sort->score[0]==0 ? 'DESC' : 'ASC').' ,'; - } - if($sort->runtime !== null) - { - $relstr = $sort->runtime[0]==0 ? '<=' : '>='; - $condstr = $condstr.'"runtime"'.$relstr.pg_escape_string($sort->runtime[1]).' AND '; - $ordstr = $ordstr.'"runtime" '.($sort->runtime[0]==0 ? 'DESC' : 'ASC').' ,'; - } - if($sort->maxmem !== null) - { - $relstr = $sort->maxmem[0]==0 ? '<=' : '>='; - $condstr = $condstr.'"memory"'.$relstr.pg_escape_string($sort->maxmem[1]).' AND '; - $ordstr = $ordstr.'"memory" '.($sort->maxmem[0]==0 ? 'DESC' : 'ASC').' ,'; - } - if($sort->subid != null) - { - $relstr = $sort->subid[0]==0 ? '<' : '>'; - $condstr = $condstr.'"subid"'.$relstr.pg_escape_string($sort->subid[1]); - $ordstr = $ordstr.'"subid" '.($sort->subid[0]==0 ? 'DESC' : 'ASC'); - } - - $sqlstr = 'SELECT "submit".*, "user"."nickname", "problem"."proname" FROM ("submit" INNER JOIN "user" ON "submit"."uid"="user"."uid") INNER JOIN "problem" ON "submit"."proid"="problem"."proid" WHERE '.$condstr.' ORDER BY '.$ordstr.' LIMIT '.pg_escape_string($count).';'; - - //echo($sqlstr.'<br>'); - $sqlr = pg_query($sqlc, $sqlstr); - //return pg_fetch_object($sqlr); - $ret = array(); - while($obj = pg_fetch_object($sqlr)) - { - $obj->subid = intval($obj->subid); - $obj->uid = intval($obj->uid); - $obj->proid = intval($obj->proid); - $obj->result = intval($obj->result); - $obj->runtime = intval($obj->runtime); - $obj->memory = intval($obj->memory); - $obj->score = intval($obj->score); - $obj->lang = intval($obj->lang); - - array_push($ret, $obj); - } - - return $ret; - } - - public static function get_by_subid($sqlc, $subid) - { - //get submit information by subid. - //return submit information. - - $sqlstr = 'SELECT "submit".*, "mod"."smodname" FROM ("submit" INNER JOIN "problem" ON "submit"."proid"="problem"."proid") INNER JOIN "mod" ON "problem"."modid"="mod"."modid" WHERE "subid"=$1;'; - $sqlarr = array($subid); - $sqlr = pg_query_params($sqlstr, $sqlarr); - $ret = pg_fetch_object($sqlr); - if(!$ret) - die('Eno_such_subid'); - $ret->subid = intval($ret->subid); - $ret->proid = intval($ret->proid); - $ret->uid = intval($ret->uid); - $ret->result = intval($ret->result); - $ret->memory = intval($ret->memory); - $ret->score = intval($ret->score); - $ret->lang = intval($ret->lang); - $ret->nickname = user::get_nickname($sqlc, $ret->uid); - - return $ret; - } - - public static function subid_is_available($sqlc, $subid) - { - //decide whether subid is visible or not. - //Return true if OK, false if permission denied or failed. - $sub = status::get_by_subid($sqlc, $subid); - if(!$sub) - return false; - $ret = problem::is_available($sqlc, $sub->proid); - if(!$ret) - return false; - return true; - } - - public static function get_submit_data($subid) - { - //get submit data files - //if nothing return false - - $ret = array(); - $path = '../center/submit/'.(floor($subid/1000)*1000).'/'.$subid.'/data'; - $dir_it = new RecursiveDirectoryIterator($path); - $it = new RecursiveIteratorIterator($dir_it, RecursiveIteratorIterator::SELF_FIRST); - - foreach($it as $file) - { - if($file->isFile()) - { - $obj = new stdClass(); - $obj->filename = $file->getPathname(); - $obj->content = file_get_contents($obj->filename); - for($i = 0; $i < 6; $i++) - { - $pos = strpos($obj->filename, '/'); - $obj->filename = substr($obj->filename, $pos+1); - } - array_push($ret, $obj); - } - } - - return $ret; - } -} - -?> diff --git a/toj/php/status.php b/toj/php/status.php deleted file mode 100755 index 488fb95..0000000 --- a/toj/php/status.php +++ /dev/null @@ -1,119 +0,0 @@ -<?php -ini_set("display_errors", "On"); -error_reporting(E_ALL & ~E_NOTICE); - -require_once('status.inc.php'); -require_once('problem.inc.php'); - -$sqlc = db_connect(); - -$action = $_POST['action']; -$data = $_POST['data']; - -if(strlen($action)==0) - die('Eno_action'); -if($action == 'get_submit') -{ - //get submit from submit table - //data: sort, sort->subid, count, [wait, filter, last_update] - $dt = json_decode($data); - if($dt->sort->subid == null) - die('Eno_sort_subid'); - if($dt->count == null) - die('Eno_count'); - $cnt = intval($dt->count); - if($cnt <= 0) - die('Etoo_few_count'); - if($cnt > SUBMIT_COUNT_MAX) - die('Etoo_many_count'); - - $wait = intval($dt->wait); - if($wait > SUBMIT_WAIT_MAX) - die('Etoo_many_wait'); - - $nowwait = $wait; - $isadm = sec_check_level($sqlc, USER_PER_PROADMIN); - - while(1) - { - $ret = status::get_submit($sqlc, $dt->filter, $dt->sort, $cnt, $dt->last_update, $isadm); - if($ret != null) - { - /* OUTPUT */ - echo(json_encode($ret)); - exit(0); - } - //die('Efail'); - $nowwait--; - if($nowwait<0)break; - sleep(SUBMIT_SLEEP_TIME); - } - die('Eno_result'); -} -if($action == 'get_by_subid') -{ - //get submission data and smodname by subid. - //problem must be available for the user. - //data: subid - $dt = json_decode($data); - $subid = intval($dt->subid); - if(!$subid) - die('Eno_subid'); - $obj = status::get_by_subid($sqlc, $subid); - - if(!problem::is_available($sqlc, $obj->proid)) - die('Epermission_denied'); - - echo(json_encode($obj)); -} -if($action == 'get_submit_data') -{ - //get submission data : code or something - //data: subid - - if(!sec_is_login()) - die('Enot_login'); - - $dt = json_decode($data); - $subid = intval($dt->subid); - if(!$subid) - die('Eno_subid'); - - $sub = status::get_by_subid($sqlc, $subid); - if(!$sub) - die('Ewrong_subid'); - - if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN) && ($sub->uid != intval($_COOKIE['uid']))) - die('Epermission_denied'); - - $ret = status::get_submit_data($subid); - if(!$ret) - die('Eerror_get_submit_data'); - - echo(json_encode($ret)); -} -if($action == 'rejudge_submit') -{ - if(!sec_is_login()) - die('Enot_login'); - - $dt = json_decode($data); - $subid = intval($dt->subid); - if(!$subid) - die('Eno_subid'); - - $sub = status::get_by_subid($sqlc, $subid); - if(!$sub) - die('Ewrong_subid'); - - if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN)) - die('Epermission_denied'); - - if(!problem::rejudge_sub($sqlc, $subid)) - die('Erejudge_sub'); - - echo('S'); -} - -db_close($sqlc); -?> diff --git a/toj/php/step.inc.php b/toj/php/step.inc.php deleted file mode 100755 index a116a64..0000000 --- a/toj/php/step.inc.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php - -require_once('common.inc.php'); -require_once('square.inc.php'); -require_once('sqlib_scoreboard.inc.php'); - -function get_prob_stat_uid($sqlc, $msqlc, $sqid, $sboard_id, $uid) -{ - $sq = square::get($sqlc, $sqid); - if(!$sq)die('Eno_such_sq'); - - $data = sqlib_scoreboard::get_scoreboard_uid($sqlc, $msqlc, $sqid, $sboard_id, null, $sq->start_time, $sq->end_time, $uid); - - return $data[0]; -} - -?> diff --git a/toj/php/step.php b/toj/php/step.php deleted file mode 100755 index 6425ae1..0000000 --- a/toj/php/step.php +++ /dev/null @@ -1,64 +0,0 @@ -<?php -//ini_set("display_errors", "On"); - -require_once('common.inc.php'); -require_once('step.inc.php'); -require_once('teamt.php'); - -$sqlc = db_connect(); -$msqlc = db_connect('toj_mod'); - -if(strlen($action)==0) - die('Eno_action'); -if($action == '') -{ -} - -$uid = $_GET['uid']; -$dat = get_prob_stat_uid($sqlc, $msqlc, 1, 2, $uid); - -//var_dump($dat); -echo('uid : '.$dat->uid.'<br>'); -foreach($dat->problem as $prob) -{ - echo('problem '.$prob->proid.' : '); - if(!$prob->tries) - { - echo('--<br>'); - continue; - } - echo($prob->best_score.' '); - if($prob->is_ac)echo('AC'); - echo('<br>'); -} - -$term = 1; -$teamid = get_teamid($msqlc, $term, $uid); -echo('<br>Team : '.$teamid.'<br>Members : <br>'); -$members = get_team_member($msqlc, $term, $teamid); -foreach($members as $mem) -{ - echo('<br>Uid : '.$mem->uid.' ( Level '.$mem->level.' )<br>'); - $uid = intval($mem->uid); - if($uid == intval($_GET['uid']))continue; - $dat = get_prob_stat_uid($sqlc, $msqlc, 1, 2, $uid); - - foreach($dat->problem as $prob) - { - echo('problem '.$prob->proid.' : '); - if(!$prob->tries) - { - echo('--<br>'); - continue; - } - echo($prob->best_score.' '); - if($prob->is_ac)echo('AC'); - echo('<br>'); - } -} - - -db_close($sqlc); -db_close($msqlc); - -?> diff --git a/toj/php/teamt.php b/toj/php/teamt.php deleted file mode 100755 index 13c7bad..0000000 --- a/toj/php/teamt.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php -// -require_once('common.inc.php'); - -function get_teamid($msqlc, $term, $uid) -{ - $sqlstr = 'SELECT "teamid" FROM "sqmod_sprout_team" WHERE "term"=$1 AND "uid"=$2;'; - $sqlarr = array($term, $uid); - $res = pg_query_params($sqlstr, $sqlarr); - $teamid = pg_fetch_result($res, 0); - return $teamid; -} - -function get_team_member($msqlc, $term, $teamid) -{ - $sqlstr = 'SELECT "uid", "level" FROM "sqmod_sprout_team" WHERE "term"=$1 AND "teamid"=$2 ORDER BY "level" DESC, "uid";'; - $sqlarr = array($term, $teamid); - $res = pg_query_params($sqlstr, $sqlarr); - $ret = array(); - while($obj = pg_fetch_object($res)) - { - array_push($ret, $obj); - } - return $ret; -} - - -?> diff --git a/toj/php/test.php b/toj/php/test.php deleted file mode 100755 index 4d39e6e..0000000 --- a/toj/php/test.php +++ /dev/null @@ -1,93 +0,0 @@ -<?php -ini_set("display_errors", "On"); -error_reporting(E_ALL & ~E_NOTICE); - -require_once('common.inc.php'); -require_once('sqlib.inc.php'); -require_once('user.inc.php'); -require_once('problem.inc.php'); - -$msqlc = db_connect('toj_mod'); -$sqlc = db_connect(); - -function func($sqid, $proid, $best_score, $best_time, $is_ac, $ac_time, $tries_before_ac, $last_score, $last_status, $last_time, $tries) -{ - return $best_score; -} - -//$a = intval($_GET['a']); -//sqlib_scoreboard::set_last_update($msqlc, 1, 4, false); -//$scb = sqlib_scoreboard::get_scoreboard($sqlc, $msqlc, 1, $a, func, null, null, 1, 20); -//var_dump($scb); -//echo(json_encode($scb)); -//$test = sqlib_scoreboard::get_last_update($msqlc, 1, $a); -//echo($test.'<br>'); -//echo(strtotime($test).'<br>'); -//echo(time()); - -/*for($i = 5; $i <= 61; $i++){ -echo('uid : '.$i.'<br>'); -$res = user::reset_password($sqlc, $i); -var_dump($res); -}*/ -//user::reset_password($sqlc, 16); - -if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN)) - die('Epermission_denied'); - -if($_GET['code']=='code') -{ - $subid = intval($_GET['subid']); - if(!$subid) - die('Eno_subid'); - $path = '../center/submit/'.(int)(floor($subid/1000)*1000).'/'.$subid.'/data/main.cpp'; - $code = file_get_contents($path); - if(!$code) - die('Eerror_get_code'); - - $sarr = array('<', '>'); - $darr = array('<', '>'); - - $ncode = str_replace($sarr, $darr, $code); - - echo('Subid: '.$subid.'<br>'); -?> -<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script> -<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js"></script> -<link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css" /> -<link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" rel="stylesheet" type="text/css" /> -<?php - echo('<pre class="brush: cpp">'); - echo($ncode); - echo('</pre>'); -?> -<script type="text/javascript"> - SyntaxHighlighter.all() -</script> -<?php -} -//exit(); -if($_GET['rejudge']=='sub') -{ - $subid = intval($_GET['subid']); - if(!$subid) - die('Eno_subid'); - $res = problem::rejudge_sub($sqlc, $subid); - if(!$res) - die('Eerror_rejudge'); - echo('S'); -} -if($_GET['rejudge']=='pro') -{ - $proid = intval($_GET['proid']); - if(!$proid) - die('Eno_proid'); - $res = problem::rejudge_pro($sqlc, $proid); - if(!$res) - die('Eerror_rejudge'); - echo('S'); -} - -db_close($sqlc); -db_close($msqlc); -?> diff --git a/toj/php/user.inc.php b/toj/php/user.inc.php deleted file mode 100755 index 46205d7..0000000 --- a/toj/php/user.inc.php +++ /dev/null @@ -1,262 +0,0 @@ -<?php - -require_once('common.inc.php'); -require_once('/srv/http/phpmailer/class.phpmailer.php'); - -const USERNAME_LEN_MIN = 5; -const USERNAME_LEN_MAX = 20; -const PASSWORD_LEN_MIN = 5; -const PASSWORD_LEN_MAX = 32; -const NICKNAME_LEN_MIN = 1; -const NICKNAME_LEN_MAX = 32; -const EMAIL_LEN_MAX = 100; - -const USER_PER_USER = 0x00000001; -const USER_PER_PROCREATOR = 0x00000002; -const USER_PER_PROADMIN = 0x00000004; - -const USER_LEVEL_USER = 0x00000001; -const USER_LEVEL_PROCREATOR = 0x00000003; -const USER_LEVEL_PROADMIN = 0x00000007; -const USER_LEVEL_ADMIN = 0x0000ffff; -const USER_LEVEL_SUPERADMIN = 0xffffffff; - -class user -{ - public $uid; - public $username; - public $password; - public $nickname; - public $aboutme; - public $avatar; - public $level; - public $email; - - public static function get_from_uid($sqlc, $uid) - { - //return user object of specified uid. False if user doesn't exists. - - $result = pg_query_params($sqlc, 'SELECT * FROM "user" WHERE "uid"=$1 LIMIT 1;', array(intval($uid))) or die ("Eerror_get_user"); - $ret = pg_fetch_object($result, null, 'user'); - pg_free_result($result); - if(!$ret) - return false; - $ret->uid = intval($ret->uid); - $ret->level = intval($ret->level); - return $ret; - } - - public static function get_from_username($sqlc, $username) - { - //return user object of specified username. False if user doesn't exists. - - $result = pg_query_params($sqlc, 'SELECT * FROM "user" WHERE "username"=$1 LIMIT 1;', array($username)); - $ret = pg_fetch_object($result, null, 'user'); - pg_free_result($result); - if(!$ret) - return false; - $ret->uid = intval($ret->uid); - $ret->level = intval($ret->level); - - return $ret; - } - - public static function add($sqlc, $user) - { - //add user to database , with $user the user data object - //return inserted user object. False if failed. - //Assume the insertion is valid!! - //requires member: string username, string nickname, string password, stirng aboutme, string avatar, string email - - $sqlstr = 'INSERT INTO "user" ("username", "nickname", "password", "aboutme", "avatar", "email") VALUES ($1, $2, $3, $4, $5, $6) RETURNING *;'; - $sqlarr = array($user->username, $user->nickname, $user->password, '', '', $user->email); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - if(!$sqlr)return false; - //$sqlr = pg_query($sqlc, 'SELECT SCOPE_IDENTITY();'); - $obj = pg_fetch_object($sqlr, null, 'user'); - pg_free_result($sqlr); - if($obj)$obj->uid = intval($obj->uid); - return $obj; - } - - public static function update($sqlc, $user) - { - //update user data into database, with $user the user data object - //return updated object. False if failed. - //Assume the update is valid!! - //requires member: string nickname, string password, string aboutme, string avatar, string email, int uid - - $sqlstr = 'UPDATE "user" SET "nickname"=$1, "password"=$2, "aboutme"=$3, "avatar"=$4, "email"=$5 WHERE "uid"=$6 RETURNING *;'; - $sqlarr = array($user->nickname, $user->password, $user->aboutme, $user->avatar, $user->email, intval($user->uid)); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - if(!$sqlr)return false; - $obj = pg_fetch_object($sqlr, null, 'user'); - pg_free_result($sqlr); - if($obj)$obj->uid = intval($obj->uid); - return $obj; - } - - /*public static function update_property($sqlc, $user) - { - //update property of given user. - //return updated object. False if failed. - //Assume the update is valid!! - //requires member: int[] property, int uid; - - $sqlstr = 'UPDATE "user" SET "property"=$1 WHERE "uid"=$2 RETURNING *;'; - $sqlarr = array($user->property, intval($user->uid)); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - if(!$sqlr)return false; - $obj = pg_fetch_object($sqlr, null, 'user'); - pg_free_result($sqlr); - if($obj)$obj->uid = intval($obj->uid); - return $obj; - }*/ - - public static function get_username($sqlc, $uid) - { - //return username of given uid. False if not found. - - $sqlstr = 'SELECT "username" FROM "user" WHERE "uid"=$1 LIMIT 1;'; - $sqlarr = array(intval($uid)); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $ret = pg_fetch_result($sqlr, 0); - pg_free_result($sqlr); - return $ret; - } - - public static function get_nickname($sqlc, $uid) - { - //return nickname of given uid. False if not found. - - $sqlstr = 'SELECT "nickname" FROM "user" WHERE "uid"=$1 LIMIT 1;'; - $sqlarr = array(intval($uid)); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $ret = pg_fetch_result($sqlr, 0); - pg_free_result($sqlr); - return $ret; - } - - public static function reset_password($sqlc, $uid) - { - //reset password for given uid. False if not found. - - $user = user::get_from_uid($sqlc, $uid); - if(!$user)return false; - $email = $user->email; - if(!$email)return false; - - $passlen = 8; - $newpass = ''; - for($i = 0; $i < $passlen; $i++) - { - $v = rand()%62; - $c = null; - if($v<10)$c = chr(48 + $v); - else if($v<36)$c = chr(65 + $v - 10); - else $c = chr(97 + $v - 36); - $newpass = $newpass.$c; - } - //echo($newpass.'<br>'); - - //email - - $cmail = new PHPMailer(); - $cmail->IsSMTP(); - - $cmail->SMTPAuth = true; - $cmail->SMTPSecure = 'SSL'; - $cmail->Host = 'ssl://'.SMTP_HOST; - $cmail->Port = 465; - $cmail->Username = SMTP_USER; - $cmail->Password = SMTP_PASS; - $cmail->From = 'sprout@csie.ntu.edu.tw'; - $cmail->FromName = 'Taiwan Online Judge'; - - $cmail->AddAddress($email, $user->nickname); - $cmail->WordWrap = 70; - $cmail->Subject = 'TOJ Password Reset Notice'; - $cmail->IsHTML = true; - $cmail->Body = 'Hi '.$user->nickname.' ('.$user->username.') , your new password is '.$newpass.' .'; - if(!$cmail->Send()) - { - //echo($cmail->ErrorInfo.'<br>'); - return false; - } - - - - $user->password = hash('sha512', $newpass); - $nuser = user::update($sqlc, $user); - if(!$nuser)return false; - - return true; - } - - public static function statistic($sqlc, $uid){ - $sqlstr = 'SELECT "proid",MIN("result") AS "result" FROM "submit" WHERE "uid"=$1 GROUP BY "proid" ORDER BY "proid" ASC;'; - $sqlarr = array(intval($uid)); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $trylist = array(); - while($obj = pg_fetch_object($sqlr)){ - $obj->proid = intval($obj->proid); - $obj->result = intval($obj->result); - array_push($trylist, $obj); - } - pg_free_result($sqlr); - - $sqlstr = 'SELECT "result",COUNT("result") AS "count" FROM "submit" WHERE "uid"=$1 GROUP BY "result" ORDER BY "result";'; - $sqlarr = array(intval($uid)); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $substatis = array(); - while($obj = pg_fetch_object($sqlr)){ - $obj->result = intval($obj->result); - $obj->count = intval($obj->count); - array_push($substatis, $obj); - } - pg_free_result($sqlr); - - $sqlstr = 'SELECT "result",COUNT("result") AS "count" FROM "submit" WHERE "uid"=$1 GROUP BY "result" ORDER BY "result";'; - $sqlarr = array(intval($uid)); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $substatis = array(); - while($obj = pg_fetch_object($sqlr)){ - $obj->result = intval($obj->result); - $obj->count = intval($obj->count); - array_push($substatis, $obj); - } - pg_free_result($sqlr); - - $sqlstr = 'SELECT TO_CHAR("submit_time",\'YYYY-MM\') AS "time",COUNT("submit_time") AS "count" FROM "submit" WHERE uid=$1 GROUP BY TO_CHAR("submit_time",\'YYYY-MM\');'; - $sqlarr = array(intval($uid)); - $sqlr = pg_query_params($sqlc, $sqlstr, $sqlarr); - $timesub = array(); - while($obj = pg_fetch_object($sqlr)){ - $obj->count = intval($obj->count); - array_push($timesub, $obj); - } - pg_free_result($sqlr); - - return array( - 'trylist' => $trylist, - 'substatis' => $substatis, - 'timesub' => $timesub - ); - } -} - -function sec_check_level($sqlc, $lv, $uid = null) -{ - $uidnull = false; - if($uid == null) - { - $uid = intval($_COOKIE['uid']); - $uidnull = true; - } - if($uidnull && !sec_is_login()) - return false; - $user = user::get_from_uid($sqlc, $uid); - return (($user->level & $lv) == $lv); -} - -?> diff --git a/toj/php/user.php b/toj/php/user.php deleted file mode 100755 index 23a15e6..0000000 --- a/toj/php/user.php +++ /dev/null @@ -1,165 +0,0 @@ -<?php -//ini_set("display_errors", "On"); -//error_reporting(E_ALL & ~E_NOTICE); - -require_once('user.inc.php'); - -$sqlc = db_connect(); - -$action = $_POST['action']; -$data = $_POST['data']; - -if(strlen($action)==0) - die('Eno_action'); -if($action == 'register') -{ - //Add new user. - //Data: username, password, nickname, email, [aboutme, avatar] - - $user = json_decode($data); - - if(strlen($user->username)<USERNAME_LEN_MIN) - die('Eusername_too_short'); - if(strlen($user->username)>USERNAME_LEN_MAX) - die('Eusername_too_long'); - if(strlen($user->password)<PASSWORD_LEN_MIN) - die('Epassword_too_short'); - if(strlen($user->password)>PASSWORD_LEN_MAX) - die('Epassword_too_long'); - if(strlen($user->nickname)<NICKNAME_LEN_MIN) - die('Enickname_too_short'); - if(strlen($user->nickname)>NICKNAME_LEN_MAX) - die('Enickname_too_long'); - if(strlen($user->email)==0) - die('Eempty_email'); - if(strlen($user->email)>EMAIL_LEN_MAX) - die('Eemail_too_long'); - //if($user->password != $user->passconf) - // die('Epassword_not_match'); - - if(user::get_from_username($sqlc, $user->username) != false) - die('Eusername_exists'); - - $user->password = hash('sha512', $user->password); - - $res = user::add($sqlc, $user); - - if(!$res) - die('Einsert_failed'); - - setcookie('uid', $res->uid, time() + 31536000, '/toj/'); - setcookie('usec', hash('sha512', $res->uid.SEC_SALT), time() + 31536000, '/toj/'); - - echo('S'); -} -if($action == 'update') -{ - //Update exist user - //data: nickname, [aboutme, avatar], [oldpw, password] - - $user = json_decode($data); - - if(!sec_is_login()) - die('Enot_login'); - - $user->uid = $_COOKIE['uid']; - - $olduser = user::get_from_uid($sqlc, $user->uid); - if(!$olduser) - die('Eget_user_failed'); - - if(strlen($user->oldpw)>0) - { - if(strlen($user->password)<PASSWORD_LEN_MIN) - die('Epassword_too_short'); - if(strlen($user->password)>PASSWORD_LEN_MAX) - die('Epassword_too_long'); - //if($user->password != $user->passconf) - // die('Epassword_not_match'); - - $oldhash = hash('sha512', $user->oldpw); - - if($olduser->password != $oldhash) - die('Eold_password_not_match'); - - $user->password = hash('sha512', $user->password); - } - else - { - $user->password = $olduser->password; - } - - if(strlen($user->nickname)<NICKNAME_LEN_MIN) - die('Enickname_too_short'); - if(strlen($user->nickname)>NICKNAME_LEN_MAX) - die('Enickname_too_long'); - if(strlen($user->email)==0) - die('Eempty_email'); - if(strlen($user->email)>EMAIL_LEN_MAX) - die('Eemail_too_long'); - - $res = user::update($sqlc, $user); - if(!$res) - die('Eupdate_failed'); - - echo('S'); -} -if($action == 'view') -{ - //View user data - //data: uid - - $cls = json_decode($data); - - if($cls->uid == null) - { - if(!sec_is_login()) - die('Enot_login_or_please_set_uid'); - $cls->uid = intval($_COOKIE['uid']); - } - $user = user::get_from_uid($sqlc, $cls->uid); - if(!$user) - die('Eget_user_failed'); - - unset($user->password); - if(intval($_COOKIE['uid']) != $user->uid) - unset($user->email); - - $statis = user::statistic($sqlc, $user->uid); - - echo(json_encode(array( - 'user' => $user, - 'statis' => $statis - ))); -} -if($action == 'login') -{ - //Login. - //data: username, password - $login = json_decode($data); - - if(strlen($login->username)==0) - die('Eno_username'); - if(strlen($login->username)>USERNAME_LEN_MAX) - die('Eusername_too_long'); - if(strlen($login->password)==0) - die('Eno_password'); - if(strlen($login->password)>PASSWORD_LEN_MAX) - die('Epassword_too_long'); - - $user = user::get_from_username($sqlc, $login->username); - if(!$user) - die('Euser_not_exist'); - - if(hash('sha512', $login->password) != $user->password) - die('Ewrong_password'); - - setcookie('uid', $user->uid, time() + 31536000, '/toj/'); - setcookie('usec', hash('sha512', $user->uid.SEC_SALT), time() + 31536000, '/toj/'); - - echo('S'); -} - -db_close($sqlc); - -?> diff --git a/toj/pmod/pmod_multisub/pmod_multisub.css b/toj/pmod/pmod_multisub/pmod_multisub.css deleted file mode 100755 index eb73770..0000000 --- a/toj/pmod/pmod_multisub/pmod_multisub.css +++ /dev/null @@ -1,57 +0,0 @@ -div.pmod_multisub > div.main_content{ - margin:32px 0px 32px 246px; -} -div.pmod_multisub > table.probox{ - width:100%; - margin:0px 0px 32px 0px; - border-collapse:collapse; -} -div.pmod_multisub > table.probox td.info{ - width:240px; - padding:0px 0px 0px 6px; - vertical-align:top; -} -div.pmod_multisub > table.probox td.info > table.statlist{ - width:100%; - text-align:left; - border-collapse:collapse; -} -div.pmod_multisub > table.probox td.info > table.statlist td.name{ - width:76px; -} -div.pmod_multisub > table.probox td.info > table.statlist td.value{ - width:auto; - padding:0px 0px 0px 6px; -} -div.pmod_multisub > table.probox td.info > table.limitlist{ - width:100%; - text-align:left; - border-collapse:collapse; -} -div.pmod_multisub > table.probox td.info > table.limitlist td.name{ - width:76px -} -div.pmod_multisub > table.probox td.info > table.limitlist td.value{ - width:auto; - padding:0px 0px 0px 6px; -} -div.pmod_multisub > table.probox td.info > table.scorelist{ - width:100%; - text-align:left; - border-collapse:collapse; -} -div.pmod_multisub > table.probox td.info > table.scorelist th.no,div.pmod_multisub > td.info > table.scorelist td.no{ - width:76px; -} -div.pmod_multisub > table.probox td.info > table.scorelist th.score,div.pmod_multisub > td.info > table.scorelist td.score{ - width:auto; - padding:0px 0px 0px 6px; -} -div.pmod_multisub > table.probox td.content{ - width:978px; - margin:0px 0px 0px 6px; - vertical-align:top; -} -div.pmod_multisub p{ - text-indent:32px; -} diff --git a/toj/pmod/pmod_multisub/pmod_multisub.html b/toj/pmod/pmod_multisub/pmod_multisub.html deleted file mode 100755 index 07b19a9..0000000 --- a/toj/pmod/pmod_multisub/pmod_multisub.html +++ /dev/null @@ -1,40 +0,0 @@ -<div class="main_content"></div> -<table class="probox ori_probox" style="display:none;"><tr> - <td class="info"> - <h2 class="partname"></h2> - <button class="submit">上傳</button> - - <h3>狀態</h3> - <table class="statlist"> - <tr> - <td class="name">最佳分數</td> - <td class="value bscore"></td> - </tr> - <tr> - <td class="name">解題狀態</td> - <td class="value stat"></td> - </tr> - </table> - - <h3>限制</h3> - <table class="limitlist"> - <tr> - <td class="name">時間限制</td> - <td class="value timelimit"></td> - </tr> - <tr> - <td class="name">記憶體限制</td> - <td class="value memlimit"></td> - </tr> - </table> - - <h3>配分</h3> - <table class="scorelist"> - <tr class="head"> - <th class="no">#</th> - <th class="score">Score</th> - </tr> - </table> - </td> - <td class="content"></td> -</tr></table> diff --git a/toj/pmod/pmod_multisub/pmod_multisub.js b/toj/pmod/pmod_multisub/pmod_multisub.js deleted file mode 100755 index 33402d0..0000000 --- a/toj/pmod/pmod_multisub/pmod_multisub.js +++ /dev/null @@ -1,93 +0,0 @@ -var pmod_multisub = function(that,j_pbox){ - var probox_add = function(proo){ - var i; - - var j_probox; - var j_table; - var j_item; - - j_probox = j_pbox.find('table.ori_probox').clone(); - j_probox.removeClass('ori_probox'); - - j_probox.find('td.info > h2.partname').text(proo.partname + ' (' + proo.score + '%)'); - j_probox.find('td.content').html(proo.content); - - $.post('/toj/php/problem.php',{'action':'get_pro_stat','data':JSON.stringify({'proid':proo.proid})},function(res){ - var reto - - if(res[0] != 'E'){ - reto = JSON.parse(res); - j_probox.find('td.info > table.statlist td.bscore').text(reto.score); - if(reto.tried == false){ - j_probox.find('td.info > table.statlist td.bscore').css('color','#1C1C1C'); - j_probox.find('td.info > table.statlist td.stat').text('未嘗試'); - }else{ - if(reto.score < 60){ - j_probox.find('td.info > table.statlist td.bscore').css('color','#FF0000'); - }else if(reto.score < 80){ - j_probox.find('td.info > table.statlist td.bscore').css('color','#00FF00'); - }else if(reto.score < 100){ - j_probox.find('td.info > table.statlist td.bscore').css('color','#FFFF00'); - }else{ - - j_probox.find('td.info > table.statlist td.bscore').css('color','#FFFFFF'); - } - - if(reto.is_ac == true){ - j_probox.find('td.info > table.statlist td.stat').text('已通過'); - }else{ - j_probox.find('td.info > table.statlist td.stat').text('已嘗試'); - } - } - } - }); - - j_probox.find('td.info > table.limitlist td.timelimit').text(proo.timelimit + ' ms'); - j_probox.find('td.info > table.limitlist td.memlimit').text(proo.memlimit + ' KB'); - - j_table = j_probox.find('table.scorelist'); - j_table.find('tr.item').remove(); - for(i = 0;i < proo.partition.count;i++){ - j_item = $('<tr class="item"><td class="no"></td><td class="score"></td></tr>'); - j_item.find('td.no').text(i + 1); - j_item.find('td.score').text(proo.partition.score[i]); - j_table.append(j_item); - } - - j_probox.find('td.info > button.submit').on('click',function(e){ - that.submit(proo.proid); - }); - - j_probox.show(); - j_pbox.append(j_probox); - } - - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - that.fadein(j_pbox); - - $.post('/toj/pmod/pmod_multisub/pmod_multisub.php',{'proid':JSON.stringify(that.proid)},function(res){ - var i; - var reto; - - reto = JSON.parse(res); - if(reto.redirect != undefined){ - com.url_push('/toj/pro/' + reto.redirect + '/'); - }else{ - j_pbox.find('div.main_content').html(reto.main_content); - index.content_set($('<span>' + reto.proname + '</span>')); - - for(i = 0;i < reto.pro.length;i++){ - probox_add(reto.pro[i]); - } - - MathJax.Hub.Queue(["Typeset",MathJax.Hub,j_pbox[0]]); - } - }); - }else if(direct == 'out'){ - that.fadeout(j_pbox); - } - }; - - -}; diff --git a/toj/pmod/pmod_multisub/pmod_multisub.php b/toj/pmod/pmod_multisub/pmod_multisub.php deleted file mode 100755 index 342ff41..0000000 --- a/toj/pmod/pmod_multisub/pmod_multisub.php +++ /dev/null @@ -1,77 +0,0 @@ -<?php -require_once('../../php/problem.inc.php'); - -const PMODNAME = 'pmod_multisub'; - -function get_set($prodir) -{ - $fd = fopen($prodir.'setting','r'); - while($line = fgets($fd)) - { - if($line[0] == '=')break; - } - $set = ''; - while(($line = fgets($fd))) - { - $set = $set.$line; - } - fclose($fd); - return json_decode($set); -} - -$sqlc = db_connect(); - -$proid = json_decode($_POST['proid']); -if(gettype($proid) != 'integer' || $proid < 1){ - exit('Eproid'); -} - -if(!problem::is_available($sqlc, $proid)){ - exit('Epermission'); -} - -$pro = problem::get($sqlc, $proid); -if($pro->pmodname != PMODNAME) - exit('Ewrong_pmod'); - -$prodir = '/srv/http/toj/center/pro/'; - -$redir = file_get_contents($prodir.$proid.'/redirect'); -if($redir) -{ - $ret = new stdClass(); - $ret->redirect = intval($redir); - exit(json_encode($ret)); -} - -$ret = new stdClass(); - -$mfile = file_get_contents($prodir.$proid.'/multiset'); -$multiset = json_decode($mfile); - -$main_cont = file_get_contents($prodir.$proid.'/public/main_content'); -$ret->main_content = $main_cont; -$ret->pro = array(); -$ret->proname = $multiset->proname; - -foreach($multiset->prolist as $spro) -{ - $apro = new stdClass(); - $apro->proid = $spro->proid; - $apro->score = $spro->score; - $apro->partname = $spro->partname; - - $apro->content = file_get_contents($prodir.$apro->proid.'/public/content'); - $setting = get_set($prodir.$apro->proid.'/'); - $apro->timelimit = $setting->timelimit; - $apro->memlimit = $setting->memlimit; - $apro->partition = new stdClass(); - $apro->partition->count = $setting->count; - $apro->partition->score = $setting->score; - - array_push($ret->pro, $apro); -} - -echo(json_encode($ret)); -db_close($sqlc); -?> diff --git a/toj/pmod/pmod_test/pmod_test.css b/toj/pmod/pmod_test/pmod_test.css deleted file mode 100755 index c238c44..0000000 --- a/toj/pmod/pmod_test/pmod_test.css +++ /dev/null @@ -1,126 +0,0 @@ -div.pmod_test > div.pro_pbox > div.info{ - width:240px; - float:left; -} -div.pmod_test > div.pro_pbox > div.info > table.statlist{ - width:100%; - text-align:left; - border-collapse:collapse; -} -div.pmod_test > div.pro_pbox > div.info > table.statlist td.name{ - width:76px; -} -div.pmod_test > div.pro_pbox > div.info > table.statlist td.value{ - width:auto; - padding:0px 0px 0px 6px; -} -div.pmod_test > div.pro_pbox > div.info > table.limitlist{ - width:100%; - text-align:left; - border-collapse:collapse; -} -div.pmod_test > div.pro_pbox > div.info > table.limitlist td.name{ - width:76px; -} -div.pmod_test > div.pro_pbox > div.info > table.limitlist td.value{ - width:auto; - padding:0px 0px 0px 6px; -} -div.pmod_test > div.pro_pbox > div.info > table.scorelist{ - width:100%; - text-align:left; - border-collapse:collapse; -} -div.pmod_test > div.pro_pbox > div.info > table.scorelist th.no,div.pmod_test > div.pro_pbox > div.info > table.scorelist td.no{ - width:76px; -} -div.pmod_test > div.pro_pbox > div.info > table.scorelist th.score,div.pmod_test > div.pro_pbox > div.info > table.scorelist td.score{ - width:auto; - padding:0px 0px 0px 6px; -} -div.pmod_test > div.pro_pbox > div.content{ - width:978px; - margin:0px 0px 0px 6px; - float:left; -} -div.pmod_test > div.pro_pbox p{ - text-indent:32px; -} - - - -div.pmod_test > div.edit_pbox > div.edit_box{ - width:976px; - margin:0px 0px 0px 246px; - padding:0px 0px 32px 0px; -} -div.pmod_test > div.edit_pbox > div.edit_box input{ - width:228px; - margin:0px 0px 16px 0px; -} -div.pmod_test > div.edit_pbox > div.edit_box > div.contentbox{ - width:100%; - height:512px; - padding:0px 0px 32px 0px; -} -div.pmod_test > div.edit_pbox > div.testdata_box{ - width:976px; - margin:0px 0px 0px 246px; - padding:0px 0px 32px 0px; -} -div.pmod_test > div.edit_pbox > div.testdata_box > table.table{ - margin:32px 0px 32px 0px; - border-collapse:collapse; - text-align:left; -} -div.pmod_test > div.edit_pbox > div.testdata_box > table.table tr.head{ - height:64px -} -div.pmod_test > div.edit_pbox > div.testdata_box > table.table tr.item{ - height:64px -} -div.pmod_test > div.edit_pbox > div.testdata_box > table.table th,div.pmod_test > div.edit_pbox > div.testdata_box > table.table td{ - width:76px; - padding:0px 0px 0px 6px; -} -div.pmod_test > div.edit_pbox > div.testdata_box > table.table th.no,div.pmod_test > div.edit_pbox > div.testdata_box > table.table td.no{ - padding:0px 0px 0px 0px; -} - -div.pmod_test > div.edit_pbox > div.testdata_box > table.table td.score > input{ - width:35px; -} -div.pmod_test > div.edit_pbox > div.testdata_box > table.table th.file,div.pmod_test > div.edit_pbox > div.testdata_box > table.table td.file{ - width:322px; -} - -div.pmod_test > div.edit_pbox div.prog_box{ - width:486px; - height:16px; - margin:0px 0px 16px 0px; - background-color:rgba(255,255,255,0.2); - color:#1C1C1C; - font-size:12px; - font-family:monospace; - line-height:16px; - text-align:right; - position:relative; -} -div.pmod_test > div.edit_pbox div.prog_box > div.total{ - width:0%; - height:16px; - position:absolute; - top:0px; - left:0%; - overflow:hidden; -} -div.pmod_test > div.edit_pbox div.prog_box > div.prog{ - width:0%; - height:16px; - background-color:#3A8FB7; - font-weight:bold; - position:absolute; - top:0px; - left:0px; - overflow:hidden; -} diff --git a/toj/pmod/pmod_test/pmod_test.html b/toj/pmod/pmod_test/pmod_test.html deleted file mode 100755 index a04c2a6..0000000 --- a/toj/pmod/pmod_test/pmod_test.html +++ /dev/null @@ -1,76 +0,0 @@ -<div class="com_pbox pro_pbox"> - <div class="info"> - <h2 class="proid">ProID:</h2> - <button class="submit">上傳</button> - - <h3>狀態</h3> - <table class="statlist"> - <tr> - <td class="name">最佳分數</td> - <td class="value bscore"></td> - </tr> - <tr> - <td class="name">解題狀態</td> - <td class="value stat"></td> - </tr> - </table> - - <h3>限制</h3> - <table class="limitlist"> - <tr> - <td class="name">執行時間</td> - <td class="value timelimit"></td> - </tr> - <tr> - <td class="name">記憶體</td> - <td class="value memlimit"></td> - </tr> - </table> - - <h3>配分</h3> - <table class="scorelist"> - <tr class="head"> - <th class="no">#</th> - <th class="score">Score</th> - </tr> - </table> - </div> - <div class="content"></div> - <div style="width:100%; height:32px; clear:both;"></div> -</div> -<div class="com_pbox edit_pbox"> - <div class="edit_box"> - <h2>限制</h2> - <label>執行時間限制(ms)</label> - <input name="timelimit" type="textbox" placeholder="1000"> - <label>記憶體限制(KB)</label> - <input name="memlimit" type="textbox" placeholder="65536"> - - <h2>內容</h2> - <div class="contentbox"></div> - <button class="submit">更新資料</button> - <button class="cancel">取消</button> - </div> - <div class="testdata_box"> - <h2>測試資料</h2> - <label>數量</label> - <input name="count" type="textbox" placeholder="10"> - <table class="table"> - <thead> - <tr class="head"> - <th class="no">#</th> - <th class="score">配分</th> - <th class="file in">輸入檔</th> - <th class="file ans">輸出檔</th> - </tr> - </thead> - <tbody></tbody> - </table> - <div class="prog_box testdata_prog" style="display:none;"> - <div class="total"></div> - <div class="prog"></div> - </div> - <button class="submit">更新測試資料</button> - <button class="cancel">取消</button> - </div> -</div> diff --git a/toj/pmod/pmod_test/pmod_test.inc.php b/toj/pmod/pmod_test/pmod_test.inc.php deleted file mode 100644 index a433404..0000000 --- a/toj/pmod/pmod_test/pmod_test.inc.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php -require_once('problem.inc.php'); -require_once('user.inc.php'); - -function event_create($proid) -{ - $sqlc = db_connect(); - - $proid = intval($proid); - $prodir = '/srv/http/toj/center/pro/'.$proid.'/'; - - mkdir($prodir); - mkdir($prodir.'public/'); - mkdir($prodir.'private/'); - - $set = new stdClass(); - $set->timelimit = 0; - $set->memlimit = 0; - $set->count = 0; - $set->score = array(); - $newstr = "jmod_test\njmod_test_check\n=====\n\n".json_encode($set); - - file_put_contents($prodir.'public/content', ''); - file_put_contents($prodir.'setting', $newstr); - - db_close($sqlc); -} - -?> diff --git a/toj/pmod/pmod_test/pmod_test.js b/toj/pmod/pmod_test/pmod_test.js deleted file mode 100755 index f21c5b0..0000000 --- a/toj/pmod/pmod_test/pmod_test.js +++ /dev/null @@ -1,275 +0,0 @@ -var pmod_test = function(that,j_page){ - var j_pro_pbox = j_page.find('div.pro_pbox'); - var j_edit_pbox = j_page.find('div.edit_pbox'); - var edit_pbox = new vus.node('edit'); - - var contentbox = CodeMirror(j_edit_pbox.find('div.contentbox')[0],{ - mode:'text/html', - theme:'lesser-dark', - lineNumbers:true, - matchBrackets:true, - indentUnit:4 - }); - - var testdata_update = function(count,scorelist){ - var i; - var count; - var trs; - var j_table; - var _testdata_listnew = function(idx,score){ - var j_item = $('<tr class="item"><td class="no"></td><td class="score"><input name="score" type="textbox"></td><td class="file ans"><input name="infile" type="file"></td><td class="file ans"><input name="ansfile" type="file"></td></tr>'); - - j_item.find('td.no').text(idx + 1); - j_item.find('[name="score"]').val(score); - - return j_item; - }; - - trs = j_edit_pbox.find('div.testdata_box > table.table tr.item'); - j_table = j_edit_pbox.find('div.testdata_box > table.table'); - for(i = count;i < trs.length;i++){ - $(trs[i]).remove(); - } - if(scorelist != null){ - for(i = trs.length;i < count;i++){ - j_table.append(_testdata_listnew(i,scorelist[i])); - } - }else{ - for(i = trs.length;i < count;i++){ - j_table.append(_testdata_listnew(i,'0')); - } - } - }; - - that.node.url_chg = function(direct,url_upart,url_dpart,param){ - var _out = function(){ - index.tab_ll('pro'); - that.fadeout(j_pro_pbox); - index.content_empty(); - }; - - if(direct == 'in' || direct == 'same'){ - if(direct == 'in' && user.level == -1){ - index.tab_add('pro','/toj/pro/' + that.proid + '/','題目'); - index.tab_add('edit','/toj/pro/' + that.proid + '/edit/','設定'); - } - - if(url_dpart.length > 0){ - _out(); - return 'cont'; - } - - index.tab_hl('pro'); - that.fadein(j_pro_pbox); - - j_pro_pbox.find('div.info > h2.proid').text('ProID:' + that.proid); - $.post('/toj/pmod/pmod_test/pmod_test.php',{'action':'get_pro_data','data':JSON.stringify({'proid':that.proid})},function(res){ - var i; - var reto; - var seto; - var j_table; - var j_item; - - if(res[0] != 'E'){ - reto = JSON.parse(res); - seto = reto.set; - index.content_set($('<span>' + that.proname + '</span>')); - - if(seto == null){ - j_pro_pbox.find('div.content').html('<h2>題目未設定</h2>'); - return; - } - - j_pro_pbox.find('div.content').html(reto.content); - - $.post('/toj/php/problem.php',{'action':'get_pro_stat','data':JSON.stringify({'proid':that.proid})},function(res){ - var reto - - if(res[0] != 'E'){ - reto = JSON.parse(res); - j_pro_pbox.find('div.info > table.statlist td.bscore').text(reto.score); - if(reto.tried == false){ - j_pro_pbox.find('div.info > table.statlist td.bscore').css('color','#1C1C1C'); - j_pro_pbox.find('div.info > table.statlist td.stat').text('未嘗試'); - }else{ - if(reto.score < 60){ - j_pro_pbox.find('div.info > table.statlist td.bscore').css('color','#FF0000'); - }else if(reto.score < 80){ - j_pro_pbox.find('div.info > table.statlist td.bscore').css('color','#00FF00'); - }else if(reto.score < 100){ - j_pro_pbox.find('div.info > table.statlist td.bscore').css('color','#FFFF00'); - }else{ - - j_pro_pbox.find('div.info > table.statlist td.bscore').css('color','#FFFFFF'); - } - - if(reto.is_ac == true){ - j_pro_pbox.find('div.info > table.statlist td.stat').text('已通過'); - }else{ - j_pro_pbox.find('div.info > table.statlist td.stat').text('已嘗試'); - } - } - } - }); - - j_pro_pbox.find('div.info > table.limitlist td.timelimit').text(seto.timelimit + ' ms'); - j_pro_pbox.find('div.info > table.limitlist td.memlimit').text(seto.memlimit + ' KB'); - - j_table = j_pro_pbox.find('table.scorelist'); - j_table.find('tr.item').remove(); - for(i = 0;i < seto.count;i++){ - j_item = $('<tr class="item"><td class="no"></td><td class="score"></td></tr>'); - j_item.find('td.no').text(i + 1); - j_item.find('td.score').text(seto.score[i]); - j_table.append(j_item); - } - - MathJax.Hub.Queue(["Typeset",MathJax.Hub,j_pro_pbox[0]]); - } - }); - }else if(direct == 'out'){ - _out(); - } - - return 'cont'; - }; - - j_pro_pbox.find('div.info > button.submit').on('click',function(e){ - that.submit(); - }); - j_edit_pbox.find('div.edit_box > button.submit').on('click',function(e){ - timelimit = parseInt(j_edit_pbox.find('div.edit_box > [name="timelimit"]').val()); - memlimit = parseInt(j_edit_pbox.find('div.edit_box > [name="memlimit"]').val()); - content = contentbox.getValue(); - - $.post('/toj/pmod/pmod_test/pmod_test.php',{'action':'set_pro_data','data':JSON.stringify({'proid':that.proid,'timelimit':timelimit,'memlimit':memlimit,'content':content})},function(res){ - com.url_push_back(); - }); - }); - j_edit_pbox.find('div.edit_box > button.cancel').on('click',function(e){ - com.url_push_back(); - }); - - j_edit_pbox.find('div.testdata_box > [name="count"]').on('change',function(e){ - testdata_update(parseInt($(this).val()),null); - }); - j_edit_pbox.find('div.testdata_box > button.submit').on('click',function(e){ - var i; - - var count; - var score; - var inputs - - var formdata; - var inputs; - var file; - - var j_progbox; - var j_total; - var j_prog; - - count = parseInt(j_edit_pbox.find('div.testdata_box > [name="count"]').val()); - - inputs = j_edit_pbox.find('div.testdata_box > table.table [name="score"]'); - score = Array(); - for(i = 0;i < count;i++){ - score[i] = parseInt($(inputs[i]).val()); - } - - formdata = new FormData(); - formdata.append('action','update_pro_testdata'); - formdata.append('data',JSON.stringify({'proid':that.proid,'count':count,'score':score})); - - inputs = j_edit_pbox.find('div.testdata_box > table.table [name="infile"]'); - for(i = 0;i < inputs.length;i++){ - if((file = inputs[i].files[0]) != undefined){ - formdata.append('infile_' + i,file); - } - } - inputs = j_edit_pbox.find('div.testdata_box > table.table [name="ansfile"]'); - for(i = 0;i < inputs.length;i++){ - if((file = inputs[i].files[0]) != undefined){ - formdata.append('ansfile_' + i,file); - } - } - - j_progbox = j_edit_pbox.find('div.testdata_box > div.testdata_prog'); - j_total = j_progbox.find('div.total'); - j_prog = j_progbox.find('div.prog'); - - j_total.css('width','100%'); - j_total.text('上傳中...'); - j_prog.css('width','0%'); - j_prog.text('0%'); - - j_progbox.show(); - - $.ajax({ - url:'/toj/pmod/pmod_test/pmod_test.php', - type:'POST', - xhr:function(){ - req = $.ajaxSettings.xhr(); - - req.upload.addEventListener('progress',function(e){ - console.log(); - j_prog.css('width',(e.loaded * 100 / e.total) + '%'); - j_prog.text(Math.round(e.loaded * 100 / e.total) + ' %'); - },false); - - return req; - }, - data:formdata, - contentType:false, - processData:false, - success:function(){ - com.url_push_back(); - } - }); - }); - j_edit_pbox.find('div.testdata_box > button.cancel').on('click',function(e){ - com.url_push_back(); - }); - - if(user.level == -1){ - edit_pbox.url_chg = function(direct,url_upart,url_dpart,param){ - if(direct == 'in'){ - index.tab_hl('edit'); - that.fadein(j_edit_pbox); - - contentbox.refresh(); - - $.post('/toj/pmod/pmod_test/pmod_test.php',{'action':'get_pro_data','data':JSON.stringify({'proid':that.proid})},function(res){ - var reto; - - if(res[0] != 'E'){ - reto = JSON.parse(res); - set = reto.set; - - j_edit_pbox.find('div.edit_box > [name="timelimit"]').val(set.timelimit); - j_edit_pbox.find('div.edit_box > [name="memlimit"]').val(set.memlimit); - - if(reto.content != false){ - contentbox.setValue(reto.content); - } - - j_edit_pbox.find('div.testdata_box > [name="count"]').val(set.count); - testdata_update(set.count,set.score); - } - }); - }else if(direct == 'out'){ - index.tab_ll('edit'); - that.fadeout(j_edit_pbox); - - j_edit_pbox.find('div.testdata_box > div.testdata_prog').hide(); - } - - return 'cont'; - }; - that.node.child_set(edit_pbox); - - contentbox.getWrapperElement().style.width = '100%'; - contentbox.getWrapperElement().style.height = '100%'; - contentbox.getScrollerElement().style.width = '100%'; - contentbox.getScrollerElement().style.height = '100%'; - } -}; diff --git a/toj/pmod/pmod_test/pmod_test.php b/toj/pmod/pmod_test/pmod_test.php deleted file mode 100755 index a472630..0000000 --- a/toj/pmod/pmod_test/pmod_test.php +++ /dev/null @@ -1,116 +0,0 @@ -<?php -require_once('problem.inc.php'); -require_once('user.inc.php'); - -const PMODNAME = 'pmod_test'; - -function get_setting($prodir) -{ - $fd = fopen($prodir.'setting','r'); - $prestr = array(); - while($line = fgets($fd)){ - if($line[0] == '='){ - break; - } - array_push($prestr, $line); - } - $set = ''; - while(($line = fgets($fd))){ - $set = $set.$line; - } - fclose($fd); - - return array($prestr, json_decode($set)); -} - -$action = $_POST['action']; -$data = json_decode($_POST['data']); - -$proid = intval($data->proid); -if(gettype($proid) != 'integer' || $proid < 1){ - exit('Eproid'); -} - -$sqlc = db_connect(); -if(!problem::is_available($sqlc,$proid)){ - exit('Epermission'); -} - -$pro = problem::get($sqlc, $proid); -if($pro->pmodname != PMODNAME) - exit('Ewrong_pmod'); - -$prodir = '/srv/http/toj/center/pro/'.$proid.'/'; - -if($action=='get_pro_data') -{ - $content = file_get_contents($prodir.'public/content'); - - echo(json_encode(array( - 'set' => get_setting($prodir)[1], - 'content' => $content - ))); -} -if($action=='set_pro_data') -{ - if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN)) - die('Epermission_denied'); - - $obj = get_setting($prodir); - $prestr = $obj[0]; - $set = $obj[1]; - $set->timelimit = $data->timelimit; - $set->memlimit = $data->memlimit; - file_put_contents($prodir.'public/content', $data->content); - - $newstr = ''; - foreach($prestr as $s) - { - $newstr = $newstr.$s; - } - $newstr = $newstr."=====\n\n"; - $newstr = $newstr.json_encode($set); - file_put_contents($prodir.'setting', $newstr); -} -if($action=='update_pro_testdata') -{ - if(!sec_check_level($sqlc, USER_LEVEL_SUPERADMIN)) - die('Epermission_denied'); - - $count = $data->count; - $score = $data->score; - - $obj = get_setting($prodir); - $prestr = $obj[0]; - $set = $obj[1]; - $set->count = $count; - $set->score = $score; - - $newstr = ''; - foreach($prestr as $s) - { - $newstr = $newstr.$s; - } - $newstr = $newstr."=====\n\n"; - $newstr = $newstr.json_encode($set); - file_put_contents($prodir.'setting', $newstr); - - $tddir = $prodir.'/private/'; - for($idx = 0;$idx < $count;$idx++){ - $dst = $tddir.strval($idx + 1); - mkdir($dst); - - $key = 'infile_'.strval($idx); - if(array_key_exists($key,$_FILES)){ - move_uploaded_file($_FILES[$key]["tmp_name"],$dst.'/in'); - } - - $key = 'ansfile_'.strval($idx); - if(array_key_exists($key,$_FILES)){ - move_uploaded_file($_FILES[$key]["tmp_name"],$dst.'/ans'); - } - } -} - -db_close($sqlc); -?> diff --git a/toj/smod/smod_test/smod_test.css b/toj/smod/smod_test/smod_test.css deleted file mode 100755 index 117c427..0000000 --- a/toj/smod/smod_test/smod_test.css +++ /dev/null @@ -1,55 +0,0 @@ -div.smod_test > h1.msg{ - margin:0px 0px 6px 82px; -} - -div.smod_test > table.subinfo{ - width:322px; - margin:0px 0px 6px 82px; - border-collapse:collapse; - text-align:left; - float:left; -} -div.smod_test > table.subinfo tr.item{ - height:32px; -} -div.smod_test > table.subinfo td.title{ - width:76px; -} -div.smod_test > table.subinfo td.value{ - width:240px; - padding:0px 0px 0px 6px; -} - -div.smod_test > table.subinfolist{ - width:486px; - padding:0px 0px 0px 6px; - text-align:left; - float:left; -} -div.smod_test > table.subinfolist tr.head{ - height:32px; -} -div.smod_test > table.subinfolist tr.item{ - height:32px; -} -div.smod_test > table.subinfolist th,div.smod_test > table.subinfolist td{ - padding:0px 0px 0px 6px; -} -div.smod_test > table.subinfolist th.runtime,div.smod_test > table.subinfolist td.runtime{ - width:76px; - padding:0px 0px 0px 0px; -} -div.smod_test > table.subinfolist th.memory,div.smod_test > table.subinfolist td.memory{ - width:76px; -} -div.smod_test > table.subinfolist th.status,div.smod_test > table.subinfolist td.status{ - width:76px; -} -div.smod_test > table.subinfolist th.score,div.smod_test > table.subinfolist td.score{ - width:76px; -} -div.smod_test > table.subinfolist td.errmsg{ - width:158px; - font-size:12px; - word-break:break-all; -} diff --git a/toj/smod/smod_test/smod_test.html b/toj/smod/smod_test/smod_test.html deleted file mode 100755 index 5d1547d..0000000 --- a/toj/smod/smod_test/smod_test.html +++ /dev/null @@ -1,46 +0,0 @@ -<h1 class="msg" style="display:none;">Waiting</h1> - -<table class="subinfo" style="display:none;"> - <tr class="item"> - <td class="title">ProID</td> - <td class="value proid"><a></a></td> - </tr> - <tr class="item"> - <td class="title">暱稱</td> - <td class="value nickname"><a></a></td> - </tr> - <tr class="item"> - <td class="title">執行時間</td> - <td class="value runtime"></td> - </tr> - <tr class="item"> - <td class="title">記憶體</td> - <td class="value memory"></td> - </tr> - <tr class="item"> - <td class="title">結果</td> - <td class="value result"></td> - </tr> - <tr class="item"> - <td class="title">分數</td> - <td class="value score"></td> - </tr> - <tr class="item"> - <td class="title">時間</td> - <td class="value time"></td> - </tr> - <tr class="item"> - <td class="title">語言</td> - <td class="value lang"></td> - </tr> -</table> -<table class="subinfolist" style="display:none;"> - <tr class="head"> - <th class="runtime">執行時間</th> - <th class="memory">記憶體</th> - <th class="status">狀態</th> - <th class="score">分數</th> - <th class="errmsg"></th> - </tr> -</table> -<div style="width:100%; height:32px; clear:both;"></div> diff --git a/toj/smod/smod_test/smod_test.js b/toj/smod/smod_test/smod_test.js deleted file mode 100755 index 90780d6..0000000 --- a/toj/smod/smod_test/smod_test.js +++ /dev/null @@ -1,65 +0,0 @@ -var smod_test = function(that,j_mbox){ - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - that.fadein(j_mbox); - $.post('/toj/smod/smod_test/smod_test.php',{'subid':JSON.stringify(that.subid)},function(res){ - var i; - var reto; - var result; - var pro_set; - var reso; - var j_table; - var j_item; - var j_a; - - if(res[0] == 'E'){ - if(res == 'Enull'){ - j_mbox.find('h1.msg').show(); - } - }else{ - reto = JSON.parse(res); - result = reto.result; - pro_set = reto.pro_setting; - - j_table = j_mbox.find('table.subinfo'); - j_a = j_table.find('td.proid > a'); - j_a.attr('href','/toj/pro/' + that.subo.proid + '/'); - j_a.text(that.subo.proid); - - j_a = j_table.find('td.nickname > a'); - j_a.attr('href','/toj/user/' + that.subo.uid+ '/'); - j_a.text(that.subo.nickname); - - j_table.find('td.runtime').text(that.subo.runtime); - j_table.find('td.memory').text(that.subo.memory); - j_table.find('td.result').text(RESULTMAP[that.subo.result]); - j_table.find('td.score').text(that.subo.score); - j_table.find('td.time').text(com.get_datestring(that.subo.submit_time,true)); - j_table.find('td.lang').text(com.get_lang(that.subo.lang)[0]); - - j_table.show(); - - j_table = j_mbox.find('table.subinfolist'); - for(i = 0;i < result.length;i++){ - reso = result[i]; - j_item = $('<tr class="item"><td class="runtime"></td><td class="memory"></td><td class="status"></td><td class="score"></td><td class="errmsg"></td></tr>') - j_item.find('td.runtime').text(reso.runtime); - j_item.find('td.memory').text(reso.memory); - j_item.find('td.status').text(RESULTMAP[reso.status]); - j_item.find('td.score').text(reso.score + ' / ' + pro_set.score[i]); - if(reso.errmsg != undefined){ - j_item.find('td.errmsg').text(reso.errmsg); - } - - j_table.append(j_item); - } - j_table.show(); - } - }); - }else if(direct == 'out'){ - that.fadeout(j_mbox); - } - - return 'cont'; - }; -}; diff --git a/toj/smod/smod_test/smod_test.php b/toj/smod/smod_test/smod_test.php deleted file mode 100755 index b458ead..0000000 --- a/toj/smod/smod_test/smod_test.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php -require_once('../../php/status.inc.php'); -require_once('../../php/problem.inc.php'); - -$subid = json_decode($_POST['subid']); -if(gettype($subid) != 'integer' || $subid < 1){ - exit('Esubid'); -} - -$sqlc = db_connect(); -if(!status::subid_is_available($sqlc,$subid)){ - exit('Epermission'); -} - -$sub = status::get_by_subid($sqlc, $subid); -$proid = $sub->proid; -if(!$proid) - exit('Eno_such_subid'); - -$prodir = '/srv/http/toj/center/pro/'.$proid.'/setting'; -db_close($sqlc); - -$fd = fopen($prodir, 'r'); -while($line = fgets($fd)){ - if($line[0] == '='){ - break; - } -} -$set = ''; -while(($line = fgets($fd))){ - $set = $set.$line; -} -fclose($fd); - -if(!$set) - exit('Eerr_pro_data'); - -$proset = json_decode($set); - -$subdir = '/srv/http/toj/center/submit/'.($subid - ($subid % 1000)).'/'.$subid.'/result/'; -if(($result = file_get_contents($subdir.'result')) == ''){ - exit('Enull'); -} - -$q = json_decode($result); -$q->pro_setting = $proset; -echo(json_encode($q)); - -//echo('{"result":'.$result.', "pro_setting"='.$set.'}'); -?> diff --git a/toj/sqmod/sqmod_contest/sqmod_contest.css b/toj/sqmod/sqmod_contest/sqmod_contest.css deleted file mode 100755 index 4932aae..0000000 --- a/toj/sqmod/sqmod_contest/sqmod_contest.css +++ /dev/null @@ -1,116 +0,0 @@ -div.sqmod_contest > div.sboard_pbox > table.sboardlist{ - margin:32px 0px 6px 0px; - border-collapse:collapse; - text-align:left; -} -div.sqmod_contest > div.sboard_pbox > table.sboardlist tr.head{ - height:32px; -} -div.sqmod_contest > div.sboard_pbox > table.sboardlist tr.item{ - height:32px; - border-top:#BDC0BA 1px solid; -} -div.sqmod_contest > div.sboard_pbox > table.sboardlist th,div.sqmod_contest > div.sboard_pbox > table.sboardlist td{ - width:76px; - padding:0px 0px 0px 6px; - border-left:#BDC0BA 1px solid; -} -div.sqmod_contest > div.sboard_pbox > table.sboardlist th.rank,div.sqmod_contest > div.sboard_pbox > table.sboardlist td.rank{ - border-width:0px; -} -div.sqmod_contest > div.sboard_pbox > table.sboardlist th.nickname,div.sqmod_contest > div.sboard_pbox > table.sboardlist td.nickname{ - width:240px; -} -div.sqmod_contest > div.sboard_pbox > table.sboardlist th.pro,div.sqmod_contest > div.sboard_pbox > table.sboardlist td.pro{ - width:117px; - position:relative; -} -div.sqmod_contest > div.sboard_pbox > table.sboardlist td.pro > sup.try{ - color:#BDC0BA; -} -div.sqmod_contest > div.sboard_pbox > table.sboardlist td.pro > sub.time{ - color:#BDC0BA; -} - -div.sqmod_contest > div.pro_pbox > table.prolist{ - width:1060px; - margin:0px 0px 6px 164px; - border-collapse:collapse; - text-align:left; -} -div.sqmod_contest > div.pro_pbox > table.prolist tr.head{ - height:64px; -} -div.sqmod_contest > div.pro_pbox > table.prolist tr.item{ - height:32px; - border-left:2px solid; - border-color:#1C1C1C; -} -div.sqmod_contest > div.pro_pbox > table.prolist tr:hover.item{ - background-color:rgba(255,255,255,0.2); -} -div.sqmod_contest > div.pro_pbox > table.prolist th,div.sqmod_contest > div.pro_pbox > table.prolist td{ - width:76px; - padding:0px 0px 0px 6px; -} -div.sqmod_contest > div.pro_pbox > table.prolist th.name,div.sqmod_contest > div.pro_pbox > table.prolist td.name{ - width:auto; - padding:0px 0px 0px 0px; -} - -div.sqmod_contest > div.pro_pbox > table.stat{ - margin:32px 0px 6px 164px; - border-collapse:collapse; - text-align:left; -} -div.sqmod_contest > div.pro_pbox > table.stat tr{ - height:32px; -} -div.sqmod_contest > div.pro_pbox div.prog_box{ - width:486px; - height:16px; - background-color:rgba(255,255,255,0.2); - color:#1C1C1C; - font-size:12px; - font-family:monospace; - line-height:16px; - text-align:right; - position:relative; -} -div.sqmod_contest > div.pro_pbox div.prog_box > div.pass{ - width:0%; - height:16px; - border-right:rgba(0,255,0,0.8) 2px solid; - position:absolute; - top:0px; - left:0%; - overflow:hidden; -} -div.sqmod_contest > div.pro_pbox div.prog_box > div.good{ - width:0%; - height:16px; - border-right:rgba(255,255,0,0.8) 2px solid; - position:absolute; - top:0px; - left:0%; - overflow:hidden; -} -div.sqmod_contest > div.pro_pbox div.prog_box > div.total{ - width:0%; - height:16px; - border-right:rgba(255,255,255,0.8) 2px solid; - position:absolute; - top:0px; - left:0%; - overflow:hidden; -} -div.sqmod_contest > div.pro_pbox div.prog_box > div.prog{ - width:0%; - height:16px; - background-color:rgba(0,0,0,0); - font-weight:bold; - position:absolute; - top:0px; - left:0px; - overflow:hidden; -} diff --git a/toj/sqmod/sqmod_contest/sqmod_contest.html b/toj/sqmod/sqmod_contest/sqmod_contest.html deleted file mode 100755 index 3f7c759..0000000 --- a/toj/sqmod/sqmod_contest/sqmod_contest.html +++ /dev/null @@ -1,39 +0,0 @@ -<div class="com_pbox sboard_pbox"> - <table class="sboardlist"> - <tr class="head"> - <th class="rank">名次</th> - <th class="nickname">昵稱</th> - <th class="ac">AC數</th> - <th class="score">總分</th> - </tr> - </table> -</div> -<div tab="pro" class="com_pbox pro_pbox"> - <table class="prolist"> - <tr class="head"> - <th class="no">#</th> - <th class="name">題目名稱</th> - <th class="bscore">最佳分數</th> - </tr> - </table> - <table class="stat"> - <tr class="user_prog"> - <td style="width:76px;">個人進度</td> - <td style="padding:0px 0px 0px 6px;"><div class="prog_box user_prog"> - <div class="pass"></div> - <div class="good"></div> - <div class="total"></div> - <div class="prog"></div> - </div></td> - </tr> - <tr class="team_prog" style="display:none;"> - <td style="width:76px;">小組進度</td> - <td style="padding:0px 0px 0px 6px;"><div class="prog_box team_prog"> - <div class="pass"></div> - <div class="good"></div> - <div class="total"></div> - <div class="prog"></div> - </div></td> - </tr> - </table> -</div> diff --git a/toj/sqmod/sqmod_contest/sqmod_contest.inc.php b/toj/sqmod/sqmod_contest/sqmod_contest.inc.php deleted file mode 100755 index b045dae..0000000 --- a/toj/sqmod/sqmod_contest/sqmod_contest.inc.php +++ /dev/null @@ -1,289 +0,0 @@ -<?php - -require_once('common.inc.php'); -require_once('square.inc.php'); -require_once('sqlib_scoreboard.inc.php'); - -const SQMODNAME = 'sqmod_contest'; - -const SCOREBOARD_ID_PROBSTAT = 1; -const SCOREBOARD_ID_SCOREBOARD = 2; - -function score_func($sqid, $proid, $best_score, $best_time, $is_ac, $ac_time, $tries_before_ac, $last_score, $last_status, $tries) -{ - $data = get_setting($sqid); - $fscore = 0; - - foreach($data->pro as $pro) - { - if($pro->proid == $proid && $pro->method == 'normal') - { - $fscore = $pro->score; - break; - } - if($pro->method == 'max') - { - foreach($pro->config as $cf) - { - foreach($cf as $sp) - { - if($sp[0] == $proid) - { - $fscore = $sp[1]; - break; - } - } - } - } - } - - $rscore = $best_score * $fscore / 100; - return $rscore; -} - -function get_pro_stat_uid($sqlc, $msqlc, $sqid, $sboard_id, $uid) -{ - //get user $uid solving status of square $sqid. $sboard_id can be set as a fixed value. - $sq = square::get($sqlc, $sqid); - if(!$sq)die('Eno_such_sq'); - - $data = sqlib_scoreboard::get_scoreboard_uid($sqlc, $msqlc, $sqid, $sboard_id, 'score_func', $sq->start_time, $sq->end_time, $uid); - - return $data[0]; -} - -function process_pro_stat($obj) -{ - $ret = array(); - foreach($obj->problem as $pro) - { - $ps = new stdClass(); - $ps->proid = $pro->proid; - $ps->is_ac = $pro->is_ac; - $ps->best_score = $pro->best_score; - //$ps->rank_score = $pro->rank_score; - $ps->tried = ($pro->tries > 0); - //array_push($ret, $ps); - $ret[$pro->proid] = $ps; - } - return $ret; -} - -function add_setting($sqid) -{ - mkdir('/srv/http/toj/center/sq/'.$sqid); -} -function del_setting($sqid) -{ - $sqdir = '/srv/http/toj/center/sq/'.$sqid.'/'; - unlink($sqdir.'setting'); - rmdir($sqdir); -} -function get_setting($sqid) -{ - $sqdir = '/srv/http/toj/center/sq/'.$sqid.'/'; - $cont = file_get_contents($sqdir.'setting'); - $data = json_decode($cont); - return $data; -} -function put_setting($sqid, $data) -{ - $sqdir = '/srv/http/toj/center/sq/'.$sqid.'/'; - file_put_contents($sqdir.'setting', json_encode($data)); -} - -function get_term($data, $sqid) -{ - return $data->term; -} - -function calc_score($stat, $data, $sqid) -{ - $prolist = $data->pro; - $ret = array(); - foreach($prolist as $pro) - { - $proid = $pro->proid; - $np = new stdClass(); - if($stat)$np = clone $stat[$proid]; - //else continue; - if(!$stat) - { - $np->proid = $proid; - $np->best_score = 0; - $np->tried = false; - $np->is_ac = false; - array_push($ret, $np); - continue; - } - $method = $pro->method; - //$np->full_score = $pro->score; - if($method == 'normal') - { - $np->best_score = $stat[$proid]->best_score / 100 * $pro->score; - } - if($method == 'max') - { - $score = 0; - $tis_ac = false; - foreach($pro->config as $conf) - { - //$np->best_score = json_encode($conf); - $nowscore = 0; - $is_ac = true; - foreach($conf as $unit) - { - $nowscore += $stat[$unit[0]]->best_score / 100 * $unit[1]; - $np->tried = $np->tried || $stat[$unit[0]]->tried; - if(!$stat[$unit[0]]->is_ac)$is_ac = false; - } - $score = max($score, $nowscore); - if($is_ac)$tis_ac = true; - } - $np->is_ac = $tis_ac; - $np->best_score = $score;// / 100 * $pro->score; - } - //$np->best_score = json_encode($np); - array_push($ret, $np); - } - //$stat[0]->best_score = json_encode($ret[0]); - return $ret; -} - -function process_pro_list($list, $data, $sqid) -{ - $prol = $data->pro; - $ret = array(); - foreach($prol as $pro) - { - $proid = $pro->proid; - $np = null; - foreach($list as $op) - { - if($op->proid == $proid) - { - $np = clone $op; - break; - } - } - $np->prono = $pro->prono; - $np->full_score = $pro->score; - if($pro->proname)$np->proname = $pro->proname; - array_push($ret, $np); - } - return $ret; -} - -function get_base_line($data, $sqid, $isteam) -{ - $ret = new stdClass(); - if($isteam) - { - $ret->total_score = $data->total_score; - $ret->pass_score = $data->pass_score_team; - $ret->good_score = $data->good_score_team; - } - else - { - $ret->total_score = $data->total_score; - $ret->pass_score = $data->pass_score; - $ret->good_score = $data->good_score; - } - - return $ret; -} - -function get_scoreboard($sqlc, $msqlc, $sqid, $sboard_id){ - $sq = square::get($sqlc, $sqid); - if(!$sq) - die('Eno_such_sq'); - - $data = sqlib_scoreboard::get_scoreboard($sqlc, $msqlc, $sqid, $sboard_id, 'score_func', $sq->start_time, $sq->end_time, 0, 65536); - - return $data; -} - -function calc_default_baseline($total_score) -{ - $ret = new stdClass(); - - $ret->pass_score = round($total_score * 0.6); - $ret->good_score = round($total_score * 0.8); - $ret->pass_score_team = round($total_score * 0.8); - $ret->good_score_team = round($total_score * 1); - - return $ret; -} - -function event_create($sqid) -{ - $set = array( - 'term' => 1, - 'pro' => [], - 'total_score' => 0, - 'pass_score' => 0, - 'good_score' => 0, - 'pass_score_team' => 0, - 'good_score_team' => 0 - ); - - add_setting($sqid); - put_setting($sqid, $set); -} -function event_destroy($sqid) -{ - del_setting($sqid); -} -function event_add_pro($sqid, $proid) -{ - $set = get_setting($sqid); - - $list = $set->pro; - for($idx = 0;$idx < count($list);$idx++){ - if($list[$idx]->proid == $proid) - return; - } - $list[$idx] = array( - "prono" => $idx + 1, - "proid" => $proid, - "score" => 100, - "method" => 'normal' - ); - $set->pro = $list; - $set->total_score += 100; - - $baseline = calc_default_baseline($set->total_score); - $set->pass_score = $baseline->pass_score; - $set->good_score = $baseline->good_score; - $set->pass_score_team = $baseline->pass_score_team; - $set->good_score_team = $baseline->good_score_team; - - put_setting($sqid, $set); -} -function event_del_pro($sqid, $proid) -{ - $set = get_setting($sqid); - - $list = $set->pro; - $idx = 0; - while($idx < count($list)){ - if($list[$idx]->proid == $proid){ - array_splice($list,$idx,1); - $set->total_score -= 100; - }else{ - $list[$idx]->prono = $idx + 1; - $idx++; - } - } - $set->pro = $list; - - $baseline = calc_default_baseline($set->total_score); - $set->pass_score = $baseline->pass_score; - $set->good_score = $baseline->good_score; - $set->pass_score_team = $baseline->pass_score_team; - $set->good_score_team = $baseline->good_score_team; - - put_setting($sqid, $set); -} - -?> diff --git a/toj/sqmod/sqmod_contest/sqmod_contest.js b/toj/sqmod/sqmod_contest/sqmod_contest.js deleted file mode 100755 index bb8d9b8..0000000 --- a/toj/sqmod/sqmod_contest/sqmod_contest.js +++ /dev/null @@ -1,425 +0,0 @@ -var sqmod_contest = function(that,j_page){ - var sboard_pbox = new class_sqmod_contest_sboard_pbox(that.sqid,j_page); - var pro_pbox = new class_sqmod_contest_pro_pbox(that.sqid,j_page); - - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - index.title_set('TOJ-' + that.sqname); - - index.tab_add('sboard','/toj/sq/' + that.sqid + '/sboard/','記分板'); - index.tab_add('pro','/toj/sq/' + that.sqid + '/pro/','題目'); - - if(url_dpart.length == 0){ - com.url_update('/toj/sq/' + that.sqid + '/pro/'); - return 'stop'; - } - }else if(direct == 'out'){ - index.tab_empty(); - } - - return 'cont'; - }; - - that.node.child_set(sboard_pbox.node); - that.node.child_set(pro_pbox.node); -}; - -var class_sqmod_contest_sboard_pbox = function(sqid,j_page){ - var that = this; - var j_pbox = j_page.find('div.sboard_pbox'); - var j_table = j_pbox.find('table.sboardlist'); - var refresh_flag = false; - - var sboard_refresh = function(){ - if(refresh_flag == false){ - return; - } - - $.post('/toj/sqmod/sqmod_contest/sqmod_contest.php',{'action':'get_prolist','data':JSON.stringify({'sqid':sqid})},function(res){ - var i; - var prolist; - var proo; - - var tds; - var j_head; - var j_td; - var j_a; - - if(res[0] != 'E'){ - prolist = JSON.parse(res); - - j_table.css('width',(486 + prolist.length * 123) + 'px'); - - j_head = j_table.find('tr.head'); - tds = j_head.find('td.pro'); - for(i = 0;i < prolist.length;i++){ - proo = prolist[i]; - if(i < tds.length){ - j_td = $(tds[i]); - }else{ - j_td = $('<td class="pro"><a></a></td>'); - j_head.append(j_td); - } - - j_a = j_td.find('a'); - j_a.text(proo.proid); - j_a.attr('href','/toj/pro/' + proo.proid + '/'); - } - for(;i < tds.length;i++){ - $(tds[i]).remove(); - } - - $.post('/toj/sqmod/sqmod_contest/sqmod_contest.php',{'action':'get_scoreboard','data':JSON.stringify({'sqid':sqid})},function(res){ - var i; - var j; - var reto; - var start_time - var sboard_list; - var sboardo; - var proo; - var total_ac; - var total_score; - var duration; - var use_time; - - var trs; - var tds; - var j_item; - var j_a; - var j_score; - - if(res[0] != 'E'){ - reto = JSON.parse(res); - start_time = reto.start_time; - sboard_list = reto.list; - - trs = j_table.find('tr.item'); - for(i = 0;i < sboard_list.length;i++){ - sboardo = sboard_list[i]; - - if(i < trs.length){ - j_item = $(trs[i]); - }else{ - j_item = $('<tr class="item"><td class="rank"></td><td class="nickname"><a></a></td><td class="ac"></td><td class="score"></td></tr>'); - j_table.append(j_item); - } - - j_a = j_item.find('td.nickname > a'); - j_a.text(sboardo.nickname); - j_a.attr('href','/toj/user/' + sboardo.uid + '/'); - - if(sboardo.rank == -1){ - j_item.find('td.rank').text('-'); - }else{ - j_item.find('td.rank').text(sboardo.rank); - } - - tds = j_item.find('td.pro'); - for(j = tds.length;j < prolist.length;j++){ - j_item.append($('<td class="pro"><span class="score"></span><sup class="try"></sup><sub class="time"></sub></td>')); - } - for(;j < tds.length;j++){ - $(tds[j]).remove(); - } - - total_ac = 0; - total_score = 0; - tds = j_item.find('td.pro'); - for(j = 0;j < prolist.length;j++){ - j_td = $(tds[j]); - if(!(prolist[j].proid in sboardo.problem) || sboardo.problem[prolist[j].proid].tries == 0){ - j_td.find('span.score').text('') - j_td.find('sup.try').text(''); - j_td.find('sub.time').text(''); - }else{ - proo = sboardo.problem[prolist[j].proid]; - - j_score = j_td.find('span.score'); - if(proo.is_ac == true){ - j_score.css('color',RESULTCOLOR[0]); - total_ac++; - - if(start_time != null){ - duration = new Date(com.get_date(proo.ac_time) - com.get_date(start_time)).getTime(); - j_td.find('sub.time').text(com.get_durstring(duration,true)); - } - }else{ - j_score.css('color',null); - } - total_score += proo.best_score; - - j_score.text(proo.best_score) - j_td.find('sup.try').text(proo.tries_before_ac); - } - } - j_item.find('td.ac').text(total_ac); - j_item.find('td.score').text(total_score); - } - for(;i < trs.length;i++){ - trs[i].remove(); - } - } - - setTimeout(sboard_refresh,5000); - }); - } - }); - }; - - that.node = new vus.node('sboard'); - - that.__super(); - - that.node.url_chg = function(direct,url_upart,url_dpart){ - var reto; - - if(direct == 'in'){ - index.tab_hl('sboard'); - - refresh_flag = true; - sboard_refresh(); - - that.fadein(j_pbox); - }else if(direct == 'out'){ - index.tab_ll('sboard'); - that.fadeout(j_pbox); - - refresh_flag = false; - - j_table.find('tr.item').remove(); - j_table.find('tr.head > td.pro').remove(); - } - }; -}; __extend(class_sqmod_contest_sboard_pbox,class_com_pbox); - -var class_sqmod_contest_pro_pbox = function(sqid,j_page){ - var that = this; - var j_pbox = j_page.find('div.pro_pbox'); - var promap = null; - - var pro_listset = function(j_item,proo){ - var i; - - var bscore; - var fscore; - var ratio; - var j_a; - var j_team; - - if(proo != null){ - j_item.attr('proid',proo.proid); - - j_item.find('td.no').text(proo.prono); - j_a = j_item.find('td.name > a'); - j_a.attr('href','/toj/pro/' + proo.proid + '/'); - j_a.text(proo.proname); - - bscore = proo.bscore; - fscore = proo.full_score; - j_item.find('td.bscore').text(Math.floor(bscore) + ' / ' + Math.floor(fscore)); - - if(proo.tried == false){ - j_item.css('border-color','#1C1C1C'); - }else{ - ratio = bscore / fscore; - - if(ratio < 0.6){ - j_item.css('border-color','#FF0000'); - }else if(ratio < 0.8){ - j_item.css('border-color','#00FF00'); - }else if(ratio < 1){ - j_item.css('border-color','#FFFF00'); - }else{ - j_item.css('border-color','#FFFFFF'); - } - } - - j_item.find('td.team').remove(); - for(i = 0;i < proo.tscore.length;i++){ - j_team = $('<td class="team"></td>'); - j_team.text(Math.floor(proo.tscore[i])); - j_item.append(j_team); - } - } - }; - var pro_listnew = function(proo){ - var j_item; - - j_item = $('<tr class="item"><td class="no"></td><td class="name"><a></a></td><td class="bscore"></td></tr>'); - pro_listset(j_item,proo); - - return j_item; - }; - var prog_set = function(j_progbox,baseline,totalscore){ - var off; - var ratio; - var j_prog; - - off = 0; - ratio = baseline.pass_score * 100 / baseline.total_score; - j_prog = j_progbox.find('div.pass'); - j_prog.css('width',ratio + '%'); - j_prog.html(Math.floor(baseline.pass_score) + ' '); - off += ratio; - ratio = (baseline.good_score - baseline.pass_score) * 100 / baseline.total_score; - j_prog = j_progbox.find('div.good'); - j_prog.css('left',off + '%'); - j_prog.css('width',ratio + '%'); - j_prog.html(Math.floor(baseline.good_score) + ' '); - off += ratio; - ratio = 100 - off; - j_prog = j_progbox.find('div.total'); - j_prog.css('left',off + '%'); - j_prog.css('width',ratio + '%'); - j_prog.html(Math.floor(baseline.total_score) + ' '); - - ratio = totalscore * 100 / baseline.total_score; - j_prog = j_progbox.find('div.prog'); - j_prog.css('width',ratio + '%'); - j_prog.html(Math.floor(totalscore) + ' '); - if(totalscore < baseline.pass_score){ - ratio = totalscore / baseline.pass_score; - j_prog.css('background-color','rgba(255,' + Math.round(64 * ratio) + ',0,0.8)'); - }else if(totalscore < baseline.good_score){ - ratio = (totalscore - baseline.pass_score) / (baseline.good_score - baseline.pass_score); - j_prog.css('background-color','rgba(' + Math.round(128 * ratio) + ',255,0,0.8)'); - }else if(totalscore < baseline.total_score){ - ratio = (totalscore - baseline.good_score) / (baseline.total_score - baseline.good_score); - j_prog.css('background-color','rgba(255,255,' + Math.round(128 * ratio) + ',0.8)'); - }else{ - j_prog.css('background-color','rgba(255,255,255,0.8)'); - } - } - var prostat_refresh = function(){ - if(refresh_flag == false){ - return; - } - - $.post('/toj/sqmod/sqmod_contest/sqmod_contest.php',{'action':'get_user_stat','data':JSON.stringify({'sqid':sqid,'display_team':true})},function(res){ - var i; - var j; - - var reto; - var team; - var teamo; - var prostat; - var prostato; - var proo; - var user_total; - var team_total; - var maxscore; - var j_list; - var j_head; - var j_team; - var j_a; - var j_item; - - if(res[0] != 'E'){ - reto = JSON.parse(res); - team = reto.team; - prostat = reto.prostat; - - j_list = j_pbox.find('table.prolist'); - if(team != undefined){ - j_head = j_list.find('tr.head'); - j_head.find('th.team').remove(); - for(i = 0;i < team.length;i++){ - teamo = team[i]; - - j_team = $('<th class="team"><a></a></th>'); - j_a = j_team.find('a'); - j_a.attr('href','/toj/user/' + teamo.uid + '/') - j_a.text(teamo.name); - - for(j = 0;j < teamo.prostat.length;j++){ - if(teamo.prostat[j].tried == true){ - promap[teamo.prostat[j].proid].tscore[i] = teamo.prostat[j].best_score; - }else{ - promap[teamo.prostat[j].proid].tscore[i] = 0; - } - } - - j_head.append(j_team); - } - - j_pbox.find('table.stat tr.team_prog').show(); - } - - user_total = 0; - team_total = 0; - for(i = 0;i < prostat.length;i++){ - prostato = prostat[i]; - proo = promap[prostato.proid]; - proo.bscore = prostato.best_score; - proo.tried = prostato.tried; - user_total += prostato.best_score; - j_item = j_list.find('[proid = "' + prostato.proid + '"]'); - if(j_item.length > 0){ - pro_listset(j_item,proo); - } - - maxscore = proo.bscore; - for(j = 0;j < proo.tscore.length;j++){ - maxscore = Math.max(maxscore,proo.tscore[j]); - } - team_total += maxscore; - } - - prog_set(j_pbox.find('table.stat div.user_prog'),reto.base_line,user_total); - if(team != undefined){ - prog_set(j_pbox.find('table.stat div.team_prog'),reto.team_base_line,team_total); - } - - setTimeout(prostat_refresh,2000); - } - }); - }; - - that.node = new vus.node('pro'); - - that.__super(); - - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - index.tab_hl('pro'); - that.fadein(j_pbox); - refresh_flag = true; - - $.post('/toj/sqmod/sqmod_contest/sqmod_contest.php',{'action':'get_prolist','data':JSON.stringify({'sqid':sqid})},function(res){ - var i; - var reto; - var proo; - var j_list; - var j_item; - - if(res[0] != 'E'){ - reto = JSON.parse(res); - - promap = new Array; - j_list = j_pbox.find('table.prolist'); - for(i = 0;i < reto.length;i++){ - proo = reto[i]; - proo.bscore = 0; - proo.tscore = new Array; - proo.tried = false; - if(proo.hidden == false || user.level == -1){ - promap[proo.proid] = proo; - j_item = pro_listnew(proo); - j_list.append(j_item); - } - } - - prostat_refresh(); - } - }); - }else if(direct == 'out'){ - index.tab_ll('pro'); - that.fadeout(j_pbox); - refresh_flag = false; - - j_pbox.find('table.prolist tr.item').remove(); - } - - return 'cont'; - }; -}; __extend(class_sqmod_contest_pro_pbox,class_com_pbox); diff --git a/toj/sqmod/sqmod_contest/sqmod_contest.php b/toj/sqmod/sqmod_contest/sqmod_contest.php deleted file mode 100755 index f999cfa..0000000 --- a/toj/sqmod/sqmod_contest/sqmod_contest.php +++ /dev/null @@ -1,123 +0,0 @@ -<?php -//ini_set("display_errors", "On"); - -require_once('common.inc.php'); -require_once('user.inc.php'); -require_once('square.inc.php'); -require_once('sqmod_contest.inc.php'); -require_once('team.inc.php'); -require_once('sqlib_scoreboard.inc.php'); - -$sqlc = db_connect(); -$msqlc = db_connect('toj_mod'); - -$action = $_POST['action']; -$data = $_POST['data']; - -if(strlen($action)==0) - die('Eno_action'); -if($action == 'get_prolist') -{ - $dt = json_decode($data); - $sqid = intval($dt->sqid); - if(square::get_sqmod($sqlc, $sqid) != SQMODNAME) - die('Eerror_sqid_this_mod'); - if(!sec_is_login()) - die('Enot_login'); - $uid = intval($_COOKIE['uid']); - if(square::get_user_relationship($sqlc, $uid, $sqid) < SQUARE_USER_ACTIVE) - die('Ecannot_view_sq'); - - $list = square::get_pro_list($sqlc, $sqid); - if(!$list) - die('Eno_problem'); - $data = get_setting($sqid); - $nlist = process_pro_list($list, $data, $sqid); - echo(json_encode($nlist)); -} -if($action == 'get_user_stat') -{ - $dt = json_decode($data); - $sqid = intval($dt->sqid); - $display_team = $dt->display_team; - if(square::get_sqmod($sqlc, $sqid) != SQMODNAME) - die('Eerror_sqid_this_mod'); - if(!sec_is_login()) - die('Enot_login'); - $uid = intval($_COOKIE['uid']); - if(square::get_user_relationship($sqlc, $uid, $sqid) < SQUARE_USER_ACTIVE) - die('Ecannot_view_sq'); - - $data = get_setting($sqid); - - $ret = new stdClass(); - $prostat = get_pro_stat_uid($sqlc, $msqlc, $sqid, SCOREBOARD_ID_PROBSTAT, $uid); - $tmpstat = process_pro_stat($prostat); - $ret->prostat = calc_score($tmpstat, $data, $sqid); - $ret->base_line = get_base_line($data, $sqid, false); - - if($display_team) - { - $term = get_term($data, $sqid); - $teamid = intval(get_teamid($msqlc, $term, $uid)); - if($teamid) - { - $ret->team_base_line = get_base_line($data, $sqid, true); - $members = get_team_member($msqlc, $term, $teamid); - $arr = array(); - foreach($members as $mem) - { - if($mem->uid == $uid)continue; - $tmpstat = process_pro_stat(get_pro_stat_uid($sqlc, $msqlc, $sqid, SCOREBOARD_ID_PROBSTAT, $mem->uid)); - $mem->prostat = calc_score($tmpstat, $data, $sqid); - array_push($arr, $mem); - } - $ret->team = $arr; - $ret->teamid = $teamid; - } - } - echo(json_encode($ret)); -} -if($action == 'get_scoreboard'){ - $dt = json_decode($data); - $sqid = intval($dt->sqid); - - $sqo = square::get($sqlc, $sqid); - if($sqo == NULL || $sqo->sqmodname != SQMODNAME) - die('Eerror_sq_error'); - if(!sec_is_login()) - die('Enot_login'); - $uid = intval($_COOKIE['uid']); - if(square::get_user_relationship($sqlc, $uid, $sqid) < SQUARE_USER_ACTIVE) - die('Ecannot_view_sq'); - - $list = get_scoreboard($sqlc, $msqlc, $sqid, SCOREBOARD_ID_SCOREBOARD); - $user_map = array(); - for($idx = 0;$idx < count($list);$idx++){ - $list[$idx]->nickname = user::get_nickname($sqlc, $list[$idx]->uid); - $user_map[$list[$idx]->uid] = true; - } - - $user_list = square::get_user_list($sqlc, $sqid); - for($idx = 0;$idx < count($user_list);$idx++){ - if(!array_key_exists($user_list[$idx]->uid,$user_map)){ - array_push($list,array( - 'uid' => $user_list[$idx]->uid, - 'nickname' => $user_list[$idx]->nickname, - 'rank' => -1, - 'rank_score' => 0, - 'problem' => [] - )); - } - } - - echo(json_encode(array( - 'start_time' => $sqo->start_time, - 'list' => $list - ))); -} - -db_close($sqlc); -db_close($msqlc); - -?> diff --git a/toj/sqmod/sqmod_contest/team.inc.php b/toj/sqmod/sqmod_contest/team.inc.php deleted file mode 100755 index 3effc0e..0000000 --- a/toj/sqmod/sqmod_contest/team.inc.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -require_once('../../php/common.inc.php'); - -const TEAM_TYPE_BOY = 1; -const TEAM_TYPE_GIRL = 2; -const TEAM_TYPE_COL = 3; -const TEAM_TYPE_TEA = 4; - -function get_teamid($msqlc, $term, $uid) -{ - //Return the teamid of $uid. False if not exists. - $sqlstr = 'SELECT "teamid" FROM "sqmod_sprout_team" WHERE "term"=$1 AND "uid"=$2;'; - $sqlarr = array($term, $uid); - $res = pg_query_params($msqlc, $sqlstr, $sqlarr); - $teamid = pg_fetch_result($res, 0); - return $teamid; -} - -function get_team_member($msqlc, $term, $teamid) -{ - //Return all team member uid, level of team $teamid. False if not exists. - $sqlstr = 'SELECT "sqmod_sprout_team"."uid", "sqmod_sprout_team"."level", "sqmod_sprout_student"."name" FROM "sqmod_sprout_team" INNER JOIN "sqmod_sprout_student" ON "sqmod_sprout_team"."uid"="sqmod_sprout_student"."uid" WHERE "sqmod_sprout_team"."term"=$1 AND "sqmod_sprout_team"."teamid"=$2 ORDER BY "sqmod_sprout_team"."level" DESC, "sqmod_sprout_team"."uid";'; - $sqlarr = array($term, $teamid); - $res = pg_query_params($msqlc, $sqlstr, $sqlarr); - $ret = array(); - while($obj = pg_fetch_object($res)) - { - $obj->uid = intval($obj->uid); - $obj->level = intval($obj->level); - array_push($ret, $obj); - } - return $ret; -} - - -?> diff --git a/toj/sqmod/sqmod_test/sqmod_test.css b/toj/sqmod/sqmod_test/sqmod_test.css deleted file mode 100755 index 4680479..0000000 --- a/toj/sqmod/sqmod_test/sqmod_test.css +++ /dev/null @@ -1,90 +0,0 @@ -div.sqmod_test > div.pro_pbox > table.prolist{ - width:1060px; - margin:0px 0px 6px 164px; - border-collapse:collapse; - text-align:left; -} -div.sqmod_test > div.pro_pbox > table.prolist tr.head{ - height:64px; -} -div.sqmod_test > div.pro_pbox > table.prolist tr.item{ - height:32px; - border-left:2px solid; - border-color:#1C1C1C; -} -div.sqmod_test > div.pro_pbox > table.prolist tr:hover.item{ - background-color:rgba(255,255,255,0.2); -} -div.sqmod_test > div.pro_pbox > table.prolist th,div.sqmod_test > div.pro_pbox > table.prolist td{ - padding:0px 0px 0px 6px; -} -div.sqmod_test > div.pro_pbox > table.prolist th.no,div.sqmod_test > div.pro_pbox > table.prolist td.no{ - width:76px; -} -div.sqmod_test > div.pro_pbox > table.prolist th.name,div.sqmod_test > div.pro_pbox > table.prolist td.name{ - width:auto; - padding:0px 0px 0px 0px; -} -div.sqmod_test > div.pro_pbox > table.prolist th.bscore,div.sqmod_test > div.pro_pbox > table.prolist td.bscore{ - width:76px; -} -div.sqmod_test > div.pro_pbox > table.prolist th.team,div.sqmod_test > div.pro_pbox > table.prolist td.team{ - width:76px; -} - -div.sqmod_test > div.pro_pbox > table.stat{ - margin:32px 0px 6px 164px; - border-collapse:collapse; - text-align:left; -} -div.sqmod_test > div.pro_pbox > table.stat tr{ - height:32px; -} -div.sqmod_test > div.pro_pbox div.prog_box{ - width:486px; - height:16px; - background-color:rgba(255,255,255,0.2); - color:#1C1C1C; - font-size:12px; - font-family:monospace; - line-height:16px; - text-align:right; - position:relative; -} -div.sqmod_test > div.pro_pbox div.prog_box > div.pass{ - width:0%; - height:16px; - border-right:rgba(0,255,0,0.8) 2px solid; - position:absolute; - top:0px; - left:0%; - overflow:hidden; -} -div.sqmod_test > div.pro_pbox div.prog_box > div.good{ - width:0%; - height:16px; - border-right:rgba(255,255,0,0.8) 2px solid; - position:absolute; - top:0px; - left:0%; - overflow:hidden; -} -div.sqmod_test > div.pro_pbox div.prog_box > div.total{ - width:0%; - height:16px; - border-right:rgba(255,255,255,0.8) 2px solid; - position:absolute; - top:0px; - left:0%; - overflow:hidden; -} -div.sqmod_test > div.pro_pbox div.prog_box > div.prog{ - width:0%; - height:16px; - background-color:rgba(0,0,0,0); - font-weight:bold; - position:absolute; - top:0px; - left:0px; - overflow:hidden; -} diff --git a/toj/sqmod/sqmod_test/sqmod_test.html b/toj/sqmod/sqmod_test/sqmod_test.html deleted file mode 100755 index 14f44dd..0000000 --- a/toj/sqmod/sqmod_test/sqmod_test.html +++ /dev/null @@ -1,29 +0,0 @@ -<div tab="pro" class="com_pbox pro_pbox"> - <table class="prolist"> - <tr class="head"> - <th class="no">#</th> - <th class="name">題目名稱</th> - <th class="bscore">最佳分數</th> - </tr> - </table> - <table class="stat"> - <tr class="user_prog"> - <td style="width:76px;">個人進度</td> - <td style="padding:0px 0px 0px 6px;"><div class="prog_box user_prog"> - <div class="pass"></div> - <div class="good"></div> - <div class="total"></div> - <div class="prog"></div> - </div></td> - </tr> - <tr class="team_prog" style="display:none;"> - <td style="width:76px;">小組進度</td> - <td style="padding:0px 0px 0px 6px;"><div class="prog_box team_prog"> - <div class="pass"></div> - <div class="good"></div> - <div class="total"></div> - <div class="prog"></div> - </div></td> - </tr> - </table> -</div> diff --git a/toj/sqmod/sqmod_test/sqmod_test.inc.php b/toj/sqmod/sqmod_test/sqmod_test.inc.php deleted file mode 100755 index c331a3f..0000000 --- a/toj/sqmod/sqmod_test/sqmod_test.inc.php +++ /dev/null @@ -1,278 +0,0 @@ -<?php - -require_once('common.inc.php'); -require_once('square.inc.php'); -require_once('sqlib_scoreboard.inc.php'); - -const SQMODNAME = 'sqmod_test'; - -const SCOREBOARD_ID_PROBSTAT = 1; - -function score_func($sqid, $proid, $best_score, $best_time, $is_ac, $ac_time, $tries_before_ac, $last_score, $last_status, $tries) -{ - $data = get_setting($sqid); - $fscore = 0; - - foreach($data->pro as $pro) - { - if($pro->proid == $proid && $pro->method == 'normal') - { - $fscore = $pro->score; - break; - } - if($pro->method == 'max') - { - foreach($pro->config as $cf) - { - foreach($cf as $sp) - { - if($sp[0] == $proid) - { - $fscore = $sp[1]; - break; - } - } - } - } - } - - $rscore = $best_score * $fscore / 100; - return $rscore; -} - -function get_pro_stat_uid($sqlc, $msqlc, $sqid, $sboard_id, $uid) -{ - //get user $uid solving status of square $sqid. $sboard_id can be set as a fixed value. - $sq = square::get($sqlc, $sqid); - if(!$sq)die('Eno_such_sq'); - - $data = sqlib_scoreboard::get_scoreboard_uid($sqlc, $msqlc, $sqid, $sboard_id, 'score_func', $sq->start_time, $sq->end_time, $uid); - - return $data[0]; -} - -function process_pro_stat($obj) -{ - $ret = array(); - foreach($obj->problem as $pro) - { - $ps = new stdClass(); - $ps->proid = $pro->proid; - $ps->is_ac = $pro->is_ac; - $ps->best_score = $pro->best_score; - //$ps->rank_score = $pro->rank_score; - $ps->tried = ($pro->tries > 0); - //array_push($ret, $ps); - $ret[$pro->proid] = $ps; - } - return $ret; -} - -function add_setting($sqid) -{ - mkdir('/srv/http/toj/center/sq/'.$sqid); -} -function del_setting($sqid) -{ - $sqdir = '/srv/http/toj/center/sq/'.$sqid.'/'; - unlink($sqdir.'setting'); - rmdir($sqdir); -} -function get_setting($sqid) -{ - $sqdir = '/srv/http/toj/center/sq/'.$sqid.'/'; - $cont = file_get_contents($sqdir.'setting'); - $data = json_decode($cont); - return $data; -} -function put_setting($sqid, $data) -{ - $sqdir = '/srv/http/toj/center/sq/'.$sqid.'/'; - file_put_contents($sqdir.'setting', json_encode($data)); -} - -function get_term($data, $sqid) -{ - return $data->term; -} - -function calc_score($stat, $data, $sqid) -{ - $prolist = $data->pro; - $ret = array(); - foreach($prolist as $pro) - { - $proid = $pro->proid; - $np = new stdClass(); - if($stat)$np = clone $stat[$proid]; - //else continue; - if(!$stat) - { - $np->proid = $proid; - $np->best_score = 0; - $np->tried = false; - $np->is_ac = false; - array_push($ret, $np); - continue; - } - $method = $pro->method; - //$np->full_score = $pro->score; - if($method == 'normal') - { - $np->best_score = $stat[$proid]->best_score / 100 * $pro->score; - } - if($method == 'max') - { - $score = 0; - $tis_ac = false; - foreach($pro->config as $conf) - { - //$np->best_score = json_encode($conf); - $nowscore = 0; - $is_ac = true; - foreach($conf as $unit) - { - $nowscore += $stat[$unit[0]]->best_score / 100 * $unit[1]; - $np->tried = $np->tried || $stat[$unit[0]]->tried; - if(!$stat[$unit[0]]->is_ac)$is_ac = false; - } - $score = max($score, $nowscore); - if($is_ac)$tis_ac = true; - } - $np->is_ac = $tis_ac; - $np->best_score = $score;// / 100 * $pro->score; - } - //$np->best_score = json_encode($np); - array_push($ret, $np); - } - //$stat[0]->best_score = json_encode($ret[0]); - return $ret; -} - -function process_pro_list($list, $data, $sqid) -{ - $prol = $data->pro; - $ret = array(); - foreach($prol as $pro) - { - $proid = $pro->proid; - $np = null; - foreach($list as $op) - { - if($op->proid == $proid) - { - $np = clone $op; - break; - } - } - $np->prono = $pro->prono; - $np->full_score = $pro->score; - if($pro->proname)$np->proname = $pro->proname; - array_push($ret, $np); - } - return $ret; -} - -function get_base_line($data, $sqid, $isteam) -{ - $ret = new stdClass(); - if($isteam) - { - $ret->total_score = $data->total_score; - $ret->pass_score = $data->pass_score_team; - $ret->good_score = $data->good_score_team; - } - else - { - $ret->total_score = $data->total_score; - $ret->pass_score = $data->pass_score; - $ret->good_score = $data->good_score; - } - - return $ret; -} - -function calc_default_baseline($total_score) -{ - $ret = new stdClass(); - - $ret->pass_score = round($total_score * 0.6); - $ret->good_score = round($total_score * 0.8); - $ret->pass_score_team = round($total_score * 0.8); - $ret->good_score_team = round($total_score * 1); - - return $ret; -} - -function event_create($sqid) -{ - $set = array( - 'term' => 1, - 'pro' => [], - 'total_score' => 0, - 'pass_score' => 0, - 'good_score' => 0, - 'pass_score_team' => 0, - 'good_score_team' => 0 - ); - - add_setting($sqid); - put_setting($sqid, $set); -} -function event_destroy($sqid) -{ - del_setting($sqid); -} -function event_add_pro($sqid, $proid) -{ - $set = get_setting($sqid); - - $list = $set->pro; - for($idx = 0;$idx < count($list);$idx++){ - if($list[$idx]->proid == $proid) - return; - } - $list[$idx] = array( - "prono" => $idx + 1, - "proid" => $proid, - "score" => 100, - "method" => 'normal' - ); - $set->pro = $list; - $set->total_score += 100; - - $baseline = calc_default_baseline($set->total_score); - $set->pass_score = $baseline->pass_score; - $set->good_score = $baseline->good_score; - $set->pass_score_team = $baseline->pass_score_team; - $set->good_score_team = $baseline->good_score_team; - - put_setting($sqid, $set); -} -function event_del_pro($sqid, $proid) -{ - $set = get_setting($sqid); - - $list = $set->pro; - $idx = 0; - while($idx < count($list)){ - if($list[$idx]->proid == $proid){ - array_splice($list,$idx,1); - $set->total_score -= 100; - }else{ - $list[$idx]->prono = $idx + 1; - $idx++; - } - } - $set->pro = $list; - - $baseline = calc_default_baseline($set->total_score); - $set->pass_score = $baseline->pass_score; - $set->good_score = $baseline->good_score; - $set->pass_score_team = $baseline->pass_score_team; - $set->good_score_team = $baseline->good_score_team; - - put_setting($sqid, $set); -} - -?> diff --git a/toj/sqmod/sqmod_test/sqmod_test.js b/toj/sqmod/sqmod_test/sqmod_test.js deleted file mode 100755 index 4923ed0..0000000 --- a/toj/sqmod/sqmod_test/sqmod_test.js +++ /dev/null @@ -1,252 +0,0 @@ -var sqmod_test = function(that,j_page){ - var pro_pbox = new class_sqmod_test_pro_pbox(that.sqid,j_page); - - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - index.title_set('TOJ-' + that.sqname); - - index.tab_add('pro','/toj/sq/' + that.sqid + '/pro/','題目'); - - if(url_dpart.length == 0){ - com.url_update('/toj/sq/' + that.sqid + '/pro/'); - return 'stop'; - } - }else if(direct == 'out'){ - index.tab_empty(); - } - - return 'cont'; - }; - that.node.child_set(pro_pbox.node); -}; - -var class_sqmod_test_pro_pbox = function(sqid,j_page){ - var that = this; - var j_pbox = j_page.find('div.pro_pbox'); - var promap = null; - - var pro_listset = function(j_item,proo){ - var i; - - var bscore; - var fscore; - var ratio; - var j_a; - var j_team; - - if(proo != null){ - j_item.attr('proid',proo.proid); - - j_item.find('td.no').text(proo.prono); - j_a = j_item.find('td.name > a'); - j_a.attr('href','/toj/pro/' + proo.proid + '/'); - j_a.text(proo.proname); - - bscore = proo.bscore; - fscore = proo.full_score; - j_item.find('td.bscore').text(Math.floor(bscore) + ' / ' + Math.floor(fscore)); - - if(proo.tried == false){ - j_item.css('border-color','#1C1C1C'); - }else{ - ratio = bscore / fscore; - - if(ratio < 0.6){ - j_item.css('border-color','#FF0000'); - }else if(ratio < 0.8){ - j_item.css('border-color','#00FF00'); - }else if(ratio < 1){ - j_item.css('border-color','#FFFF00'); - }else{ - j_item.css('border-color','#FFFFFF'); - } - } - - j_item.find('td.team').remove(); - for(i = 0;i < proo.tscore.length;i++){ - j_team = $('<td class="team"></td>'); - j_team.text(Math.floor(proo.tscore[i])); - j_item.append(j_team); - } - } - }; - var pro_listnew = function(proo){ - var j_item; - - j_item = $('<tr class="item"><td class="no"></td><td class="name"><a></a></td><td class="bscore"></td></tr>'); - pro_listset(j_item,proo); - - return j_item; - }; - var prog_set = function(j_progbox,baseline,totalscore){ - var off; - var ratio; - var j_prog; - - off = 0; - ratio = baseline.pass_score * 100 / baseline.total_score; - j_prog = j_progbox.find('div.pass'); - j_prog.css('width',ratio + '%'); - j_prog.html(Math.floor(baseline.pass_score) + ' '); - off += ratio; - ratio = (baseline.good_score - baseline.pass_score) * 100 / baseline.total_score; - j_prog = j_progbox.find('div.good'); - j_prog.css('left',off + '%'); - j_prog.css('width',ratio + '%'); - j_prog.html(Math.floor(baseline.good_score) + ' '); - off += ratio; - ratio = 100 - off; - j_prog = j_progbox.find('div.total'); - j_prog.css('left',off + '%'); - j_prog.css('width',ratio + '%'); - j_prog.html(Math.floor(baseline.total_score) + ' '); - - ratio = totalscore * 100 / baseline.total_score; - j_prog = j_progbox.find('div.prog'); - j_prog.css('width',ratio + '%'); - j_prog.html(Math.floor(totalscore) + ' '); - if(totalscore < baseline.pass_score){ - ratio = totalscore / baseline.pass_score; - j_prog.css('background-color','rgba(255,' + Math.round(64 * ratio) + ',0,0.8)'); - }else if(totalscore < baseline.good_score){ - ratio = (totalscore - baseline.pass_score) / (baseline.good_score - baseline.pass_score); - j_prog.css('background-color','rgba(' + Math.round(128 * ratio) + ',255,0,0.8)'); - }else if(totalscore < baseline.total_score){ - ratio = (totalscore - baseline.good_score) / (baseline.total_score - baseline.good_score); - j_prog.css('background-color','rgba(255,255,' + Math.round(128 * ratio) + ',0.8)'); - }else{ - j_prog.css('background-color','rgba(255,255,255,0.8)'); - } - } - var prostat_refresh = function(){ - if(refresh_flag == false){ - return; - } - - $.post('/toj/sqmod/sqmod_test/sqmod_test.php',{'action':'get_user_stat','data':JSON.stringify({'sqid':sqid,'display_team':true})},function(res){ - var i; - var j; - - var reto; - var team; - var teamo; - var prostat; - var prostato; - var proo; - var user_total; - var team_total; - var maxscore; - var j_list; - var j_head; - var j_team; - var j_a; - var j_item; - - if(res[0] != 'E'){ - reto = JSON.parse(res); - team = reto.team; - prostat = reto.prostat; - - j_list = j_pbox.find('table.prolist'); - if(team != undefined){ - j_head = j_list.find('tr.head'); - j_head.find('th.team').remove(); - for(i = 0;i < team.length;i++){ - teamo = team[i]; - - j_team = $('<th class="team"><a></a></th>'); - j_a = j_team.find('a'); - j_a.attr('href','/toj/user/' + teamo.uid + '/') - j_a.text(teamo.name); - - for(j = 0;j < teamo.prostat.length;j++){ - if(teamo.prostat[j].tried == true){ - promap[teamo.prostat[j].proid].tscore[i] = teamo.prostat[j].best_score; - }else{ - promap[teamo.prostat[j].proid].tscore[i] = 0; - } - } - - j_head.append(j_team); - } - - j_pbox.find('table.stat tr.team_prog').show(); - } - - user_total = 0; - team_total = 0; - for(i = 0;i < prostat.length;i++){ - prostato = prostat[i]; - proo = promap[prostato.proid]; - proo.bscore = prostato.best_score; - proo.tried = prostato.tried; - user_total += prostato.best_score; - j_item = j_list.find('[proid = "' + prostato.proid + '"]'); - if(j_item.length > 0){ - pro_listset(j_item,proo); - } - - maxscore = proo.bscore; - for(j = 0;j < proo.tscore.length;j++){ - maxscore = Math.max(maxscore,proo.tscore[j]); - } - team_total += maxscore; - } - - prog_set(j_pbox.find('table.stat div.user_prog'),reto.base_line,user_total); - if(team != undefined){ - prog_set(j_pbox.find('table.stat div.team_prog'),reto.team_base_line,team_total); - } - - setTimeout(prostat_refresh,2000); - } - }); - }; - - that.node = new vus.node('pro'); - - that.__super(); - - that.node.url_chg = function(direct,url_upart,url_dpart){ - if(direct == 'in'){ - index.tab_hl('pro'); - that.fadein(j_pbox); - refresh_flag = true; - - $.post('/toj/sqmod/sqmod_test/sqmod_test.php',{'action':'get_prolist','data':JSON.stringify({'sqid':sqid})},function(res){ - var i; - var reto; - var proo; - var j_list; - var j_item; - - if(res[0] != 'E'){ - reto = JSON.parse(res); - - promap = new Array; - j_list = j_pbox.find('table.prolist'); - console.log(j_pbox.length); - for(i = 0;i < reto.length;i++){ - proo = reto[i]; - proo.bscore = 0; - proo.tscore = new Array; - proo.tried = false; - if(proo.hidden == false || user.level == -1){ - promap[proo.proid] = proo; - j_item = pro_listnew(proo); - j_list.append(j_item); - } - } - - prostat_refresh(); - } - }); - }else if(direct == 'out'){ - index.tab_ll('pro'); - that.fadeout(j_pbox); - refresh_flag = false; - } - - return 'cont'; - }; -}; __extend(class_sqmod_test_pro_pbox,class_com_pbox); diff --git a/toj/sqmod/sqmod_test/sqmod_test.php b/toj/sqmod/sqmod_test/sqmod_test.php deleted file mode 100755 index 341daae..0000000 --- a/toj/sqmod/sqmod_test/sqmod_test.php +++ /dev/null @@ -1,84 +0,0 @@ -<?php -//ini_set("display_errors", "On"); - -require_once('common.inc.php'); -require_once('php/user.inc.php'); -require_once('sqmod_test.inc.php'); -require_once('team.inc.php'); -require_once('php/sqlib_scoreboard.inc.php'); - -$sqlc = db_connect(); -$msqlc = db_connect('toj_mod'); - -$action = $_POST['action']; -$data = $_POST['data']; - -if(strlen($action)==0) - die('Eno_action'); -if($action == 'get_prolist') -{ - $dt = json_decode($data); - $sqid = intval($dt->sqid); - if(square::get_sqmod($sqlc, $sqid) != SQMODNAME) - die('Eerror_sqid_this_mod'); - if(!sec_is_login()) - die('Enot_login'); - $uid = intval($_COOKIE['uid']); - if(square::get_user_relationship($sqlc, $uid, $sqid) < SQUARE_USER_ACTIVE) - die('Ecannot_view_sq'); - - $list = square::get_pro_list($sqlc, $sqid); - if(!$list) - die('Eno_problem'); - $data = get_setting($sqid); - $nlist = process_pro_list($list, $data, $sqid); - echo(json_encode($nlist)); -} -if($action == 'get_user_stat') -{ - $dt = json_decode($data); - $sqid = intval($dt->sqid); - $display_team = $dt->display_team; - if(square::get_sqmod($sqlc, $sqid) != SQMODNAME) - die('Eerror_sqid_this_mod'); - if(!sec_is_login()) - die('Enot_login'); - $uid = intval($_COOKIE['uid']); - if(square::get_user_relationship($sqlc, $uid, $sqid) < SQUARE_USER_ACTIVE) - die('Ecannot_view_sq'); - - $data = get_setting($sqid); - - $ret = new stdClass(); - $prostat = get_pro_stat_uid($sqlc, $msqlc, $sqid, SCOREBOARD_ID_PROBSTAT, $uid); - $tmpstat = process_pro_stat($prostat); - $ret->prostat = calc_score($tmpstat, $data, $sqid); - $ret->base_line = get_base_line($data, $sqid, false); - - if($display_team) - { - $term = get_term($data, $sqid); - $teamid = intval(get_teamid($msqlc, $term, $uid)); - if($teamid) - { - $ret->team_base_line = get_base_line($data, $sqid, true); - $members = get_team_member($msqlc, $term, $teamid); - $arr = array(); - foreach($members as $mem) - { - if($mem->uid == $uid)continue; - $tmpstat = process_pro_stat(get_pro_stat_uid($sqlc, $msqlc, $sqid, SCOREBOARD_ID_PROBSTAT, $mem->uid)); - $mem->prostat = calc_score($tmpstat, $data, $sqid); - array_push($arr, $mem); - } - $ret->team = $arr; - $ret->teamid = $teamid; - } - } - echo(json_encode($ret)); -} - -db_close($sqlc); -db_close($msqlc); - -?> diff --git a/toj/sqmod/sqmod_test/team.inc.php b/toj/sqmod/sqmod_test/team.inc.php deleted file mode 100755 index 3effc0e..0000000 --- a/toj/sqmod/sqmod_test/team.inc.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -require_once('../../php/common.inc.php'); - -const TEAM_TYPE_BOY = 1; -const TEAM_TYPE_GIRL = 2; -const TEAM_TYPE_COL = 3; -const TEAM_TYPE_TEA = 4; - -function get_teamid($msqlc, $term, $uid) -{ - //Return the teamid of $uid. False if not exists. - $sqlstr = 'SELECT "teamid" FROM "sqmod_sprout_team" WHERE "term"=$1 AND "uid"=$2;'; - $sqlarr = array($term, $uid); - $res = pg_query_params($msqlc, $sqlstr, $sqlarr); - $teamid = pg_fetch_result($res, 0); - return $teamid; -} - -function get_team_member($msqlc, $term, $teamid) -{ - //Return all team member uid, level of team $teamid. False if not exists. - $sqlstr = 'SELECT "sqmod_sprout_team"."uid", "sqmod_sprout_team"."level", "sqmod_sprout_student"."name" FROM "sqmod_sprout_team" INNER JOIN "sqmod_sprout_student" ON "sqmod_sprout_team"."uid"="sqmod_sprout_student"."uid" WHERE "sqmod_sprout_team"."term"=$1 AND "sqmod_sprout_team"."teamid"=$2 ORDER BY "sqmod_sprout_team"."level" DESC, "sqmod_sprout_team"."uid";'; - $sqlarr = array($term, $teamid); - $res = pg_query_params($msqlc, $sqlstr, $sqlarr); - $ret = array(); - while($obj = pg_fetch_object($res)) - { - $obj->uid = intval($obj->uid); - $obj->level = intval($obj->level); - array_push($ret, $obj); - } - return $ret; -} - - -?> |