Skip to content

Commit

Permalink
2025/1/14-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Lake1059 committed Jan 14, 2025
1 parent 5fc82dc commit 50edd1b
Show file tree
Hide file tree
Showing 55 changed files with 765 additions and 338 deletions.
Binary file removed ImaginWorld/DLC/FinalTown/Music/AdvantageIsMine.mp3
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/BookTower.mp3
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/EmptyCityEchoe.mp3
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/EmptySnowfield.mp3
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/Endding1.mp3
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/FantasyForest.mp3
Binary file not shown.
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/FrostWind.mp3
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/MidnightLight.mp3
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/OceanDrifting.mp3
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/PowerfulEnemy.mp3
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/ProsperousTown.mp3
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/QuickVictory.mp3
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/SilenceRain.mp3
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/StarlitFade.mp3
Binary file not shown.
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/TotalWar.mp3
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/UnderseaRuins.mp3
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/WanderingMusic.mp3
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/WarmHome.mp3
Binary file not shown.
Binary file removed ImaginWorld/DLC/FinalTown/Music/WhispersMist.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/一类星体.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/一触即发.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/全面战争.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/击破强敌.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/奇幻森林.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/巧克力糖.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/海洋漂流.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/温暖的家.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/温馨小镇.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/稳步推进.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/绝境遭遇.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/群星闪耀.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/胜券在握.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/荧光蘑菇.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/落日余晖.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/藏书高塔.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/虚空边缘.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/谜题玄机.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/谢幕.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/遗忘废墟.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/随风飘荡.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/雨滴淅沥.mp3
Binary file not shown.
Binary file added ImaginWorld/DLC/FinalTown/Music/霜冻寒风.mp3
Binary file not shown.
6 changes: 4 additions & 2 deletions ImaginWorld/多人游戏/客户端.vb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ Public Class 客户端
Public Shared Property 是否收到响应 As Boolean = False

Public Shared Sub 启动客户端(服务器IP As String, 服务器端口 As String)
是否正在运行 = True
是否收到响应 = False
UDP客户端 = New UdpClient()
服务器地址 = New IPEndPoint(IPAddress.Parse(服务器IP), 服务器端口)
取消令牌源 = New CancellationTokenSource()
监听任务 = Task.Run(AddressOf 监听消息, 取消令牌源.Token)
是否正在运行 = True
是否收到响应 = False
UDP客户端.Client.ReceiveTimeout = 10000
End Sub

Public Shared Sub 监听消息()
Expand All @@ -31,6 +32,7 @@ Public Class 客户端
DebugPrint(ex.Message, Color.Tomato)
End Try
End While
UI同步上下文.Post(Sub() DebugPrint("客户端消息处理线程已停止运行", Color.Tomato), Nothing)
End Sub

Public Shared Sub 发送消息(message As List(Of String))
Expand Down
44 changes: 34 additions & 10 deletions ImaginWorld/多人游戏/客户端的消息响应.vb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

Imports System.Net

Public Class 客户端的消息响应
Public Shared Property 消息字典 As New Dictionary(Of String, Action(Of List(Of String)))

Expand All @@ -9,6 +7,8 @@ Public Class 客户端的消息响应
消息字典.Add("iw_sever_message", AddressOf 收到弹出式消息)
消息字典.Add("iw_sever_playerlist", AddressOf 收到多人模式空位列表)
消息字典.Add("iw_sever_powerdown", AddressOf 收到服务器已停止运行)
消息字典.Add("iw_sever_remove", AddressOf 收到服务器移出此设备)
消息字典.Add("iw_sever_ban", AddressOf 收到服务器封禁此设备)

DebugPrint($"客户端消息响应初始化完成,共计 {消息字典.Count } 个消息处理方法", Color.CornflowerBlue)
End Sub
Expand All @@ -28,22 +28,46 @@ Public Class 客户端的消息响应
End Sub

Public Shared Sub 收到弹出式消息(消息 As List(Of String))
Dim a1 As New 多项单选对话框($"收到弹出式消息", {"OK"}, 消息.Last)
a1.ShowDialog(Form1)
UI同步上下文.Post(Sub()
Dim a1 As New 多项单选对话框($"收到弹出式消息", {"OK"}, 消息.Last)
a1.ShowDialog(Form1)
End Sub, Nothing)
End Sub

Public Shared Sub 收到多人模式空位列表(消息 As List(Of String))
客户端.是否收到响应 = True
Dim a1 As New 多项单选对话框($"收到了多人模式玩家空位信息", {"OK"}, "假设这里是那个界面,因为还没做所以先用这个对话框代替",, 500)
a1.ShowDialog(Form1)
UI同步上下文.Post(Sub()
Dim a1 As New 多项单选对话框($"连接成功,现在选择角色", {"OK"}, "因为还没做,所以先用这个对话框顶一下", 300, 500)
a1.ShowDialog(Form1)
界面控制.切换界面(界面控制.主界面图层.主层, New 界面主层_殖民地)
End Sub, Nothing)
End Sub

