Skip to content

Commit

Permalink
Merge pull request #181 from robinje/cloudwatch
Browse files Browse the repository at this point in the history
Logs and Metrics
  • Loading branch information
robinje authored Aug 30, 2024
2 parents c4386be + 2816485 commit 1b6403d
Show file tree
Hide file tree
Showing 19 changed files with 727 additions and 313 deletions.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ The current implementation includes an SSH server for secure authentication and
- [x] Implement a database for the game.
- [x] Implement a character creation system.
- [x] Implement a text colorization system.
- [ ] Add Cloudwatch Logs and Metrics.
- [x] Add Cloudwatch Logs and Metrics.
- [x] Build an interactive password change system.
- [ ] Construct the item system.
- [ ] Develop game mechanics.
- [ ] Design an ecenomic framework.
Expand All @@ -22,10 +23,12 @@ The current implementation includes an SSH server for secure authentication and
- [ ] Build a direct messaging system.
- [ ] Develop more complex Non-Player Characters (NPCs) with basic AI.
- [ ] Implement a dynamic content updating system.
- [ ] Build an interactive password change system.
- [ ] Implement a player-to-player trading system.
- [ ] Develop more complex Non-Player Characters (NPCs) with basic AI.
- [ ] Build an interactive password change system.
- [ ] Create a crafting system for items.
- [ ] Develop a weather and time system.
- [ ] Implement a party system for cooperative gameplay.
- [ ] Implement a magic system.


## TODO

Expand All @@ -42,18 +45,19 @@ The current implementation includes an SSH server for secure authentication and
- [x] Add wear item command.
- [x] Add remove item command.
- [x] Add examine item command.
- [x] Implement Persistent Logging.
- [x] Load item prototypes at start.
- [x] Create function for creating items from prototypes.
- [x] Ensure that a message is passed when a characters is added to the game.
- [ ] Add a Message of the Day (MOTD) command.
- [ ] Implement Persistent Logging.
- [ ] Add the ability to delete characters.
- [ ] Add the ability to delete accounts.
- [ ] Implement an obscenity filter.
- [ ] Validate graph of loaded rooms and exits.
- [ ] Load item prototypes at start.
- [ ] Create function for creating items from prototypes.
- [ ] Add look at item command.
- [ ] Improve the say commands.
- [ ] Improve the input filters
- [ ] Ensure that a message is passed when a characters is added to the game.



## Project Overview
Expand Down
53 changes: 53 additions & 0 deletions cloudformation/cloudwatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
AWSTemplateFormatVersion: '2010-09-09'
Description: 'CloudFormation template for CloudWatch Log Group, Metrics, and IAM Policy'

Parameters:
LogGroupName:
Type: String
Description: Name for the CloudWatch Log Group
Default: '/mud/application'

MetricNamespace:
Type: String
Description: Namespace for CloudWatch Metrics
Default: 'MUD/Application'

Resources:
MUDLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Ref LogGroupName
RetentionInDays: 30

MUDCloudWatchPolicy:
Type: AWS::IAM::ManagedPolicy
Properties:
Description: Allows writing to CloudWatch Logs and Metrics
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogStream
- logs:PutLogEvents
Resource: !GetAtt MUDLogGroup.Arn
- Effect: Allow
Action:
- cloudwatch:PutMetricData
Resource: '*'
Condition:
StringEquals:
'cloudwatch:namespace': !Ref MetricNamespace

Outputs:
LogGroupName:
Description: Name of the created CloudWatch Log Group
Value: !Ref MUDLogGroup

MetricNamespace:
Description: Namespace for CloudWatch Metrics
Value: !Ref MetricNamespace

CloudWatchPolicyArn:
Description: ARN of the IAM Managed Policy for CloudWatch access
Value: !Ref MUDCloudWatchPolicy
3 changes: 1 addition & 2 deletions core/archtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package core
import (
"encoding/json"
"fmt"
"log"
"os"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -50,7 +49,7 @@ func (kp *KeyPair) StoreArchetypes(archetypes *ArchetypesData) error {
return fmt.Errorf("error storing archetype %s: %w", archetype.Name, err)
}

log.Printf("Stored archetype: %s", archetype.Name)
Logger.Info("Loaded archetype", "name", archetype.Name)
}

return nil
Expand Down
27 changes: 13 additions & 14 deletions core/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package core

