Skip to content

Commit

Permalink
2023.12.26
Browse files Browse the repository at this point in the history
  • Loading branch information
SheepYhangCN committed Dec 26, 2023
1 parent 00121a3 commit 8871e6b
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 17 deletions.
3 changes: 2 additions & 1 deletion AutoLoad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ public partial class AutoLoad : Node
internal string name="";
internal string ip="127.0.0.1";
internal int port=1145;
internal bool popup=false;
internal int popup=0;
internal bool is_connection_lost=false;
internal string version="v2023.12.26";
public override void _Ready()
{
}
Expand Down
61 changes: 55 additions & 6 deletions ChatRoom/ChatRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public override void _Ready()
{
Rpc("Joined",autoload.name,Multiplayer.MultiplayerPeer.GetUniqueId());
RpcId(MultiplayerPeer.TargetPeerServer,"SyncFromServer",Multiplayer.MultiplayerPeer.GetUniqueId());
/*if (OS.GetName()=="Windows" ||OS.GetName()=="macOS"||OS.GetName()=="Linux")
{
RpcId(MultiplayerPeer.TargetPeerServer,"Sha256Check",Multiplayer.MultiplayerPeer.GetUniqueId(),FileAccess.GetSha256(OS.GetExecutablePath()));
}*/
RpcId(MultiplayerPeer.TargetPeerServer,"VersionCheck",Multiplayer.MultiplayerPeer.GetUniqueId(),autoload.version);
}
SendSystemMessage(autoload.name+TranslationServer.Translate("locJoined"));
Rpc("SendSystemMessage",autoload.name+TranslationServer.Translate("locJoined"));
Expand Down Expand Up @@ -101,30 +106,30 @@ private async void disconnected()
{
GetNode<Button>("VBoxContainer/Title/Quit").Disabled=true;
await ToSignal(GetTree().CreateTimer(0.25), "timeout");
GetNode<AutoLoad>("/root/AutoLoad").popup=true;
GetNode<AutoLoad>("/root/AutoLoad").popup=1;
GetNode<AutoLoad>("/root/AutoLoad").is_connection_lost=true;
Multiplayer.MultiplayerPeer.Close();
Multiplayer.MultiplayerPeer=null;
GetTree().ChangeSceneToFile("res://Menu.tscn");
}
private void client_disconnected(long id)
{
var normal=true;
var normal=1;
var children=GetNode<VBoxContainer>("List/Panel/ScrollContainer/VBoxContainer").GetChildren();
for (var a=0;a<children.Count;a+=1)
{
if (children[a] is Members_Member && (int)children[a].Get("peer")==(int)id)
{
normal=false;
normal=0;
}
}
Rpc("ClientDisconnected",(int)id,member_list[(int)id],normal);
ClientDisconnected((int)id,member_list[(int)id],normal);
}
[Rpc(MultiplayerApi.RpcMode.AnyPeer)]
internal void ClientDisconnected(int id,string name,bool normal)
internal void ClientDisconnected(int id,string name,int normal)
{
SendSystemMessage(name+TranslationServer.Translate(normal ? "locQuitted" : "locLostConnection"));
SendSystemMessage(name+TranslationServer.Translate(normal==1 ? "locQuitted" : "locLostConnection"));
Quitted(id);
}
[Rpc(MultiplayerApi.RpcMode.AnyPeer)]
Expand Down Expand Up @@ -210,7 +215,7 @@ internal async void Removed()
await ToSignal(GetTree().CreateTimer(0.25), "timeout");
Multiplayer.MultiplayerPeer.Close();
Multiplayer.MultiplayerPeer=null;
GetNode<AutoLoad>("/root/AutoLoad").popup=true;
GetNode<AutoLoad>("/root/AutoLoad").popup=1;
GetTree().ChangeSceneToFile("res://Menu.tscn");
}
[Rpc(MultiplayerApi.RpcMode.AnyPeer)]
Expand All @@ -235,4 +240,48 @@ internal void SetMemberList(Dictionary<int,string> member_lista)
{
member_list=member_lista;
}
[Rpc(MultiplayerApi.RpcMode.AnyPeer)]
internal void Sha256Check(int peer,string sha256)
{
if (sha256 != FileAccess.GetSha256(OS.GetExecutablePath()))
{
RpcId(peer,"Sha256DoesntMatch");
}
}
[Rpc(MultiplayerApi.RpcMode.AnyPeer)]
internal async void Sha256DoesntMatch()
{
GetNode<Button>("VBoxContainer/Title/Quit").Disabled=true;
Rpc("Quitted",Multiplayer.MultiplayerPeer.GetUniqueId());
Quitted(Multiplayer.MultiplayerPeer.GetUniqueId());
SendSystemMessage(GetNode<AutoLoad>("/root/AutoLoad").name+TranslationServer.Translate("locWasRemoved"));
Rpc("SendSystemMessage",GetNode<AutoLoad>("/root/AutoLoad").name+TranslationServer.Translate("locWasRemoved"));
await ToSignal(GetTree().CreateTimer(0.25), "timeout");
Multiplayer.MultiplayerPeer.Close();
Multiplayer.MultiplayerPeer=null;
GetNode<AutoLoad>("/root/AutoLoad").popup=2;
GetTree().ChangeSceneToFile("res://Menu.tscn");
}
[Rpc(MultiplayerApi.RpcMode.AnyPeer)]
internal void VersionCheck(int peer,string version)
{
if (version != GetNode<AutoLoad>("/root/AutoLoad").version)
{
RpcId(peer,"VersionDoesntMatch");
}
}
[Rpc(MultiplayerApi.RpcMode.AnyPeer)]
internal async void VersionDoesntMatch()
{
GetNode<Button>("VBoxContainer/Title/Quit").Disabled=true;
Rpc("Quitted",Multiplayer.MultiplayerPeer.GetUniqueId());
Quitted(Multiplayer.MultiplayerPeer.GetUniqueId());
SendSystemMessage(GetNode<AutoLoad>("/root/AutoLoad").name+TranslationServer.Translate("locWasRemoved"));
Rpc("SendSystemMessage",GetNode<AutoLoad>("/root/AutoLoad").name+TranslationServer.Translate("locWasRemoved"));
await ToSignal(GetTree().CreateTimer(0.25), "timeout");
Multiplayer.MultiplayerPeer.Close();
Multiplayer.MultiplayerPeer=null;
GetNode<AutoLoad>("/root/AutoLoad").popup=3;
GetTree().ChangeSceneToFile("res://Menu.tscn");
}
}
2 changes: 1 addition & 1 deletion LocalChat.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Godot.NET.Sdk/4.2.0">
<Project Sdk="Godot.NET.Sdk/4.2.1">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
Expand Down
4 changes: 3 additions & 1 deletion Locale/Locale.csv
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ locCopy;Copy;复制;拷貝;コピー
locDelete;Delete;刪除;删除;削除
locRemoveMember;Remove;移出;移出;除去
locYouWasRemoved;You was removed from the\nChat Room by the Host;你被主机移出了聊天室;你被主機移出了聊天室;あなたは司会者にチャットルーム\nから除去されました
locConnectionLost;Connection Lost;连接已丢失;連線已丟失;接続が失われました
locConnectionLost;Connection Lost;连接已丢失;連線已丟失;接続が失われました
locSha256DoesntMatch;Sha256 doesn't match with Host\nMake sure you are using the\nsame version as Host;与主机的 Sha256 不匹配\n请确保你使用的是与主机相同的版本;與主機的 Sha256 不匹配\n請確保你是用的是與主機相同的版本;Sha256とホストの不一致\nホストと同じバージョンを使用していることを確認します
locVersionDoesntMatch;Version doesn't match with Host\nMake sure you are using the\nsame version as Host;与主机的版本号不匹配\n请确保你使用的是与主机相同的版本;與主機的版本號不匹配\n請確保你是用的是與主機相同的版本;バージョン番号の不一致\nホストと同じバージョンを使用していることを確認してく
Binary file modified Locale/Locale.en.translation
Binary file not shown.
Binary file modified Locale/Locale.ja.translation
Binary file not shown.
Binary file modified Locale/Locale.zh_CN.translation
Binary file not shown.
Binary file modified Locale/Locale.zh_TW.translation
Binary file not shown.
24 changes: 18 additions & 6 deletions Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,29 @@ public override void _Ready()
node.Selected=3;
break;
}
if (autoload.popup)
GetNode<Label>("Version").Text=autoload.version;
if (autoload.popup >= 1)
{
if (autoload.is_connection_lost)
if (autoload.popup == 1)
{
GetNode<Label>("Popup/PanelContainer/Label").Text="locConnectionLost";
if (autoload.is_connection_lost)
{
GetNode<Label>("Popup/PanelContainer/Label").Text="locConnectionLost";
}
else
{
GetNode<Label>("Popup/PanelContainer/Label").Text="locYouWasRemoved";
}
}
else
else if (autoload.popup == 2)
{
GetNode<Label>("Popup/PanelContainer/Label").Text="locYouWasRemoved";
GetNode<Label>("Popup/PanelContainer/Label").Text="locSha256DoesntMatch";
}
autoload.popup=false;
else if (autoload.popup == 3)
{
GetNode<Label>("Popup/PanelContainer/Label").Text="locVersionDoesntMatch";
}
autoload.popup=0;
autoload.is_connection_lost=false;
GetNode<Panel>("Popup").Visible=true;
}
Expand Down
12 changes: 12 additions & 0 deletions Menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ size_flags_vertical = 4
theme_override_font_sizes/font_size = 48
text = " OK "

