Пример #1
0
        public void SendMessage(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                CallMessage("Fail. Message empty.", true);
            }

            else if (text.Length > _maxMessageLenght)
            {
                CallMessage("Fail. Message to big.", true);
            }

            else
            {
                var value = new ChatValue(_name, text);
                _network.Request(_owner, value, new ChatMessageCallbacks(this));
                string message = _name + ": " + text;
                CallMessage(message, false);
            }
        }
Пример #2
0
        public void Udpate()
        {
            _network.Update();
            while (_request.Count > 0)
            {
                var request  = _request.Dequeue();
                var value    = request.Item2 as ChatValue;
                var callback = request.Item3;
                var owner    = request.Item1;
                if (value == null)
                {
                    callback.Fail(_unknownFormat);
                    return;
                }

                if (string.IsNullOrEmpty(value.Message))
                {
                    callback.Fail(_toEmptyMessage);
                    return;
                }

                if (value.Message.Length > _maxLengthMessage)
                {
                    callback.Fail(_toBigChatMessage);
                    return;
                }

                string name = _clients[owner];
                foreach (var client in _clients)
                {
                    IOwner clientOwner = client.Key;
                    if (clientOwner != owner)
                    {
                        _network.Request(clientOwner, value, new ChatCallbacks(name, client.Value, value.Message));
                    }
                }
                callback.Ack(_ok);
            }
        }