Skip to content

Commit

Permalink
Moving package.json to root and making things a bit more release ready.
Browse files Browse the repository at this point in the history
  • Loading branch information
kylepaulsen committed Apr 19, 2021
1 parent 310aef9 commit dc13fac
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 39 deletions.
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
# Valheim WebMap

This server side mod creates a web based map that shows live players and allows shared exploration. After port forwarding the correct port, you can share http://your_ip:port url to anyone else and they can see the map too. Clients do not need to have any mods installed.
This server side mod creates a web based map that shows live players and allows shared exploration. After port forwarding the correct port, you can share `http://your_ip:port` to anyone else and they can see the map too. **Clients do not need to have any mods installed!**

For players to show up on the map, they must set `visible to other players` in the in-game map screen.

This has only been tested on a Valheim dedicated server. I'm not sure this will work with the built in server inclued with the base game.

## Installation

Place the WebMap directory in:

`Steam\steamapps\common\Valheim dedicated server\BepInEx\plugins\WebMap`

Optionally, open `config.json` with a text editor and change stuff in there.

## Chat Commands

This mod supports placing pins with chat commands. Press `Enter` to start chatting in game. The commands are as follows:

* `/pin` - Place a "dot" pin with no text on the map where you are currently standing.
* `/pin my pin name` - Place a "dot" pin with "my pin name" under it on the map where you are currently standing.
* `/pin [pin-type] [text]` - Place a pin of a certain type with optional text under it on the map where you are currently standing.
* Pin types are: `dot`, `fire`, `mine`, `house` and `cave`. Example command: `/pin house my awesome base`
* `/undoPin` - Delete your most recent pin.
* `/deletePin [text]` - Delete the most recent pin that matches the text exactly.

If a player creates too many pins, their oldest pin will be removed. There is a setting to control how many pins a player can create in `config.json`.

## Development

To get your environment working, you will need to find and place these .dll files in the WebMap/libs directory. These dlls are usually found in:

`Steam\steamapps\common\Valheim\valheim_server_Data\Managed`
`Steam\steamapps\common\Valheim dedicated server\valheim_server_Data\Managed`
* assembly_valheim.dll
* UnityEngine.CoreModule.dll
* UnityEngine.dll
* UnityEngine.ImageConversionModule.dll (This one might be harder to find. Try googling.)
* UnityEngine.UI.dll

To get the fontend part building, you'll need node installed. After, just do `npm install` to install webpack. Then you can run `npm run build` to build `main.js` which should be included with the other web resources in `WebMap/web`.

I wanted to get this working as soon as possible, so apollogies for messy code.

## Licence

