| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #if UNITY_WEBGL
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- namespace ET
- {
- public class WService : AService
- {
- private long idGenerater = 200000000;
- private readonly Dictionary<long, WChannel> channels = new Dictionary<long, WChannel>();
- public override void Dispose()
- {
- if (this.IsDisposed())
- {
- return;
- }
- this.Id = 0;
- foreach (var kv in this.channels.ToArray())
- {
- kv.Value.Dispose();
- }
- }
- public WService(IEnumerable<string> prefixs)
- {
- this.ServiceType = ServiceType.Outer;
- }
- public WService()
- {
- this.ServiceType = ServiceType.Outer;
- }
- private long GetId
- {
- get { return ++this.idGenerater; }
- }
- public override void Create(long id, IPEndPoint ipEndPoint, string address)
- {
- if (!this.channels.TryGetValue(id, out _))
- {
- WChannel channel = new WChannel(id, ipEndPoint, this, address);
- this.channels[channel.Id] = channel;
- }
- }
- public override void Remove(long id, int error = 0)
- {
- WChannel channel;
- if (!this.channels.TryGetValue(id, out channel))
- {
- return;
- }
- channel.Error = error;
- this.channels.Remove(id);
- channel.Dispose();
- }
- protected void Get(long id, IPEndPoint ipEndPoint)
- {
- // if (!this.channels.TryGetValue(id, out _))
- // {
- // this.Create(id, ipEndPoint);
- // }
- }
- public WChannel Get(long id)
- {
- WChannel channel = null;
- this.channels.TryGetValue(id, out channel);
- return channel;
- }
- public override void Send(long channelId, long actorId, MemoryStream stream)
- {
- this.channels.TryGetValue(channelId, out WChannel channel);
- if (channel == null)
- {
- return;
- }
- channel.Send(stream);
- }
- public override void Update()
- {
- }
- public override bool IsDisposed()
- {
- return this.Id == 0;
- }
- }
- }
- #endif
|