public void Join(Player joining) { lock (Everyone) Everyone.Add(joining); throw new NotImplementedException(); }
public void Join(Player p) { lock (this) { var po = new BufferBlock<string>(); pmscp.Add(p, new MultiplayerScriptContextPlayer(p, po, OnJoin(p))); } }
public void Part(Player p) { lock (this) { playerToScriptInput[p].Complete(); playerToScriptInput.Remove(p); } }
public void Join(Player p) { lock (this) { var bb = new BufferBlock<string>(); playerToScriptInput.Add(p, bb); script(p, bb).Start(); } }
protected override async Task script(Player p, BufferBlock<string> input) { // todo: what happens if the player quits during chargen? do we get an exception? // todo: ignore input when not expecting it p.Tell(@"Welcome to Chargen. Your GUID is {0}.", p.Guid); var name = ""; while (name == "") { p.Tell("\nWhat is your name? >"); string s = (await input.ReceiveAsync()).Trim(); Action<string> e = (m => p.Tell(m, "'" + s + "'")); // TODO: check if name is already in use and the user would like to disambiguate? // One-character names are allowed if they're not some English alphabet character, basically. // Otherwise, names must be at least two characters after trimming. // The name must also contain at least one unicode 'letter'. if (s.Length < 1) e("{0} is too short. Please choose a name at least two characters in length."); else if (((s[0] >= 'a' && s[0] <= 'z') || (s[0] >= 'A' && s[0] <= 'Z')) && s.Length == 1) e("{0} is too short. Please choose a name at least two characters in length."); else if (s.Length > 16) e("That name's pretty long! Could you squeeze it down to no more than 16 characters?!"); else if (s.All(c => !Char.IsLetter(c))) e("{0} doesn't contain any letters. Chuck one in for us, would you?"); else if (s.Contains("'") || s.Contains('"') || s.EndsWith(".") || s.EndsWith(",") || s.EndsWith(";") || s.EndsWith(">")) e("{0} contains a ' or a \" or ends with a '.', ',', '>', or ';'. You can't do this - sorry. It'd make the game look odd."); else if ((s.Count(c => c == '(') != s.Count(c => c == ')')) || (s.Count(c => c == '[') != s.Count(c => c == ']')) || (s.Count(c => c == '{') != s.Count(c => c == '}')) || (s.Count(c => c == '<') != s.Count(c => c == '>'))) e("{0} contains mismatched brackets, a real pet hate of mine. Please make sure there's the same number of open as close brackets for each bracket type."); else { p.Tell("You entered your name as '{0}'. Is this the handle you wish to use? y/n >", s); string yn = (await input.ReceiveAsync()).Trim().ToLower(); if (yn.StartsWith("y") || new List<string> { "yes", "y", "yep", "you bet", "of course", "absolutely", "very yes", "very much so", "indubitably", "hell yes", "hell yeah", "yea", "ye" }.Contains(yn)) name = s; else p.Tell("Okay. Let's have another go."); } } p.Tell("That's all I needed to know. Let's begin!"); // actually set the properties p.Name = name; }
async Task playerScriptWrapper(Player player, BufferBlock<string> po, PlayerScript initialScript) { var csd = new Action<PlayerScript>(setNextScript); this.ContextPlayerData = new Dictionary<string, object>(); this.Player = player; this.PlayerOutput = po; this.nextScript = initialScript; while (true) { lock (this) if (nextScript != null) { playerScript = nextScript; nextScript = null; } else break; await nextScript(this, csd); } }
public void Parse(Player from, string message) { lock (this) pmscp[from].PlayerOutput.Post(message); }
public void Part(Player p) { lock (this) { pmscp[p].PlayerOutput.Complete(); pmscp.Remove(p); } }
protected abstract PlayerScript OnJoin(Player p);
internal MultiplayerScriptContextPlayer(Player player, BufferBlock<string> playerOutput, PlayerScript initialScript) { playerScriptWrapper(player, playerOutput, initialScript).Start(); }
// See CharGenContext for an example impl of this. protected abstract Task script(Player p, BufferBlock<string> input);
public void Parse(Player from, string message) { lock (this) playerToScriptInput[from].Post(message); }
internal virtual void OnPartScript(Player p) { }
internal abstract void OnJoinScript(Player p);
public void Part(Player parting) { throw new NotImplementedException(); }
public void Parse(Player from, string message) { throw new NotImplementedException(); }