Public Shared Sub 收到服务器已停止运行(消息 As List(Of String))
客户端.停止客户端()
Dim a1 As New 多项单选对话框($"断开连接", {"OK"}, "服务器已停止运行,自动返回主菜单")
a1.ShowDialog(Form1)
Form1.重新创建句柄()
Form1.Invoke(Sub() 界面控制.切换界面(界面控制.主界面图层.主层, New 界面主层_主菜单))
UI同步上下文.Post(Sub()
Dim a1 As New 多项单选对话框($"自动断开连接", {"OK"}, "服务器已停止运行")
a1.ShowDialog(Form1)
Form1.释放所有资源回主菜单()
End Sub, Nothing)
End Sub

Public Shared Sub 收到服务器移出此设备(消息 As List(Of String))
客户端.停止客户端()
UI同步上下文.Post(Sub()
Dim a1 As New 多项单选对话框($"主动断开连接", {"OK"}, "你已被服务器移出")
a1.ShowDialog(Form1)
Form1.释放所有资源回主菜单()
End Sub, Nothing)
End Sub

Public Shared Sub 收到服务器封禁此设备(消息 As List(Of String))
客户端.停止客户端()
UI同步上下文.Post(Sub()
Dim a1 As New 多项单选对话框($"强制断开连接", {"OK"}, "你已被服务器封禁")
a1.ShowDialog(Form1)
Form1.释放所有资源回主菜单()
End Sub, Nothing)
End Sub

End Class
63 changes: 45 additions & 18 deletions ImaginWorld/多人游戏/服务器.vb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
Imports System.Net
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Imports System.Text.Json
Imports Microsoft.VisualBasic.FileIO.FileSystem

Public Class 服务器
Public Shared Property UDP广播 As UdpClient
Expand All @@ -22,9 +25,8 @@ Public Class 服务器
Public Shared Property 是否允许新地址加入 As Boolean = False
Public Shared Property 自动踢出延迟 As Integer = Integer.MaxValue
Public Shared Property 自动开始广播 As Boolean = False
Public Shared Property 是否启用广播 As Boolean = False
Public Shared Property 保留的客户端列表 As New List(Of IPEndPoint)
Public Shared Property 黑名单 As New List(Of IPEndPoint)
Public Shared Property 保留的客户端列表 As New List(Of String)
Public Shared Property 黑名单 As New List(Of String)
Public Shared Property 开放单人数据位 As Boolean = False

Public Shared Property 已发送字节 As Long = 0
Expand All @@ -43,7 +45,7 @@ Public Class 服务器
Public Property 心跳包接收时间 As Date = Nothing
Public Property 连续超时次数 As Integer = 0
Public Property 玩家对象名称 As String = ""
Public Property 玩家所在主场景 As String = "在选择玩家界面"
Public Property 玩家所在主场景 As String = "等待角色选择"
End Class

Enum 玩家权限类型
Expand All @@ -54,27 +56,32 @@ Public Class 服务器

Public Shared Sub 启动服务器()
Try
是否正在运行 = True
UDP广播 = New UdpClient()
取消广播任务令牌源 = New CancellationTokenSource()
If 自动开始广播 Then
取消广播任务令牌源 = New CancellationTokenSource()
广播任务 = Task.Run(AddressOf 广播服务器游戏信息, 取消广播任务令牌源.Token)
End If
取消令牌源 = New CancellationTokenSource()
广播任务 = Task.Run(AddressOf 广播服务器游戏信息, 取消广播任务令牌源.Token)
UDP服务器 = New UdpClient(服务器端口)
UDP服务器.Client.ReceiveTimeout = 10000
For i As Integer = 1 To 响应线程数量
Dim 响应任务 As Task = Task.Run(AddressOf 监听消息, 取消令牌源.Token)
响应任务列表.Add(响应任务)
Next
Dim 黑名单文件 = Path.Combine(Application.StartupPath, "PlayerData", "SeverBan.json")
If FileExists(黑名单文件) Then 黑名单 = JsonSerializer.Deserialize(Of List(Of String))(ReadAllText(黑名单文件))
已发送字节 = 0
已接收字节 = 0
已发送个数 = 0
已接收个数 = 0
最近处理时长.Clear()
Ping任务 = Task.Run(AddressOf 计算所有客户端的延迟并发送下一次Ping, 取消令牌源.Token)
是否正在运行 = True
DebugPrint($"服务器已经启动,地址:{获取本地IPv4()}:{服务器端口}", Color.YellowGreen)
DebugPrint($"服务器已在 {获取本地IPv4()}:{服务器端口} 上启动", Color.YellowGreen)
Form服务器.Show()
Catch ex As Exception
停止服务器()
DebugPrint(ex.Message, Color.Tomato,, True)
停止服务器()
End Try
End Sub