[node name="Version" type="Label" parent="."]
layout_mode = 1
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_top = -32.0
offset_right = 144.0
grow_vertical = 0
theme = ExtResource("1_ord5l")
theme_override_font_sizes/font_size = 32
text = "v2024.1.1"

[connection signal="pressed" from="VBoxContainer/HBoxContainer/Create" to="." method="_on_create_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Join" to="." method="_on_join_pressed"]
[connection signal="item_selected" from="OptionButton" to="." method="_on_option_button_item_selected"]
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ I made this because i want to chat with my classmates in information technology
My teachers are really fond of unplugging the network cable between switcher and the router.

## Environment Dependence
Godot 4.2 Stable Mono Official<br>
Godot 4.2.1 Stable Mono Official<br>
.NET 8.0.100 (well actually, .net8 is not necessary, if you want to use other version of .net, just change the `TargetFramework` in `LocalChat.csproj`)

## Open-source License
MIT License

## To-do List
- [x] Enter to Send
- [x] Message Tim
- [x] Message Time
- [x] Localization
- [x] Sounds (From [Mixkit](https://mixkit.co))
- [x] Member List
- [x] Copy Message
- [x] Delete Message
- [x] Remove Member
- [x] Add Version Check
- [ ] Add Sha256 Check
- [ ] Sending Image
- [ ] ~~Sending Files~~ Use [LocalSend](https://localsend.org) instead

0 comments on commit 8871e6b

Please sign in to comment.