Added basic area system
- Added playerdata.c - Added basic move command - Added a basic initialisation of two connected rooms - Added datastructures for areas and paths
This commit is contained in:
parent
ae8373d4ce
commit
85a31a2933
|
@ -0,0 +1,8 @@
|
|||
* Game Design
|
||||
** The gameplay:
|
||||
- Each player may travel to areas connected to the current one, depending on flags.
|
||||
- Players may perform actions, success depending on their stats.
|
||||
- Players may create characters.
|
||||
- A GM may create content using GNU Guile.
|
||||
* Implementation Plans
|
||||
* TODOs
|
|
@ -25,15 +25,28 @@ int main()
|
|||
int clientSockets[64];
|
||||
int maxClients = 64;
|
||||
userMessage sendBuffer;
|
||||
playerArea areaA, areaB;
|
||||
playerPath pathA, pathB;
|
||||
char receiveBuffer[MAX];
|
||||
fd_set connectedClients;
|
||||
playerInfo connectedPlayers[64];
|
||||
struct sockaddr_in serverAddress, clientAddress;
|
||||
|
||||
// Initialize playerdata:
|
||||
// Initialize areas:
|
||||
strncpy(areaA.areaName, "Spawn - North", 32);
|
||||
strncpy(areaB.areaName, "Spawn - South", 32);
|
||||
strncpy(pathA.pathName, "To South Spawn", 32);
|
||||
strncpy(pathB.pathName, "To North Spawn", 32);
|
||||
pathA.areaToJoin = &areaB;
|
||||
pathB.areaToJoin = &areaA;
|
||||
areaA.areaExits[0] = &pathA;
|
||||
areaB.areaExits[0] = &pathB;
|
||||
|
||||
// Initialize playerdata:
|
||||
for (int index = 0; index < maxClients; index++)
|
||||
{
|
||||
strcpy(connectedPlayers[index].playerName, "UNNAMED");
|
||||
connectedPlayers[index].currentArea = &areaA;
|
||||
}
|
||||
|
||||
// Give an intro: Display the Silverkin Industries logo and splash text.
|
||||
|
@ -89,7 +102,6 @@ int main()
|
|||
}
|
||||
length = sizeof(clientAddress);
|
||||
|
||||
//connectionFileDesc = accept(socketFileDesc, (sockaddr*)&clientAddress, &length);
|
||||
// Accept the data packet from client and verification
|
||||
while (1)
|
||||
{
|
||||
|
@ -175,10 +187,10 @@ int main()
|
|||
}
|
||||
// Name change command: Move logic to a command interpreter later:
|
||||
else if (receiveBuffer[0] == '/')
|
||||
{
|
||||
char newName[32];
|
||||
{
|
||||
if(strncmp(receiveBuffer, "/NAME", 5) == 0)
|
||||
{
|
||||
char newName[32];
|
||||
strncpy(newName, &receiveBuffer[6], 32);
|
||||
// Remove newlines:
|
||||
for (int index = 0; index < 32; index++)
|
||||
|
@ -197,17 +209,31 @@ int main()
|
|||
}
|
||||
strncpy(connectedPlayers[i].playerName, newName, 32);
|
||||
}
|
||||
else if(strncmp(receiveBuffer, "/MOVE", 5) == 0)
|
||||
{
|
||||
char requestedPath[32];
|
||||
strncpy(requestedPath, &receiveBuffer[6], 32);
|
||||
// Remove newlines:
|
||||
for (int index = 0; index < 32; index++)
|
||||
{
|
||||
if (requestedPath[index] == '\n')
|
||||
{
|
||||
requestedPath[index] = '\0';
|
||||
}
|
||||
}
|
||||
movePlayerToArea(&connectedPlayers[i], requestedPath);
|
||||
}
|
||||
}
|
||||
// Echo back the message that came in:
|
||||
else
|
||||
{
|
||||
printf("%d/%s: %s", clientSockets[i], connectedPlayers[i].playerName, receiveBuffer);
|
||||
printf("%d/%s/%s: %s", clientSockets[i], connectedPlayers[i].currentArea->areaName, connectedPlayers[i].playerName, receiveBuffer);
|
||||
fflush(stdout);
|
||||
strcpy(sendBuffer.senderName, connectedPlayers[i].playerName);
|
||||
strcpy(sendBuffer.messageContent, receiveBuffer);
|
||||
for (int sendIndex = 0; sendIndex < clientsAmount; sendIndex++)
|
||||
{
|
||||
if(clientSockets[sendIndex] != STDIN_FILENO && clientSockets[sendIndex] != STDOUT_FILENO && clientSockets[sendIndex] != STDERR_FILENO)
|
||||
if(clientSockets[sendIndex] != STDIN_FILENO && (connectedPlayers[i].currentArea == connectedPlayers[sendIndex].currentArea))
|
||||
{
|
||||
write(clientSockets[sendIndex], sendBuffer.senderName, sizeof(sendBuffer.senderName));
|
||||
write(clientSockets[sendIndex], sendBuffer.messageContent, sizeof(sendBuffer.messageContent));
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
// playerdata.c: Contains functions definitions for working with player data.
|
||||
// Barry Kane, 2021
|
||||
#include <string.h>
|
||||
#include "playerdata.h"
|
||||
|
||||
// Move a player to a different area given a path in the area.
|
||||
int movePlayerToArea(playerInfo * player, char * requestedPath)
|
||||
{
|
||||
for (int index = 0; index < 32; index++)
|
||||
{
|
||||
if(strncmp(player->currentArea->areaExits[index]->pathName, requestedPath, 32) == 0)
|
||||
{
|
||||
player->currentArea = player->currentArea->areaExits[index]->areaToJoin;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -6,12 +6,29 @@ typedef struct userMessage
|
|||
{
|
||||
char senderName[32];
|
||||
char messageContent[1024];
|
||||
|
||||
} userMessage;
|
||||
|
||||
typedef struct playerPath playerPath;
|
||||
typedef struct playerArea playerArea;
|
||||
|
||||
struct playerPath
|
||||
{
|
||||
char pathName[32];
|
||||
playerArea * areaToJoin;
|
||||
};
|
||||
|
||||
struct playerArea
|
||||
{
|
||||
char areaName[32];
|
||||
playerPath * areaExits[32];
|
||||
};
|
||||
|
||||
typedef struct playerInfo
|
||||
{
|
||||
char playerName[32];
|
||||
playerArea * currentArea;
|
||||
} playerInfo;
|
||||
|
||||
|
||||
|
||||
// Move a player to a different area given a path in the area.
|
||||
int movePlayerToArea(playerInfo * player, char * requestedPath);
|
||||
|
|
Loading…
Reference in New Issue