Cleaned commands
This commit is contained in:
parent
8e6f99ecb7
commit
3d56a4ec61
23
src/cmds.c
23
src/cmds.c
|
@ -36,8 +36,7 @@ char *CmdHelp(char **argv, Server_t *args)
|
|||
char *CmdModel(char **argv, Server_t *args)
|
||||
{
|
||||
char *buf;
|
||||
char temp[255];
|
||||
int tempsize, id, eid;
|
||||
int id, eid;
|
||||
Model_t *newModel;
|
||||
|
||||
buf = (char *) calloc(LINE_NUMBER, LINE_LENGTH * sizeof(char));
|
||||
|
@ -66,12 +65,8 @@ char *CmdModel(char **argv, Server_t *args)
|
|||
|
||||
strcpy(newModel->name, argv[2] + 5);
|
||||
|
||||
strcat(buf, "Model ");
|
||||
tempsize = sprintf(temp, "%s", newModel->name);
|
||||
strcat(buf, temp);
|
||||
strcat(buf, " created with id");
|
||||
tempsize = sprintf(temp, " %d\n", newModel->id);
|
||||
strcat(buf, temp);
|
||||
sprintf(buf + strlen(buf), "Model %s created with id %d\n",
|
||||
newModel->name, newModel->id);
|
||||
goto CmdModelEnd;
|
||||
|
||||
} else {
|
||||
|
@ -96,18 +91,12 @@ char *CmdModel(char **argv, Server_t *args)
|
|||
id = (int) strtol(argv[2] + 3, NULL, 10);
|
||||
|
||||
if (id == 0 || (eid = ModelLoad(id)) <= 0) {
|
||||
strcat(buf, "Failed to load model id");
|
||||
tempsize = sprintf(temp, " %d\n", id);
|
||||
strcat(buf, temp);
|
||||
sprintf(buf + strlen(buf), "Failed to load model id %d\n", id);
|
||||
goto CmdModelEnd;
|
||||
}
|
||||
|
||||
strcat(buf, "Model id");
|
||||
tempsize = sprintf(temp, " %d ", id); //XXX
|
||||
strcat(buf, temp);
|
||||
strcat(buf, "loaded with eid ");
|
||||
tempsize = sprintf(temp, " %d\n", eid);
|
||||
strcat(buf, temp);
|
||||
sprintf(buf + strlen(buf), "Model id %d loaded with eid %d\n",
|
||||
id, eid); //XXX
|
||||
goto CmdModelEnd;
|
||||
loadEnd:
|
||||
// invalid use
|
||||
|
|
11
src/server.c
11
src/server.c
|
@ -113,7 +113,7 @@ static void *serverMain(void *server)
|
|||
sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sockfd == -1) {
|
||||
printLog("Socket creation failed!\n");
|
||||
return NULL;
|
||||
goto serverExiting;
|
||||
}
|
||||
|
||||
// Prepare binding structure
|
||||
|
@ -127,13 +127,13 @@ static void *serverMain(void *server)
|
|||
// Binding newly created socket
|
||||
if ((bind(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr))) != 0) {
|
||||
printLog("Socket bind failed!\n");
|
||||
return NULL;
|
||||
goto serverEarlyExiting;
|
||||
}
|
||||
|
||||
// Now server is ready to listen and verification
|
||||
if ((listen(sockfd, 5)) != 0) {
|
||||
printLog("Socket listening failed!\n");
|
||||
return NULL;
|
||||
goto serverExiting;
|
||||
}
|
||||
|
||||
printLog("Server listening...\n");
|
||||
|
@ -143,17 +143,18 @@ static void *serverMain(void *server)
|
|||
connfd = accept(sockfd, (struct sockaddr*)&cli, &len);
|
||||
if (connfd < 0) {
|
||||
printLog("Server acccept failed!\n");
|
||||
return NULL;
|
||||
goto serverExiting;
|
||||
}
|
||||
printLog("Client accepted\n");
|
||||
|
||||
// Function for chatting between client and server
|
||||
serverCommunicationInstance(args, connfd);
|
||||
|
||||
serverExiting:
|
||||
// After communication ended close the socket
|
||||
close(sockfd);
|
||||
|
||||
serverEarlyExiting:
|
||||
printLog("Server #%lu offline\n", *args->id);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue