-
Notifications
You must be signed in to change notification settings - Fork 0
/
NoSpec.cs
147 lines (121 loc) · 3.44 KB
/
NoSpec.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System.Collections.Generic;
using HOPEless.Bancho;
using HOPEless.Bancho.Objects;
using HOPEless.Extensions;
using HOPEless.osu;
using osu_HOPE.Plugin;
using osu.Shared;
using exys228.HopeCommands;
/*
* The main reason i created NoSpec is to show how HopeCommands works.
* Don't search for hidden meaning in this plugin.
*/
namespace Hope.Plugin.NoSpec
{
public class NoSpecPlugin : CommandBase, IHopePlugin
{
private bool Activated = true;
private string BeatmapHash = "ffffffffffffffffffffffffffffffff";
private string ActionText = "something"; // In user search menu: "Playing something"
private int BeatmapID = 0;
private Mods BeatmapMods = Mods.None;
private GameMode PlayMode = GameMode.Standard;
private const string PluginName = "NoSpec";
private const string ChannelName = "#nospec";
private int? UserID = null;
private Queue<BanchoPacket> ServerReplies = new Queue<BanchoPacket>();
public NoSpecPlugin() : base(PluginName, ChannelName)
{
}
public PluginMetadata GetMetadata()
{
return new PluginMetadata
{
Name = PluginName,
Author = "exys",
ShortDescription = "Fucks up activity data so no one can see what beatmap are you playing.",
Version = "1.0"
};
}
public void Load()
{
AddCommand("nsp", "turn NoSpec on/off", delegate (string[] args)
{
Activated ^= true;
SendPlayerMessage(PluginName, "Turned " + (Activated ? "on" : "off") + "!", ChannelName, UserID.Value);
});
/*
AddCommand("h", "set fake beatmap hash", delegate(string[] args)
{
if (args.Length < 1)
{
SendPlayerMessage(PluginName, "", ChannelName, UserID.Value); // todo: what even is that??
return;
}
});
*/
}
public override void OnBanchoRequest(ref List<BanchoPacket> plist)
{
base.OnBanchoRequest(ref plist);
for (int i = 0; i < plist.Count; i++)
{
switch (plist[i].Type)
{
case PacketType.ClientSpectateData:
{
if (Activated) plist.RemoveAt(i);
break;
}
case PacketType.ClientUserStatus:
{
if (!Activated) break;
BanchoUserStatus status = new BanchoUserStatus();
status.Populate(plist[i].Data);
if (status.Action == BanchoAction.Playing || status.Action == BanchoAction.Multiplaying)
{
status.BeatmapChecksum = BeatmapHash;
status.ActionText = ActionText;
status.CurrentMods = BeatmapMods;
status.BeatmapId = BeatmapID;
status.PlayMode = PlayMode;
plist[i].Data = status.Serialize();
}
break;
}
}
}
}
public override void OnBanchoResponse(ref List<BanchoPacket> plist)
{
base.OnBanchoResponse(ref plist);
for (int i = 0; i < plist.Count; i++)
{
switch (plist[i].Type)
{
case PacketType.ServerLoginReply:
{
BanchoInt userid = new BanchoInt(plist[i].Data);
if (userid.Value >= 0)
{
UserID = userid.Value;
SendPlayerMessage(PluginName, "Hey there, you're using NoSpec plugin! Enter !help to get list of available commands. Good luck :з", ChannelName, UserID.Value);
}
else UserID = null;
break;
}
}
}
if (ServerReplies.Count > 0)
plist.Add(ServerReplies.Dequeue());
}
private void SendPlayerMessage(string sender, string message, string channel, int senderid)
{
ServerReplies.Enqueue
(
new BanchoPacket(PacketType.ServerChatMessage,
new BanchoChatMessage(sender, message, channel, senderid))
);
}
}
}