Expand All @@ -94,15 +101,14 @@ Public Class 服务器

Public Shared Sub 监听消息()
While 是否正在运行 AndAlso Not 取消令牌源.Token.IsCancellationRequested

Try
Dim 发送者地址 As New IPEndPoint(IPAddress.Any, 服务器端口)
Dim 数据_接收到的字节 As Byte() = UDP服务器.Receive(发送者地址)
If 数据_接收到的字节.Length = 0 Then Continue While
已接收字节 += 数据_接收到的字节.LongLength
已接收个数 += 1
SyncLock 黑名单
If 黑名单.Contains(发送者地址) Then
If 黑名单.Contains(发送者地址.Address.ToString) Then
发送消息(发送者地址, New List(Of String) From {"iw_sever_message", "你已被此服务器封禁"})
DebugPrint($"已拒绝黑名单 {发送者地址} 的请求", Color.YellowGreen)
Continue While
Expand All @@ -121,7 +127,7 @@ Public Class 服务器
End If
End If
Else
If Not 保留的客户端列表.Contains(发送者地址) Then
If Not 保留的客户端列表.Contains(发送者地址.Address.ToString) Then
发送消息(发送者地址, New List(Of String) From {"iw_sever_message", "此服务器已禁止新玩家加入,而您不在设备列表中,所以无法加入此服务器"})
DebugPrint($"已拒绝 {发送者地址} 的请求", Color.YellowGreen)
Continue While
Expand All @@ -140,10 +146,12 @@ Public Class 服务器
最近处理时长.Add(计时器.ElapsedMilliseconds)
If 最近处理时长.Count > 10 Then 最近处理时长.RemoveRange(0, 最近处理时长.Count - 10)
End SyncLock
Catch ex As SocketException When ex.SocketErrorCode = SocketError.TimedOut
Catch ex As Exception
DebugPrint(ex.Message, Color.Tomato)
End Try
End While
UI同步上下文.Post(Sub() DebugPrint("服务器消息处理线程已停止运行", Color.Tomato), Nothing)
End Sub

Public Shared Sub 发送消息(IP As IPEndPoint, message As List(Of String))
Expand All @@ -159,15 +167,21 @@ Public Class 服务器
End Try
End Sub

Shared ReadOnly 心跳包数据 As Byte() = Encoding.UTF8.GetBytes(String.Join("<iw_separator>", {"iw_sever_ping", ""}))
Shared ReadOnly 心跳包数据 As Byte() = Encoding.UTF8.GetBytes(String.Join("<iw_separator>", {"iw_sever_ping"}))

Public Shared Sub 计算所有客户端的延迟并发送下一次Ping()
While 是否正在运行 AndAlso Not 取消令牌源.Token.IsCancellationRequested

For Each 客户端信息 In 客户端列表
Dim 延迟 As Integer = (客户端信息.Value.心跳包接收时间 - 客户端信息.Value.心跳包发送时间).Milliseconds
客户端信息.Value.延迟 = 延迟
If 客户端信息.Value.延迟 > 自动踢出延迟 Then

If 延迟 < 0 Then
客户端信息.Value.延迟 = Integer.MaxValue
Else
客户端信息.Value.延迟 = 延迟
End If

If 客户端信息.Value.延迟 >= 自动踢出延迟 Then
客户端信息.Value.连续超时次数 += 1
If 客户端信息.Value.连续超时次数 >= 10 Then
客户端列表.Remove(客户端信息.Key)
Expand Down Expand Up @@ -204,8 +218,10 @@ Public Class 服务器
End Sub

Public Shared Async Sub 停止服务器()
DebugPrint("已开始进行服务器停止流程,网络上的任务可能不会立即停止", Color.Gold)
DebugPrint("请在再次启动服务器之前耐心等待其超时自动停止", Color.Gold)
是否正在运行 = False
广播全体消息(New List(Of String) From {"iw_sever_powerdown"})
Await Task.Run(Sub() 广播全体消息(New List(Of String) From {"iw_sever_powerdown"}))
If 取消广播任务令牌源 IsNot Nothing Then
取消广播任务令牌源.Cancel()
Await 广播任务
Expand All @@ -215,6 +231,10 @@ Public Class 服务器
End If
End If
UDP广播?.Close()
UDP广播?.Dispose()
UDP广播 = Nothing
广播任务 = Nothing

