public void SendMessage(string MessageHeader, IEnumerable <JsEncoder.IAbstractValue> Contents, bool SendImmediately) { AssertNotDisposed(); if (_ConnectionStatus == 1 || _ConnectionStatus == 2) { List <JsEncoder.IAbstractValue> ResponseArray = new List <JsEncoder.IAbstractValue>() { new JsEncoder.StringValue(MessageHeader) }; foreach (JsEncoder.IAbstractValue item in Contents) { ResponseArray.Add(item); } JsEncoder.TableValue ResponseTable = JsEncoder.TableValue.ArrayToTable(ResponseArray.ToArray()); if (SendImmediately) { JsEncoder.IAbstractValue[] Param1 = new JsEncoder.IAbstractValue[1]; Param1[0] = ResponseTable; Encoding_SendInput(Param1); } else { _MessageOutbox.Add(ResponseTable); } } }
public PeerMessage(JsEncoder.TableValue Table) { this.Table = Table; JsEncoder.StringValue headerV = (JsEncoder.StringValue)Table[1]; Header = headerV.Value; // First two values Contents1V = Table[2]; Contents2V = Table[3]; // Convert them to Strings JsEncoder.StringValue?contents1SV = Contents1V as JsEncoder.StringValue?; JsEncoder.StringValue?contents2SV = Contents2V as JsEncoder.StringValue?; Contents1S = contents1SV?.Value; Contents2S = contents2SV?.Value; }
public void SendGreeting() { if (_ConnectionStatus == 2 & !_GreetingSent) { JsEncoder.IAbstractValue[] Values = new JsEncoder.IAbstractValue[2]; Values[0] = new JsEncoder.StringValue(NetworkConfig.VersionString); Values[1] = new JsEncoder.StringValue(_ThisPeerID); SendMessage("GREETING", Values); _GreetingSent = true; } else { Log_Write_System("SendGreeting was called even though it's not necessary."); } }
public void BeginDisconnect(bool WarnOtherPeer = true) // Begins disconnecting from the other peer. { AssertNotDisposed(); if (_ConnectionStatus == 1) { Log_Write_System("Disconnecting..."); if (WarnOtherPeer) { JsEncoder.IAbstractValue[] Param2 = new JsEncoder.IAbstractValue[1]; Param2[0] = new JsEncoder.IntValue(0); SendMessage("DISCONNECTING", Param2, true); } ChangeConnectionStatusValue(3); } else { throw new Exception("Already disconnected!"); } }
public static UserHostList FromTable(JsEncoder.TableValue Value) { JsEncoder.TableValue ft = (JsEncoder.TableValue)Value[1]; JsEncoder.TableValue rt = (JsEncoder.TableValue)Value[2]; UserHostList r = new UserHostList(); for (int i = 1; ft.ContainsKey(i); i++) { JsEncoder.IAbstractValue item = ft[i]; JsEncoder.TableValue v = (JsEncoder.TableValue)item; r.FavoriteHosts.Add(HostInformation.FromTable(v)); } for (int i = 1; rt.ContainsKey(i); i++) { JsEncoder.IAbstractValue item = rt[i]; JsEncoder.TableValue v = (JsEncoder.TableValue)item; r.RecentHosts.Add(HostInformation.FromTable(v)); } return(r); }
public void SendMessage(string MessageHeader, string Contents) { JsEncoder.IAbstractValue[] NewArray = new JsEncoder.IAbstractValue[1]; NewArray[0] = new JsEncoder.StringValue(Contents); SendMessage(MessageHeader, NewArray); }