public void AddGroup(string group) { SpreadGroup spreadGroup = new SpreadGroup(null, group); AddGroup(spreadGroup); }
// Puts a group name into an array of bytes. //////////////////////////////////////////// private static void toBytes(SpreadGroup group, byte[] buffer, int bufferIndex) { // Get the group's name. //////////////////////// byte[] name; try { name = System.Text.Encoding.ASCII.GetBytes(group.ToString()); } catch (Exception e) { // Already checked for this exception in connect. ///////////////////////////////////////////////// name = new byte[0]; Console.WriteLine(e); } // Put a cap on the length. /////////////////////////// int len = name.Length; if (len > MAX_GROUP_NAME) len = MAX_GROUP_NAME; // Copy the name into the buffer. ///////////////////////////////// System.Array.Copy(name, 0, buffer, bufferIndex, len); for (; len < MAX_GROUP_NAME; len++) buffer[bufferIndex + len] = 0; }
public void AddGroup(SpreadGroup group) { groups.Add(group); }
// Constructor. /////////////// internal MembershipInfo(SpreadConnection connection, SpreadMessage message, bool daemonEndianMismatch) { // Set local variables. /////////////////////// this.serviceType = message.ServiceType; this.group = message.Sender; this.members = message.Groups; // Is this a regular membership message. //////////////////////////////////////// if (IsRegularMembership) { // Extract the groupID. /////////////////////// int dataIndex = 0; int[] id = new int[3]; id[0] = SpreadConnection.toInt(message.Data, dataIndex); dataIndex += 4; id[1] = SpreadConnection.toInt(message.Data, dataIndex); dataIndex += 4; id[2] = SpreadConnection.toInt(message.Data, dataIndex); dataIndex += 4; // Endian-flip? /////////////// if (daemonEndianMismatch) { id[0] = SpreadConnection.flip(id[0]); id[1] = SpreadConnection.flip(id[1]); id[2] = SpreadConnection.flip(id[2]); } // Create the group ID. /////////////////////// this.groupID = new GroupID(id[0], id[1], id[2]); // Get the number of groups. //////////////////////////// int numGroups = SpreadConnection.toInt(message.Data, dataIndex); if (daemonEndianMismatch) { numGroups = SpreadConnection.flip(numGroups); } dataIndex += 4; // Get the groups. ////////////////// this.groups = new SpreadGroup[numGroups]; for (int i = 0; i < numGroups; i++) { this.groups[i] = connection.toGroup(message.Data, dataIndex); dataIndex += SpreadConnection.MAX_GROUP_NAME; } } }
// Get the private group name. ////////////////////////////// private void ReadGroup() { // Read the length. /////////////////// int len; try { len = stream.ReadByte(); } catch (Exception e) { throw new SpreadException("read(): " + e); } // Check for no more data. ////////////////////////// if (len == -1) { throw new SpreadException("Connection closed during connect attempt"); } // Read the name. ///////////////// byte[] buffer = new byte[len]; int numRead; try { numRead = stream.Read(buffer, 0, buffer.Length); } catch (Exception e) { throw new SpreadException("read(): " + e); } // Check for not enough data. ///////////////////////////// if (numRead != len) { throw new SpreadException("Connection closed during connect attempt"); } // Store the group. /////////////////// group = new SpreadGroup(this, System.Text.Encoding.ASCII.GetString(buffer, 0, buffer.Length)); }
private void button5_Click(object sender, EventArgs e) { SpreadGroup grp = new SpreadGroup(connection, comboBox1.Text); if (grp != null) { try { grp.Leave(); richTextBox1.AppendText("Left " + grp + "."); } catch (SpreadException se) { richTextBox1.AppendText("Not joined to this Group\n"); } } else { richTextBox1.AppendText("No group to leave."); } }
private void button2_Click(object sender, EventArgs e) { try { group = new SpreadGroup(); string grp = comboBox1.Text; group.Join(connection, grp); richTextBox1.AppendText("Joined " + group + "." + "\n"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }