Skip to content

Commit

Permalink
Merge pull request #46 from COS301-OptimizePrime/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Quantum-Sicarius authored Jul 27, 2018
2 parents b774047 + 19f7abc commit e1ea34c
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,30 @@ make test
```bash
python -m grpc.tools.protoc -I./protos --python_out=./server --grpc_python_out=./server ./protos/server.proto
```

## Fedora Installation
```bash
sudo dnf update
sudo dnf install postgresql-server postgresql-contrib
sudo systemctl enable postgresql
sudo postgresql-setup --initdb --unit postgresql
sudo systemctl start postgresql
pypy -m ensurepip
```

## Arch Linux Installation
```bash
pacman -S sudo
sudo pacaman -Syyu
sudo pacman -S postgresql

sudo -u postgres -i
initdb --locale en_US.UTF-8 -E UTF8 -D '/var/lib/postgres/data'
exit

sudo systemctl enable postgresql
sudo systemctl start postgresql
sudo -u postgres -i

createuser --interactive
```
2 changes: 1 addition & 1 deletion dnd_backend.service
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Type=simple
User=develop
WorkingDirectory=/home/develop/COS301_DND_Backend
Environment=ENV=prod
ExecStart=/usr/bin/python /home/develop/COS301_DND_Backend/server/main.py
ExecStart=/usr/bin/pypy3 /home/develop/COS301_DND_Backend/main.py
Restart=on-failure

[Install]
Expand Down
12 changes: 11 additions & 1 deletion server/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ def UpdateCharacter(self, request, context):
return server_pb2.Character(
status="FAILED",
status_message="Database error!")

finally:
self.conn.close()

# [CHEAP] Using light characters
def GetCharacters(self, request, context):
self.logger.debug(context.peer())
Expand Down Expand Up @@ -134,6 +136,8 @@ def GetCharacters(self, request, context):
return server_pb2.GetCharactersReply(
status="FAILED",
status_message="Database error!")
finally:
self.conn.close()

def DeleteCharacter(self, request, context):
self.logger.debug(context.peer())
Expand Down Expand Up @@ -193,6 +197,8 @@ def DeleteCharacter(self, request, context):
return server_pb2.DeleteCharacterReply(
status="FAILED",
status_message="Database error!")
finally:
self.conn.close()

def GetCharacterById(self, request, context):
self.logger.debug(context.peer())
Expand Down Expand Up @@ -244,6 +250,8 @@ def GetCharacterById(self, request, context):
return server_pb2.Character(
status="FAILED",
status_message="Database error!")
finally:
self.conn.close()

def CreateCharacter(self, request, context):
self.logger.debug(context.peer())
Expand Down Expand Up @@ -471,3 +479,5 @@ def CreateCharacter(self, request, context):
return server_pb2.Character(
status="FAILED",
status_message="[CreateCharacter] Database error!")
finally:
self.conn.close()
32 changes: 32 additions & 0 deletions server/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ def Create(self, request, context):
name="NULL",
status="FAILED",
status_message="Database error!")
finally:
self.conn.close()

def Join(self, request, context):
logger = logging.getLogger("cos301-DND")
Expand Down Expand Up @@ -215,6 +217,8 @@ def Join(self, request, context):
name="NULL",
status="FAILED",
status_message="Database error!")
finally:
self.conn.close()

def Leave(self, request, context):
logger = logging.getLogger("cos301-DND")
Expand Down Expand Up @@ -307,6 +311,8 @@ def Leave(self, request, context):
name="NULL",
status="FAILED",
status_message="Database error!")
finally:
self.conn.close()

def Ready(self, request, context):
logger = logging.getLogger("cos301-DND")
Expand Down Expand Up @@ -402,6 +408,8 @@ def Ready(self, request, context):
return server_pb2.ReadyUpReply(
status="FAILED",
status_message="Database error!")
finally:
self.conn.close()

