first commit
This commit is contained in:
commit
c08dad8d42
125
Program.cs
Normal file
125
Program.cs
Normal file
@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
class Player
|
||||
{
|
||||
public int Id;
|
||||
public int Row;
|
||||
public int Col;
|
||||
public ConsoleColor Color;
|
||||
public TcpClient Client;
|
||||
}
|
||||
|
||||
class Server
|
||||
{
|
||||
static int[,] maze = new int[,]
|
||||
{
|
||||
{ 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
|
||||
{ 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1 },
|
||||
{ 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1 },
|
||||
{ 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
|
||||
{ 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1 },
|
||||
{ 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1 },
|
||||
{ 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1 },
|
||||
{ 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1 },
|
||||
{ 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1 },
|
||||
{ 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
|
||||
{ 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
|
||||
};
|
||||
|
||||
static List<Player> players = new List<Player>();
|
||||
static Random rand = new Random();
|
||||
|
||||
static void Main()
|
||||
{
|
||||
TcpListener listener = new TcpListener(IPAddress.Any, 65500);
|
||||
listener.Start();
|
||||
Console.WriteLine("Server running...");
|
||||
|
||||
while (true)
|
||||
{
|
||||
TcpClient client = listener.AcceptTcpClient();
|
||||
Thread t = new Thread(() => HandleClient(client));
|
||||
t.Start();
|
||||
}
|
||||
}
|
||||
|
||||
static void HandleClient(TcpClient client)
|
||||
{
|
||||
Player player = new Player
|
||||
{
|
||||
Id = rand.Next(1000, 9999),
|
||||
Row = 1,
|
||||
Col = 5,
|
||||
Color = (ConsoleColor)rand.Next(1, 15),
|
||||
Client = client
|
||||
};
|
||||
lock (players) { players.Add(player); }
|
||||
|
||||
NetworkStream stream = client.GetStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
int read = stream.Read(buffer, 0, buffer.Length);
|
||||
if (read == 0) break;
|
||||
string move = Encoding.UTF8.GetString(buffer, 0, read);
|
||||
|
||||
int newRow = player.Row;
|
||||
int newCol = player.Col;
|
||||
if (move == "W") newRow--;
|
||||
if (move == "S") newRow++;
|
||||
if (move == "A") newCol--;
|
||||
if (move == "D") newCol++;
|
||||
|
||||
if (maze[newRow, newCol] != 1)
|
||||
{
|
||||
player.Row = newRow;
|
||||
player.Col = newCol;
|
||||
}
|
||||
|
||||
SendMapToAll();
|
||||
}
|
||||
catch { break; }
|
||||
}
|
||||
|
||||
lock (players) { players.Remove(player); }
|
||||
client.Close();
|
||||
}
|
||||
|
||||
static void SendMapToAll()
|
||||
{
|
||||
lock (players)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < maze.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < maze.GetLength(1); j++)
|
||||
{
|
||||
var playerHere = players.Find(p => p.Row == i && p.Col == j);
|
||||
if (playerHere != null)
|
||||
sb.Append("00");
|
||||
else if (maze[i, j] == 1)
|
||||
sb.Append("██");
|
||||
else if (maze[i, j] == 2)
|
||||
sb.Append("XX");
|
||||
else
|
||||
sb.Append(" ");
|
||||
}
|
||||
sb.AppendLine();
|
||||
}
|
||||
|
||||
byte[] data = Encoding.UTF8.GetBytes(sb.ToString());
|
||||
foreach (var p in players)
|
||||
{
|
||||
try { p.Client.GetStream().Write(data, 0, data.Length); } catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
bin/Debug/net8.0/server_labytint
Executable file
BIN
bin/Debug/net8.0/server_labytint
Executable file
Binary file not shown.
23
bin/Debug/net8.0/server_labytint.deps.json
Normal file
23
bin/Debug/net8.0/server_labytint.deps.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"runtimeTarget": {
|
||||
"name": ".NETCoreApp,Version=v8.0",
|
||||
"signature": ""
|
||||
},
|
||||
"compilationOptions": {},
|
||||
"targets": {
|
||||
".NETCoreApp,Version=v8.0": {
|
||||
"server_labytint/1.0.0": {
|
||||
"runtime": {
|
||||
"server_labytint.dll": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"server_labytint/1.0.0": {
|
||||
"type": "project",
|
||||
"serviceable": false,
|
||||
"sha512": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
bin/Debug/net8.0/server_labytint.dll
Normal file
BIN
bin/Debug/net8.0/server_labytint.dll
Normal file
Binary file not shown.
BIN
bin/Debug/net8.0/server_labytint.pdb
Normal file
BIN
bin/Debug/net8.0/server_labytint.pdb
Normal file
Binary file not shown.
12
bin/Debug/net8.0/server_labytint.runtimeconfig.json
Normal file
12
bin/Debug/net8.0/server_labytint.runtimeconfig.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"tfm": "net8.0",
|
||||
"framework": {
|
||||
"name": "Microsoft.NETCore.App",
|
||||
"version": "8.0.0"
|
||||
},
|
||||
"configProperties": {
|
||||
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
|
||||
BIN
obj/Debug/net8.0/apphost
Executable file
BIN
obj/Debug/net8.0/apphost
Executable file
Binary file not shown.
BIN
obj/Debug/net8.0/ref/server_labytint.dll
Normal file
BIN
obj/Debug/net8.0/ref/server_labytint.dll
Normal file
Binary file not shown.
BIN
obj/Debug/net8.0/refint/server_labytint.dll
Normal file
BIN
obj/Debug/net8.0/refint/server_labytint.dll
Normal file
Binary file not shown.
22
obj/Debug/net8.0/server_labytint.AssemblyInfo.cs
Normal file
22
obj/Debug/net8.0/server_labytint.AssemblyInfo.cs
Normal file
@ -0,0 +1,22 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("server_labytint")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("server_labytint")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("server_labytint")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
// Generated by the MSBuild WriteCodeFragment class.
|
||||
|
||||
@ -0,0 +1 @@
|
||||
1801560a49bd7289f28b578147fb98b059fb9237c25a461abb52cb8cdd09c5c1
|
||||
@ -0,0 +1,13 @@
|
||||
is_global = true
|
||||
build_property.TargetFramework = net8.0
|
||||
build_property.TargetPlatformMinVersion =
|
||||
build_property.UsingMicrosoftNETSdkWeb =
|
||||
build_property.ProjectTypeGuids =
|
||||
build_property.InvariantGlobalization =
|
||||
build_property.PlatformNeutralAssembly =
|
||||
build_property.EnforceExtendedAnalyzerRules =
|
||||
build_property._SupportedPlatformList = Linux,macOS,Windows
|
||||
build_property.RootNamespace = server_labytint
|
||||
build_property.ProjectDir = /home/twelve/Code/sharp/server_labytint/
|
||||
build_property.EnableComHosting =
|
||||
build_property.EnableGeneratedComInterfaceComImportInterop =
|
||||
8
obj/Debug/net8.0/server_labytint.GlobalUsings.g.cs
Normal file
8
obj/Debug/net8.0/server_labytint.GlobalUsings.g.cs
Normal file
@ -0,0 +1,8 @@
|
||||
// <auto-generated/>
|
||||
global using global::System;
|
||||
global using global::System.Collections.Generic;
|
||||
global using global::System.IO;
|
||||
global using global::System.Linq;
|
||||
global using global::System.Net.Http;
|
||||
global using global::System.Threading;
|
||||
global using global::System.Threading.Tasks;
|
||||
BIN
obj/Debug/net8.0/server_labytint.assets.cache
Normal file
BIN
obj/Debug/net8.0/server_labytint.assets.cache
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
||||
266ac63c091ce2746152dc20e12bf1ae87591659a897be89c831ee71b4829b90
|
||||
14
obj/Debug/net8.0/server_labytint.csproj.FileListAbsolute.txt
Normal file
14
obj/Debug/net8.0/server_labytint.csproj.FileListAbsolute.txt
Normal file
@ -0,0 +1,14 @@
|
||||
/home/twelve/Code/sharp/server_labytint/bin/Debug/net8.0/server_labytint
|
||||
/home/twelve/Code/sharp/server_labytint/bin/Debug/net8.0/server_labytint.deps.json
|
||||
/home/twelve/Code/sharp/server_labytint/bin/Debug/net8.0/server_labytint.runtimeconfig.json
|
||||
/home/twelve/Code/sharp/server_labytint/bin/Debug/net8.0/server_labytint.dll
|
||||
/home/twelve/Code/sharp/server_labytint/bin/Debug/net8.0/server_labytint.pdb
|
||||
/home/twelve/Code/sharp/server_labytint/obj/Debug/net8.0/server_labytint.GeneratedMSBuildEditorConfig.editorconfig
|
||||
/home/twelve/Code/sharp/server_labytint/obj/Debug/net8.0/server_labytint.AssemblyInfoInputs.cache
|
||||
/home/twelve/Code/sharp/server_labytint/obj/Debug/net8.0/server_labytint.AssemblyInfo.cs
|
||||
/home/twelve/Code/sharp/server_labytint/obj/Debug/net8.0/server_labytint.csproj.CoreCompileInputs.cache
|
||||
/home/twelve/Code/sharp/server_labytint/obj/Debug/net8.0/server_labytint.dll
|
||||
/home/twelve/Code/sharp/server_labytint/obj/Debug/net8.0/refint/server_labytint.dll
|
||||
/home/twelve/Code/sharp/server_labytint/obj/Debug/net8.0/server_labytint.pdb
|
||||
/home/twelve/Code/sharp/server_labytint/obj/Debug/net8.0/server_labytint.genruntimeconfig.cache
|
||||
/home/twelve/Code/sharp/server_labytint/obj/Debug/net8.0/ref/server_labytint.dll
|
||||
BIN
obj/Debug/net8.0/server_labytint.dll
Normal file
BIN
obj/Debug/net8.0/server_labytint.dll
Normal file
Binary file not shown.
1
obj/Debug/net8.0/server_labytint.genruntimeconfig.cache
Normal file
1
obj/Debug/net8.0/server_labytint.genruntimeconfig.cache
Normal file
@ -0,0 +1 @@
|
||||
298a3d36b4e168b9fc9928099d091a54ec114e7d2bf2583da2226bbc2afcaeb3
|
||||
BIN
obj/Debug/net8.0/server_labytint.pdb
Normal file
BIN
obj/Debug/net8.0/server_labytint.pdb
Normal file
Binary file not shown.
71
obj/project.assets.json
Normal file
71
obj/project.assets.json
Normal file
@ -0,0 +1,71 @@
|
||||
{
|
||||
"version": 3,
|
||||
"targets": {
|
||||
"net8.0": {}
|
||||
},
|
||||
"libraries": {},
|
||||
"projectFileDependencyGroups": {
|
||||
"net8.0": []
|
||||
},
|
||||
"packageFolders": {
|
||||
"/home/twelve/.nuget/packages/": {}
|
||||
},
|
||||
"project": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "/home/twelve/Code/sharp/server_labytint/server_labytint.csproj",
|
||||
"projectName": "server_labytint",
|
||||
"projectPath": "/home/twelve/Code/sharp/server_labytint/server_labytint.csproj",
|
||||
"packagesPath": "/home/twelve/.nuget/packages/",
|
||||
"outputPath": "/home/twelve/Code/sharp/server_labytint/obj/",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"/home/twelve/.nuget/NuGet/NuGet.Config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net8.0"
|
||||
],
|
||||
"sources": {
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
"net8.0": {
|
||||
"targetAlias": "net8.0",
|
||||
"projectReferences": {}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
"warnAsError": [
|
||||
"NU1605"
|
||||
]
|
||||
},
|
||||
"restoreAuditProperties": {
|
||||
"enableAudit": "true",
|
||||
"auditLevel": "low",
|
||||
"auditMode": "direct"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"net8.0": {
|
||||
"targetAlias": "net8.0",
|
||||
"imports": [
|
||||
"net461",
|
||||
"net462",
|
||||
"net47",
|
||||
"net471",
|
||||
"net472",
|
||||
"net48",
|
||||
"net481"
|
||||
],
|
||||
"assetTargetFallback": true,
|
||||
"warn": true,
|
||||
"frameworkReferences": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "/nix/store/xd9xy9mf4wmmlcdk51kzvsrnazqsajfz-dotnet-sdk-8.0.412/share/dotnet/sdk/8.0.412/PortableRuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
obj/project.nuget.cache
Normal file
8
obj/project.nuget.cache
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "c05mmQVMoyU=",
|
||||
"success": true,
|
||||
"projectFilePath": "/home/twelve/Code/sharp/server_labytint/server_labytint.csproj",
|
||||
"expectedPackageFiles": [],
|
||||
"logs": []
|
||||
}
|
||||
66
obj/server_labytint.csproj.nuget.dgspec.json
Normal file
66
obj/server_labytint.csproj.nuget.dgspec.json
Normal file
@ -0,0 +1,66 @@
|
||||
{
|
||||
"format": 1,
|
||||
"restore": {
|
||||
"/home/twelve/Code/sharp/server_labytint/server_labytint.csproj": {}
|
||||
},
|
||||
"projects": {
|
||||
"/home/twelve/Code/sharp/server_labytint/server_labytint.csproj": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "/home/twelve/Code/sharp/server_labytint/server_labytint.csproj",
|
||||
"projectName": "server_labytint",
|
||||
"projectPath": "/home/twelve/Code/sharp/server_labytint/server_labytint.csproj",
|
||||
"packagesPath": "/home/twelve/.nuget/packages/",
|
||||
"outputPath": "/home/twelve/Code/sharp/server_labytint/obj/",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"/home/twelve/.nuget/NuGet/NuGet.Config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
"net8.0"
|
||||
],
|
||||
"sources": {
|
||||
"https://api.nuget.org/v3/index.json": {}
|
||||
},
|
||||
"frameworks": {
|
||||
"net8.0": {
|
||||
"targetAlias": "net8.0",
|
||||
"projectReferences": {}
|
||||
}
|
||||
},
|
||||
"warningProperties": {
|
||||
"warnAsError": [
|
||||
"NU1605"
|
||||
]
|
||||
},
|
||||
"restoreAuditProperties": {
|
||||
"enableAudit": "true",
|
||||
"auditLevel": "low",
|
||||
"auditMode": "direct"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"net8.0": {
|
||||
"targetAlias": "net8.0",
|
||||
"imports": [
|
||||
"net461",
|
||||
"net462",
|
||||
"net47",
|
||||
"net471",
|
||||
"net472",
|
||||
"net48",
|
||||
"net481"
|
||||
],
|
||||
"assetTargetFallback": true,
|
||||
"warn": true,
|
||||
"frameworkReferences": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"privateAssets": "all"
|
||||
}
|
||||
},
|
||||
"runtimeIdentifierGraphPath": "/nix/store/xd9xy9mf4wmmlcdk51kzvsrnazqsajfz-dotnet-sdk-8.0.412/share/dotnet/sdk/8.0.412/PortableRuntimeIdentifierGraph.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
obj/server_labytint.csproj.nuget.g.props
Normal file
15
obj/server_labytint.csproj.nuget.g.props
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
|
||||
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
|
||||
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
|
||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/home/twelve/.nuget/packages/</NuGetPackageRoot>
|
||||
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/home/twelve/.nuget/packages/</NuGetPackageFolders>
|
||||
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.11.1</NuGetToolVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<SourceRoot Include="/home/twelve/.nuget/packages/" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
2
obj/server_labytint.csproj.nuget.g.targets
Normal file
2
obj/server_labytint.csproj.nuget.g.targets
Normal file
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
|
||||
10
server_labytint.csproj
Normal file
10
server_labytint.csproj
Normal file
@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
Loading…
Reference in New Issue
Block a user