1. C# / Говнокод #17186

    +134

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    public void OnKillEvent_ServerOnly(PhotonPlayer player)
        {
        case MatchTypeInfo.TDM:
    
                    if (player != null)
                    {
                        var hash = player.customProperties;
    
                        if (hash != null)
                        {
                            var team = (int) hash["team"];
    
                            var realScore = match.GetTeamScores();
    
                            var teamAScor = team == 0 ? realScore.x + TeamDeathScores : realScore.x;
                            var teamBScor = team == 1 ? realScore.y + TeamDeathScores : realScore.y;
    
                            //DebugModule("Kill Processed On Server completed: " + team + "// " + teamAScor + "/" + teamBScor);
    
                            match.ChangeTeamScores((int)teamAScor, (int)teamBScor);
                        }
                        else
                        {
                            Debug.LogError("OnKillEvent_ServerOnly ERROR Team hash");
                        }
                    }
    
                    break;
    }  {
    //через 500 строк кода
       private void LocalUpdate()
        { 
        if (Application.isEditor)
            {
                if (Input.GetKeyDown(KeyCode.Y))
                {
                    switch (MatchType)
                    {
    
                        case MatchTypeInfo.TDM:
                            ChangeTeamScores((int)(_teamScores.x - 1), (int)(_teamScores.y - 1), true);
                            break;   }
    
                    SendTeamScoresToUI();
                }
            }
    
       switch (MatchType)
            {
                case MatchTypeInfo.TDM:
                   // DebugModule("Load TDM type game");
                    break;
    }
    }
    //ещё 500 строк
     public void ChangeTeamScores(int a, int b, bool force = false)
        {
    
            if (PhotonNetwork.isMasterClient)
            {
                // check server rules
                var rules = GetGameRules();
                if (rules != null)
                {
                    if (!rules.CheckPlayerCountRules() && !force)
                    {
                        Debug.LogError("Game is not started, beacuse server has no players: " + rules.MinimumPlayerToPlay + "/" +
                                       PhotonNetwork.room.playerCount);
                        return;
                    }
                }
                else
                {
                    Debug.LogError("Rule error");
                    return;
                }
    
                _teamScores.x = Mathf.Clamp(a, 0, float.MaxValue);
                _teamScores.y = Mathf.Clamp(b, 0, float.MaxValue);
    
                var matchIsCompleted = false;
    
                switch (MatchType)
                {
                    case MatchTypeInfo.TDM:
                        matchIsCompleted = _teamScores.x <= 0 || _teamScores.y <= 0;
                        break;
                }
                   if (matchIsCompleted)
                {
                    Server_CallEndRound();
                }
                else
                {
                    // Call Event??
                  }
    }
    }

    Чтобы я ещё раз полез помогать инди-разработчикам, мать их за ногу.

    noshitleft, 26 Ноября 2014

    Комментарии (3)
  2. bash / Говнокод #17185

    −103

    1. 1
    2. 2
    3. 3
    if [ "valid" == "$x" ]; then
       echo "x has the value 'valid'"
    fi

    One last point (of style): <...> is better because it avoids the possibility of accidentally assigning the string "valid" to x.

    Йода-стайл теперь и в вашем баше.

    bormand, 26 Ноября 2014

    Комментарии (7)
  3. C# / Говнокод #17184

    +134

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    protected static DataTable[] ExecuteDataTablesReader(string ProcedureName, SqlParameter[] Params = null) {
    
                SqlConnection cnn = new SqlConnection(ConnectionString);
                SqlCommand cmd = new SqlCommand(ProcedureName, cnn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                if (Params != null && Params.Count() > 0) {
                    cmd.Parameters.AddRange(Params);
                }
                cnn.Open();
                
                IDataReader rd = cmd.ExecuteReader();
                List<DataTable> tables = new List<DataTable>();
                do {
                    DataTable dt = new DataTable();
                    dt.Load(rd);
                    tables.Add(dt);
                } while (rd.NextResult());
    
                return tables.ToArray();
    
            }

    может я чего не понимаю, но какого хера rd.NextResult() кидает мне exception, что ридер закрыт?

    Lokich, 26 Ноября 2014

    Комментарии (13)
  4. C# / Говнокод #17183

    +135

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    public void Login(ClientHandlers<int> actions)
            {
                var request = GetGetRequest("/user/xml/{0}", _login);
    
                var act = new Action<IRestResponse<GetUserInfoResult>>(response =>
                    {
                        if (CheckUserInfo(response))
                        {
                            throw new Exception("Невозможно получить информацию о пользователе\r\nНеобработанное исключение");
                        }
    
                        UserInfo = response.Data.UserInfo;
                        actions.Completed(UserInfo.idUser);
                    });
                _client.ExecuteAsync(request, act);
            }
    
            private bool CheckUserInfo(IRestResponse<GetUserInfoResult> response)
            {
                if (response != null && response.Data != null && response.Data.UserInfo != null && response.Data.UserInfo.idUser != 0)
                {
                    return true;
                }
    
                var message = "Невозможно получить информацию о пользователе";
                if (response == null)
                {
                    message = string.Format("{0}\r\n{1}", 
                                            message, 
                                            "Response is null");
                    throw new Exception(message);
                }
    
                message = string.Format("{0}\r\nResponse data is null\r\nContext: {1}", 
                                        message, 
                                        response.Content);
    
                if (response.Data == null)
                {
                    throw new Exception(message);
                }
    
                message = string.Format("{0}\r\nIs exception: {1}\r\nMessage: {2}", 
                                        message, 
                                        response.Data.IsException, 
                                        response.Data.Message);
    
                if (response.Data.UserInfo == null)
                {
                    throw new Exception(message);
                }
    
                message = string.Format("{0}\r\nSiteName: {1}\r\nUserName: {2}\r\nUserRole: {3}", 
                                        message, 
                                        response.Data.UserInfo.SiteName, 
                                        response.Data.UserInfo.UserName, 
                                        response.Data.UserInfo.UserRole);
                if (response.Data.UserInfo.idUser == 0)
                {
                    throw new Exception(message);
                }
    
                return false;
            }

    Внимательность, внимательность и еще раз внимательность...

    HellMaster_HaiL, 26 Ноября 2014

    Комментарии (3)
  5. Java / Говнокод #17180

    +71

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    public static void main(String[] args) {
    	Map<String, ClassLink<?>> children = new HashMap<String, ClassLink<?>>();
    	children.put("test1", new ClassLink<Dall>());
    	children.put("test2", new ClassLink<Son>());
    
    	String test = children.get("test1").classObjectGenerator().getName();
    	test.toString();
    
    }
    
    static class ClassLink<X extends ChildBase> {
    	public X classObjectGenerator() {
    		return (X) new Dall();
    	};
    }
    
    static class Dall implements ChildBase {
    	public String getName() {
    		return "Ivan";
    	}
    }
    
    static class Son implements ChildBase {
    	public String getName() {
    		return "Vera";
    	}
    }
    
    interface ChildBase {
    	String getName();
    }

    Фабрика. Загнать в map легковесный класс - создатель, а когда понадобится - создать объект.

    nick252, 26 Ноября 2014

    Комментарии (10)
  6. Си / Говнокод #17179

    +133

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    if (*wpPat == L'\\')
        {
          wpCharStart=wpPat;
          if (++wpPat >= wpMaxPat) goto Error;
    
          if (*wpPat == L'x')
          {
            if (++wpPat >= wpMaxPat) goto Error;
    
            if (*wpPat == L'{')
            {
              wpStrTmp=++wpPat;
              for (;;)
              {
                if (wpPat >= wpMaxPat) goto Error;
                if (*wpPat++ == L'}') break;
              }
              if (lpREGroupItem->nGroupLen != -1 && !bClassOpen)
              {
                nPatChar=(int)hex2decW(wpStrTmp, (wpPat - 1) - wpStrTmp);
                if (nPatChar == -1)
                {
                  wpPat=wpStrTmp;
                  goto Error;
                }
                if (nPatChar <= MAXWORD)
                  lpREGroupItem->nGroupLen+=1;
                else
                  lpREGroupItem->nGroupLen+=2;
              }
            }
            else
            {
              if (wpPat + 2 > wpMaxPat)
                goto Error;
              wpPat+=2;
              if (lpREGroupItem->nGroupLen != -1 && !bClassOpen)
                ++lpREGroupItem->nGroupLen;
            }
          }
          else if (*wpPat == L'u')
          {
            if (wpPat + 5 > wpMaxPat)
              goto Error;
            wpPat+=5;
            if (lpREGroupItem->nGroupLen != -1 && !bClassOpen)
              ++lpREGroupItem->nGroupLen;
          }

    Регулярные велосипеды.
    Akelpad.

    gost, 25 Ноября 2014

    Комментарии (1)
  7. Си / Говнокод #17178

    +133

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    if (wParam == MI_CMDLINEBEGIN)
              return xstrcpyW((void *)lParam, wpCmdLineBegin);
            if (wParam == MI_CMDLINEEND)
              return xstrcpyW((void *)lParam, wpCmdLineEnd);
            if (wParam == MI_SHOWMODIFY)
              return moCur.dwShowModify;
            if (wParam == MI_STATUSPOSTYPE)
              return moCur.dwStatusPosType;
            if (wParam == MI_STATUSUSERFORMAT)
              return xstrcpynW((void *)lParam, moCur.wszStatusUserFormat, MAX_PATH);
            if (wParam == MI_WORDBREAKCUSTOM)
              return moCur.dwWordBreakCustom;
            if (wParam == MI_PAINTOPTIONS)
              return moCur.dwPaintOptions;
            if (wParam == MI_EDITSTYLE)
              return moCur.dwEditStyle;
            if (wParam == MI_RICHEDITCLASS)
              return moCur.bRichEditClass;
            if (wParam == MI_AKELADMINRESIDENT)
              return moCur.bAkelAdminResident;
            if (wParam == MI_DATELOGFORMAT)
              return xstrcpynW((void *)lParam, moCur.wszDateLogFormat, 128);
            if (wParam == MI_DATEINSERTFORMAT)
              return xstrcpynW((void *)lParam, moCur.wszDateInsertFormat, 128);
            if (wParam == MI_AKELUPDATEROPTIONS)
              return xstrcpynW((void *)lParam, moCur.wszAkelUpdaterOptions, MAX_PATH);
            if (wParam == MI_URLCOMMAND)
              return xstrcpynW((void *)lParam, moCur.wszUrlCommand, MAX_PATH);
            if (wParam == MI_TABNAMEFIND)
              return xstrcpynW((void *)lParam, moCur.wszTabNameFind, MAX_PATH);
            if (wParam == MI_TABNAMEREP)
              return xstrcpynW((void *)lParam, moCur.wszTabNameRep, MAX_PATH);
            if (wParam == MI_ONTOP)
              return moCur.bOnTop;
            if (wParam == MI_STATUSBAR)
              return moCur.bStatusBar;
            if (wParam == MI_KEEPSPACE)
              return moCur.bKeepSpace;
            if (wParam == MI_WATCHFILE)
              return moCur.bWatchFile;
            if (wParam == MI_SAVETIME)
              return moCur.bSaveTime;
            if (wParam == MI_SINGLEOPENFILE)
              return moCur.bSingleOpenFile;
            if (wParam == MI_SINGLEOPENPROGRAM)
              return moCur.dwSingleOpenProgram;
            if (wParam == MI_TABOPTIONSMDI)
              return moCur.dwTabOptionsMDI;
            if (wParam == MI_EXECUTECOMMAND)

    И такого больше сотни строк.
    Akelpad.

    gost, 25 Ноября 2014

    Комментарии (14)
  8. Си / Говнокод #17177

    +132

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    LRESULT CALLBACK MainProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
      if (uMsg == WM_CREATE)
      {
        int *lpSBParts;
        int iBorders[3];
        CLIENTCREATESTRUCT ccs;
        DWORD dwClassStyle;
        RECT rcRect;
        HMENU hMenu;
    
        hMainWnd=hWnd;
        hPopupEdit=GetSubMenu(hPopupMenu, MENU_POPUP_EDIT);
        hPopupView=GetSubMenu(hPopupMenu, MENU_POPUP_VIEW);
        hPopupCodepage=GetSubMenu(hPopupMenu, MENU_POPUP_CODEPAGE);
        hPopupOpenCodepage=GetSubMenu(hPopupCodepage, MENU_POPUP_CODEPAGE_OPEN);
        hPopupSaveCodepage=GetSubMenu(hPopupCodepage, MENU_POPUP_CODEPAGE_SAVE);
        hPopupHeadline=GetSubMenu(hPopupMenu, MENU_POPUP_HEADLINE);
    
        hMenu=GetSubMenu(hMainMenu, MENU_FILE_POSITION);
        hMenuRecentFiles=GetSubMenu(hMenu, MENU_FILE_RECENTFILES_4X);
        hMenu=GetSubMenu(hMainMenu, MENU_VIEW_POSITION);
        hMenuLanguage=GetSubMenu(hMenu, MENU_VIEW_LANGUAGE_4X);

    Плотная простынка, спать можно.
    Akelpad.

    gost, 25 Ноября 2014

    Комментарии (0)
  9. C++ / Говнокод #17176

    +49

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    for (int i = 0; i <= 10000; i++)
    {
    if (a[i]=='a')
    a[i] == "000";
    continue;
    }

    Цикл, который в строке a меняет все символы 'a' на три ноля. Говнолабка одногруппницы.

    b2soft, 25 Ноября 2014

    Комментарии (28)
  10. Java / Говнокод #17175

    +72

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    private String shutdown = "SHUTDOWN";
    
    ........
    
    // Read a set of characters from the socket
    int expected = 1024; // Cut off to avoid DoS attack
    
    <--Зачем это тут?-->
    while (expected < shutdown.length()) {
        if (random == null)
            random = new Random();
        expected += (random.nextInt() % 1024);
    }
    
    
    while (expected > 0) {
        int ch = -1;
        try {
            ch = stream.read();
        } catch (IOException e) {
            log.warn("StandardServer.await: read: ", e);
            ch = -1;
        }
        if (ch < 32)  // Control character or EOF terminates loop
            break;
        command.append((char) ch);
        expected--;
    }

    Не понимаю зачем тут while. Авторы Apache Tomcat расскажите...

    mrFoxs, 25 Ноября 2014

    Комментарии (2)