def Kick(self, request, context):
logger = logging.getLogger("cos301-DND")
Expand Down Expand Up @@ -485,6 +493,8 @@ def Kick(self, request, context):
name="NULL",
status="FAILED",
status_message="[KICK] Database error!")
finally:
self.conn.close()

# This is a Dungeon Master only command.
def SetMax(self, request, context):
Expand Down Expand Up @@ -550,6 +560,8 @@ def SetMax(self, request, context):
name="NULL",
status="FAILED",
status_message="Database error!")
finally:
self.conn.close()

# This is a Dungeon Master only command.
def SetName(self, request, context):
Expand Down Expand Up @@ -614,6 +626,8 @@ def SetName(self, request, context):
name="NULL",
status="FAILED",
status_message="[SETNAME] Database error!")
finally:
self.conn.close()

# This is a Dungeon Master only command.
def ChangeState(self, request, context):
Expand Down Expand Up @@ -694,6 +708,8 @@ def ChangeState(self, request, context):
name="NULL",
status="FAILED",
status_message="[ChangeState] Database error!")
finally:
self.conn.close()

# This is a Dungeon Master only command.
def SetPrivate(self, request, context):
Expand Down Expand Up @@ -750,6 +766,8 @@ def SetPrivate(self, request, context):
name="NULL",
status="FAILED",
status_message="[SETPRIVATE] Database error!")
finally:
self.conn.close()

# This is a Dungeon Master only command.
def ChangeReadyUpExpiryTime(self, request, context):
Expand Down Expand Up @@ -799,6 +817,8 @@ def ChangeReadyUpExpiryTime(self, request, context):
return server_pb2.ChangeReadyUpExpiryTimeResponse(
status="FAILED",
status_message="[ChangeReadyUpExpiryTime] Database error!")
finally:
self.conn.close()

def List(self, request, context):
logger = logging.getLogger("cos301-DND")
Expand Down Expand Up @@ -865,6 +885,8 @@ def List(self, request, context):
return server_pb2.ListReply(
status="FAILED",
status_message="[List] Database error!")
finally:
self.conn.close()

def GetSessionById(self, request, context):
logger = logging.getLogger("cos301-DND")
Expand Down Expand Up @@ -924,6 +946,8 @@ def GetSessionById(self, request, context):
name="NULL",
status="FAILED",
status_message="Database error!")
finally:
self.conn.close()

def GetSessionsOfUser(self, request, context):
self.logger.info("GetSessionsOfUser sessions called!")
Expand Down Expand Up @@ -967,6 +991,8 @@ def GetSessionsOfUser(self, request, context):
return server_pb2.GetSessionsOfUserReply(
status="FAILED",
status_message="[GetSessionsOfUser] Database error!")
finally:
self.conn.close()

def GetCharactersInSession(self, request, context):
self.logger.info("GetCharactersInSession called!")
Expand Down Expand Up @@ -1010,6 +1036,8 @@ def GetCharactersInSession(self, request, context):
return server_pb2.GetCharactersInSessionResponse(
status="FAILED",
status_message="[GetCharactersInSession] Database error!")
finally:
self.conn.close()

def AddCharacterToSession(self, request, context):
self.logger.info("AddCharacterToSession called!")
Expand Down Expand Up @@ -1065,6 +1093,8 @@ def AddCharacterToSession(self, request, context):
return server_pb2.Session(
status="FAILED",
status_message="[AddCharacterToSession] Database error!")
finally:
self.conn.close()

def RemoveCharacterFromSession(self, request, context):
self.logger.info("RemoveCharacterFromSession called!")
Expand Down Expand Up @@ -1128,6 +1158,8 @@ def RemoveCharacterFromSession(self, request, context):
return server_pb2.Session(
status="FAILED",
status_message="[RemoveCharacterFromSession] Database error!")
finally:
self.conn.close()

def __del__(self):
self.logger.info("Socket destroyed ...")

0 comments on commit e1ea34c

Please sign in to comment.