-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.c
83 lines (77 loc) · 2.01 KB
/
Server.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// Created by admin on 11/3/2020.
//
#include <stdio.h>
#include<unistd.h>
#include <string.h>
#include "Server.h"
#include"readline/readline.h"
#include"readline/history.h"
bool server_loop = true;
TCPsocket psocket;
Version ServerVer = {0,0,0,"DEV",__DATE__};
void CreateServer(const char* server_address){
}
void InitNetworking(){
//TODO: Fix/Clarify error messages
if(SDLNet_Init() == -1){
printf("The network in the server failed to init because of an error!\nThe Error was %s",SDLNet_GetError());
exit(-1);
}
}
void StartServer(){
IPaddress address;
int resolve = SDLNet_ResolveHost(&address,NULL,25565);
if(resolve == -1){
printf("The Server failed to start because of an error\n The Error was %s",SDLNet_GetError());
exit(-1);
}
psocket = SDLNet_TCP_Open(&address);
if(!psocket){
printf("The Server failed to start because of an error\n The Error was %s",SDLNet_GetError());
exit(-1);
}
}
void FileExists(const char* path){
if(access(path,F_OK) != 0){
printf("File doesn't exist! Creating file at %s",path);
}
}
void ServerInput(){
gets(current_command);
}
void ServerLoop(){
while(server_loop == true){
// printf(">");
//rl_save_prompt();
// rl_message();
//rl_restore_prompt();
char* in = readline(">");
rl_message("");
//rl_forced_update_display();
//rl_clear_message();
if(strcmp("stop",in) == 0){
StopServer();
server_loop = false;
//printf("test");
}
else if(strcmp("help",in) == 0){
printf("Command Name\nstop\nUsage\nCloses the server and prints the command name\n");
}else if(strcmp("version",in) == 0){
printf("");
}
else{
printf("Unknown command!\n");
}
if(!in)
break;
//printf("%s", in);
}
}
TCPsocket GetTCPSocket(){
return psocket;
}
void StopServer(){
SDLNet_TCP_Send(psocket,"Server is going down!",strlen("Server is going down!"));
SDLNet_TCP_Close(psocket);
}