When applicable, assume stuff is under the MIT licence ( https://opensource.org/licenses/MIT )
Expand Down
8 changes: 4 additions & 4 deletions WebMap/MapDataServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public MapDataServer() {

httpServer.OnGet += (sender, e) => {
var req = e.Request;
Debug.Log("~~~ Got GET Request for: " + req.RawUrl);
// Debug.Log("~~~ Got GET Request for: " + req.RawUrl);

if (ProcessSpecialRoutes(e)) {
return;
Expand Down Expand Up @@ -114,7 +114,7 @@ private void ServeStaticFiles(HttpRequestEventArgs e) {
fileCache.Add(requestedFile, requestedFileBytes);
}
} catch (Exception ex) {
Debug.Log("FAILED TO READ FILE! " + ex.Message);
Debug.Log("WebMap: FAILED TO READ FILE! " + ex.Message);
}
}

Expand Down Expand Up @@ -182,9 +182,9 @@ public void ListenAsync() {
httpServer.Start();

if (httpServer.IsListening) {
Debug.Log($"~~~ HTTP Server Listening on port {WebMapConfig.SERVER_PORT} ~~~");
Debug.Log($"WebMap: HTTP Server Listening on port {WebMapConfig.SERVER_PORT}");
} else {
Debug.Log("!!! HTTP Server Failed To Start !!!");
Debug.Log("WebMap: HTTP Server Failed To Start !!!");
}
}

Expand Down
30 changes: 13 additions & 17 deletions WebMap/WebMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Awake() {
try {
mapDataServer.mapImageData = File.ReadAllBytes(mapImagePath);
} catch (Exception e) {
Debug.Log("Failed to read map image data from disk. " + e.Message);
Debug.Log("WebMap: Failed to read map image data from disk. " + e.Message);
}

var fogImagePath = Path.Combine(worldDataPath, "fog.png");
Expand All @@ -57,7 +57,7 @@ public void Awake() {
fogTexture.LoadImage(fogBytes);
mapDataServer.fogTexture = fogTexture;
} catch (Exception e) {
Debug.Log("Failed to read fog image data from disk... Making new fog image..." + e.Message);
Debug.Log("WebMap: Failed to read fog image data from disk... Making new fog image..." + e.Message);
var fogTexture = new Texture2D(WebMapConfig.TEXTURE_SIZE, WebMapConfig.TEXTURE_SIZE, TextureFormat.RGB24, false);
var fogColors = new Color32[WebMapConfig.TEXTURE_SIZE * WebMapConfig.TEXTURE_SIZE];
for (var t = 0; t < fogColors.Length; t++) {
Expand All @@ -70,7 +70,7 @@ public void Awake() {
try {
File.WriteAllBytes(fogImagePath, fogPngBytes);
} catch {
Debug.Log("FAILED TO WRITE FOG FILE!");
Debug.Log("WebMap: FAILED TO WRITE FOG FILE!");
}
}

Expand All @@ -82,7 +82,7 @@ public void Awake() {
var pinsLines = File.ReadAllLines(mapPinsFile);
mapDataServer.pins = new List<string>(pinsLines);
} catch (Exception e) {
Debug.Log("Failed to read pins.csv from disk. " + e.Message);
Debug.Log("WebMap: Failed to read pins.csv from disk. " + e.Message);
}
}

Expand Down Expand Up @@ -126,12 +126,12 @@ public void SaveFogTexture() {
if (mapDataServer.players.Count > 0 && fogTextureNeedsSaving) {
byte[] pngBytes = mapDataServer.fogTexture.EncodeToPNG();

Debug.Log("Saving fog file...");
// Debug.Log("Saving fog file...");
try {
File.WriteAllBytes(Path.Combine(worldDataPath, "fog.png"), pngBytes);
fogTextureNeedsSaving = false;
} catch {
Debug.Log("FAILED TO WRITE FOG FILE!");
Debug.Log("WebMap: FAILED TO WRITE FOG FILE!");
}
}
}
Expand All @@ -141,7 +141,7 @@ public static void SavePins() {
try {
File.WriteAllLines(mapPinsFile, mapDataServer.pins);
} catch {
Debug.Log("FAILED TO WRITE PINS FILE!");
Debug.Log("WebMap: FAILED TO WRITE PINS FILE!");
}
}

Expand Down Expand Up @@ -226,10 +226,10 @@ static Color GetPixelColor(Heightmap.Biome biome) {

static void Postfix(ZoneSystem __instance) {
if (mapDataServer.mapImageData != null) {
Debug.Log("MAP ALREADY BUILT!");
Debug.Log("WebMap: MAP ALREADY BUILT!");
return;
}
Debug.Log("BUILD MAP!");
Debug.Log("WebMap: BUILD MAP!");

int num = WebMapConfig.TEXTURE_SIZE / 2;
float num2 = WebMapConfig.PIXEL_SIZE / 2f;
Expand Down Expand Up @@ -302,9 +302,9 @@ static void Postfix(ZoneSystem __instance) {
try {
File.WriteAllBytes(Path.Combine(worldDataPath, "map"), pngBytes);
} catch {
Debug.Log("FAILED TO WRITE MAP FILE!");
Debug.Log("WebMap: FAILED TO WRITE MAP FILE!");
}
Debug.Log("BUILDING MAP DONE!");
Debug.Log("WebMap: BUILDING MAP DONE!");
}
}

Expand Down Expand Up @@ -389,9 +389,7 @@ static void Prefix(RoutedRPCData data) {
}
}
//Debug.Log("SAY!!! " + messageType + " | " + userName + " | " + message);
} catch (Exception e) {
Debug.Log("Failed processing RoutedRPCData" + e);
}
} catch {}
} else if (data?.m_methodHash == chatMessageMethodHash) {
try {
ZPackage package = new ZPackage(data.m_parameters.GetArray());
Expand All @@ -405,9 +403,7 @@ static void Prefix(RoutedRPCData data) {
mapDataServer.BroadcastPing(data.m_senderPeerID, userName, pos);
}
// Debug.Log("CHAT!!! " + pos + " | " + messageType + " | " + userName + " | " + message);
} catch (Exception e) {
Debug.Log("Failed processing RoutedRPCData" + e);
}
} catch {}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion WebMap/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"save_fog_texture_interval": 30,

"// Should the server cache web files to be more performant? Default: true": 0,
"cache_server_files": false,
"cache_server_files": true,

"// How large is the map texture? Probably dont change this. Default: 2048": 0,
"texture_size": 2048,
Expand Down
24 changes: 13 additions & 11 deletions WebMap/web-src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,19 @@ const setup = async () => {
const lines = text.split('\n');
lines.forEach(line => {
const lineParts = line.split(',');
const pin = {
id: lineParts[1],
uid: lineParts[0],
type: lineParts[2],
name: lineParts[3],
x: lineParts[4],
z: lineParts[5],
text: lineParts[6],
static: true
};
map.addIcon(pin, false);
if (lineParts.length > 5) {
const pin = {
id: lineParts[1],
uid: lineParts[0],
type: lineParts[2],
name: lineParts[3],
x: lineParts[4],
z: lineParts[5],
text: lineParts[6],
static: true
};
map.addIcon(pin, false);
}
});
map.updateIcons();
});
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "WebMap",
"description": "testing...",
"website_url": "https://github.com/kylepaulsen/",
"description": "A Valheim dedicated server mod to host a web accessible map.",
"website_url": "https://github.com/kylepaulsen/ValheimWebMap",
"version_number": "1.0.0",
"dependencies": []
}
File renamed without changes.
4 changes: 2 additions & 2 deletions WebMap/package.json → package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "1.0.0",
"description": "A Valheim map viewer for the browser",
"scripts": {
"build": "webpack ./web-src/index.js -o ./web --mode development",
"build-prod": "webpack ./web-src/index.js -o ./web --mode production"
"build": "webpack ./WebMap/web-src/index.js -o ./WebMap/web --mode development",
"build-prod": "webpack ./WebMap/web-src/index.js -o ./WebMap/web --mode production"
},
"author": "Kyle Paulsen <[email protected]>",
"license": "ISC",
Expand Down
Binary file added thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dc13fac

Please sign in to comment.