Skip to content

Commit

Permalink
Initial upload
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Nov 24, 2016
1 parent e172ace commit 783fdea
Show file tree
Hide file tree
Showing 32 changed files with 93 additions and 81 deletions.
52 changes: 26 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CC = gcc
AR = ar
CC = i686-w64-mingw32-gcc
AR = i686-w64-mingw32-ar
OBJS = obj/libio.o obj/libmisc.o obj/libclient.o obj/libuser.o obj/libsh.o
LDFLAGS = -L${PWD} -Wl,-rpath=${PWD}
CFLAGS = -Werror -Iinclude -O2 -g -fPIC -std=gnu99
LDFLAGS = -L${PWD} -Wl,-rpath=${PWD} -lws2_32
CFLAGS = -Iinclude -O2 -g -fPIC -std=gnu99
PREFIX=/usr/local
all:
@echo "CC libio.o"
Expand All @@ -17,28 +17,28 @@ all:
@${CC} -c lib/libsh.c -o obj/libsh.o ${CFLAGS}
@echo "AR libsm.a"
@${AR} rcs libsm.a ${OBJS}
@echo "LDCC libsm.so"
@${CC} -o libsm.so ${OBJS} -shared ${LDFLAGS} ${CFLAGS}
@echo "LDCC server.proto"
@${CC} server/server.c -o server/server.proto ${CFLAGS} ${LDFLAGS} -lsm
@echo "LDCC client.proto"
@${CC} client/client.c -o client/client.proto ${CFLAGS} ${LDFLAGS} -lsm
@echo "LDCC tools_dDat"
@${CC} ${OBJS} src/tools_dDat.c -o tools_dDat ${LDFLAGS} ${CFLAGS}
@echo "LDCC tools_wfDat"
@${CC} ${OBJS} src/tools_wfDat.c -o tools_wfDat ${LDFLAGS} ${CFLAGS}
@echo "LDCC tools_dfDat"
@${CC} ${OBJS} src/tools_dfDat.c -o tools_dfDat ${LDFLAGS} ${CFLAGS}
@echo "LDCC tools_wDat"
@${CC} ${OBJS} src/tools_wDat.c -o tools_wDat ${LDFLAGS} ${CFLAGS}
@echo "LDCC dev_dump_fDat"
@${CC} ${OBJS} src/dump_fDat.c -o dev_dump_fDat ${LDFLAGS} ${CFLAGS}
@echo "LDCC dev_send_txt"
@${CC} ${OBJS} src/dev_send_txt.c -o dev_send_txt ${LDFLAGS} ${CFLAGS}
@echo "LDCC client_txt_generic"
@${CC} ${LDFLAGS} ${CFLAGS} -o client_txt_generic src/client_txt_generic.c -lsm
@echo "LDCC dump_serverconf"
@${CC} ${LDFLAGS} ${CFLAGS} -o dump_serverconf debug/dump_serverconf.c ${OBJS}
@echo "LDCC libsm.dll"
@${CC} -o libsm.dll ${OBJS} -shared ${LDFLAGS} ${CFLAGS}
@echo "LDCC server.proto.exe"
@${CC} server/server.c -o server/server.proto.exe ${CFLAGS} ${LDFLAGS} -lsm
@echo "LDCC client.proto.exe"
@${CC} client/client.c -o client/client.proto.exe ${CFLAGS} ${LDFLAGS} -lsm
@echo "LDCC tools_dDat.exe"
@${CC} ${OBJS} src/tools_dDat.c -o tools_dDat.exe ${LDFLAGS} ${CFLAGS}
@echo "LDCC tools_wfDat.exe"
@${CC} ${OBJS} src/tools_wfDat.c -o tools_wfDat.exe ${LDFLAGS} ${CFLAGS}
@echo "LDCC tools_dfDat.exe"
@${CC} ${OBJS} src/tools_dfDat.c -o tools_dfDat.exe ${LDFLAGS} ${CFLAGS}
@echo "LDCC tools_wDat.exe"
@${CC} ${OBJS} src/tools_wDat.c -o tools_wDat.exe ${LDFLAGS} ${CFLAGS}
@echo "LDCC dev_dump_fDat.exe"
@${CC} ${OBJS} src/dump_fDat.c -o dev_dump_fDat.exe ${LDFLAGS} ${CFLAGS}
@echo "LDCC dev_send_txt.exe"
@${CC} ${OBJS} src/dev_send_txt.c -o dev_send_txt.exe ${LDFLAGS} ${CFLAGS}
@echo "LDCC client_txt_generic.exe"
@${CC} -o client_txt_generic src/client_txt_generic.c ${LDFLAGS} ${CFLAGS} -lsm
@echo "LDCC dump_serverconf.exe"
@${CC} ${CFLAGS} -o dump_serverconf.exe debug/dump_serverconf.c ${OBJS} ${LDFLAGS}
@echo "TEST tests"
@make -C tests tests
install:
Expand Down
42 changes: 24 additions & 18 deletions client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <strings.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <winsock.h>
//#include <netinet/in.h>
//#include <arpa/inet.h>
#include <opensm_libio.h>
#include <libuser.h>
#include <libmisc.h>
Expand Down Expand Up @@ -41,7 +41,7 @@ int main(int argc,char *argv[]){
send(sock,&cmd[i],1,0);
int end = END;
send(sock,&end,1,0);
int err = mkdir("/usr/local/share/opensm",0777);
int err = mkdir("/usr/local/share/opensm");
FILE *f = fopen("/usr/local/share/opensm/user.dat","rb");
if(!(f)){
char *user = malloc(1024);
Expand Down Expand Up @@ -126,7 +126,9 @@ int main(int argc,char *argv[]){
send(sock,&end,1,0);
}
else if(cmds == CMD_WRITE){
int zero = 0;
send(sock,&cmds,1,0);

int sb = 0x0f;
int byte = 1;

Expand Down Expand Up @@ -154,17 +156,17 @@ int main(int argc,char *argv[]){
uint32_t size = ftell(f);
fseek(f,0,SEEK_SET);
printf("Read file %d bytes\n",size);
int res;
int res, _sendb = 0x1F;
recv(sock,&res,1,0);
while(1){
int tmpb;
recv(sock,&tmpb,1,0);
if(tmpb == 0x0f)
if(res == 5)
break;
}
recv(sock,&res,1,0);
if(res != 5){
printf("Invalid name got byte: %d\n",res);
goto a;
else if(res == 1){
printf("Invalid name!\n");
goto a;
}
else
recv(sock,&res,1,0);
}
/*int res = 0;
recv(sock,&res,1,0);
Expand Down Expand Up @@ -209,6 +211,8 @@ int main(int argc,char *argv[]){
send(sock,&nsize,sizeof(uint32_t),0);
//for(int i = 0; i < 4;i++)
// printf("[%d]\n",by[i]);
printf("Syncing...\n");
int __sendb = 0x1f,_recvb;
printf("Uploading file\n");
int bytes_written = 0;
while((c = getc(f)) != EOF){
Expand All @@ -230,11 +234,13 @@ int main(int argc,char *argv[]){
continue;
}
int c = 0;
while(1){
recv(sock,&c,1,0);
if(c == END)
break;
printf("%c",c);
if(cmds != CMD_WRITE){
while(1){
recv(sock,&c,1,0);
if(c == END)
break;
printf("%c",c);
}
}
send(sock,&end,1,0);
}
Expand Down
Binary file removed client/client.proto
Binary file not shown.
Binary file added client/client.proto.exe
Binary file not shown.
Binary file modified client_txt_generic
Binary file not shown.
Binary file added dev_dump_fDat.exe
Binary file not shown.
Binary file added dev_send_txt.exe
Binary file not shown.
Binary file added dump_serverconf.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/libclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <winsock.h>
#include <opensm_libio.h>
int send_txt_data(int sockfd,struct txt_data *d){
int size = (12 + d->username_len + d->txt_length);
Expand Down
Binary file modified libsm.a
Binary file not shown.
Binary file added libsm.dll
Binary file not shown.
Binary file modified obj/libclient.o
Binary file not shown.
Binary file modified obj/libio.o
Binary file not shown.
Binary file modified obj/libmisc.o
Binary file not shown.
Binary file modified obj/libsh.o
Binary file not shown.
Binary file modified obj/libuser.o
Binary file not shown.
36 changes: 20 additions & 16 deletions server/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
#include <strings.h>
#include <errno.h>
#include <dirent.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <winsock2.h>
#include <winsock.h>
#include <windows.h>
//#include <netinet/in.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <sys/select.h>
//#include <arpa/inet.h>
//#include <sys/select.h>
#include <opensm_libio.h>
#include <libmisc.h>
#include <libuser.h>
Expand All @@ -26,6 +28,7 @@ int main(int argc,char *argv[]){
usage(argv[0]);
return -1;
}
printf("[WRN]Very buggy no checks in place either! Will likely not work as intended.Use linux version if at all possible\n");
FILE *f = fopen(argv[1],"r");
if(!f){
perror("Error opening file");
Expand Down Expand Up @@ -60,15 +63,15 @@ int main(int argc,char *argv[]){
address.sin_port = htons(2718);
address.sin_addr.s_addr = INADDR_ANY;;
printf("Binding port\n");
if(bind(es_socket,(struct sockaddr *)&address,sizeof(address)) < 0){
if(bind(es_socket,(struct sockaddr *)&address,sizeof(address)) < 0 || 1){
perror("Couldn't bind to port");
return -1;
}

printf("Listening\n");
if(listen(es_socket,3) < 0){
perror("Failed to listen");
return -1;
// return -1;
}
int sd;
int activity;
Expand All @@ -90,9 +93,9 @@ int main(int argc,char *argv[]){
printf("Socket error");
}
if(FD_ISSET(es_socket,&rfds)){
new_socket = accept(es_socket,(struct sockaddr *)&address,(socklen_t *)&addrlen);
new_socket = accept(es_socket,(struct sockaddr *)&address,&addrlen);
if(new_socket < 0){
printf("Error accepting\n");
perror("Error accepting");
return -1;
}
printf("Got connection!\n");
Expand Down Expand Up @@ -144,7 +147,7 @@ int main(int argc,char *argv[]){
int nametaken = 0;
int err = 0;
while((ent = readdir(d))){
if(ent->d_type == DT_REG){
if(1){
FILE *tmpf = fopen(path,"rb");
if(!tmpf){
int errsv = errno;
Expand Down Expand Up @@ -224,9 +227,9 @@ int main(int argc,char *argv[]){
int succ = LOGIN_SUCC;
send(new_socket,&succ,1,0);
}
pid_t pid;
pid = fork();
if(pid == 0){
// pid_t pid;
// pid = fork();
if(1){
while(1){
int cmd = 0x7F;
printf("Reciving command\n");
Expand All @@ -251,7 +254,7 @@ int main(int argc,char *argv[]){
}
struct dirent *ent;
while((ent = readdir(d)) != 0){
if(ent->d_type == DT_REG){
if(1){
char *tmppath = malloc(1024);
sprintf(tmppath,"%s/%s",cfg->user_path,ent->d_name);
FILE *f = fopen(tmppath,"rb");
Expand Down Expand Up @@ -335,7 +338,7 @@ int main(int argc,char *argv[]){
}
struct dirent *ent;
while((ent = readdir(d)) != 0){
if(ent->d_type == DT_REG){
if(1){
char *path = malloc(1024);
sprintf(path,"%s/%s",cfg->story_path,ent->d_name);
FILE *tmpfile = fopen(path,"rb");
Expand All @@ -362,6 +365,8 @@ int main(int argc,char *argv[]){
}
send(new_socket,&end,1,0);
}else if(cmd == CMD_WRITE){
int sendb = 0x0f,resvb;
int zero = 0;
printf("Got command write!\n");
int b = 0;
char *fpath = malloc(1024);
Expand All @@ -386,8 +391,6 @@ int main(int argc,char *argv[]){
resb = 5;
else
resb = 1;
int tmpb = 0x0f;
send(new_socket,&tmpb,1,0);
send(new_socket,&resb,1,0);
if(resb != 5){
printf("Invalid name!\n");
Expand All @@ -412,6 +415,7 @@ int main(int argc,char *argv[]){
printf("File is %z" PRIu32" bytes\n",size);
c = 0;
i = 0;
int _sendb = 0x0f,_recvb;
while(i < size){
recv(new_socket,&c,1,0);
putc(c,f);
Expand Down
Binary file removed server/server.proto
Binary file not shown.
Binary file added server/server.proto.exe
Binary file not shown.
9 changes: 5 additions & 4 deletions src/client_txt_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#include <string.h>
#include <opensm_libio.h>
#include <libclient.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>
//#include <netinet/in.h>
//#include <netdb.h>
//#include <sys/socket.h>
#include <winsock2.h>
//#include <arpa/inet.h>

int main(int argc,char *argv[]){
if(argc != 2)
Expand Down
4 changes: 2 additions & 2 deletions src/dev_send_txt.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <unistd.h>
#include <string.h>
#include <opensm_libio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <winsock2.h>
//#include <netinet/in.h>
#include <libclient.h>
int main(int argc,char *argv[]){
if(argc != 2)
Expand Down
28 changes: 14 additions & 14 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
CC = gcc
AR = ar
CC = i686-w64-mingw32-gcc
AR = i686-w64-mingw32-ar
LDFLAGS = -L${PWD} -L${PWD}/.. -lsm -Wl,-rpath=${PWD}
CFLAGS = -Werror -I../include -O2 -g -fPIC -std=c99
PREFIX=/usr/local
tests:
@echo "LDCC opensm-libio-test-txt"
@${CC} -o opensm-libio-test-txt opensm-libio-test-txt.c ${CFLAGS} ${LDFLAGS}
@echo "TEST opensm-libio-test-txt"
@./opensm-libio-test-txt
@echo "LDCC opensm-libio-test-file"
@${CC} -o opensm-libio-test-file opensm-libio-test-file.c ${CFLAGS} ${LDFLAGS}
@echo "TEST opensm-lbio-test-file"
@./opensm-libio-test-file
@echo "LDCC opensm-libuser-test"
@${CC} -o opensm-libuser-test opensm-libuser-test.c ${CFLAGS} ${LDFLAGS}
@echo "TEST opensm-libuser-test"
@./opensm-libuser-test
@echo "LDCC opensm-libio-test-txt.exe"
@${CC} -o opensm-libio-test-txt.exe opensm-libio-test-txt.c ${CFLAGS} ${LDFLAGS}
@echo "TEST opensm-libio-test-txt.exe"
@wine ./opensm-libio-test-txt.exe
@echo "LDCC opensm-libio-test-file.exe"
@${CC} -o opensm-libio-test-file.exe opensm-libio-test-file.c ${CFLAGS} ${LDFLAGS}
@echo "TEST opensm-lbio-test-file.exe"
@wine ./opensm-libio-test-file.exe
@echo "LDCC opensm-libuser-test.exe"
@${CC} -o opensm-libuser-test.exe opensm-libuser-test.c ${CFLAGS} ${LDFLAGS}
@echo "TEST opensm-libuser-test.exxe"
@wine ./opensm-libuser-test.exe
Binary file removed tests/opensm-libio-test-file
Binary file not shown.
Binary file added tests/opensm-libio-test-file.exe
Binary file not shown.
Binary file removed tests/opensm-libio-test-txt
Binary file not shown.
Binary file added tests/opensm-libio-test-txt.exe
Binary file not shown.
Binary file added tests/opensm-libuser-test.exe
Binary file not shown.
1 change: 1 addition & 0 deletions tests/tmp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test1234
Binary file added tools_dDat.exe
Binary file not shown.
Binary file added tools_dfDat.exe
Binary file not shown.
Binary file added tools_wDat.exe
Binary file not shown.
Binary file added tools_wfDat.exe
Binary file not shown.

0 comments on commit 783fdea

Please sign in to comment.