import (
"fmt"
"log"
"strings"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -62,7 +61,7 @@ func (c *Character) FromData(cd *CharacterData) error {

room, exists := c.Server.Rooms[cd.RoomID]
if !exists {
log.Printf("room with ID %d not found", cd.RoomID)
Logger.Warn("Room not found", "roomID", cd.RoomID)
room = c.Server.Rooms[0]
}
c.Room = room
Expand All @@ -71,7 +70,7 @@ func (c *Character) FromData(cd *CharacterData) error {
for key, objID := range cd.Inventory {
obj, err := c.Server.Database.LoadItem(objID, false)
if err != nil {
log.Printf("Error loading object %s for character %s: %v", objID, c.Name, err)
Logger.Error("Error loading object for character", "objectID", objID, "characterName", c.Name, "error", err)
continue
}
c.Inventory[key] = obj
Expand Down Expand Up @@ -128,7 +127,7 @@ func (kp *KeyPair) WriteCharacter(character *Character) error {
return fmt.Errorf("error writing character data: %w", err)
}

log.Printf("Successfully wrote character %s with ID %s to database", character.Name, character.ID)
Logger.Info("Successfully wrote character to database", "characterName", character.Name, "characterID", character.ID)
return nil
}

Expand Down Expand Up @@ -160,12 +159,12 @@ func (kp *KeyPair) LoadCharacter(characterID uuid.UUID, player *Player, server *
}
character.Room.Characters[character.ID] = character
character.Room.Mutex.Unlock()
log.Printf("Added character %s (ID: %s) to room %d", character.Name, character.ID, character.Room.RoomID)
Logger.Info("Added character to room", "characterName", character.Name, "characterID", character.ID, "roomID", character.Room.RoomID)
} else {
log.Printf("Warning: Character %s (ID: %s) loaded without a valid room", character.Name, character.ID)
Logger.Warn("Character loaded without a valid room", "characterName", character.Name, "characterID", character.ID)
}

log.Printf("Loaded character %s (ID: %s) in Room %d", character.Name, character.ID, character.Room.RoomID)
Logger.Info("Loaded character in room", "characterName", character.Name, "characterID", character.ID, "roomID", character.Room.RoomID)

return character, nil
}
Expand Down Expand Up @@ -197,7 +196,7 @@ func SaveActiveCharacters(s *Server) error {
s.Mutex.Lock()
defer s.Mutex.Unlock()

log.Println("Saving active characters...")
Logger.Info("Saving active characters...")

for _, character := range s.Characters {
err := s.Database.WriteCharacter(character)
Expand All @@ -206,7 +205,7 @@ func SaveActiveCharacters(s *Server) error {
}
}

log.Println("Active characters saved successfully.")
Logger.Info("Active characters saved successfully.")

return nil
}
Expand Down Expand Up @@ -255,7 +254,7 @@ func WearItem(c *Character, item *Item) error {

func ListInventory(c *Character) string {

log.Printf("Character %s is listing inventory", c.Name)
Logger.Debug("Character is listing inventory", "characterName", c.Name)

c.Mutex.Lock()
defer c.Mutex.Unlock()
Expand Down Expand Up @@ -290,7 +289,7 @@ func ListInventory(c *Character) string {

func AddToInventory(c *Character, item *Item) {

log.Printf("Character %s is adding item %s to inventory", c.Name, item.Name)
Logger.Debug("Character is adding item to inventory", "characterName", c.Name, "itemName", item.Name)

c.Mutex.Lock()
defer c.Mutex.Unlock()
Expand All @@ -307,7 +306,7 @@ func AddToInventory(c *Character, item *Item) {

func FindInInventory(c *Character, itemName string) *Item {

log.Printf("Character %s is searching inventory for item %s", c.Name, itemName)
Logger.Debug("Character is searching inventory for item", "characterName", c.Name, "itemName", itemName)

c.Mutex.Lock()
defer c.Mutex.Unlock()
Expand All @@ -325,7 +324,7 @@ func FindInInventory(c *Character, itemName string) *Item {

func RemoveFromInventory(c *Character, item *Item) {

log.Printf("Character %s is removing item %s from inventory", c.Name, item.Name)
Logger.Debug("Character is removing item from inventory", "characterName", c.Name, "itemName", item.Name)

c.Mutex.Lock()
defer c.Mutex.Unlock()
Expand All @@ -342,7 +341,7 @@ func RemoveFromInventory(c *Character, item *Item) {

func CanCarryItem(c *Character, item *Item) bool {

log.Printf("Character %s is checking if they can carry item %s", c.Name, item.Name)
Logger.Info("Character is checking if they can carry item", "characterName", c.Name, "itemName", item.Name)

// Placeholder implementation
return true
Expand Down
Loading

0 comments on commit 1b6403d

Please sign in to comment.