If 取消令牌源 IsNot Nothing Then
取消令牌源.Cancel()
Await Ping任务
Expand All @@ -225,11 +245,18 @@ Public Class 服务器
End If
End If
UDP服务器?.Close()
UDP服务器?.Dispose()
UDP服务器 = Nothing
Ping任务 = Nothing
响应任务列表.Clear()
客户端列表?.Clear()

Form服务器.Close()
GC.Collect()

Dim 黑名单文件 = Path.Combine(Application.StartupPath, "PlayerData", "SeverBan.json")
WriteAllText(黑名单文件, JsonSerializer.Serialize(黑名单, JSON序列化选项), False)
DebugPrint("服务器已停止", Color.Tomato)
GC.Collect()
End Sub

Public Shared Function 获取本地IPv4() As String
Expand Down
9 changes: 6 additions & 3 deletions ImaginWorld/底层调度/Module1.vb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ Imports Svg
Imports Microsoft.VisualBasic.FileIO.FileSystem
Imports System.IO
Imports Sunny.UI
Imports System.Threading

Module Module1

Public 控制台界面实例 As New 界面顶层_控制台

Public JSON序列化选项 As New JsonSerializerOptions With {.WriteIndented = True}

Public UI同步上下文 As SynchronizationContext = SynchronizationContext.Current


<Extension>
Public Sub DoubleBuffer(control As Control)
Dim propertyInfo As PropertyInfo = control.GetType().GetProperty("DoubleBuffered", BindingFlags.Instance Or BindingFlags.NonPublic)
Expand All @@ -28,16 +32,15 @@ Module Module1
If String.IsNullOrEmpty(文本) Then Exit Sub
If 时间戳 Then 文本 = $"{TimeString} " & 文本
Dim 文本长度 = Len(文本)
Form1.重新创建句柄()
Form1.Invoke(Sub()
UI同步上下文.Post(Sub()
控制台界面实例.RichTextBox1.AppendText(vbCrLf & 文本)
Dim 添加起始位 As Integer = 控制台界面实例.RichTextBox1.TextLength - 文本长度
控制台界面实例.RichTextBox1.Select(添加起始位, 文本长度)
控制台界面实例.RichTextBox1.SelectionColor = 颜色
控制台界面实例.RichTextBox1.Select(控制台界面实例.RichTextBox1.TextLength, 0)
控制台界面实例.RichTextBox1.ScrollToCaret()
If 强制切换到控制台 Then 界面控制.切换界面(界面控制.主界面图层.顶层, 控制台界面实例)
End Sub)
End Sub, Nothing)
End Sub

Public Function LaunchSvgToImage(SvgPath As String) As Image
Expand Down
14 changes: 14 additions & 0 deletions ImaginWorld/核心/游戏设置.vb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ Public Class 游戏设置
Public Property ColonyCalculationThreads As Integer = 1
Public Property WorldStateCalculationThreads As Integer = 1
Public Property RandomEventsTriggerCalculationThreads As Integer = 1
Public Property BattleModeSelection As Integer = 0

Public Property Sever_Port As String = ""
Public Property Sever_Name As String = ""
Public Property Sever_Description As String = ""
Public Property Sever_DefaultPermission As Integer = -1
Public Property Sever_MaxPing As Integer = -1
Public Property Sever_Broadcast As Integer = -1
Public Property Sever_AllowedConnection As Integer = -1
Public Property Sever_MessageProcessMultithread As Integer = -1
Public Property Sever_OpenSinglePlayerLocation As Integer = -1
Public Property ConnectSever_IP As String = ""
Public Property ConnectSever_Port As String = ""

End Class

Public Shared Sub 保存()
Expand Down
20 changes: 17 additions & 3 deletions ImaginWorld/界面/Form1.vb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Imports System.IO
Imports Microsoft.VisualBasic.FileIO.FileSystem
Imports System.ComponentModel
Imports System.ComponentModel

Public Class Form1
Protected Overrides Sub WndProc(ByRef m As Message)
Expand Down Expand Up @@ -80,4 +78,20 @@ Public Class Form1
全局键盘钩子.Unhook()
End
End Sub

Public Sub 释放所有资源回主菜单()
界面图层_主层?.Dispose()
界面图层_二层?.Dispose()
界面图层_三层?.Dispose()
If 界面图层_顶层 IsNot Nothing Then
If 界面图层_顶层.GetType = GetType(界面顶层_控制台) Then
控制台界面实例.UiButton关闭控制台.PerformClick()
Else
界面图层_顶层?.Dispose()
End If
End If
界面控制.切换界面(界面控制.主界面图层.主层, New 界面主层_主菜单)
End Sub


End Class
Loading

0 comments on commit 50edd1b

Please sign in to comment.