private void Form1_Load(object sender, EventArgs e) { try { // ServerDLL.TCPServer server = new ServerDLL.TCPServer(); // \\risinas\Temp\Greg // server = SeverFactory.GetServer(ServerType.TCPServer,"1234"); //server = SeverFactory.GetServer(ServerType.SyncFileServer , @"\\risinas\Temp\Greg"); server = new ParentServer(); server.StartDirectly(ServerDLL._ServerType.SyncFileServer, sharedPath); // server.StartDirectly(ServerDLL.ServerType.TCPServer, @"1020"); // server.StartWise("10.253.19.44"); ThreadStart st = new ThreadStart(HideWindow); Thread th = new Thread(st); th.Start(); } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(ex.StackTrace); Application.Exit(); } }
/// <summary> /// Create new empty request in list. /// </summary> public Request CreateNewRequest() { // Get max ID int _requestId = 1, _position = 1; // There are some members of request in list (get Max) if (Requests.Count > 0) { _requestId = Requests.Max(x => x.Id) + 1; _position = Requests.Max(x => x.Position) + 1; } // Create request Request ret = new Request(_requestId, _position, Director.Properties.Resources.NewRequestName) { ParentScenario = this, Url = ParentServer.GetUrl() }; // Copy Server Headers foreach (var h in ParentServer.DefaultHeaders) { ret.Headers.Add(new Header(h)); } // Add new request Requests.Add(ret); // Return request return(ret); }
public void Send() { if (ParentServer == null) { return; } if (mustSend)//only send a packet if we have data to send { lock (this) { IBitStream stream = BitStream.Create(); //create new bitstream stream.WriteBasicHeader(15, ConnectionId); //write packet type and client id stream.WriteExtendedHeader(ServerPacketId, ClientPacketId, (uint)v54); //write packet identifiers ServerPacketId++; var position = stream.GetPosition(); stream.SkipBits(16); stream.WriteBits(0, 1);//playeractionmanager if (GameEvents.Count > 0) { stream.WriteBits(1, 1); lock (GameEvents) { List <IGameEvent> events = new List <IGameEvent>(); for (int i = 4; i > 0; i--) { IGameEvent gameEvent; if (!GameEvents.TryDequeue(out gameEvent)) { break; } events.Add(gameEvent); } GameEventManager.Transmit(stream, events); } } else { stream.WriteBits(0, 1); } stream.WriteBits(0, 1);//ghostmanager var lastPosition = stream.GetPosition(); stream.SetPosition(position); stream.WriteBits(((uint)(lastPosition - 72) / 8), 16); stream.SetPosition(lastPosition); ParentServer.Send(stream.GetRawBuffer(), RemoteEndPoint); Console.WriteLine("[NetworkingClient - " + RemoteEndPoint.ToString() + "] sent packet type " + Convert.ToString(PacketType.Data)); mustSend = false; } } else { SendPingRequest(); } }
internal void RaiseMessageReceived(object message) { if (MesageReceived != null) { MesageReceived(this, message); } if (ParentServer != null) { ParentServer.RaiseMessageReceived(this, message); } }
public byte Login(string user, string pass) { var ret = ParentServer.Login(this, user, pass); if (ret == 0) { LoggedIn = true; } return(ret); }
public void Send(string hex) { lock (this) { IBitStream stream = new BitStream(DevelopmentHelper.ParseHexString(hex)); //create new bitstream stream.WriteBasicHeader(15, ConnectionId); //write packet type and client id stream.WriteExtendedHeader(ServerPacketId, ClientPacketId, (uint)v54); //write packet identifiers ServerPacketId++; ParentServer.Send(stream.GetRawBuffer(), RemoteEndPoint); Console.WriteLine("[NetworkingClient - " + RemoteEndPoint.ToString() + "] sent packet type " + Convert.ToString(PacketType.Data)); } }
public void SetField(int nMapId, byte nPortal, short nFh) { var newField = ParentServer.GetField(nMapId); if (newField != null) { var oldField = GetCharField(); oldField.Remove(this); Character.Stats.dwPosMap = nMapId; Character.Stats.nPortal = nPortal; Character.Position.Foothold = nFh; newField.Add(this); } }
public void SendPingResponse(uint token) { try { var buff = new byte[0xffff]; var stream = new BitStream(buff); stream.WriteBasicHeader((uint)PacketType.PingResponse, ConnectionId); stream.WriteExtendedHeader(ServerPacketId, ClientPacketId, (uint)v54); stream.WriteBits(0, 1); stream.WriteBits(token, 32); stream.WriteBits(0, 32);//some timestamp ParentServer.Send(stream.GetRawBuffer(), RemoteEndPoint); Console.WriteLine("[NetworkingClient - " + RemoteEndPoint.ToString() + "] sent packet type " + Convert.ToString(PacketType.PingResponse)); } catch (Exception) { } }
public void Close() { try { ConnectionSocket.Shutdown(SocketShutdown.Both); ConnectionSocket.Close(); if (ParentServer.WriteDebugLogs) { Logs.WriteLog("black", "Connection with index [{0}] closed.", cIndex); } ParentServer.CloseConnection(this); } catch (Exception Ex) { if (ParentServer.WriteDebugLogs) { Logs.WriteLog("red", Ex.Message); } } }
public CField GetCharField() => ParentServer.GetField(Character.Stats.dwPosMap);
public void Load(int charId) { Character = ParentServer.LoadCharacter(charId); LoggedIn = true; }